scipp / essreduce

Common functionality for ESS data reduction
https://scipp.github.io/essreduce/
BSD 3-Clause "New" or "Revised" License
1 stars 1 forks source link

[Requirement] Tools for processing time-dependent instrument parameters #24

Open SimonHeybrock opened 4 months ago

SimonHeybrock commented 4 months ago

Executive summary

Instrument parameters are time dependent, this needs to be processed before, e.g., associating neutron events with parameter values

Context and background knowledge

Version 0.1 of summary written by @g5t:

time_parameter_report.pdf

Inputs

1-D DataArray, typically loaded from an NXlog in a NeXus file.

Methodology

To be determined for individual cases. See also attached PDF.

Outputs

Processed DataArray that can be used, e.g., with Scipp's event filtering.

Which interfaces are required?

Python module / function

Test cases

Creating synthetic data is easy and a good start, but we should consider testing robustness on real data.

Comments

This is likely very generic functionality and may result in addition of basic tools in Scipp as well as ScippNeutron.

jokasimr commented 1 month ago

Seems to me that the interface here should look something like this:

Input: A time dependent log. Output: A function that maps arrays of time-points to a DataArray containing the interpolated log values.

Example

class LinearInterpolation:
    def __init__(self, log_data):
        ...
    def __call__(self, time_range):
        ...
        return DataArray(interpolated_data_with_variance_in_time_range, coords={'time': ...}, masks={'interpolation_invalid_here_for_some_reason':  ...})

class SimpleConstantInterpolation:
    ...
class StepwiseInterpolation:
    ...
class FancySplineInterpolation:
    ...

# usage:
log_data_interpolated = LinearInterpolation(raw_log_data)
values = log_data_interpolated(sc.linspace('time', 1, 5, 50, unit='s'))
other_values = log_data_interpolated(sc.linspace('time', 5, 6, 10, unit='s'))

This would cover the cases in the time-parameter report by @g5t and it would make a simple interface for downstream code using values from the log.

This would probably not need much changes, we already have the lookup method, and some wrappers around scipy.interpolate. It's mainly a question of putting it behind a uniform interface.