Skip to content

Commit 530f109

Browse files
committed
Subtract sample run by empty can
1 parent 2d391a8 commit 530f109

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

src/ess/dream/io/geant4.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from scippneutron.metadata import ESS_SOURCE
99

1010
from ess.powder.types import (
11+
BackgroundRun,
1112
Beamline,
1213
CalibratedBeamline,
1314
CalibratedDetector,
@@ -320,7 +321,7 @@ def LoadGeant4Workflow() -> sciline.Pipeline:
320321
Workflow for loading NeXus data.
321322
"""
322323
wf = GenericTofWorkflow(
323-
run_types=[SampleRun, VanadiumRun], monitor_types=[CaveMonitor]
324+
run_types=[SampleRun, VanadiumRun, BackgroundRun], monitor_types=[CaveMonitor]
324325
)
325326
wf.insert(extract_geant4_detector)
326327
wf.insert(load_geant4_csv)

src/ess/dream/workflow.py

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
)
1919
from ess.powder.types import (
2020
AccumulatedProtonCharge,
21+
BackgroundRun,
2122
CaveMonitorPosition, # Should this be a DREAM-only parameter?
2223
PixelMaskFilename,
2324
Position,
@@ -69,10 +70,13 @@ def default_parameters() -> dict:
6970
return {
7071
Position[snx.NXsample, SampleRun]: sample_position,
7172
Position[snx.NXsample, VanadiumRun]: sample_position,
73+
Position[snx.NXsample, BackgroundRun]: sample_position,
7274
Position[snx.NXsource, SampleRun]: source_position,
7375
Position[snx.NXsource, VanadiumRun]: source_position,
76+
Position[snx.NXsource, BackgroundRun]: source_position,
7477
AccumulatedProtonCharge[SampleRun]: charge,
7578
AccumulatedProtonCharge[VanadiumRun]: charge,
79+
AccumulatedProtonCharge[BackgroundRun]: charge,
7680
TofMask: None,
7781
WavelengthMask: None,
7882
TwoThetaMask: None,

src/ess/powder/correction.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
from ._util import event_or_outer_coord
1313
from .types import (
1414
AccumulatedProtonCharge,
15+
BackgroundRun,
16+
BackgroundSubtractedData,
17+
BackgroundSubtractedDataTwoTheta,
1518
CaveMonitor,
1619
DataWithScatteringCoordinates,
1720
FocussedDataDspacing,
@@ -155,7 +158,7 @@ def _normalize_by_vanadium(
155158

156159

157160
def normalize_by_vanadium_dspacing(
158-
data: FocussedDataDspacing[SampleRun],
161+
data: BackgroundSubtractedData[SampleRun],
159162
vanadium: FocussedDataDspacing[VanadiumRun],
160163
uncertainty_broadcast_mode: UncertaintyBroadcastMode,
161164
) -> IofDspacing:
@@ -185,7 +188,7 @@ def normalize_by_vanadium_dspacing(
185188

186189

187190
def normalize_by_vanadium_dspacing_and_two_theta(
188-
data: FocussedDataDspacingTwoTheta[SampleRun],
191+
data: BackgroundSubtractedDataTwoTheta[SampleRun],
189192
vanadium: FocussedDataDspacingTwoTheta[VanadiumRun],
190193
uncertainty_broadcast_mode: UncertaintyBroadcastMode,
191194
) -> IofDspacingTwoTheta:
@@ -335,6 +338,22 @@ def _shallow_copy(da: sc.DataArray) -> sc.DataArray:
335338
return out
336339

337340

341+
def subtract_background(
342+
data: FocussedDataDspacing[SampleRun],
343+
background: FocussedDataDspacing[BackgroundRun],
344+
) -> BackgroundSubtractedData[SampleRun]:
345+
return BackgroundSubtractedData[SampleRun](data.bins.concatenate(-background))
346+
347+
348+
def subtract_background_two_theta(
349+
data: FocussedDataDspacingTwoTheta[SampleRun],
350+
background: FocussedDataDspacingTwoTheta[BackgroundRun],
351+
) -> BackgroundSubtractedDataTwoTheta[SampleRun]:
352+
return BackgroundSubtractedDataTwoTheta[SampleRun](
353+
data.bins.concatenate(-background)
354+
)
355+
356+
338357
class RunNormalization(enum.Enum):
339358
"""Type of normalization applied to each run."""
340359

@@ -357,6 +376,8 @@ def insert_run_normalization(
357376

358377

359378
providers = (
379+
subtract_background,
380+
subtract_background_two_theta,
360381
normalize_by_proton_charge,
361382
normalize_by_vanadium_dspacing,
362383
normalize_by_vanadium_dspacing_and_two_theta,

src/ess/powder/types.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
TimeOfFlightLookupTable = tof_t.TimeOfFlightLookupTable
5757
SimulationResults = tof_t.SimulationResults
5858

59-
RunType = TypeVar("RunType", SampleRun, VanadiumRun)
59+
RunType = TypeVar("RunType", SampleRun, VanadiumRun, BackgroundRun)
6060
MonitorType = TypeVar("MonitorType", CaveMonitor, BunkerMonitor)
6161

6262

@@ -173,6 +173,16 @@ class NormalizedRunData(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
173173
"""Data that has been normalized by proton charge."""
174174

175175

176+
class BackgroundSubtractedData(sciline.Scope[RunType, sc.DataArray], sc.DataArray):
177+
"""Data where background has been subtracted."""
178+
179+
180+
class BackgroundSubtractedDataTwoTheta(
181+
sciline.Scope[RunType, sc.DataArray], sc.DataArray
182+
):
183+
"""Data with 2theta bins where background has been subtracted."""
184+
185+
176186
PixelMaskFilename = NewType("PixelMaskFilename", str)
177187
"""Filename of a pixel mask."""
178188

0 commit comments

Comments
 (0)