Commit 54933377 authored by Neil Vaytet's avatar Neil Vaytet
Browse files

Merge branch 'auto_window_finder' into 'master'

Automatic frame edge finder

See merge request !8
parents 7a705ecc b2ae333e
......@@ -17,5 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# *********************************************************************
from wfm_processing import WFMProcessor, make_frame_shifts
from data_handling import load, save_fits_stack, normalize
\ No newline at end of file
from .wfm_processing import WFMProcessor, make_frame_shifts, get_frame_shifts
from .data_handling import load, save_fits_stack, normalize
from .get_wfm_windows import get_wfm_windows
This diff is collapsed.
......@@ -17,11 +17,56 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# *********************************************************************
import numpy as np
from .readout_gaps import ReadoutGaps
from itertools import chain
from mantid.simpleapi import *
import matplotlib.pyplot as plt
def _wfm_psc_1():
"""
Definition V20 for wfm pulse shaping chopper 1 (closest to source)
:return: Returns the sorted angles of all edges in degrees. First entry is start angle of the first cut-out
second entry is end angle of first cut-out
"""
return [83.71, 94.7, 140.49, 155.79, 193.26, 212.56, 242.32, 265.33, 287.91, 314.37, 330.3, 360.0]
def _wfm_psc_2():
"""
Definition V20 for wfm pulse shaping chopper 2 (closest to sample)
:return: Returns the sorted angles of all edges in degrees. First entry is start angle of the first cut-out
second entry is end angle of first cut-out
"""
return [65.04, 76.03, 126.1, 141.4, 182.88, 202.18, 235.67, 254.97, 284.73, 307.74, 330.00, 360.0]
def _tof_shifts(pscdata, psc_frequency=0):
cut_out_centre = np.reshape(pscdata,(len(pscdata)//2, 2)).mean(1)
cut_out_diffs = np.ediff1d(cut_out_centre)
return cut_out_diffs / (360.0*psc_frequency)
def get_frame_shifts(frequency_wfm_psc=None):
"""
This function generates a list of proper shifting parameters from psc data.
:param frequency_wfm_psc: Rotation frequency in Hz for WFM phase shaping choppers 1 & 2.
:return: List of relative frame shifts in microseconds.
"""
if type(frequency_wfm_psc) == list:
frequ1 = frequency_wfm_psc[0]
frequ2 = frequency_wfm_psc[1]
elif type(frequency_wfm_psc) == int:
frequ1 = frequency_wfm_psc
frequ2 = frequency_wfm_psc
else:
raise TypeError("Unknown frequency type")
relative_shifts = (_tof_shifts(_wfm_psc_1(), psc_frequency=frequ1) + \
_tof_shifts(_wfm_psc_2(), psc_frequency=frequ2)) * \
5.0e+05 # factor of 0.5 * 1.0e6 (taking mean and converting to microseconds)
return -relative_shifts
def make_frame_shifts(initial_shift, other_shifts=(-2420, -2253, -2095, -1946, -1810)):
"""
This function constructs a list of proper shifting parameters for wavelength frames.
......@@ -167,8 +212,9 @@ class WFMProcessor(object):
def _transform_frame(self, input_workspace, output_workspace, slice_parameters,
shift_parameter, rebin_parameters):
Rebin(InputWorkspace=input_workspace, OutputWorkspace='tmp', Params=slice_parameters)
Rebin(InputWorkspace=input_workspace, OutputWorkspace='tmp', Params=slice_parameters, PreserveEvents=False)
ScaleX(InputWorkspace='tmp', OutputWorkspace='tmp', Factor=shift_parameter,
Operation='Add')
Rebin(InputWorkspace='tmp', OutputWorkspace='tmp', Params=rebin_parameters)
RenameWorkspace(InputWorkspace='tmp', OutputWorkspace=output_workspace)
return
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment