Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/essreduce/src/ess/reduce/nexus/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ class TransformationOverrides(
the overrides as well if the motor does not move all of those components.

Overrides only reach providers that use :class:`NeXusTransformationChain` or
:class:`NeXusMultiTransformationChain`. Providers that read from a component or
file directly keep using the stored value, e.g., for chopper positions, the
BIFROST sample angle, or the ESTIA detector rotation.
:class:`NeXusMultiTransformationChain`, which includes chopper positions.
Providers that read from a component or file directly keep using the stored
value, e.g., for the BIFROST sample angle or the ESTIA detector rotation.
"""


Expand Down
23 changes: 19 additions & 4 deletions packages/essreduce/src/ess/reduce/nexus/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,19 @@ def assemble_monitor_data(

def parse_raw_choppers(
choppers: NeXusMultiComponent[snx.NXdisk_chopper, RunType],
chains: NeXusMultiTransformationChain[snx.NXdisk_chopper, RunType],
) -> RawChoppers[RunType]:
"""Convert the NeXus representation of a chopper to ours.

Parameters
----------
choppers:
Loaded NeXus chopper groups.
chains:
Transformation chains of the choppers, with
:class:`ess.reduce.nexus.types.TransformationOverrides` applied.
They replace the chains stored in ``choppers``.

Returns
-------
:
Expand All @@ -722,10 +732,15 @@ def parse_raw_choppers(
:class:`ess.reduce.nexus.types.DiskChoppers`.
"""
return RawChoppers[RunType](
choppers.apply(
lambda chopper: extract_chopper_from_nexus(
nexus.compute_component_position(chopper)
)
sc.DataGroup(
{
name: extract_chopper_from_nexus(
nexus.compute_component_position(
sc.DataGroup({**chopper, 'depends_on': chains[name]})
)
)
for name, chopper in choppers.items()
}
)
)

Expand Down
18 changes: 18 additions & 0 deletions packages/essreduce/tests/nexus/workflow_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1467,3 +1467,21 @@ def overrides(
assert_identical(single.transformations[TRANS1].value, expected)
assert_identical(multi['a'].transformations[TRANS1].value, expected)
assert_identical(multi['b'].transformations[TRANS1].value, expected)


def test_transformation_overrides_apply_to_chopper_positions(
depends_on, time_dependent_depends_on
) -> None:
wf = GenericNeXusWorkflow(run_types=[SampleRun], monitor_types=[])
wf[workflow.NeXusMultiComponent[snx.NXdisk_chopper, SampleRun]] = sc.DataGroup(
a=sc.DataGroup(depends_on=depends_on),
b=sc.DataGroup(depends_on=time_dependent_depends_on),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure if I follow this here. time_dependent_depends_on() stacks trans1 (time-independent) on top of trans2 (time-dependent), so shouldn't the entire result be time dependent? In that case, seeing that we haven't explicitly selected a time coordinate, why would choppers['b']['position'] be a single vector instead of an array thereof?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Never mind, so I guess the point is that the time dependence in Transform.value has been overridden by our sc.scalar(5.0, unit='m') then? Hence we just get from trans2 Transform.value * Transform.vector = [0., 5., 0.], and that plus the [1., 0., 0.] from trans1.

)
wf[TransformationOverrides[snx.NXdisk_chopper, SampleRun]] = {
TRANS2: sc.scalar(5.0, unit='m')
}

choppers = wf.compute(RawChoppers[SampleRun])

assert_identical(choppers['a']['position'], sc.vector([1.0, 2.0, 3.0], unit='m'))
assert_identical(choppers['b']['position'], sc.vector([1.0, 5.0, 0.0], unit='m'))
Loading