Skip to content

[essreflectometry] Amor: read 2026 file layout and add direct-beam normalization - #895

Open
paracini wants to merge 4 commits into
scipp:mainfrom
paracini:amor-direct-beam-workflow
Open

paracini wants to merge 4 commits into
scipp:mainfrom
paracini:amor-direct-beam-workflow

Conversation

@paracini

Copy link
Copy Markdown
Contributor

Summary

ess.amor.AmorWorkflow now reads the files written by Amor since the 2026 change of the file layout, and can normalize by a measurement of the direct beam in addition to a supermirror:

AmorWorkflow(*, normalized_by: Literal['supermirror', 'direct_beam'] = 'supermirror')

The previous workflow is kept as AmorWorkflow2025. AmorWorkflow itself does not read the old layout any more.

Direct-beam normalization

normalized_by='direct_beam' follows the direct-beam normalization of the Amor reduction software eos (3.3.4):

  • Wavelength: the event time is shifted by the chopper trigger phase and by the chopper-opening correction of the pixel, and folded into the frame that starts at the lower edge of WavelengthBins.
  • Proton charge: the proton current at the start of each chopper revolution (taken from the beam-monitor time stamps, so revolutions without events count) times the duration of the revolution. Revolutions below ProtonCurrentThreshold are discarded together with their events. Sample and reference are divided by the integrated charge.
  • Reference: the direct beam is histogrammed over detector row and wavelength and mirrored along the scattering direction, since a reflection reverses the angular profile of the beam. The divergence limits are applied to the reference at the angles of the sample run.
  • Footprint: applied to the sample only. eos applies none; a large SampleSize[SampleRun] makes the correction equal to one.

The geometry, constants and gravity correction are those already in ess.amor, and Q is assigned to each sample event rather than to (wavelength, row) cells as in eos.

Changes

  • ess.amor.load: loaders for the 2026 layout (measurement_configuration/mu|nu, chopper group, proton current log, beam-monitor times).
  • ess.amor.conversions: new wavelength and coordinate graph; ChopperPhaseOffset replaces ChopperPhase in the new workflow.
  • ess.amor.corrections (new): per-revolution proton charge, masking of low-current revolutions, normalization by total charge.
  • ess.amor.normalization: provider sets for the supermirror and the direct-beam reference, inserted by AmorWorkflow.
  • ess.amor.legacy (new): the providers that are specific to the layout used until 2025, used by AmorWorkflow2025.
  • ess.reflectometry.workflow.with_filenames: also combines ProtonCharge and CoordTransformationGraph across runs, so that added runs give total counts over total charge and reference runs can be added too. This function is shared with the other instruments; the new entries are only evaluated if something downstream asks for them.
  • ess.reflectometry.gui: the Amor batch GUI uses AmorWorkflow2025, as it reads the old layout and is tested with old files.
  • Docs: new page user-guide/amor/amor-workflow.md; the existing Amor notebooks use AmorWorkflow2025.

Testing

  • No public example file exists in the 2026 layout, so the new tests (tests/amor/pipeline_test.py) write small synthetic files with h5py (tests/amor/conftest.py). They check the wavelength conversion against simulated event times, the proton charge and the low-current selection, the mirroring, the recovered reflectivity in both modes, adding runs, and the ORSO output. The docs page is not executed for the same reason.
  • The previous tests are unchanged apart from the workflow name and live in tests/amor/pipeline_2025_test.py.
  • On measurements of a Si/D2O interface at three angles from a recent Amor beamtime (not public), the integrated proton charge is identical to the eos monitor, and the error-weighted mean ratio of the reflectivity to eos is 0.995, 0.991 and 0.977. Against a cell-based re-implementation of eos that uses the ess.amor conventions it is 0.998, 1.000 and 1.001; the remaining difference to eos comes from the path length inside the detector ((nWires - 1 - wire) * dX here, wire * dX in eos, see the TODO in ess.amor.geometry).

Open points

  • The supermirror mode has only been run as a smoke test on the 2026 layout; I have no supermirror measurement in that layout.
  • A public example file in the 2026 layout would allow an executed notebook and tests on real data.
  • The first two commits add a stand-alone script under tools/ that the last commit removes again; squashing on merge leaves only the integration.

🤖 Generated with Claude Code

paracini and others added 4 commits November 19, 2026 17:31
Standalone validation script under essreflectometry/tools that follows the
eos 3.3.4 direct-beam algorithm with scipp, scippnexus and the ess.amor
detector geometry. Reproduces eos to better than 1e-7 in R, sigma R and
sigma Q on a 12-curve dataset. The README documents the algorithm, why
AmorWorkflow could not be used directly for 2026 files, and the effect of
the three convention differences between eos and ess.amor.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Step-by-step notebook in the style of the Amor user-guide notebooks,
stored without outputs, plus the script that generates it. amor_scipp.py
is split into named step functions (make_config, detector_image,
direct_beam_map, sample_map, lz_grid, project_to_q, reduce) so the
notebook can show each stage; results are unchanged and were re-checked
against eos 3.3.4 on the 12-curve dataset (largest difference 9.6e-8).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
AmorWorkflow now reads the files written by Amor since 2026 and takes
normalized_by='supermirror' (default) or 'direct_beam'. The direct-beam
mode follows the normalization of the Amor reduction software eos:
wavelength frame convention, selection of chopper revolutions by proton
current, normalization by integrated proton charge, mirrored direct beam.

The previous workflow is kept as AmorWorkflow2025 (ess.amor.legacy).
with_filenames also combines the proton charge and the coordinate
transformation graph, so sample and reference runs can both be added.

The stand-alone script in tools/amor-eos-direct-beam is removed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The docs and a docstring advised a large SampleSize[SampleRun] for direct
beams measured through a footprint-matched opening. The sample size also
enters the resolution in Q, which then becomes far too wide. A small
BeamSize[SampleRun] makes the correction equal to one without that side
effect. The tests now do the same and check the relative resolution.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@paracini

Copy link
Copy Markdown
Contributor Author

A design question on the footprint correction in direct-beam mode, for whoever reviews this.

The direct-beam mode applies the footprint correction to the sample run only. That is right when the direct beam was measured with the full beam. On Amor the direct beam is often measured through an opening that matches the footprint of the sample, and then the correction must not be applied at all.

As it stands, the only way to switch it off is to set BeamSize[SampleRun] to something much smaller than the sample, so that the correction evaluates to one (documented in 8717278). Making SampleSize[SampleRun] large does not work, because the sample size also enters the Q resolution. I got that wrong in the first version of the docs.

A tiny beam size is a workaround rather than an interface. Would you prefer an explicit switch? Two options I can see:

  • a parameter in the Amor workflow, e.g. FootprintCorrection: bool, read by the two sample-normalization providers, or
  • a keyword on AmorWorkflow, next to normalized_by, that selects providers with or without the correction.

I have not added either, since it touches how the other instruments might want to handle the same thing. Happy to implement whichever you prefer in this PR.

🤖 Generated with Claude Code

@jokasimr

jokasimr commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

About the footprint correction question. Is it really correct that the footprint correction should not be applied at all when the direct beam is measured through an opening that matches the footprint of the sample?

It seems to me that is only correct if the direct beam is measured at the same sample rotation as the sample measurement. Is that an assumption we should make?

If it isn't then we should apply the footprint correction to both measurements in that case. I think the interface should be that we add another option to the normalized_by argument. The third option is normalized_by='direct_beam_restricted_to_sample_footprint' or something similar but less verbose. Then we can change the workflow depending on that.

@jokasimr jokasimr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good overall 👍 I've some questions about details, and if there are no blockers I'd like to see some changes to the structure that I have specified more in the comments.

@@ -0,0 +1,145 @@
# Reduction of current Amor files

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just " Amor data reduction" is a better title.

return out.to(unit='angstrom', copy=False)
frame_start = wavelength_min * time_per_wavelength
time_of_flight = (time_of_flight - frame_start) % half_period + frame_start
return (time_of_flight / time_per_wavelength).to(unit='angstrom', copy=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should try to do inplace operations where we can to avoid allocations and save memory.

sc.scalar(np.nan, unit=unit),
),
'''
Wavelength of the neutrons from their arrival time at the detector.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like the procedure here changed since it now uses a wavelength_min argument. Was this procedure taken from the eos software? It seems like it would be preferable to calculate the wavelength from the chopper parameters and the geometry only without the user defined wavelength_min parameter, because it's unclear what it should be set to.

"chopper_frequency": lambda: chopper_frequency,
"chopper_separation": lambda: chopper_separation,
"chopper_distance": lambda: chopper_distance,
"wavelength_min": lambda: wavelength_bins[0],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See comment above questioning the introduction of the extra parameter.

pulse_times: PulseTimes[RunType],
chopper_frequency: ChopperFrequency[RunType],
threshold: ProtonCurrentThreshold,
) -> ProtonCharge[RunType]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this function used anywhere? It seems like the "charge is too low" mask is duplicated in this function and in the masking function. Maybe this function can be removed?

The correction is equal to one if ``BeamSize[SampleRun]`` is much smaller
than the sample. Use that, and not a large ``SampleSize[SampleRun]``, for a
direct beam that was measured through an opening that matches the footprint
of the sample: the size of the sample also enters the resolution in

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This documentation should probably be removed once we have fixed the footprint correction issue mentioned in the comment above.

# The divergence limits select a part of the reflected beam.
# The matching part of the direct beam is selected after mirroring,
# in evaluate_direct_beam_at_sample_coords.
reference = reference.bins.drop_masks('divergence_too_large')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer that the divergence angle computation is changed for the direct beam reference measurement by changing the coordinate transformation graph for the reference (there are similar examples in other instrument packages) instead of computed the same for both sample and reference and then dropped here. That would also allow us to avoid re-computing the mask in evaluate_direct_beam_at_sample_coords.

This branch has not been deployed

No deployments
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.

2 participants