Skip to content

Commit ec58d43

Browse files
committed
Use scn.metadata models
1 parent 34f4996 commit ec58d43

File tree

4 files changed

+64
-8
lines changed

4 files changed

+64
-8
lines changed

src/ess/dream/io/cif.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@
77
from scippneutron.io import cif
88

99
from ess.powder.calibration import OutputCalibrationData
10-
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+
)
1118

1219

1320
def prepare_reduced_tof_cif(
14-
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,
1528
) -> ReducedTofCIF:
1629
"""Construct a CIF builder with reduced data in d-spacing.
1730
@@ -24,6 +37,12 @@ def prepare_reduced_tof_cif(
2437
Reduced 1d data with a ``'tof'`` dimension and coordinate.
2538
authors:
2639
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.
2746
calibration:
2847
Coefficients for conversion between d-spacing and final ToF.
2948
See :meth:`scippneutron.io.cif.CIF.with_powder_calibration`.
@@ -34,14 +53,12 @@ def prepare_reduced_tof_cif(
3453
An object that contains the reduced data and metadata.
3554
Us its ``save`` method to write the CIF file.
3655
"""
37-
from .. import __version__
38-
3956
to_save = _prepare_data(da)
4057
return ReducedTofCIF(
4158
cif.CIF('reduced_tof')
42-
.with_reducers(f'ess.dream v{__version__}')
59+
.with_reducers(*(reducer.compact_repr for reducer in reducers))
4360
.with_authors(*authors)
44-
.with_beamline(beamline='DREAM', facility='ESS')
61+
.with_beamline(beamline, source)
4562
.with_powder_calibration(calibration.to_cif_format())
4663
.with_reduced_powder_data(to_save)
4764
)

src/ess/dream/io/geant4.py

+17
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
import sciline
66
import scipp as sc
77
import scippnexus as snx
8+
from scippneutron.metadata import ESS_SOURCE
89

910
from ess.powder.types import (
11+
Beamline,
1012
CalibratedDetector,
1113
CalibratedMonitor,
1214
CalibrationData,
@@ -23,6 +25,7 @@
2325
Position,
2426
RunType,
2527
SampleRun,
28+
Source,
2629
VanadiumRun,
2730
)
2831
from ess.reduce.nexus.types import CalibratedBeamline
@@ -269,6 +272,18 @@ def dummy_sample_position() -> Position[snx.NXsample, RunType]:
269272
)
270273

271274

275+
def dream_beamline() -> Beamline:
276+
return Beamline(
277+
name="DREAM",
278+
facility="ESS",
279+
site="ESS",
280+
)
281+
282+
283+
def ess_source() -> Source:
284+
return ESS_SOURCE
285+
286+
272287
def LoadGeant4Workflow() -> sciline.Pipeline:
273288
"""
274289
Workflow for loading NeXus data.
@@ -285,4 +300,6 @@ def LoadGeant4Workflow() -> sciline.Pipeline:
285300
wf.insert(dummy_assemble_monitor_data)
286301
wf.insert(dummy_source_position)
287302
wf.insert(dummy_sample_position)
303+
wf.insert(dream_beamline)
304+
wf.insert(ess_source)
288305
return wf

src/ess/dream/workflow.py

+14-1
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,
@@ -50,14 +52,25 @@ def default_parameters() -> dict:
5052
Position[snx.NXsource, VanadiumRun]: source_position,
5153
AccumulatedProtonCharge[SampleRun]: charge,
5254
AccumulatedProtonCharge[VanadiumRun]: charge,
53-
CIFAuthors: CIFAuthors([]),
5455
TofMask: None,
5556
WavelengthMask: None,
5657
TwoThetaMask: None,
5758
CaveMonitorPosition: sc.vector([0.0, 0.0, -4220.0], unit='mm'),
59+
CIFAuthors: CIFAuthors([]),
60+
ReducerSoftwares: _collect_reducer_software(),
5861
}
5962

6063

64+
def _collect_reducer_software() -> ReducerSoftwares:
65+
return ReducerSoftwares(
66+
[
67+
Software.from_package_metadata('essdiffraction'),
68+
Software.from_package_metadata('scippneutron'),
69+
Software.from_package_metadata('scipp'),
70+
]
71+
)
72+
73+
6174
def DreamGeant4Workflow(*, run_norm: RunNormalization) -> sciline.Pipeline:
6275
"""
6376
Workflow with default parameters for the Dream Geant4 simulation.

src/ess/powder/types.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import sciline
1515
import scipp as sc
1616
from scippneutron.io import cif
17+
from scippneutron.metadata import Person, Software
1718

1819
from ess.reduce.nexus import types as reduce_t
1920
from ess.reduce.uncertainty import UncertaintyBroadcastMode as _UncertaintyBroadcastMode
@@ -181,8 +182,16 @@ class RawDataAndMetadata(sciline.Scope[RunType, sc.DataGroup], sc.DataGroup):
181182
WavelengthMask = NewType("WavelengthMask", Callable | None)
182183
"""WavelengthMask is a callable that returns a mask for a given WavelengthData."""
183184

185+
Beamline = reduce_t.Beamline
186+
"""Beamline metadata."""
184187

185-
CIFAuthors = NewType('CIFAuthors', list[cif.Author])
188+
ReducerSoftwares = NewType('ReducerSoftware', list[Software])
189+
"""Pieces of software used to reduce the data."""
190+
191+
Source = reduce_t.Source
192+
"""Neutron source metadata."""
193+
194+
CIFAuthors = NewType('CIFAuthors', list[Person])
186195
"""List of authors to save to output CIF files."""
187196

188197
ReducedTofCIF = NewType('ReducedTofCIF', cif.CIF)

0 commit comments

Comments
 (0)