Skip to content

Commit a9bc401

Browse files
committed
Merge branch 'main' into tof-workflow
2 parents 55ec664 + 646574e commit a9bc401

File tree

9 files changed

+117
-17
lines changed

9 files changed

+117
-17
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ requires-python = ">=3.10"
3232
# Make sure to list one dependency per line.
3333
dependencies = [
3434
"dask",
35-
"essreduce>=25.02.3",
35+
"essreduce>=25.02.4",
3636
"graphviz",
3737
"numpy",
3838
"plopp",
3939
"pythreejs",
4040
"sciline>=24.06.0",
4141
"scipp>=24.09.1",
42-
"scippneutron>=24.11.0",
42+
"scippneutron>=25.02.0",
4343
"scippnexus>=23.12.0",
4444
"tof>=25.01.2",
4545
]

requirements/base.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@
33
# --- END OF CUSTOM SECTION ---
44
# The following was generated by 'tox -e deps', DO NOT EDIT MANUALLY!
55
dask
6+
<<<<<<< HEAD
67
essreduce>=25.02.3
8+
=======
9+
essreduce>=25.02.4
10+
>>>>>>> main
711
graphviz
812
numpy
913
plopp
1014
pythreejs
1115
sciline>=24.06.0
1216
scipp>=24.09.1
13-
scippneutron>=24.11.0
17+
scippneutron>=25.02.0
1418
scippnexus>=23.12.0
1519
tof>=25.01.2

requirements/base.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
<<<<<<< HEAD
12
# SHA1:453953b7160748669892413b1efa541107c4a89b
3+
=======
4+
# SHA1:4b779f60b811ecde0982bc9dc5df5ed5b296b876
5+
>>>>>>> main
26
#
37
# This file is autogenerated by pip-compile-multi
48
# To update, run:
@@ -29,7 +33,11 @@ dnspython==2.7.0
2933
# via email-validator
3034
email-validator==2.2.0
3135
# via scippneutron
36+
<<<<<<< HEAD
3237
essreduce==25.2.3
38+
=======
39+
essreduce==25.2.4
40+
>>>>>>> main
3341
# via -r base.in
3442
executing==2.2.0
3543
# via stack-data
@@ -45,8 +53,11 @@ h5py==3.12.1
4553
# scippnexus
4654
idna==3.10
4755
# via email-validator
56+
<<<<<<< HEAD
4857
importlib-resources==6.5.2
4958
# via tof
59+
=======
60+
>>>>>>> main
5061
ipydatawidgets==4.3.5
5162
# via pythreejs
5263
ipython==8.32.0
@@ -138,7 +149,10 @@ scipp==25.2.0
138149
# essreduce
139150
# scippneutron
140151
# scippnexus
152+
<<<<<<< HEAD
141153
# tof
154+
=======
155+
>>>>>>> main
142156
scippneutron==25.2.0
143157
# via
144158
# -r base.in

requirements/nightly.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ idna==3.10
5454
# via
5555
# email-validator
5656
# requests
57+
<<<<<<< HEAD
5758
importlib-resources==6.5.2
5859
# via tof
60+
=======
61+
>>>>>>> main
5962
iniconfig==2.0.0
6063
# via pytest
6164
ipydatawidgets==4.3.5
@@ -188,8 +191,11 @@ six==1.17.0
188191
# via python-dateutil
189192
stack-data==0.6.3
190193
# via ipython
194+
<<<<<<< HEAD
191195
tof @ git+https://github.com/scipp/tof@main
192196
# via -r nightly.in
197+
=======
198+
>>>>>>> main
193199
toolz==1.0.0
194200
# via
195201
# dask

src/ess/dream/io/cif.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,27 @@
44
"""CIF writer for DREAM."""
55

66
import scipp as sc
7-
from scippneutron import metadata
87
from scippneutron.io import cif
98

109
from ess.powder.calibration import OutputCalibrationData
11-
from ess.powder.types import CIFAuthors, IofTof, ReducedTofCIF
10+
from ess.powder.types import (
11+
Beamline,
12+
CIFAuthors,
13+
IofTof,
14+
ReducedTofCIF,
15+
ReducerSoftwares,
16+
Source,
17+
)
1218

1319

1420
def prepare_reduced_tof_cif(
15-
da: IofTof, *, authors: CIFAuthors, calibration: OutputCalibrationData
21+
da: IofTof,
22+
*,
23+
authors: CIFAuthors,
24+
beamline: Beamline,
25+
source: Source,
26+
reducers: ReducerSoftwares,
27+
calibration: OutputCalibrationData,
1628
) -> ReducedTofCIF:
1729
"""Construct a CIF builder with reduced data in d-spacing.
1830
@@ -25,6 +37,12 @@ def prepare_reduced_tof_cif(
2537
Reduced 1d data with a ``'tof'`` dimension and coordinate.
2638
authors:
2739
List of authors to write to the file.
40+
beamline:
41+
Information about the beamline that the data was produced at.
42+
source:
43+
Information about the neutron source.
44+
reducers:
45+
List of software pieces used to reduce the data.
2846
calibration:
2947
Coefficients for conversion between d-spacing and final ToF.
3048
See :meth:`scippneutron.io.cif.CIF.with_powder_calibration`.
@@ -35,14 +53,12 @@ def prepare_reduced_tof_cif(
3553
An object that contains the reduced data and metadata.
3654
Us its ``save`` method to write the CIF file.
3755
"""
38-
from .. import __version__
39-
4056
to_save = _prepare_data(da)
4157
return ReducedTofCIF(
4258
cif.CIF('reduced_tof')
43-
.with_reducers(f'ess.dream v{__version__}')
59+
.with_reducers(*(reducer.compact_repr for reducer in reducers))
4460
.with_authors(*authors)
45-
.with_beamline(beamline=metadata.Beamline(name='DREAM', facility='ESS'))
61+
.with_beamline(beamline, source)
4662
.with_powder_calibration(calibration.to_cif_format())
4763
.with_reduced_powder_data(to_save)
4864
)

src/ess/dream/io/geant4.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import scipp as sc
77
import scippneutron as scn
88
import scippnexus as snx
9+
from scippneutron.metadata import ESS_SOURCE
910

1011
from ess.powder.types import (
12+
Beamline,
1113
CalibratedDetector,
1214
CalibratedMonitor,
1315
CalibrationData,
@@ -26,6 +28,7 @@
2628
Position,
2729
RunType,
2830
SampleRun,
31+
Source,
2932
VanadiumRun,
3033
)
3134
from ess.reduce.nexus.types import CalibratedBeamline
@@ -347,6 +350,18 @@ def extract_monitor_ltotal(
347350
return MonitorLtotal[RunType, MonitorType](monitor.coords["Ltotal"])
348351

349352

353+
def dream_beamline() -> Beamline:
354+
return Beamline(
355+
name="DREAM",
356+
facility="ESS",
357+
site="ESS",
358+
)
359+
360+
361+
def ess_source() -> Source:
362+
return ESS_SOURCE
363+
364+
350365
def LoadGeant4Workflow() -> sciline.Pipeline:
351366
"""
352367
Workflow for loading NeXus data.
@@ -365,4 +380,6 @@ def LoadGeant4Workflow() -> sciline.Pipeline:
365380
wf.insert(dummy_sample_position)
366381
wf.insert(extract_detector_ltotal)
367382
wf.insert(extract_monitor_ltotal)
383+
wf.insert(dream_beamline)
384+
wf.insert(ess_source)
368385
return wf

src/ess/dream/workflow.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sciline
99
import scipp as sc
1010
import scippnexus as snx
11+
from scippneutron.metadata import Software
1112

1213
from ess.powder import providers as powder_providers
1314
from ess.powder import with_pixel_mask_filenames
@@ -20,6 +21,7 @@
2021
CaveMonitorPosition, # Should this be a DREAM-only parameter?
2122
PixelMaskFilename,
2223
Position,
24+
ReducerSoftwares,
2325
SampleRun,
2426
TofMask,
2527
TwoThetaMask,
@@ -51,14 +53,27 @@ def default_parameters() -> dict:
5153
Position[snx.NXsource, VanadiumRun]: source_position,
5254
AccumulatedProtonCharge[SampleRun]: charge,
5355
AccumulatedProtonCharge[VanadiumRun]: charge,
54-
CIFAuthors: CIFAuthors([]),
5556
TofMask: None,
5657
WavelengthMask: None,
5758
TwoThetaMask: None,
5859
CaveMonitorPosition: sc.vector([0.0, 0.0, -4220.0], unit='mm'),
60+
CIFAuthors: CIFAuthors([]),
61+
ReducerSoftwares: _collect_reducer_software(),
5962
}
6063

6164

65+
def _collect_reducer_software() -> ReducerSoftwares:
66+
return ReducerSoftwares(
67+
[
68+
Software.from_package_metadata('ess.diffraction'),
69+
Software.from_package_metadata('ess.dream'),
70+
Software.from_package_metadata('ess.powder'),
71+
Software.from_package_metadata('scippneutron'),
72+
Software.from_package_metadata('scipp'),
73+
]
74+
)
75+
76+
6277
def DreamGeant4Workflow(*, run_norm: RunNormalization) -> sciline.Pipeline:
6378
"""
6479
Workflow with default parameters for the Dream Geant4 simulation.

src/ess/powder/types.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import scipp as sc
1616
from scippneutron import metadata
1717
from scippneutron.io import cif
18+
from scippneutron.metadata import Person, Software
1819

1920
from ess.reduce.nexus import types as reduce_t
2021
from ess.reduce.time_of_flight import types as tof_t
@@ -198,8 +199,16 @@ class RawDataAndMetadata(sciline.Scope[RunType, sc.DataGroup], sc.DataGroup):
198199
WavelengthMask = NewType("WavelengthMask", Callable | None)
199200
"""WavelengthMask is a callable that returns a mask for a given WavelengthData."""
200201

202+
Beamline = reduce_t.Beamline
203+
"""Beamline metadata."""
201204

202-
CIFAuthors = NewType("CIFAuthors", list[metadata.Person])
205+
ReducerSoftwares = NewType('ReducerSoftware', list[Software])
206+
"""Pieces of software used to reduce the data."""
207+
208+
Source = reduce_t.Source
209+
"""Neutron source metadata."""
210+
211+
CIFAuthors = NewType('CIFAuthors', list[Person])
203212
"""List of authors to save to output CIF files."""
204213

205214
ReducedTofCIF = NewType("ReducedTofCIF", cif.CIF)

tests/dream/io/cif_test.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
import pytest
77
import scipp as sc
8-
from scippneutron import metadata
98
from scippneutron.io import cif
9+
from scippneutron.metadata import ESS_SOURCE, Person
1010

1111
import ess.dream.io.cif
1212
from ess.powder.calibration import OutputCalibrationData
13-
from ess.powder.types import CIFAuthors, IofTof
13+
from ess.powder.types import Beamline, CIFAuthors, IofTof, ReducerSoftwares, Software
1414

1515

1616
@pytest.fixture
@@ -44,14 +44,33 @@ def save_reduced_tof_to_str(cif_: cif.CIF) -> str:
4444
def test_save_reduced_tof(ioftof: IofTof, cal: OutputCalibrationData) -> None:
4545
from ess.dream import __version__
4646

47-
author = metadata.Person(name='John Doe', corresponding=True)
47+
author = Person(name='John Doe', corresponding=True)
4848
cif_ = ess.dream.io.cif.prepare_reduced_tof_cif(
49-
ioftof, authors=CIFAuthors([author]), calibration=cal
49+
ioftof,
50+
authors=CIFAuthors([author]),
51+
beamline=Beamline(
52+
name="DREAM",
53+
facility="ESS",
54+
site="ESS",
55+
),
56+
source=ESS_SOURCE,
57+
reducers=ReducerSoftwares(
58+
[
59+
Software.from_package_metadata('ess.diffraction'),
60+
Software.from_package_metadata('ess.dream'),
61+
Software.from_package_metadata('ess.powder'),
62+
Software.from_package_metadata('scippneutron'),
63+
Software.from_package_metadata('scipp'),
64+
]
65+
),
66+
calibration=cal,
5067
)
5168
result = save_reduced_tof_to_str(cif_)
5269

5370
assert "_audit_contact_author.name 'John Doe'" in result
54-
assert f"_computing.diffrn_reduction 'ess.dream v{__version__}'" in result
71+
assert f"_computing.diffrn_reduction\n'ess.diffraction {__version__}'" in result
72+
assert f"ess.dream {__version__}" in result
73+
assert f"ess.powder {__version__}" in result
5574
assert '_diffrn_source.beamline DREAM' in result
5675
assert 'ZERO 0 0.2' in result
5776
assert 'DIFC 1 1.2' in result

0 commit comments

Comments
 (0)