diff --git a/packages/essspectroscopy/src/ess/bifrost/data.py b/packages/essspectroscopy/src/ess/bifrost/data.py index 9e8f0f356..8e8fe1128 100644 --- a/packages/essspectroscopy/src/ess/bifrost/data.py +++ b/packages/essspectroscopy/src/ess/bifrost/data.py @@ -11,13 +11,13 @@ 'ess/bifrost', files={ "bifrost_260526T151446.repack.h5": "md5:0f60f5938b0dce87542dd525a2f9a5c4", - "computed_energy_data_simulated_5x2.h5": "md5:6fee639c3c05523dfa18262cf2b03958", + "computed_energy_data_simulated_5x2.h5": "md5:eca18246329f8e6c05154323f7af677a", "BIFROST-simulation-lookup-table.h5": "md5:0a4df8039b9610df80fb7bd567736eeb", "coda_bifrost_999999_00026862.stripped.hdf": ( "md5:bab18faa48de3b4617332a24dacd58a2" ), }, - version="10", + version="11", ) diff --git a/packages/essspectroscopy/src/ess/bifrost/detector.py b/packages/essspectroscopy/src/ess/bifrost/detector.py index a35c32ad5..13424addf 100644 --- a/packages/essspectroscopy/src/ess/bifrost/detector.py +++ b/packages/essspectroscopy/src/ess/bifrost/detector.py @@ -192,6 +192,18 @@ def _fold_detector_to_arc_and_channel( folded.coords['channel'] = sc.array( dims=['channel'], values=channels[:n_channels], unit=None ) + + # Transpose to make `detector_number` contiguous: + detector_dims = ['arc', 'tube', 'channel', 'length'] + target_dims = [ + *(d for d in folded.dims if d not in detector_dims), + *detector_dims, + ] + folded = folded.transpose(target_dims).copy() + for name, coord in folded.coords.items(): + folded.coords[name] = coord.transpose( + [d for d in target_dims if d in coord.dims] + ).copy() return folded else: # Not a rectangular subset, cannot fold. diff --git a/packages/essspectroscopy/tests/bifrost/workflow_test.py b/packages/essspectroscopy/tests/bifrost/workflow_test.py index f227516d8..8975f38d6 100644 --- a/packages/essspectroscopy/tests/bifrost/workflow_test.py +++ b/packages/essspectroscopy/tests/bifrost/workflow_test.py @@ -20,6 +20,7 @@ Analyzers, DataAtSample, ElasticMonitor, + EmptyDetector, EnergyQDetector, Filename, LookupTableFilename, @@ -212,6 +213,21 @@ def test_simulation_workflow_produces_the_same_data_as_before( ) +def test_calibrated_detector_has_contiguous_detector_number() -> None: + # This test requires all detector pixels. + # (the `workflow` fixture only uses the first 10.) + workflow = bifrost.BifrostSimulationWorkflow() + workflow[Filename[SampleRun]] = simulated_elastic_incoherent_with_phonon() + + detector = workflow.compute(EmptyDetector[SampleRun]) + detector_number = detector.coords['detector_number'] + # Both the memory layout and the actual values should be contiguous + assert detector_number.values.flags['C_CONTIGUOUS'] + + flat = detector_number.flatten(to='x') + sc.testing.assert_identical(flat, sc.arange('x', 1, 1 + len(flat), unit=None)) + + @pytest.fixture def coda_workflow(detector_names: list[str]) -> sciline.Pipeline: workflow = bifrost.BifrostWorkflow()