Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Monte-Carlo simulations for frame unwrapping and WFM #163

Merged
merged 50 commits into from
Jan 23, 2025
Merged
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e6dc175
bring in unwrap module from scippneutron and turn types into generics
nvaytet Jan 15, 2025
0845ec6
initial working version of workflow, with first wfm tests
nvaytet Jan 16, 2025
d4b2ba9
add unwrap tests
nvaytet Jan 16, 2025
bac2407
add to_events tests
nvaytet Jan 16, 2025
f8547ea
fix last tests and start adding notebooks
nvaytet Jan 16, 2025
2927ca0
update docs
nvaytet Jan 16, 2025
8a3c0ac
add missing docstrings
nvaytet Jan 16, 2025
769cf91
fix formatting
nvaytet Jan 16, 2025
55a83d9
Merge branch 'main' into unwrap-tof
nvaytet Jan 16, 2025
1824760
fix imports and dependencies
nvaytet Jan 16, 2025
98267c9
update tox ini for nightly deps
nvaytet Jan 16, 2025
7816dc5
update deps
nvaytet Jan 16, 2025
45b19ed
add workflow
nvaytet Jan 16, 2025
052919e
fix distances and add helper class to create workflow and cache expen…
nvaytet Jan 17, 2025
4b74bd7
remove commented code
nvaytet Jan 17, 2025
ea6d5c2
compute variances on tof instead
nvaytet Jan 17, 2025
770c80a
Apply automatic formatting
pre-commit-ci-lite[bot] Jan 17, 2025
d5c82aa
move applying nans where masked to masking provider
nvaytet Jan 17, 2025
0bc07e7
Merge branch 'unwrap-tof' of github.com:scipp/essreduce into unwrap-tof
nvaytet Jan 17, 2025
6932051
use relative error
nvaytet Jan 17, 2025
f917644
fix values units
nvaytet Jan 17, 2025
5d7720f
fix naming start_time -> pivot_time and fix table when ltot_min = lto…
nvaytet Jan 17, 2025
04aa7b9
update dream notebook
nvaytet Jan 17, 2025
4f0229d
update wfm notebook
nvaytet Jan 17, 2025
3f17b46
update frame unwrapping notebook
nvaytet Jan 17, 2025
0242581
fix unwrap tests
nvaytet Jan 17, 2025
8cac75f
start fixing wfm tests
nvaytet Jan 20, 2025
9f2cc93
fix table range and some more tests
nvaytet Jan 20, 2025
15e18dd
clarify docstring for LtotalRange
nvaytet Jan 20, 2025
d787d23
ReHistogrammed -> Resampled
nvaytet Jan 20, 2025
5324701
update docstrings
nvaytet Jan 20, 2025
114100a
add docstring to SimulationResults
nvaytet Jan 20, 2025
b19acf1
clarify distance resolutino
nvaytet Jan 20, 2025
a81ff6f
decouple tof simulation from unwrap pipeline by only supplying the Si…
nvaytet Jan 20, 2025
773a380
use module scope fixture to run simulation and speed up tests
nvaytet Jan 20, 2025
7dd1d5f
Apply automatic formatting
pre-commit-ci-lite[bot] Jan 20, 2025
e5e720f
use simulation results as input arg to TofWorkflow
nvaytet Jan 20, 2025
1c68772
formatting
nvaytet Jan 20, 2025
dde1b78
Merge branch 'unwrap-tof' of github.com:scipp/essreduce into unwrap-tof
nvaytet Jan 20, 2025
8e5074c
update wfm and dream notebooks
nvaytet Jan 20, 2025
cad4de5
update frame unwrapping notebook
nvaytet Jan 20, 2025
998af65
clarify shape of members in SimulationResults
nvaytet Jan 20, 2025
68e4d47
fix argument name in dream notebook
nvaytet Jan 20, 2025
7e8d164
update fakes module docstring
nvaytet Jan 21, 2025
64f9acc
update comments
nvaytet Jan 21, 2025
02f22b1
use assign_coords for cleaner code
nvaytet Jan 22, 2025
13460df
add comment about correlations in variances
nvaytet Jan 22, 2025
19142a2
bump scipp version
nvaytet Jan 23, 2025
b417f73
update deps
nvaytet Jan 23, 2025
1a32329
Merge branch 'main' into unwrap-tof
nvaytet Jan 23, 2025
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
Prev Previous commit
Next Next commit
use simulation results as input arg to TofWorkflow
nvaytet committed Jan 20, 2025
commit e5e720fe5dab081daa9ab3345f6f1ee4ded90917
54 changes: 39 additions & 15 deletions src/ess/reduce/time_of_flight/toa_to_tof.py
Original file line number Diff line number Diff line change
@@ -461,29 +461,55 @@ class TofWorkflow:
"""
Helper class to build a time-of-flight workflow and cache the expensive part of
the computation: running the simulation and building the lookup table.

Parameters
----------
simulated_neutrons:
Results of a time-of-flight simulation used to create a lookup table.
The results should be a flat table with columns for time-of-arrival, speed,
wavelength, and weight.
ltotal_range:
Range of total flight path lengths from the source to the detector.
This is used to create the lookup table to compute the neutron time-of-flight.
Note that the resulting table will extend slightly beyond this range, as the
supplied range is not necessarily a multiple of the distance resolution.
pulse_stride:
Stride of used pulses. Usually 1, but may be a small integer when
pulse-skipping.
pulse_stride_offset:
Integer offset of the first pulse in the stride (typically zero unless we are
using pulse-skipping and the events do not begin with the first pulse in the
stride).
distance_resolution:
Resolution of the distance axis in the lookup table.
Should be a single scalar value with a unit of length.
This is typically of the order of 1-10 cm.
toa_resolution:
Resolution of the time of arrival axis in the lookup table.
Can be an integer (number of bins) or a sc.Variable (bin width).
error_threshold:
Threshold for the variance of the projected time-of-flight above which regions
are masked.
"""

def __init__(
self,
choppers,
facility,
ltotal_range,
pulse_stride=None,
pulse_stride_offset=None,
distance_resolution=None,
toa_resolution=None,
error_threshold=None,
seed=None,
number_of_neutrons=None,
simulated_neutrons: SimulationResults,
ltotal_range: LtotalRange,
pulse_stride: PulseStride | None = None,
pulse_stride_offset: PulseStrideOffset | None = None,
distance_resolution: DistanceResolution | None = None,
toa_resolution: TimeOfArrivalResolution | None = None,
error_threshold: LookupTableRelativeErrorThreshold | None = None,
):
import sciline as sl

self.pipeline = sl.Pipeline(standard_providers())
self.pipeline[Facility] = facility
self.pipeline[Choppers] = choppers
self.pipeline = sl.Pipeline(providers())
self.pipeline[SimulationResults] = simulated_neutrons
self.pipeline[LtotalRange] = ltotal_range

params = default_parameters()
self.pipeline[PulsePeriod] = params[PulsePeriod]
self.pipeline[PulseStride] = pulse_stride or params[PulseStride]
self.pipeline[PulseStrideOffset] = (
pulse_stride_offset or params[PulseStrideOffset]
@@ -497,8 +523,6 @@ def __init__(
self.pipeline[LookupTableRelativeErrorThreshold] = (
error_threshold or params[LookupTableRelativeErrorThreshold]
)
self.pipeline[SimulationSeed] = seed or params[SimulationSeed]
self.pipeline[NumberOfNeutrons] = number_of_neutrons or params[NumberOfNeutrons]

def __getitem__(self, key):
return self.pipeline[key]
2 changes: 0 additions & 2 deletions src/ess/reduce/time_of_flight/types.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2025 Scipp contributors (https://github.com/scipp)

from collections.abc import Mapping
from dataclasses import dataclass
from typing import NewType

import scipp as sc
from scippneutron.chopper import DiskChopper

Ltotal = NewType("Ltotal", sc.Variable)
"""