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,19 @@
"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",
"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 Expand Up @@ -136,7 +145,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
"version": "3.11.13"
}
},
"nbformat": 4,
Expand Down
130 changes: 130 additions & 0 deletions packages/essdiffraction/src/ess/beer/parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# 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,
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',
description='NeXus file path for the sample run.',
default=None,
)
parameters[Filename[VanadiumRun]] = ParameterSpec(
model=str | None,
category='Files',
title='Vanadium Run',
description='NeXus file path for the vanadium normalization run.',
default=None,
)
parameters[Filename[EmptyCanRun]] = ParameterSpec(
model=str | None,
category='Files',
title='Empty Can Run',
description='NeXus file path for the empty-can background run.',
default=None,
)
parameters[CalibrationFilename] = ParameterSpec(
model=str | None,
category='Files',
title='Calibration',
description='Path to the calibration file used for detector calibration.',
default=None,
)
parameters[MonitorFilename[SampleRun]] = ParameterSpec(
model=str | None,
category='Files',
title='Sample Monitor',
description='NeXus file path for the sample monitor data.',
default=None,
)
parameters[PixelMaskFilename] = ParameterSpec(
model=tuple[str, ...],
category='Files',
title='Pixel Masks',
description='Comma-separated paths to detector pixel mask files.',
default=(),
apply=with_pixel_mask_filenames,
)

parameters[NeXusDetectorName] = ParameterSpec(
model=str,
category='NeXus',
title='Detector',
description='Name of the detector group in the NeXus files.',
default='detector',
)

parameters[DspacingBins] = ParameterSpec(
model=DspacingEdges,
category='Binning',
title='D-spacing Edges',
description='D-spacing bin edges used for diffraction intensity outputs.',
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',
description='Two-theta bin edges used for two-dimensional diffraction outputs.',
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',
description='How uncertainties are broadcast when reduced data are combined.',
default=UncertaintyBroadcastMode.upper_bound,
)
parameters[DetectorBank] = ParameterSpec(
model=DetectorBank,
category='Reduction',
title='Detector Bank',
description='BEER detector bank to include in the reduction.',
default=DetectorBank.south,
)


typical_outputs = (
IntensityDspacing[SampleRun],
IntensityDspacingTwoTheta[SampleRun],
ReducedTofCIF,
)
60 changes: 48 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,65 @@
CalibrationData,
CaveMonitor,
EmptyCanRun,
Filename,
KeepEvents,
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,
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 +51 to +65

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(parameters=parameters, typical_outputs=typical_outputs)
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 +80,14 @@ def BeerModMcStasWorkflow():
params=default_parameters,
constraints={RunType: (SampleRun,)},
)
return wf


@register_workflow(parameters=parameters, typical_outputs=typical_outputs)
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 +96,21 @@ def BeerModMcStasWorkflowKnownPeaks():
params=default_parameters,
constraints={RunType: (SampleRun,)},
)
return wf


@register_workflow(parameters=parameters, typical_outputs=typical_outputs)
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,)},
)
return wf


@register_workflow(parameters=parameters, typical_outputs=typical_outputs)
def BeerMcStasWorkflowPulseShapingAnalytical():
"""Workflow to process BEER pulse-shaping McStas files using analytical
frame unwrapping."""
Expand All @@ -99,8 +129,11 @@ def BeerMcStasWorkflowPulseShapingAnalytical():
return wf


@register_workflow(parameters=parameters, typical_outputs=typical_outputs)
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 @@ -134,8 +167,11 @@ def BeerPowderWorkflow(
return wf


@register_workflow(parameters=parameters, typical_outputs=typical_outputs)
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 @@ -176,19 +212,19 @@ def BeerPowderWorkflowAnalytical(
return wf


@register_workflow(parameters=parameters, typical_outputs=typical_outputs)
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)

return wf


@register_workflow(parameters=parameters, typical_outputs=typical_outputs)
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)

return wf
Loading
Loading