2828 RunType ,
2929)
3030from .resample import rebin_strictly_increasing
31- from .to_events import to_events
3231from .types import (
3332 DetectorLtotal ,
3433 DetectorTofData ,
@@ -665,51 +664,13 @@ def monitor_time_of_flight_data(
665664 )
666665
667666
668- def _resample_tof_data (da : sc .DataArray ) -> sc .DataArray :
669- """
670- Histogrammed data that has been converted to `tof` will typically have
671- unsorted bin edges (due to either wrapping of `time_of_flight` or wavelength
672- overlap between subframes).
673- This function re-histograms the data to ensure that the bin edges are sorted.
674- It makes use of the ``to_events`` helper which generates a number of events in each
675- bin with a uniform distribution. The new events are then histogrammed using a set of
676- sorted bin edges.
677-
678- WARNING:
679- This function is highly experimental, has limitations and should be used with
680- caution. It is a workaround to the issue that rebinning data with unsorted bin
681- edges is not supported in scipp.
682- As such, this function is not part of the default set of providers, and needs to be
683- inserted manually into the workflow.
684-
685- Parameters
686- ----------
687- da:
688- Histogrammed data with the time-of-flight coordinate.
689- """
690- dim = next (iter (set (da .dims ) & {"time_of_flight" , "tof" }))
691- data = da .rename_dims ({dim : "tof" }).drop_coords (
692- [name for name in da .coords if name != "tof" ]
693- )
694- events = to_events (data , "event" )
695-
696- # Define a new bin width, close to the original bin width.
697- # TODO: this could be a workflow parameter
698- coord = da .coords ["tof" ]
699- bin_width = (coord [dim , 1 :] - coord [dim , :- 1 ]).nanmedian ()
700- rehist = events .hist (tof = bin_width )
701- return rehist .assign_coords (
702- {key : var for key , var in da .coords .items () if dim not in var .dims }
703- )
704-
705-
706667def resample_detector_time_of_flight_data (
707668 da : DetectorTofData [RunType ],
708669) -> ResampledDetectorTofData [RunType ]:
709670 """
710671 Resample the detector time-of-flight data to ensure that the bin edges are sorted.
711672 """
712- return ResampledDetectorTofData (rebin_strictly_increasing (da , dim = 'tof' ))
673+ return ResampledDetectorTofData [ RunType ] (rebin_strictly_increasing (da , dim = 'tof' ))
713674
714675
715676def resample_monitor_time_of_flight_data (
@@ -718,7 +679,9 @@ def resample_monitor_time_of_flight_data(
718679 """
719680 Resample the monitor time-of-flight data to ensure that the bin edges are sorted.
720681 """
721- return ResampledMonitorTofData (rebin_strictly_increasing (da , dim = 'tof' ))
682+ return ResampledMonitorTofData [RunType , MonitorType ](
683+ rebin_strictly_increasing (da , dim = 'tof' )
684+ )
722685
723686
724687def default_parameters () -> dict :
0 commit comments