Skip to content

Commit 3c00508

Browse files
authored
Merge pull request #166 from scipp/scn-metadata-utils
Use ScippNeutron's metadata utilities
2 parents 911306f + 16a74f0 commit 3c00508

13 files changed

+110
-58
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ requires-python = ">=3.10"
3333
dependencies = [
3434
"sciline>=24.06.2",
3535
"scipp>=25.01.0",
36-
"scippneutron>=24.11.0",
36+
"scippneutron>=25.02.0",
3737
"scippnexus>=24.11.0",
3838
]
3939

requirements/base.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
# The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY!
55
sciline>=24.06.2
66
scipp>=25.01.0
7-
scippneutron>=24.11.0
7+
scippneutron>=25.02.0
88
scippnexus>=24.11.0

requirements/base.txt

+26-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1-
# SHA1:d18487328be0c30ec0a6929501d1c4a58c71bd48
1+
# SHA1:0aac37186f254abb39dbd8f3c3c6ad52bafc0553
22
#
33
# This file is autogenerated by pip-compile-multi
44
# To update, run:
55
#
66
# pip-compile-multi
77
#
8+
annotated-types==0.7.0
9+
# via pydantic
810
contourpy==1.3.1
911
# via matplotlib
1012
cyclebane==24.10.0
1113
# via sciline
1214
cycler==0.12.1
1315
# via matplotlib
16+
dnspython==2.7.0
17+
# via email-validator
18+
email-validator==2.2.0
19+
# via scippneutron
1420
fonttools==4.56.0
1521
# via matplotlib
1622
h5py==3.12.1
1723
# via
1824
# scippneutron
1925
# scippnexus
26+
idna==3.10
27+
# via email-validator
2028
kiwisolver==1.4.8
2129
# via matplotlib
30+
lazy-loader==0.4
31+
# via scippneutron
2232
matplotlib==3.10.0
2333
# via
2434
# mpltoolbox
@@ -27,7 +37,7 @@ mpltoolbox==24.5.1
2737
# via scippneutron
2838
networkx==3.4.2
2939
# via cyclebane
30-
numpy==2.2.2
40+
numpy==2.2.3
3141
# via
3242
# contourpy
3343
# h5py
@@ -37,16 +47,23 @@ numpy==2.2.2
3747
# scippneutron
3848
# scipy
3949
packaging==24.2
40-
# via matplotlib
50+
# via
51+
# lazy-loader
52+
# matplotlib
4153
pillow==11.1.0
4254
# via matplotlib
4355
plopp==24.10.0
4456
# via scippneutron
57+
pydantic==2.10.6
58+
# via scippneutron
59+
pydantic-core==2.27.2
60+
# via pydantic
4561
pyparsing==3.2.1
4662
# via matplotlib
4763
python-dateutil==2.9.0.post0
4864
# via
4965
# matplotlib
66+
# scippneutron
5067
# scippnexus
5168
sciline==24.10.0
5269
# via -r base.in
@@ -55,15 +72,19 @@ scipp==25.2.0
5572
# -r base.in
5673
# scippneutron
5774
# scippnexus
58-
scippneutron==25.1.0
75+
scippneutron==25.2.0
5976
# via -r base.in
6077
scippnexus==24.11.1
6178
# via
6279
# -r base.in
6380
# scippneutron
64-
scipy==1.15.1
81+
scipy==1.15.2
6582
# via
6683
# scippneutron
6784
# scippnexus
6885
six==1.17.0
6986
# via python-dateutil
87+
typing-extensions==4.12.2
88+
# via
89+
# pydantic
90+
# pydantic-core

requirements/basetest.txt

+2-10
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ cycler==0.12.1
1919
# via matplotlib
2020
decorator==5.1.1
2121
# via ipython
22-
exceptiongroup==1.2.2
23-
# via
24-
# ipython
25-
# pytest
2622
executing==2.2.0
2723
# via stack-data
2824
fonttools==4.56.0
@@ -47,7 +43,7 @@ matplotlib==3.10.0
4743
# via plopp
4844
matplotlib-inline==0.1.7
4945
# via ipython
50-
numpy==2.2.2
46+
numpy==2.2.3
5147
# via
5248
# contourpy
5349
# matplotlib
@@ -90,7 +86,7 @@ requests==2.32.3
9086
# via pooch
9187
scipp==25.2.0
9288
# via tof
93-
scipy==1.15.1
89+
scipy==1.15.2
9490
# via
9591
# -r basetest.in
9692
# tof
@@ -100,16 +96,12 @@ stack-data==0.6.3
10096
# via ipython
10197
tof==25.2.0
10298
# via -r basetest.in
103-
tomli==2.2.1
104-
# via pytest
10599
traitlets==5.14.3
106100
# via
107101
# comm
108102
# ipython
109103
# ipywidgets
110104
# matplotlib-inline
111-
typing-extensions==4.12.2
112-
# via ipython
113105
urllib3==2.3.0
114106
# via requests
115107
wcwidth==0.2.13

requirements/ci.txt

-6
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,8 @@ requests==2.32.3
4444
# via -r ci.in
4545
smmap==5.0.2
4646
# via gitdb
47-
tomli==2.2.1
48-
# via
49-
# pyproject-api
50-
# tox
5147
tox==4.24.1
5248
# via -r ci.in
53-
typing-extensions==4.12.2
54-
# via tox
5549
urllib3==2.3.0
5650
# via requests
5751
virtualenv==20.29.2

requirements/dev.txt

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
-r static.txt
1313
-r test.txt
1414
-r wheels.txt
15-
annotated-types==0.7.0
16-
# via pydantic
1715
anyio==4.8.0
1816
# via
1917
# httpx
@@ -32,7 +30,7 @@ click==8.1.8
3230
# via
3331
# pip-compile-multi
3432
# pip-tools
35-
copier==9.4.1
33+
copier==9.5.0
3634
# via -r dev.in
3735
dunamai==1.23.0
3836
# via copier
@@ -91,10 +89,6 @@ prometheus-client==0.21.1
9189
# via jupyter-server
9290
pycparser==2.22
9391
# via cffi
94-
pydantic==2.10.6
95-
# via copier
96-
pydantic-core==2.27.2
97-
# via pydantic
9892
python-json-logger==3.2.1
9993
# via jupyter-events
10094
questionary==2.1.0

requirements/docs.txt

+1-16
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ accessible-pygments==0.0.5
1010
# via pydata-sphinx-theme
1111
alabaster==1.0.0
1212
# via sphinx
13-
appnope==0.1.4
14-
# via ipykernel
1513
asttokens==3.0.0
1614
# via stack-data
1715
attrs==25.1.0
@@ -48,16 +46,12 @@ docutils==0.21.2
4846
# nbsphinx
4947
# pydata-sphinx-theme
5048
# sphinx
51-
exceptiongroup==1.2.2
52-
# via ipython
5349
executing==2.2.0
5450
# via stack-data
5551
fastjsonschema==2.21.1
5652
# via nbformat
5753
graphviz==0.20.3
5854
# via -r docs.in
59-
idna==3.10
60-
# via requests
6155
imagesize==1.4.1
6256
# via sphinx
6357
importlib-resources==6.5.2
@@ -141,7 +135,7 @@ platformdirs==4.3.6
141135
# via jupyter-core
142136
prompt-toolkit==3.0.50
143137
# via ipython
144-
psutil==6.1.1
138+
psutil==7.0.0
145139
# via ipykernel
146140
ptyprocess==0.7.0
147141
# via pexpect
@@ -209,8 +203,6 @@ tinycss2==1.4.0
209203
# via bleach
210204
tof==25.2.0
211205
# via -r docs.in
212-
tomli==2.2.1
213-
# via sphinx
214206
tornado==6.4.2
215207
# via
216208
# ipykernel
@@ -228,13 +220,6 @@ traitlets==5.14.3
228220
# nbconvert
229221
# nbformat
230222
# nbsphinx
231-
typing-extensions==4.12.2
232-
# via
233-
# beautifulsoup4
234-
# ipython
235-
# mistune
236-
# pydata-sphinx-theme
237-
# referencing
238223
urllib3==2.3.0
239224
# via requests
240225
wcwidth==0.2.13

requirements/nightly.txt

+2-9
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ dnspython==2.7.0
3232
# via email-validator
3333
email-validator==2.2.0
3434
# via scippneutron
35-
exceptiongroup==1.2.2
36-
# via
37-
# ipython
38-
# pytest
3935
executing==2.2.0
4036
# via stack-data
4137
fonttools==4.56.0
@@ -74,7 +70,7 @@ mpltoolbox==24.5.1
7470
# via scippneutron
7571
networkx==3.4.2
7672
# via cyclebane
77-
numpy==2.2.2
73+
numpy==2.2.3
7874
# via
7975
# contourpy
8076
# h5py
@@ -142,7 +138,7 @@ scippnexus @ git+https://github.com/scipp/scippnexus@main
142138
# via
143139
# -r nightly.in
144140
# scippneutron
145-
scipy==1.15.1
141+
scipy==1.15.2
146142
# via
147143
# -r nightly.in
148144
# scippneutron
@@ -154,8 +150,6 @@ stack-data==0.6.3
154150
# via ipython
155151
tof @ git+https://github.com/scipp/tof@main
156152
# via -r nightly.in
157-
tomli==2.2.1
158-
# via pytest
159153
traitlets==5.14.3
160154
# via
161155
# comm
@@ -164,7 +158,6 @@ traitlets==5.14.3
164158
# matplotlib-inline
165159
typing-extensions==4.12.2
166160
# via
167-
# ipython
168161
# pydantic
169162
# pydantic-core
170163
urllib3==2.3.0

requirements/wheels.txt

-2
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,3 @@ packaging==24.2
1111
# via build
1212
pyproject-hooks==1.2.0
1313
# via build
14-
tomli==2.2.1
15-
# via build

src/ess/reduce/nexus/_nexus_loader.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
from contextlib import AbstractContextManager, contextmanager, nullcontext
99
from dataclasses import dataclass
1010
from math import prod
11-
from typing import cast
11+
from typing import TypeVar, cast
1212

1313
import scipp as sc
1414
import scippnexus as snx
1515

1616
from ..logging import get_logger
1717
from .types import (
18+
Beamline,
1819
FilePath,
20+
Measurement,
1921
NeXusAllLocationSpec,
2022
NeXusEntryName,
2123
NeXusFile,
@@ -27,6 +29,8 @@
2729
class NoNewDefinitionsType: ...
2830

2931

32+
_Model = TypeVar('_Model', Beamline, Measurement)
33+
3034
NoNewDefinitions = NoNewDefinitionsType()
3135

3236

@@ -74,6 +78,18 @@ def load_all_components(
7478
return components
7579

7680

81+
def load_metadata(
82+
file_path: FilePath | NeXusFile | NeXusGroup,
83+
model: type[_Model],
84+
*,
85+
entry_name: NeXusEntryName | None = None,
86+
definitions: Mapping | NoNewDefinitionsType = NoNewDefinitions,
87+
) -> _Model:
88+
with _open_nexus_file(file_path, definitions=definitions) as f:
89+
entry = _unique_child_group(f, snx.NXentry, entry_name)
90+
return model.from_nexus_entry(entry)
91+
92+
7793
def compute_component_position(dg: sc.DataGroup) -> sc.DataGroup:
7894
# In some downstream packages we use some of the Nexus components which attempt
7995
# to compute positions without having actual Nexus data defining depends_on chains.

src/ess/reduce/nexus/types.py

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sciline
88
import scipp as sc
99
import scippnexus as snx
10+
from scippneutron import metadata as scn_meta
1011

1112
FilePath = NewType('FilePath', Path)
1213
"""Full path to a NeXus file on disk."""
@@ -177,6 +178,13 @@ class TransmissionRun(Generic[ScatteringRunType]):
177178
UniqueComponent = TypeVar('UniqueComponent', snx.NXsample, snx.NXsource)
178179
"""Components that can be identified by their type as there will only be one."""
179180

181+
Beamline = scn_meta.Beamline
182+
"""Beamline metadata."""
183+
Measurement = scn_meta.Measurement
184+
"""measurement metadata."""
185+
Source = scn_meta.Source
186+
"""Neutron source metadata."""
187+
180188

181189
class NeXusName(sciline.Scope[Component, str], str):
182190
"""Name of a component in a NeXus file."""

0 commit comments

Comments
 (0)