Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/ess/dream/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@

from .beamline import InstrumentConfiguration
from .instrument_view import instrument_view
from .io import load_geant4_csv, nexus
from .workflow import DreamGeant4Workflow, default_parameters
from .io import load_geant4_csv
from .workflows import (
DreamGeant4MonitorHistogramWorkflow,
DreamGeant4MonitorIntegratedWorkflow,
DreamGeant4ProtonChargeWorkflow,
DreamGeant4Workflow,
DreamPowderWorkflow,
DreamWorkflow,
)

try:
__version__ = importlib.metadata.version("essdiffraction")
Expand All @@ -20,11 +27,14 @@
del importlib

__all__ = [
'DreamGeant4MonitorHistogramWorkflow',
'DreamGeant4MonitorIntegratedWorkflow',
'DreamGeant4ProtonChargeWorkflow',
'DreamGeant4Workflow',
'DreamPowderWorkflow',
'DreamWorkflow',
'InstrumentConfiguration',
'__version__',
'default_parameters',
'instrument_view',
'load_geant4_csv',
'nexus',
]
3 changes: 1 addition & 2 deletions src/ess/dream/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

"""Input/output for DREAM."""

from . import nexus
from .cif import prepare_reduced_tof_cif
from .geant4 import load_geant4_csv

providers = (prepare_reduced_tof_cif,)

__all__ = ["load_geant4_csv", "nexus", "prepare_reduced_tof_cif", "providers"]
__all__ = ["load_geant4_csv", "prepare_reduced_tof_cif", "providers"]
36 changes: 13 additions & 23 deletions src/ess/dream/io/geant4.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
CaveMonitor,
CaveMonitorPosition,
DetectorData,
EmptyCanRun,
Filename,
MonitorData,
MonitorFilename,
Expand All @@ -26,11 +25,8 @@
NeXusDetectorName,
Position,
RunType,
SampleRun,
Source,
VanadiumRun,
)
from ess.reduce.time_of_flight.workflow import GenericTofWorkflow

MANTLE_DETECTOR_ID = sc.index(7)
HIGH_RES_DETECTOR_ID = sc.index(8)
Expand Down Expand Up @@ -316,22 +312,16 @@ def ess_source() -> Source:
return ESS_SOURCE


def LoadGeant4Workflow() -> sciline.Pipeline:
"""
Workflow for loading NeXus data.
"""
wf = GenericTofWorkflow(
run_types=[SampleRun, VanadiumRun, EmptyCanRun], monitor_types=[CaveMonitor]
)
wf.insert(extract_geant4_detector)
wf.insert(load_geant4_csv)
wf.insert(load_mcstas_monitor)
wf.insert(geant4_load_calibration)
wf.insert(get_calibrated_geant4_detector)
wf.insert(assemble_detector_data)
wf.insert(assemble_monitor_data)
wf.insert(dummy_source_position)
wf.insert(dummy_sample_position)
wf.insert(dream_beamline)
wf.insert(ess_source)
return wf
providers = (
load_geant4_csv,
extract_geant4_detector,
get_calibrated_geant4_detector,
assemble_detector_data,
assemble_monitor_data,
load_mcstas_monitor,
geant4_load_calibration,
dummy_source_position,
dummy_sample_position,
dream_beamline,
ess_source,
)
66 changes: 0 additions & 66 deletions src/ess/dream/io/nexus.py

This file was deleted.

141 changes: 93 additions & 48 deletions src/ess/dream/workflow.py → src/ess/dream/workflows.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)

from __future__ import annotations
# Copyright (c) 2025 Scipp contributors (https://github.com/scipp)

import itertools

Expand All @@ -12,12 +10,10 @@

from ess.powder import providers as powder_providers
from ess.powder import with_pixel_mask_filenames
from ess.powder.correction import (
RunNormalization,
insert_run_normalization,
)
from ess.powder.correction import RunNormalization, insert_run_normalization
from ess.powder.types import (
AccumulatedProtonCharge,
BunkerMonitor,
CaveMonitor,
CaveMonitorPosition, # Should this be a DREAM-only parameter?
EmptyCanRun,
Expand All @@ -32,8 +28,7 @@
VanadiumRun,
WavelengthMask,
)
from ess.reduce import time_of_flight
from ess.reduce.nexus.types import NeXusName
from ess.reduce.nexus.types import DetectorBankSizes, NeXusName
from ess.reduce.parameter import parameter_mappers
from ess.reduce.time_of_flight import GenericTofWorkflow
from ess.reduce.workflow import register_workflow
Expand All @@ -44,9 +39,35 @@
prepare_reduced_empty_can_subtracted_tof_cif,
prepare_reduced_tof_cif,
)
from .io.geant4 import LoadGeant4Workflow
from .io.geant4 import providers as geant4_providers
from .parameters import typical_outputs

DETECTOR_BANK_SIZES = {
"endcap_backward_detector": {
"strip": 16,
"wire": 16,
"module": 11,
"segment": 28,
"counter": 2,
},
"endcap_forward_detector": {
"strip": 16,
"wire": 16,
"module": 5,
"segment": 28,
"counter": 2,
},
"mantle_detector": {
"wire": 32,
"module": 5,
"segment": 6,
"strip": 256,
"counter": 2,
},
"high_resolution_detector": {"strip": 32, "other": -1},
"sans_detector": {"strip": 32, "other": -1},
}


def _get_lookup_table_filename_from_configuration(
configuration: InstrumentConfiguration,
Expand All @@ -64,52 +85,58 @@ def _get_lookup_table_filename_from_configuration(
return TimeOfFlightLookupTableFilename(out)


_dream_providers = (
def _collect_reducer_software() -> ReducerSoftware:
return ReducerSoftware(
[
Software.from_package_metadata('essdiffraction'),
Software.from_package_metadata('scippneutron'),
Software.from_package_metadata('scipp'),
]
)


def DreamWorkflow() -> sciline.Pipeline:
"""
Dream generic workflow with default parameters.
The workflow is based on the GenericTofWorkflow.
It can load data from a NeXus file recorded on the DREAM instrument, and can
compute time-of-flight for the neutron events.

It can be used as is, or as a base for more specific workflows, such as
``DreamPowderWorkflow``.
"""
wf = GenericTofWorkflow(
run_types=[SampleRun, VanadiumRun, EmptyCanRun],
monitor_types=[BunkerMonitor, CaveMonitor],
)
wf[DetectorBankSizes] = DETECTOR_BANK_SIZES
wf[NeXusName[BunkerMonitor]] = "monitor_bunker"
wf[NeXusName[CaveMonitor]] = "monitor_cave"
wf.insert(_get_lookup_table_filename_from_configuration)
wf[ReducerSoftware] = _collect_reducer_software()
return wf


_cif_providers = (
prepare_reduced_tof_cif,
prepare_reduced_empty_can_subtracted_tof_cif,
_get_lookup_table_filename_from_configuration,
)

parameter_mappers[PixelMaskFilename] = with_pixel_mask_filenames


def default_parameters() -> dict:
# Quantities not available in the simulated data
sample_position = sc.vector([0.0, 0.0, 0.0], unit="mm")
source_position = sc.vector([-3.478, 0.0, -76550], unit="mm")
charge = sc.scalar(1.0, unit="µAh")
return {
KeepEvents[SampleRun]: KeepEvents[SampleRun](True),
KeepEvents[VanadiumRun]: KeepEvents[VanadiumRun](False),
KeepEvents[EmptyCanRun]: KeepEvents[EmptyCanRun](True),
Position[snx.NXsample, SampleRun]: sample_position,
Position[snx.NXsample, VanadiumRun]: sample_position,
Position[snx.NXsample, EmptyCanRun]: sample_position,
Position[snx.NXsource, SampleRun]: source_position,
Position[snx.NXsource, VanadiumRun]: source_position,
Position[snx.NXsource, EmptyCanRun]: source_position,
AccumulatedProtonCharge[SampleRun]: charge,
AccumulatedProtonCharge[VanadiumRun]: charge,
AccumulatedProtonCharge[EmptyCanRun]: charge,
TofMask: None,
WavelengthMask: None,
TwoThetaMask: None,
CaveMonitorPosition: sc.vector([0.0, 0.0, -4220.0], unit='mm'),
CIFAuthors: CIFAuthors([]),
ReducerSoftware: _collect_reducer_software(),
}


def _collect_reducer_software() -> ReducerSoftware:
return ReducerSoftware(
[
Software.from_package_metadata('essdiffraction'),
Software.from_package_metadata('scippneutron'),
Software.from_package_metadata('scipp'),
]
)


def DreamPowderWorkflow(*, run_norm: RunNormalization) -> sciline.Pipeline:
"""
Dream powder workflow with default parameters.
Expand All @@ -124,14 +151,11 @@ def DreamPowderWorkflow(*, run_norm: RunNormalization) -> sciline.Pipeline:
:
A workflow object for DREAM.
"""
wf = GenericTofWorkflow(run_types=[SampleRun], monitor_types=[CaveMonitor])
for provider in itertools.chain(powder_providers, _dream_providers):
wf = DreamWorkflow()
for provider in itertools.chain(powder_providers, _cif_providers):
wf.insert(provider)
wf[NeXusName[CaveMonitor]] = "monitor_cave"
insert_run_normalization(wf, run_norm)
for key, value in itertools.chain(
default_parameters().items(), time_of_flight.default_parameters().items()
):
for key, value in default_parameters().items():
wf[key] = value
wf.typical_outputs = typical_outputs
return wf
Expand All @@ -151,14 +175,33 @@ def DreamGeant4Workflow(*, run_norm: RunNormalization) -> sciline.Pipeline:
:
A workflow object for DREAM.
"""
wf = LoadGeant4Workflow()
for provider in itertools.chain(powder_providers, _dream_providers):
wf = DreamWorkflow()
for provider in itertools.chain(geant4_providers, powder_providers, _cif_providers):
wf.insert(provider)
insert_run_normalization(wf, run_norm)
for key, value in itertools.chain(
default_parameters().items(), time_of_flight.default_parameters().items()
):
for key, value in default_parameters().items():
wf[key] = value

# Quantities not available in the simulated data
sample_position = sc.vector([0.0, 0.0, 0.0], unit="mm")
source_position = sc.vector([-3.478, 0.0, -76550], unit="mm")
charge = sc.scalar(1.0, unit="µAh")

additional_parameters = {
Position[snx.NXsample, SampleRun]: sample_position,
Position[snx.NXsample, VanadiumRun]: sample_position,
Position[snx.NXsample, EmptyCanRun]: sample_position,
Position[snx.NXsource, SampleRun]: source_position,
Position[snx.NXsource, VanadiumRun]: source_position,
Position[snx.NXsource, EmptyCanRun]: source_position,
AccumulatedProtonCharge[SampleRun]: charge,
AccumulatedProtonCharge[VanadiumRun]: charge,
AccumulatedProtonCharge[EmptyCanRun]: charge,
CaveMonitorPosition: sc.vector([0.0, 0.0, -4220.0], unit='mm'),
}
for key, value in additional_parameters.items():
wf[key] = value

wf.typical_outputs = typical_outputs
return wf

Expand Down Expand Up @@ -195,5 +238,7 @@ def DreamGeant4ProtonChargeWorkflow() -> sciline.Pipeline:
'DreamGeant4MonitorIntegratedWorkflow',
'DreamGeant4ProtonChargeWorkflow',
'DreamGeant4Workflow',
'DreamPowderWorkflow',
'DreamWorkflow',
'default_parameters',
]
Loading
Loading