Skip to content

Commit 496ec23

Browse files
committed
Use scn.Measurement instead of separate variables
1 parent 1ed4717 commit 496ec23

File tree

4 files changed

+22
-29
lines changed

4 files changed

+22
-29
lines changed

src/ess/isissans/general.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
DetectorPixelShape,
2121
DetectorPositionOffset,
2222
Incident,
23+
Measurement,
2324
MonitorData,
2425
MonitorPositionOffset,
2526
MonitorType,
2627
NeXusComponent,
2728
NeXusMonitorName,
2829
NonBackgroundWavelengthRange,
29-
RunNumber,
30-
RunTitle,
3130
RunType,
3231
SampleRun,
3332
ScatteringRunType,
@@ -174,14 +173,12 @@ def monitor_to_tof(
174173
return TofMonitor[RunType, MonitorType](da)
175174

176175

177-
def run_number(dg: LoadedFileContents[SampleRun]) -> RunNumber:
178-
"""Get the run number from the raw sample data."""
179-
return RunNumber(int(dg['run_number']))
180-
181-
182-
def run_title(dg: LoadedFileContents[SampleRun]) -> RunTitle:
183-
"""Get the run title from the raw sample data."""
184-
return RunTitle(dg['run_title'].value)
176+
def experiment_metadata(dg: LoadedFileContents[SampleRun]) -> Measurement:
177+
"""Get experiment metadata from the raw sample data."""
178+
return Measurement(
179+
title=dg['run_title'].value,
180+
run_number=dg['run_number'],
181+
)
185182

186183

187184
def helium3_tube_detector_pixel_shape() -> DetectorPixelShape[ScatteringRunType]:
@@ -235,6 +232,7 @@ def get_detector_ids_from_sample_run(data: TofData[SampleRun]) -> DetectorIDs:
235232
providers = (
236233
dummy_assemble_detector_data,
237234
dummy_assemble_monitor_data,
235+
experiment_metadata,
238236
to_detector_position_offset,
239237
to_monitor_position_offset,
240238
get_source_position,
@@ -245,8 +243,6 @@ def get_detector_ids_from_sample_run(data: TofData[SampleRun]) -> DetectorIDs:
245243
get_monitor_data,
246244
data_to_tof,
247245
monitor_to_tof,
248-
run_number,
249-
run_title,
250246
lab_frame_transform,
251247
helium3_tube_detector_pixel_shape,
252248
)

src/ess/sans/io.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@
88
from .types import (
99
BackgroundSubtractedIofQ,
1010
MaskedDetectorIDs,
11+
Measurement,
1112
OutFilename,
1213
PixelMaskFilename,
13-
RunNumber,
14-
RunTitle,
1514
)
1615

1716

1817
def save_background_subtracted_iofq(
1918
*,
2019
iofq: BackgroundSubtractedIofQ,
2120
out_filename: OutFilename,
22-
run_number: RunNumber,
23-
run_title: RunTitle,
21+
measurement: Measurement,
2422
) -> None:
2523
"""Save background-subtracted I(Q) histogram as an NXcanSAS file."""
2624
if iofq.bins is None:
@@ -30,7 +28,9 @@ def save_background_subtracted_iofq(
3028
if da.coords.is_edges('Q'):
3129
da.coords['Q'] = sc.midpoints(da.coords['Q'])
3230
with snx.File(out_filename, 'w') as f:
33-
f['sasentry'] = nxcansas.SASentry(title=run_title, run=run_number)
31+
f['sasentry'] = nxcansas.SASentry(
32+
title=measurement.title, run=measurement.run_number_maybe_int
33+
)
3434
f['sasentry']['sasdata'] = nxcansas.SASdata(da, Q_variances='resolutions')
3535

3636

src/ess/sans/types.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,5 @@ class CleanMonitor(
285285

286286
# 4 Metadata
287287

288-
RunTitle = NewType('RunTitle', str)
289-
"""Title of the run."""
290-
291-
RunNumber = NewType('RunNumber', int)
292-
"""Run number."""
288+
Beamline = reduce_t.Beamline
289+
Measurement = reduce_t.Measurement

tests/io_test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from scippnexus.application_definitions import nxcansas
1010

1111
from ess.sans.io import save_background_subtracted_iofq
12-
from ess.sans.types import BackgroundSubtractedIofQ, OutFilename, RunNumber, RunTitle
12+
from ess.sans.types import BackgroundSubtractedIofQ, Measurement, OutFilename
1313

1414

1515
@pytest.mark.parametrize('use_edges', [True, False])
@@ -26,15 +26,15 @@ def background_subtracted_iofq() -> BackgroundSubtractedIofQ:
2626
)
2727
)
2828

29-
def run_number() -> RunNumber:
30-
return RunNumber(7419)
31-
32-
def run_title() -> RunTitle:
33-
return RunTitle('Test-title')
29+
def experiment_metadata() -> Measurement:
30+
return Measurement(
31+
title='Test-title',
32+
run_number='7419',
33+
)
3434

3535
out_filename = tmp_path / 'test.nxs'
3636

37-
providers = (background_subtracted_iofq, run_number, run_title)
37+
providers = (background_subtracted_iofq, experiment_metadata)
3838
params = {OutFilename: str(out_filename)}
3939
pipeline = sciline.Pipeline(providers=providers, params=params)
4040
pipeline.bind_and_call(save_background_subtracted_iofq)

0 commit comments

Comments
 (0)