From 496ec2354762dfd3180b2c0a5dd3b06b651cbb91 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Wynen Date: Tue, 21 Jan 2025 16:24:38 +0100 Subject: [PATCH 1/3] Use scn.Measurement instead of separate variables --- src/ess/isissans/general.py | 20 ++++++++------------ src/ess/sans/io.py | 10 +++++----- src/ess/sans/types.py | 7 ++----- tests/io_test.py | 14 +++++++------- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/ess/isissans/general.py b/src/ess/isissans/general.py index 05403efd..a2e6e57c 100644 --- a/src/ess/isissans/general.py +++ b/src/ess/isissans/general.py @@ -20,14 +20,13 @@ DetectorPixelShape, DetectorPositionOffset, Incident, + Measurement, MonitorData, MonitorPositionOffset, MonitorType, NeXusComponent, NeXusMonitorName, NonBackgroundWavelengthRange, - RunNumber, - RunTitle, RunType, SampleRun, ScatteringRunType, @@ -174,14 +173,12 @@ def monitor_to_tof( return TofMonitor[RunType, MonitorType](da) -def run_number(dg: LoadedFileContents[SampleRun]) -> RunNumber: - """Get the run number from the raw sample data.""" - return RunNumber(int(dg['run_number'])) - - -def run_title(dg: LoadedFileContents[SampleRun]) -> RunTitle: - """Get the run title from the raw sample data.""" - return RunTitle(dg['run_title'].value) +def experiment_metadata(dg: LoadedFileContents[SampleRun]) -> Measurement: + """Get experiment metadata from the raw sample data.""" + return Measurement( + title=dg['run_title'].value, + run_number=dg['run_number'], + ) def helium3_tube_detector_pixel_shape() -> DetectorPixelShape[ScatteringRunType]: @@ -235,6 +232,7 @@ def get_detector_ids_from_sample_run(data: TofData[SampleRun]) -> DetectorIDs: providers = ( dummy_assemble_detector_data, dummy_assemble_monitor_data, + experiment_metadata, to_detector_position_offset, to_monitor_position_offset, get_source_position, @@ -245,8 +243,6 @@ def get_detector_ids_from_sample_run(data: TofData[SampleRun]) -> DetectorIDs: get_monitor_data, data_to_tof, monitor_to_tof, - run_number, - run_title, lab_frame_transform, helium3_tube_detector_pixel_shape, ) diff --git a/src/ess/sans/io.py b/src/ess/sans/io.py index 1dd6d5fc..472fc625 100644 --- a/src/ess/sans/io.py +++ b/src/ess/sans/io.py @@ -8,10 +8,9 @@ from .types import ( BackgroundSubtractedIofQ, MaskedDetectorIDs, + Measurement, OutFilename, PixelMaskFilename, - RunNumber, - RunTitle, ) @@ -19,8 +18,7 @@ def save_background_subtracted_iofq( *, iofq: BackgroundSubtractedIofQ, out_filename: OutFilename, - run_number: RunNumber, - run_title: RunTitle, + measurement: Measurement, ) -> None: """Save background-subtracted I(Q) histogram as an NXcanSAS file.""" if iofq.bins is None: @@ -30,7 +28,9 @@ def save_background_subtracted_iofq( if da.coords.is_edges('Q'): da.coords['Q'] = sc.midpoints(da.coords['Q']) with snx.File(out_filename, 'w') as f: - f['sasentry'] = nxcansas.SASentry(title=run_title, run=run_number) + f['sasentry'] = nxcansas.SASentry( + title=measurement.title, run=measurement.run_number_maybe_int + ) f['sasentry']['sasdata'] = nxcansas.SASdata(da, Q_variances='resolutions') diff --git a/src/ess/sans/types.py b/src/ess/sans/types.py index a7322b4f..4d80ea09 100644 --- a/src/ess/sans/types.py +++ b/src/ess/sans/types.py @@ -285,8 +285,5 @@ class CleanMonitor( # 4 Metadata -RunTitle = NewType('RunTitle', str) -"""Title of the run.""" - -RunNumber = NewType('RunNumber', int) -"""Run number.""" +Beamline = reduce_t.Beamline +Measurement = reduce_t.Measurement diff --git a/tests/io_test.py b/tests/io_test.py index 014a4be7..9b66a976 100644 --- a/tests/io_test.py +++ b/tests/io_test.py @@ -9,7 +9,7 @@ from scippnexus.application_definitions import nxcansas from ess.sans.io import save_background_subtracted_iofq -from ess.sans.types import BackgroundSubtractedIofQ, OutFilename, RunNumber, RunTitle +from ess.sans.types import BackgroundSubtractedIofQ, Measurement, OutFilename @pytest.mark.parametrize('use_edges', [True, False]) @@ -26,15 +26,15 @@ def background_subtracted_iofq() -> BackgroundSubtractedIofQ: ) ) - def run_number() -> RunNumber: - return RunNumber(7419) - - def run_title() -> RunTitle: - return RunTitle('Test-title') + def experiment_metadata() -> Measurement: + return Measurement( + title='Test-title', + run_number='7419', + ) out_filename = tmp_path / 'test.nxs' - providers = (background_subtracted_iofq, run_number, run_title) + providers = (background_subtracted_iofq, experiment_metadata) params = {OutFilename: str(out_filename)} pipeline = sciline.Pipeline(providers=providers, params=params) pipeline.bind_and_call(save_background_subtracted_iofq) From 58fccfc1ee2cecd018d762b20bb6c2c1bf226925 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Wynen Date: Thu, 20 Feb 2025 13:30:06 +0100 Subject: [PATCH 2/3] Require new ScippNeutron and ESSreduce Needed for metadata utils. --- pyproject.toml | 4 ++-- requirements/base.in | 4 ++-- requirements/base.txt | 35 +++++++++++++++++++++++++++-------- requirements/basetest.txt | 4 ++-- requirements/dev.txt | 8 +------- requirements/docs.txt | 8 ++------ requirements/nightly.txt | 8 ++++---- 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 617bcb7e..69a98f60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,14 +33,14 @@ requires-python = ">=3.10" dependencies = [ "dask", "graphviz", - "essreduce>=24.11.3", + "essreduce>=25.02.4", "numpy", "pandas", "plopp", "pythreejs", "sciline>=24.06.2", "scipp>=24.09.1", # Fixed new hist/bin API - "scippneutron>=24.06.0", + "scippneutron>=25.02.0", "scippnexus>=23.12.1", # 23.12.0 and below deadlock in threaded use ] diff --git a/requirements/base.in b/requirements/base.in index dc371692..81f129c0 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -4,12 +4,12 @@ # The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY! dask graphviz -essreduce>=24.11.3 +essreduce>=25.02.4 numpy pandas plopp pythreejs sciline>=24.06.2 scipp>=24.09.1 -scippneutron>=24.06.0 +scippneutron>=25.02.0 scippnexus>=23.12.1 diff --git a/requirements/base.txt b/requirements/base.txt index 41f5d065..07c847d9 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,10 +1,12 @@ -# SHA1:71fbc763453db59fbe23acb0df92531c0434f7ef +# SHA1:0ba7285c8699fdf116b0f88f7bed0e143d9889eb # # This file is autogenerated by pip-compile-multi # To update, run: # # pip-compile-multi # +annotated-types==0.7.0 + # via pydantic asttokens==3.0.0 # via stack-data click==8.1.8 @@ -19,11 +21,15 @@ cyclebane==24.10.0 # via sciline cycler==0.12.1 # via matplotlib -dask==2025.1.0 +dask==2025.2.0 # via -r base.in decorator==5.1.1 # via ipython -essreduce==25.2.0 +dnspython==2.7.0 + # via email-validator +email-validator==2.2.0 + # via scippneutron +essreduce==25.2.4 # via -r base.in exceptiongroup==1.2.2 # via ipython @@ -35,10 +41,12 @@ fsspec==2025.2.0 # via dask graphviz==0.20.3 # via -r base.in -h5py==3.12.1 +h5py==3.13.0 # via # scippneutron # scippnexus +idna==3.10 + # via email-validator importlib-metadata==8.6.1 # via dask ipydatawidgets==4.3.5 @@ -55,6 +63,8 @@ jupyterlab-widgets==3.0.13 # via ipywidgets kiwisolver==1.4.8 # via matplotlib +lazy-loader==0.4 + # via scippneutron locket==1.0.0 # via partd matplotlib==3.10.0 @@ -67,7 +77,7 @@ mpltoolbox==24.5.1 # via scippneutron networkx==3.4.2 # via cyclebane -numpy==2.2.2 +numpy==2.2.3 # via # -r base.in # contourpy @@ -83,6 +93,7 @@ numpy==2.2.2 packaging==24.2 # via # dask + # lazy-loader # matplotlib pandas==2.2.3 # via -r base.in @@ -104,6 +115,10 @@ ptyprocess==0.7.0 # via pexpect pure-eval==0.2.3 # via stack-data +pydantic==2.10.6 + # via scippneutron +pydantic-core==2.27.2 + # via pydantic pygments==2.19.1 # via ipython pyparsing==3.2.1 @@ -112,6 +127,7 @@ python-dateutil==2.9.0.post0 # via # matplotlib # pandas + # scippneutron # scippnexus pythreejs==2.4.2 # via -r base.in @@ -129,7 +145,7 @@ scipp==25.2.0 # essreduce # scippneutron # scippnexus -scippneutron==25.1.0 +scippneutron==25.2.0 # via # -r base.in # essreduce @@ -138,7 +154,7 @@ scippnexus==24.11.1 # -r base.in # essreduce # scippneutron -scipy==1.15.1 +scipy==1.15.2 # via # scippneutron # scippnexus @@ -161,7 +177,10 @@ traitlets==5.14.3 traittypes==0.2.1 # via ipydatawidgets typing-extensions==4.12.2 - # via ipython + # via + # ipython + # pydantic + # pydantic-core tzdata==2025.1 # via pandas wcwidth==0.2.13 diff --git a/requirements/basetest.txt b/requirements/basetest.txt index bdad58d7..827641d7 100644 --- a/requirements/basetest.txt +++ b/requirements/basetest.txt @@ -15,7 +15,7 @@ idna==3.10 # via requests iniconfig==2.0.0 # via pytest -numpy==2.2.2 +numpy==2.2.3 # via scipy packaging==24.2 # via @@ -31,7 +31,7 @@ pytest==8.3.4 # via -r basetest.in requests==2.32.3 # via pooch -scipy==1.15.1 +scipy==1.15.2 # via -r basetest.in tomli==2.2.1 # via pytest diff --git a/requirements/dev.txt b/requirements/dev.txt index 814d4763..b9014c97 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -12,8 +12,6 @@ -r static.txt -r test.txt -r wheels.txt -annotated-types==0.7.0 - # via pydantic anyio==4.8.0 # via # httpx @@ -28,7 +26,7 @@ async-lru==2.0.4 # via jupyterlab cffi==1.17.1 # via argon2-cffi-bindings -copier==9.4.1 +copier==9.5.0 # via -r dev.in dunamai==1.23.0 # via copier @@ -87,10 +85,6 @@ prometheus-client==0.21.1 # via jupyter-server pycparser==2.22 # via cffi -pydantic==2.10.6 - # via copier -pydantic-core==2.27.2 - # via pydantic python-json-logger==3.2.1 # via jupyter-events questionary==2.1.0 diff --git a/requirements/docs.txt b/requirements/docs.txt index 4512446c..90b0bf3f 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -10,8 +10,6 @@ accessible-pygments==0.0.5 # via pydata-sphinx-theme alabaster==1.0.0 # via sphinx -appnope==0.1.4 - # via ipykernel attrs==25.1.0 # via # jsonschema @@ -42,8 +40,6 @@ docutils==0.21.2 # sphinx fastjsonschema==2.21.1 # via nbformat -idna==3.10 - # via requests imagesize==1.4.1 # via sphinx ipykernel==6.29.5 @@ -83,7 +79,7 @@ mdit-py-plugins==0.4.2 # via myst-parser mdurl==0.1.2 # via markdown-it-py -mistune==3.1.1 +mistune==3.1.2 # via nbconvert myst-parser==4.0.1 # via -r docs.in @@ -108,7 +104,7 @@ platformdirs==4.3.6 # pooch pooch==1.8.2 # via -r docs.in -psutil==6.1.1 +psutil==7.0.0 # via ipykernel pydata-sphinx-theme==0.16.1 # via -r docs.in diff --git a/requirements/nightly.txt b/requirements/nightly.txt index 14caa371..e5601846 100644 --- a/requirements/nightly.txt +++ b/requirements/nightly.txt @@ -28,7 +28,7 @@ cyclebane==24.10.0 # via sciline cycler==0.12.1 # via matplotlib -dask==2025.1.0 +dask==2025.2.0 # via -r nightly.in decorator==5.1.1 # via ipython @@ -50,7 +50,7 @@ fsspec==2025.2.0 # via dask graphviz==0.20.3 # via -r nightly.in -h5py==3.12.1 +h5py==3.13.0 # via # scippneutron # scippnexus @@ -92,7 +92,7 @@ mpltoolbox==24.5.1 # via scippneutron networkx==3.4.2 # via cyclebane -numpy==2.2.2 +numpy==2.2.3 # via # -r nightly.in # contourpy @@ -181,7 +181,7 @@ scippnexus @ git+https://github.com/scipp/scippnexus@main # -r nightly.in # essreduce # scippneutron -scipy==1.15.1 +scipy==1.15.2 # via # -r nightly.in # scippneutron From 9e76fbfe6710db8259137987f4f68c1e57410624 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Wynen Date: Fri, 21 Feb 2025 15:51:39 +0100 Subject: [PATCH 3/3] Bump scippneutron to 25.02.1 --- pyproject.toml | 2 +- requirements/base.in | 2 +- requirements/base.txt | 4 ++-- requirements/ci.txt | 2 +- requirements/docs.txt | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 69a98f60..1fab023c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ dependencies = [ "pythreejs", "sciline>=24.06.2", "scipp>=24.09.1", # Fixed new hist/bin API - "scippneutron>=25.02.0", + "scippneutron>=25.02.1", "scippnexus>=23.12.1", # 23.12.0 and below deadlock in threaded use ] diff --git a/requirements/base.in b/requirements/base.in index 81f129c0..98e31ae1 100644 --- a/requirements/base.in +++ b/requirements/base.in @@ -11,5 +11,5 @@ plopp pythreejs sciline>=24.06.2 scipp>=24.09.1 -scippneutron>=25.02.0 +scippneutron>=25.02.1 scippnexus>=23.12.1 diff --git a/requirements/base.txt b/requirements/base.txt index 07c847d9..31731992 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,4 +1,4 @@ -# SHA1:0ba7285c8699fdf116b0f88f7bed0e143d9889eb +# SHA1:4505a5e875bef5ea2f9d5ce0d28ffeafee367336 # # This file is autogenerated by pip-compile-multi # To update, run: @@ -145,7 +145,7 @@ scipp==25.2.0 # essreduce # scippneutron # scippnexus -scippneutron==25.2.0 +scippneutron==25.2.1 # via # -r base.in # essreduce diff --git a/requirements/ci.txt b/requirements/ci.txt index 078cca56..1faaceaf 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -5,7 +5,7 @@ # # pip-compile-multi # -cachetools==5.5.1 +cachetools==5.5.2 # via tox certifi==2025.1.31 # via requests diff --git a/requirements/docs.txt b/requirements/docs.txt index 90b0bf3f..40809442 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -120,7 +120,7 @@ requests==2.32.3 # via # pooch # sphinx -rpds-py==0.22.3 +rpds-py==0.23.0 # via # jsonschema # referencing