Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mcstas instrument geometry in the loader. #18

Merged
merged 10 commits into from
Jan 10, 2024
Merged

Conversation

YooSunYoung
Copy link
Member

@YooSunYoung YooSunYoung commented Jan 9, 2024

Fixes #10

Continued from #15

Now all fields that could be derived from the geometry xml description are included as coordinates of the NMXData (the output type of the workflow.)

image

These coordinates cover most of the output fields that need to be saved as an intermediate result for #16

@YooSunYoung
Copy link
Member Author

YooSunYoung commented Jan 9, 2024

The instrument view is inserted as a code-snippet not as a cell.
It was because the output of the instrument view causes the error/warnings below
and the notebook is not linked to the index.html at the end, since it couldn't find the title...

ERROR: Line 404 exceeds the line-length-limit.
WARNING: Each notebook should have at least one section title

Here is the screen shot of the instrument view:

image

@YooSunYoung YooSunYoung marked this pull request as ready for review January 9, 2024 14:44
docs/examples/workflow.ipynb Outdated Show resolved Hide resolved
src/ess/nmx/rotation.py Outdated Show resolved Hide resolved
src/ess/nmx/rotation.py Outdated Show resolved Hide resolved
theta, x, y, z = find_attributes(
location, 'rot', 'axis-x', 'axis-y', 'axis-z'
).values()
q = axis_angle_to_quaternion(x, y, z, sc.scalar(-theta, unit=angle_unit))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using keyword args would avoid potential bugs in functions like this with many similar arguments.

Comment on lines 162 to 163
def _rotate_axis(matrix: sc.Variable, axis: sc.Variable) -> sc.Variable:
return sc.vector(np.round((matrix * axis).values, 2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do? Why are we rounding?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Justin said that's the precision that is needed so I kept it here.
Hmm... but I will remove rounding here so that it is handled in the next step if necessary.

src/ess/nmx/mcstas_xml.py Outdated Show resolved Hide resolved
src/ess/nmx/mcstas_xml.py Show resolved Hide resolved
Position of each pixel is relative to the position_offset.
"""
pixel_idx = sc.arange('id', detector.total_pixels)
n_row = sc.scalar(detector.num_fast_pixels_per_row)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this n_col?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah actually column is more correct.

'pixel_ids': _construct_pixel_ids(self.detectors),
'fast_axis': sc.concat(fast_axes, detector_dim),
'slow_axis': sc.concat(slow_axes, detector_dim),
'origin_position': sc.concat(origins, detector_dim),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the origin of each panel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is. The position of the first pixel (lowest pixel ID).
I couldn't come up with a better name...

src/ess/nmx/mcstas_xml.py Outdated Show resolved Hide resolved
Comment on lines 168 to 169
def _rotate_axis(matrix: sc.Variable, axis: sc.Variable) -> sc.Variable:
return matrix * axis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper seems pointless now, just inline the multiplication?

@YooSunYoung YooSunYoung merged commit 3b1c0de into main Jan 10, 2024
3 checks passed
@YooSunYoung YooSunYoung deleted the mcstas-instrument branch January 10, 2024 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Geometric information parsing (McStas loader mainly)
2 participants