Repository navigation
Conversation
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>
|
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 A tiny beam size is a workaround rather than an interface. Would you prefer an explicit switch? Two options I can see:
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 |
|
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 |
jokasimr
left a comment
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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], |
There was a problem hiding this comment.
See comment above questioning the introduction of the extra parameter.
| pulse_times: PulseTimes[RunType], | ||
| chopper_frequency: ChopperFrequency[RunType], | ||
| threshold: ProtonCurrentThreshold, | ||
| ) -> ProtonCharge[RunType]: |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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.
Summary
ess.amor.AmorWorkflownow 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:The previous workflow is kept as
AmorWorkflow2025.AmorWorkflowitself does not read the old layout any more.Direct-beam normalization
normalized_by='direct_beam'follows the direct-beam normalization of the Amor reduction softwareeos(3.3.4):WavelengthBins.ProtonCurrentThresholdare discarded together with their events. Sample and reference are divided by the integrated charge.eosapplies none; a largeSampleSize[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 ineos.Changes
ess.amor.load: loaders for the 2026 layout (measurement_configuration/mu|nu, chopper group, proton current log, beam-monitor times).ess.amor.conversions: newwavelengthand coordinate graph;ChopperPhaseOffsetreplacesChopperPhasein 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 byAmorWorkflow.ess.amor.legacy(new): the providers that are specific to the layout used until 2025, used byAmorWorkflow2025.ess.reflectometry.workflow.with_filenames: also combinesProtonChargeandCoordTransformationGraphacross 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 usesAmorWorkflow2025, as it reads the old layout and is tested with old files.user-guide/amor/amor-workflow.md; the existing Amor notebooks useAmorWorkflow2025.Testing
tests/amor/pipeline_test.py) write small synthetic files withh5py(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.tests/amor/pipeline_2025_test.py.eosmonitor, and the error-weighted mean ratio of the reflectivity toeosis 0.995, 0.991 and 0.977. Against a cell-based re-implementation ofeosthat uses theess.amorconventions it is 0.998, 1.000 and 1.001; the remaining difference toeoscomes from the path length inside the detector ((nWires - 1 - wire) * dXhere,wire * dXineos, see the TODO iness.amor.geometry).Open points
tools/that the last commit removes again; squashing on merge leaves only the integration.🤖 Generated with Claude Code