Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"import scipp as sc\n",
"import scippnexus as snx\n",
"from ess.reduce import unwrap\n",
"from ess.reduce.nexus.types import AnyRun, Position\n",
"from ess.reduce.nexus.types import AnyRun, NeutronSourcePosition\n",
"from ess.dream.beamline import InstrumentConfiguration, choppers"
]
},
Expand Down Expand Up @@ -65,7 +65,7 @@
"\n",
"wf[unwrap.LtotalRange[AnyRun, snx.NXdetector]] = sc.scalar(5.0, unit=\"m\"), sc.scalar(80.0, unit=\"m\")\n",
"wf[unwrap.NumberOfSimulatedNeutrons] = 200_000 # Increase this number for more reliable results\n",
"wf[Position[snx.NXsource, AnyRun]] = sc.vector([0, 0, 0], unit='m')\n",
"wf[NeutronSourcePosition[AnyRun]] = sc.vector([0, 0, 0], unit='m')\n",
"wf[unwrap.DiskChoppers[AnyRun]] = disk_choppers\n",
"wf[unwrap.DistanceResolution] = sc.scalar(0.1, unit=\"m\")\n",
"wf[unwrap.TimeResolution] = sc.scalar(250.0, unit='us')\n",
Expand Down
6 changes: 3 additions & 3 deletions packages/essdiffraction/src/ess/beer/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from scippneutron.chopper import DiskChopper
from scippneutron.conversion.tof import wavelength_from_tof

from ess.reduce.nexus.types import DiskChoppers, Position
from ess.reduce.nexus.types import DiskChoppers, NeutronSourcePosition, Position
from ess.reduce.unwrap.lut import ActiveDiskChoppers, chopper_distance_along_beam
from ess.reduce.unwrap.types import DetectorLtotal

Expand Down Expand Up @@ -97,7 +97,7 @@ def _modulation_period(choppers: DiskChoppers[RunType]) -> sc.Variable:


def powder_beamline_geometry_graph(
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
sample_position: Position[snx.NXsample, RunType],
gravity: GravityVector,
) -> BeamlineGeometryGraph[RunType]:
Expand All @@ -113,7 +113,7 @@ def powder_beamline_geometry_graph(


def modulation_beamline_geometry_graph(
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
sample_position: Position[snx.NXsample, RunType],
gravity: GravityVector,
choppers: ActiveDiskChoppers[RunType],
Expand Down
16 changes: 11 additions & 5 deletions packages/essdiffraction/src/ess/beer/mcstas/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
import mcstastox
import scipp as sc
import scippnexus as snx
from ess.powder.types import CaveMonitor, EmptyDetector, RunType, WavelengthMonitor
from ess.powder.types import (
CaveMonitor,
EmptyDetector,
NeutronSourcePosition,
RunType,
WavelengthMonitor,
)

from ess.reduce.nexus.types import DiskChoppers, Position
from ess.reduce.unwrap.types import DetectorLtotal
Expand Down Expand Up @@ -273,7 +279,7 @@ def chopper_mode_from_mcstas_mode(mode: str) -> PulseShapingMode | ModulationMod

def mcstas_source_position(
fname: Filename[RunType], sample_position: Position[snx.NXsample, RunType]
) -> Position[snx.NXsource, RunType]:
) -> NeutronSourcePosition[RunType]:
"""Return the effective source position for the McStas geometry.

``sourceMantid`` is close to the choppers and its direction towards the sample
Expand Down Expand Up @@ -314,7 +320,7 @@ def mcstas_sample_position(

def mcstas_choppers(
da: RawDetector[RunType],
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
) -> DiskChoppers[RunType]:
"""Return BEER choppers for the McStas mode in the data."""
mode = chopper_mode_from_mcstas_mode(da.coords['mode'].value)
Expand All @@ -323,7 +329,7 @@ def mcstas_choppers(

def _mcstas_choppers_from_file(
fname: Filename[RunType],
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
) -> DiskChoppers[RunType]:
"""Return BEER choppers without loading detector events."""
fname = Path(fname)
Expand All @@ -334,7 +340,7 @@ def _mcstas_choppers_from_file(

def mcstas_detector_ltotal(
detector: EmptyDetector[RunType],
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
sample_position: Position[snx.NXsample, RunType],
) -> DetectorLtotal[RunType]:
"""Return moderator-to-detector flight path lengths for BEER McStas data."""
Expand Down
5 changes: 3 additions & 2 deletions packages/essdiffraction/src/ess/dream/io/geant4.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Filename,
MonitorFilename,
MonitorType,
NeutronSourcePosition,
NeXusComponent,
NeXusDetectorName,
Position,
Expand Down Expand Up @@ -319,8 +320,8 @@ def assemble_monitor_data(
return RawMonitor[RunType, MonitorType](monitor)


def dummy_source_position() -> Position[snx.NXsource, RunType]:
return Position[snx.NXsource, RunType](
def dummy_source_position() -> NeutronSourcePosition[RunType]:
return NeutronSourcePosition[RunType](
sc.vector([np.nan, np.nan, np.nan], unit="mm")
)

Expand Down
7 changes: 4 additions & 3 deletions packages/essdiffraction/src/ess/dream/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
LookupTableFilename,
LookupTableRelativeErrorThreshold,
Measurement,
NeutronSourcePosition,
Position,
ReducerSoftware,
SampleRun,
Expand Down Expand Up @@ -219,9 +220,9 @@ def DreamGeant4Workflow(*, run_norm: RunNormalization, **kwargs) -> sciline.Pipe
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,
NeutronSourcePosition[SampleRun]: source_position,
NeutronSourcePosition[VanadiumRun]: source_position,
NeutronSourcePosition[EmptyCanRun]: source_position,
AccumulatedProtonCharge[SampleRun]: charge,
AccumulatedProtonCharge[VanadiumRun]: charge,
AccumulatedProtonCharge[EmptyCanRun]: charge,
Expand Down
3 changes: 2 additions & 1 deletion packages/essdiffraction/src/ess/powder/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DetectorTwoTheta,
EmptyDetector,
GravityVector,
NeutronSourcePosition,
Position,
RunType,
SampleRun,
Expand Down Expand Up @@ -105,7 +106,7 @@ def to_cif_format(self) -> sc.DataArray:

def detector_two_theta(
detector: EmptyDetector[RunType],
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
sample_position: Position[snx.NXsample, RunType],
gravity: GravityVector,
) -> DetectorTwoTheta[RunType]:
Expand Down
5 changes: 3 additions & 2 deletions packages/essdiffraction/src/ess/powder/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
IntensityDspacing,
IntensityTof,
MonitorCoordTransformGraph,
NeutronSourcePosition,
Position,
QDetector,
RunType,
Expand Down Expand Up @@ -145,7 +146,7 @@ def to_dspacing_with_calibration(


def powder_coordinate_transformation_graph(
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
sample_position: Position[snx.NXsample, RunType],
gravity: GravityVector,
) -> ElasticCoordTransformGraph[RunType]:
Expand Down Expand Up @@ -256,7 +257,7 @@ def convert_reduced_to_empty_can_subtracted_tof(


def powder_monitor_coordinate_transformation_graph(
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
sample_position: Position[snx.NXsample, RunType],
gravity: GravityVector,
) -> MonitorCoordTransformGraph[RunType]:
Expand Down
1 change: 1 addition & 0 deletions packages/essdiffraction/src/ess/powder/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
GravityVector = reduce_t.GravityVector
RawMonitor = reduce_t.RawMonitor
MonitorPositionOffset = reduce_t.MonitorPositionOffset
NeutronSourcePosition = reduce_t.NeutronSourcePosition
NeXusDetectorName = reduce_t.NeXusDetectorName
NeXusMonitorName = reduce_t.NeXusName
NeXusComponent = reduce_t.NeXusComponent
Expand Down
9 changes: 5 additions & 4 deletions packages/essdiffraction/src/ess/snspowder/powgen/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
GravityVector,
MonitorCoordTransformGraph,
MonitorType,
NeutronSourcePosition,
Position,
ProtonCharge,
RawDataAndMetadata,
Expand Down Expand Up @@ -242,9 +243,9 @@ def extract_accumulated_proton_charge(
return AccumulatedProtonCharge[RunType](data.coords["gd_prtn_chrg"])


def source_position(dg: RawDataAndMetadata[RunType]) -> Position[snx.NXsource, RunType]:
def source_position(dg: RawDataAndMetadata[RunType]) -> NeutronSourcePosition[RunType]:
"""Return the source position from a loaded data group."""
return Position[snx.NXsource, RunType](dg["data"].coords["source_position"])
return NeutronSourcePosition[RunType](dg["data"].coords["source_position"])


def sample_position(dg: RawDataAndMetadata[RunType]) -> Position[snx.NXsample, RunType]:
Expand All @@ -268,7 +269,7 @@ def _coordinate_transformation_graph(


def detector_coordinate_transformation_graph(
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
sample_position: Position[snx.NXsample, RunType],
gravity: GravityVector,
) -> ElasticCoordTransformGraph[RunType]:
Expand Down Expand Up @@ -296,7 +297,7 @@ def detector_coordinate_transformation_graph(


def monitor_coordinate_transformation_graph(
source_position: Position[snx.NXsource, RunType],
source_position: NeutronSourcePosition[RunType],
sample_position: Position[snx.NXsample, RunType],
gravity: GravityVector,
) -> MonitorCoordTransformGraph[RunType]:
Expand Down
4 changes: 2 additions & 2 deletions packages/essdiffraction/tests/beer/mcstas_beamline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ess.beer.types import SampleRun

from ess.reduce import unwrap
from ess.reduce.nexus.types import Position
from ess.reduce.nexus.types import NeutronSourcePosition
from ess.reduce.unwrap import lut


Expand All @@ -24,7 +24,7 @@ def test_can_make_analytical_lookup_table_from_beer_choppers(
run_types=[SampleRun], monitor_types=[], wavelength_from="analytical"
)
source_position = sc.vector([0.0, 0.0, 0.0], unit="m")
wf[Position[snx.NXsource, SampleRun]] = source_position
wf[NeutronSourcePosition[SampleRun]] = source_position
wf[unwrap.DiskChoppers[SampleRun]] = simulation_choppers(mode, source_position)
wf[lut.LtotalRange[SampleRun, snx.NXdetector]] = (
sc.scalar(150.0, unit="m"),
Expand Down
3 changes: 2 additions & 1 deletion packages/essdiffraction/tests/beer/mcstas_reduction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
ElasticCoordTransformGraph,
EmptyDetector,
KeepEvents,
NeutronSourcePosition,
NormalizedDspacing,
PixelMasks,
QDetector,
Expand Down Expand Up @@ -229,7 +230,7 @@ def test_beer_workflows_compute_dspacing_bins(make_workflow, mode, pulse_skippin

if pulse_skipping:
# Use pulse-skipping choppers with the existing detector geometry.
source_position = wf.compute(Position[snx.NXsource, SampleRun])
source_position = wf.compute(NeutronSourcePosition[SampleRun])
chopper_mode = ModulationMode.ds0 if mode == 7 else PulseShapingMode.ds1
wf[DiskChoppers[SampleRun]] = simulation_choppers(chopper_mode, source_position)

Expand Down
6 changes: 3 additions & 3 deletions packages/essdiffraction/tests/dream/geant4_reduction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
KeepEvents,
LookupTableFilename,
MonitorFilename,
NeutronSourcePosition,
NeXusDetectorName,
OutFilename,
PixelMaskFilenames,
Expand All @@ -44,11 +45,10 @@
WavelengthMask,
)
from scippneutron import metadata
from scippnexus import NXsource

from ess.reduce import unwrap
from ess.reduce import workflow as reduce_workflow
from ess.reduce.nexus.types import AnyRun, Position
from ess.reduce.nexus.types import AnyRun

PARAMETRIZATION = ("detector_name", ["mantle", "endcap_backward", "endcap_forward"])

Expand All @@ -62,7 +62,7 @@
MonitorFilename[VanadiumRun]: dream.data.simulated_monitor_vanadium_sample(),
MonitorFilename[EmptyCanRun]: dream.data.simulated_monitor_empty_can(),
dream.InstrumentConfiguration: dream.beamline.InstrumentConfiguration.high_flux_BC215, # noqa: E501
Position[NXsource, AnyRun]: sc.vector(value=[0, 0, -76.55], unit="m"),
NeutronSourcePosition[AnyRun]: sc.vector(value=[0, 0, -76.55], unit="m"),
CalibrationFilename: None,
UncertaintyBroadcastMode: UncertaintyBroadcastMode.drop,
DspacingBins: sc.linspace('dspacing', 0.0, 2.3434, 201, unit='angstrom'),
Expand Down
2 changes: 1 addition & 1 deletion packages/essimaging/docs/odin/odin-data-reduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"source": [
"from ess.odin.beamline import choppers\n",
"\n",
"disk_choppers = choppers(source_position=wf.compute(Position[snx.NXsource, SampleRun]))\n",
"disk_choppers = choppers(source_position=wf.compute(NeutronSourcePosition[SampleRun]))\n",
"wf[unwrap.DiskChoppers[SampleRun]] = disk_choppers"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"import scipp as sc\n",
"import scippnexus as snx\n",
"from ess.reduce import unwrap\n",
"from ess.reduce.nexus.types import AnyRun, Position\n",
"from ess.reduce.nexus.types import AnyRun, NeutronSourcePosition\n",
"from ess.odin.beamline import choppers"
]
},
Expand All @@ -42,7 +42,7 @@
"\n",
"wf = unwrap.LookupTableWorkflow()\n",
"wf[unwrap.DiskChoppers[AnyRun]] = disk_choppers\n",
"wf[Position[snx.NXsource, AnyRun]] = source_position\n",
"wf[NeutronSourcePosition[AnyRun]] = source_position\n",
"wf[unwrap.NumberOfSimulatedNeutrons] = 200_000 # Increase this number for more reliable results\n",
"wf[unwrap.SimulationSeed] = 1234\n",
"wf[unwrap.LtotalRange[AnyRun, snx.NXdetector]] = sc.scalar(5.0, unit=\"m\"), sc.scalar(65.0, unit=\"m\")\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"import scipp as sc\n",
"import scippnexus as snx\n",
"from ess.reduce import unwrap\n",
"from ess.reduce.nexus.types import AnyRun, Position"
"from ess.reduce.nexus.types import AnyRun, NeutronSourcePosition"
]
},
{
Expand All @@ -40,7 +40,7 @@
"\n",
"wf = unwrap.LookupTableWorkflow()\n",
"wf[unwrap.DiskChoppers[AnyRun]] = {}\n",
"wf[Position[snx.NXsource, AnyRun]] = source_position\n",
"wf[NeutronSourcePosition[AnyRun]] = source_position\n",
"wf[unwrap.NumberOfSimulatedNeutrons] = 200_000 # Increase this number for more reliable results\n",
"wf[unwrap.SimulationSeed] = 1234\n",
"wf[unwrap.LtotalRange[AnyRun, snx.NXdetector]] = sc.scalar(5.0, unit=\"m\"), sc.scalar(35.0, unit=\"m\")\n",
Expand Down
5 changes: 2 additions & 3 deletions packages/essimaging/tests/odin/data_reduction_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
Filename,
LookupTableFilename,
MaskingRules,
NeutronSourcePosition,
NeXusDetectorName,
NXsource,
OpenBeamRun,
Position,
RawDetector,
SampleRun,
TofDetector,
Expand All @@ -40,7 +39,7 @@ def _make_workflow(wavelength_from: unwrap.WavelengthLutMode) -> sl.Pipeline:
wf[LookupTableFilename] = odin.data.odin_wavelength_lookup_table()
else:
disk_choppers = odin_choppers(
source_position=wf.compute(Position[NXsource, SampleRun])
source_position=wf.compute(NeutronSourcePosition[SampleRun])
)
# Shortcut to set DiskChoppers for both [SampleRun, NXdetector] and
# [OpenBeamRun, NXdetector] at once
Expand Down
1 change: 1 addition & 0 deletions packages/essnmx/src/ess/nmx/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

RunType = nexus_types.RunType
SampleRun = nexus_types.SampleRun
NeutronSourcePosition = nexus_types.NeutronSourcePosition
TofDetector = unwrap_types.TofDetector


Expand Down
5 changes: 3 additions & 2 deletions packages/essnmx/src/ess/nmx/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from ess.reduce.nexus.types import (
EmptyDetector,
Filename,
NeutronSourcePosition,
NeXusComponent,
NeXusTransformation,
Position,
Expand Down Expand Up @@ -86,7 +87,7 @@ def assemble_sample_metadata(


def assemble_source_metadata(
source_position: Position[snx.NXsource, SampleRun],
source_position: NeutronSourcePosition[SampleRun],
) -> NMXSourceMetadata:
"""Assemble source metadata for NMX reduction workflow."""
return NMXSourceMetadata(position=source_position)
Expand Down Expand Up @@ -150,7 +151,7 @@ def assemble_detector_metadata(
detector_component: NeXusComponent[snx.NXdetector, SampleRun],
transformation: NeXusTransformation[snx.NXdetector, SampleRun],
sample_position: Position[snx.NXsample, SampleRun],
source_position: Position[snx.NXsource, SampleRun],
source_position: NeutronSourcePosition[SampleRun],
empty_detector: EmptyDetector[SampleRun],
) -> NMXDetectorMetadata:
"""Assemble detector metadata for NMX reduction workflow."""
Expand Down
Loading
Loading