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 @@ -47,7 +47,13 @@
},
"outputs": [],
"source": [
"from ess.powder.types import DspacingBins, Filename, SampleRun, VanadiumRun\n",
"from ess.powder.types import (\n",
" DspacingBins,\n",
" Filename,\n",
" SampleRun,\n",
" UncertaintyBroadcastMode,\n",
" VanadiumRun,\n",
")\n",
"import ess.dream.data # noqa: F401\n",
"from ess.dream import InstrumentConfiguration\n",
"\n",
Expand All @@ -59,16 +65,20 @@
"wfw = widget.children[1].children[0]\n",
"outputs = wfw.output_selection_box.typical_outputs_widget\n",
"keys, values = zip(*outputs.options, strict=True)\n",
"ind = keys.index(\"IntensityDspacing[SampleRun]\")\n",
"ind = keys.index(\"IntensityDspacingTwoTheta[SampleRun]\")\n",
"outputs.value = (values[ind],)\n",
"# Refresh parameters\n",
"pbox = wfw.parameter_box\n",
"pbox.parameter_refresh_button.click()\n",
"# Set parameters\n",
"pbox._input_widgets[Filename[SampleRun]].children[0].value = str(dream.data.simulated_diamond_sample())\n",
"pbox._input_widgets[Filename[VanadiumRun]].children[0].value = str(dream.data.simulated_vanadium_sample())\n",
"pbox._input_widgets[InstrumentConfiguration].value = InstrumentConfiguration.high_flux_BC215\n",
"pbox._input_widgets[DspacingBins].fields[\"stop\"].value = 2.3434\n",
"wfw.parameter_box.parameter_refresh_button.click()\n",
"ui.set_parameter_widget_values(\n",
" wfw,\n",
" {\n",
" Filename[SampleRun]: str(dream.data.simulated_diamond_sample()),\n",
" Filename[VanadiumRun]: str(dream.data.simulated_vanadium_sample()),\n",
" InstrumentConfiguration: InstrumentConfiguration.high_flux_BC215,\n",
" UncertaintyBroadcastMode: UncertaintyBroadcastMode.drop,\n",
" DspacingBins: {\"stop\": 2.3434},\n",
" },\n",
")\n",
"# Run the workflow\n",
"rbox = wfw.result_box\n",
"rbox.run_button.click()"
Expand Down
121 changes: 121 additions & 0 deletions packages/essdiffraction/src/ess/beer/parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2024 Scipp contributors (https://github.com/scipp)
"""Default parameter specs for BEER workflows."""

from __future__ import annotations

from math import pi

from ess.powder.masking import with_pixel_mask_filenames
from ess.powder.types import (
CalibrationFilename,
DspacingBins,
EmptyCanRun,
Filename,
IntensityDspacing,
IntensityDspacingTwoTheta,
MaskedDetectorIDs,
MonitorFilename,
NeXusDetectorName,
PixelMaskFilename,
ReducedTofCIF,
SampleRun,
TwoThetaBins,
UncertaintyBroadcastMode,
VanadiumRun,
)

from ess.reduce.parameter import ParameterRegistry, ParameterSpec
from ess.reduce.parameter_models import AngleUnit, DspacingEdges, TwoTheta

from .types import DetectorBank


def _edges(model):
return model.get_edges()


parameters = ParameterRegistry()

parameters[Filename[SampleRun]] = ParameterSpec(
model=str | None,
category='Files',
title='Sample Run',
default=None,
)
parameters[Filename[VanadiumRun]] = ParameterSpec(
model=str | None,
category='Files',
title='Vanadium Run',
default=None,
)
parameters[Filename[EmptyCanRun]] = ParameterSpec(
model=str | None,
category='Files',
title='Empty Can Run',
default=None,
)
parameters[CalibrationFilename] = ParameterSpec(
model=str | None,
category='Files',
title='Calibration',
default=None,
)
parameters[MonitorFilename[SampleRun]] = ParameterSpec(
model=str | None,
category='Files',
title='Sample Monitor',
default=None,
)
parameters[PixelMaskFilename] = ParameterSpec(
model=tuple[str, ...],
category='Files',
title='Pixel Masks',
default=(),
apply=with_pixel_mask_filenames,
filter_keys=(MaskedDetectorIDs, PixelMaskFilename),
)

parameters[NeXusDetectorName] = ParameterSpec(
model=str,
category='NeXus',
title='Detector',
default='detector',
)

parameters[DspacingBins] = ParameterSpec(
model=DspacingEdges,
category='Binning',
title='D-spacing Edges',
default=DspacingEdges(start=0.0, stop=2.0, num_bins=200),
transform=_edges,
use_workflow_default=False,
)
parameters[TwoThetaBins] = ParameterSpec(
model=TwoTheta,
category='Binning',
title='Two-Theta Edges',
default=TwoTheta(start=0.0, stop=pi, num_bins=180, unit=AngleUnit.RADIAN),
transform=_edges,
use_workflow_default=False,
)

parameters[UncertaintyBroadcastMode] = ParameterSpec(
model=UncertaintyBroadcastMode,
category='Reduction',
title='Uncertainty Broadcast',
default=UncertaintyBroadcastMode.upper_bound,
)
parameters[DetectorBank] = ParameterSpec(
model=DetectorBank,
category='Reduction',
title='Detector Bank',
default=DetectorBank.south,
)


typical_outputs = (
IntensityDspacing[SampleRun],
IntensityDspacingTwoTheta[SampleRun],
ReducedTofCIF,
)
76 changes: 64 additions & 12 deletions packages/essdiffraction/src/ess/beer/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,67 @@
CalibrationData,
CaveMonitor,
EmptyCanRun,
Filename,
KeepEvents,
MaskedDetectorIDs,
NeXusDetectorName,
RunType,
SampleRun,
TofMask,
TwoThetaMask,
VanadiumRun,
WavelengthMask,
)

from ess.reduce.nexus.types import DetectorBankSizes, NeXusName
from ess.reduce.unwrap import GenericUnwrapWorkflow
from ess.reduce.unwrap.types import LookupTableRelativeErrorThreshold
from ess.reduce.workflow import register_workflow

from .clustering import providers as clustering_providers
from .conversions import convert_from_known_peaks_providers, convert_pulse_shaping
from .conversions import providers as conversion_providers
from .data import (
mcstas_powder_empty_can,
mcstas_powder_silicon_in_vanadium_can,
mcstas_powder_vanadium,
)
from .mcstas import (
mcstas_modulation_period_from_mode,
mcstas_providers,
pulse_shaping_mcstas_providers,
)
from .types import (
PulseLength,
)
from .parameters import parameters, typical_outputs
from .types import DetectorBank, PulseLength

default_parameters = {
CalibrationData: None,
PulseLength: sc.scalar(0.003, unit='s'),
DetectorBankSizes: {
'south_detector': {'y': 200, 'x': 500},
'north_detector': {'y': 200, 'x': 500},
DetectorBank.south: {'y': 200, 'x': 500},
DetectorBank.north: {'y': 200, 'x': 500},
},
KeepEvents[RunType]: KeepEvents(False),
TwoThetaMask: lambda two_theta: (
(two_theta < sc.scalar(float('inf'), unit=two_theta.unit))
| (two_theta > sc.scalar(float('-inf'), unit=two_theta.unit))
),
TofMask: None,
WavelengthMask: None,
MaskedDetectorIDs: MaskedDetectorIDs({}),
NeXusDetectorName: "detector",
DetectorBank: DetectorBank.south,
Filename[SampleRun]: str(mcstas_powder_silicon_in_vanadium_can()),
Filename[VanadiumRun]: str(mcstas_powder_vanadium()),
Filename[EmptyCanRun]: str(mcstas_powder_empty_can()),
Comment on lines +52 to +67

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes will be revisited or removed.

They were added mainly for debugging purposes.

}


@register_workflow
def BeerModMcStasWorkflow():
"""Workflow to process BEER (modulation regime) McStas files without a list
of estimated peak positions."""
return sl.Pipeline(
wf = sl.Pipeline(
(
*mcstas_providers,
mcstas_modulation_period_from_mode,
Expand All @@ -56,12 +82,16 @@ def BeerModMcStasWorkflow():
params=default_parameters,
constraints={RunType: (SampleRun,)},
)
wf.typical_outputs = typical_outputs
wf.parameter_registry = parameters
return wf


@register_workflow
def BeerModMcStasWorkflowKnownPeaks():
"""Workflow to process BEER (modulation regime) McStas files using a list
of estimated peak positions."""
return sl.Pipeline(
wf = sl.Pipeline(
(
*mcstas_providers,
mcstas_modulation_period_from_mode,
Expand All @@ -70,17 +100,25 @@ def BeerModMcStasWorkflowKnownPeaks():
params=default_parameters,
constraints={RunType: (SampleRun,)},
)
wf.typical_outputs = typical_outputs
wf.parameter_registry = parameters
return wf


@register_workflow
def BeerMcStasWorkflowPulseShaping():
"""Workflow to process BEER (pulse shaping modes) McStas files"""
return sl.Pipeline(
wf = sl.Pipeline(
(*mcstas_providers, *convert_pulse_shaping),
params=default_parameters,
constraints={RunType: (SampleRun,)},
)
wf.typical_outputs = typical_outputs
wf.parameter_registry = parameters
return wf


@register_workflow
def BeerMcStasWorkflowPulseShapingAnalytical():
"""Workflow to process BEER pulse-shaping McStas files using analytical
frame unwrapping."""
Expand All @@ -96,11 +134,16 @@ def BeerMcStasWorkflowPulseShapingAnalytical():
wf[key] = value
wf[NeXusName[snx.NXdetector]] = 'detector'
wf[LookupTableRelativeErrorThreshold] = {'detector': float('inf')}
wf.typical_outputs = typical_outputs
wf.parameter_registry = parameters
return wf


@register_workflow
def BeerPowderWorkflow(
*, run_norm: RunNormalization = RunNormalization.monitor_integrated, **kwargs
*,
run_norm: RunNormalization = RunNormalization.monitor_integrated,
**kwargs,
) -> sl.Pipeline:
"""
Beer powder workflow with default parameters.
Expand Down Expand Up @@ -131,11 +174,16 @@ def BeerPowderWorkflow(
insert_run_normalization(wf, run_norm)
for key, value in default_parameters.items():
wf[key] = value
wf.typical_outputs = typical_outputs
wf.parameter_registry = parameters
return wf


@register_workflow
def BeerPowderWorkflowAnalytical(
*, run_norm: RunNormalization = RunNormalization.monitor_integrated, **kwargs
*,
run_norm: RunNormalization = RunNormalization.monitor_integrated,
**kwargs,
) -> sl.Pipeline:
"""
Beer powder workflow using analytical lookup-table frame unwrapping.
Expand Down Expand Up @@ -173,22 +221,26 @@ def BeerPowderWorkflowAnalytical(
'monitor_bunker': float('inf'),
'monitor_cave': float('inf'),
}
wf.typical_outputs = typical_outputs
wf.parameter_registry = parameters
return wf


@register_workflow
def BeerPowderMcStasWorkflow(**kwargs) -> sl.Pipeline:
"""Create the BEER powder workflow with McStas loaders inserted."""
wf = BeerPowderWorkflow(**kwargs)
for provider in mcstas_providers:
wf.insert(provider)

wf.parameter_registry = parameters
return wf


@register_workflow
def BeerPowderMcStasWorkflowAnalytical(**kwargs) -> sl.Pipeline:
"""Create the BEER analytical powder workflow with McStas loaders inserted."""
wf = BeerPowderWorkflowAnalytical(**kwargs)
for provider in itertools.chain(mcstas_providers, pulse_shaping_mcstas_providers):
wf.insert(provider)

wf.parameter_registry = parameters
return wf
Loading
Loading