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

Merge branch 'auto_window_finder' of http://git.esss.dk/wedel/wfm_stitching into auto_window_finder

parents 7e31b3cb 72ff204c
......@@ -18,9 +18,10 @@
# *********************************************************************
import numpy as np
from .readout_gaps import ReadoutGaps
from readout_gaps import ReadoutGaps
from itertools import chain
from mantid.simpleapi import *
import matplotlib.pyplot as plt
def _wfm_psc_1():
......@@ -138,6 +139,7 @@ class WFMProcessor(object):
# at the end.
sum_workspace = None
for i, (x_min, x_max) in enumerate(zip(gap_data[::2], gap_data[1::2])):
print("READOUT GAPS:", x_min, x_max)
extract_spectra_params = {
'OutputWorkspace': '{}_readout_region_{}'.format(workspace_name, i + 1),
'XMin': x_min,
......@@ -203,6 +205,7 @@ class WFMProcessor(object):
else:
Plus(LHSWorkspace=summed_ws, RHSWorkspace=current_ws_name,
OutputWorkspace=summed_ws)
print("Memory: ", mtd[current_ws_name].getMemorySize(), mtd[summed_ws].getMemorySize())
if delete_temporary_workspace:
DeleteWorkspace(current_ws_name)
......@@ -211,8 +214,63 @@ 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)
print("Memory: input_workspace ", mtd[input_workspace].getMemorySize())
Rebin(InputWorkspace=input_workspace, OutputWorkspace='tmp', Params=slice_parameters, PreserveEvents=False)
# print("Memory: tmp 1 ", mtd['tmp'].getMemorySize())
ScaleX(InputWorkspace='tmp', OutputWorkspace='tmp', Factor=shift_parameter,
Operation='Add')
# print("Memory: tmp 2 ", mtd['tmp'].getMemorySize())
Rebin(InputWorkspace='tmp', OutputWorkspace='tmp', Params=rebin_parameters)
print("Memory: tmp ", mtd['tmp'].getMemorySize())
RenameWorkspace(InputWorkspace='tmp', OutputWorkspace=output_workspace)
def event_stitching(self, input_workspace, output_workspace):
specinfo = input_workspace.spectrumInfo()
for index, spec in enumerate(specinfo):
event_list = input_workspace.getSpectrum(index)
nevents = event_list.getNumberEvents()
if nevents > 0:
print(event_list.getNumberEvents())
# events = event_list.getEvents()
tofs = event_list.getTofs()
# print(np.amin(tofs), np.amax(tofs))
# print("tofs[0]", tofs[0])
# tofs[0] = 111.0
# print("tofs[0]", tofs[0])
fig = plt.figure()
ax1 = fig.add_subplot(211)
ax2 = fig.add_subplot(212)
bins = np.arange(0, 72000.0, 256)
ax1.hist(tofs, bins=bins, label='before')
# First exclude all events that are outside the frames
selection = np.where(np.logical_or(
tofs < self.frame_parameters[0],
np.logical_or(np.logical_and(tofs > self.frame_parameters[1], tofs < self.frame_parameters[2]),
np.logical_or(np.logical_and(tofs > self.frame_parameters[3], tofs < self.frame_parameters[4]),
np.logical_or(np.logical_and(tofs > self.frame_parameters[5], tofs < self.frame_parameters[6]),
np.logical_or(np.logical_and(tofs > self.frame_parameters[7], tofs < self.frame_parameters[8]),
np.logical_or(np.logical_and(tofs > self.frame_parameters[9], tofs < self.frame_parameters[10]),
tofs > self.frame_parameters[11]
)))))))
# selection = np.where(tofs < self.frame_parameters[0])
tofs[selection] = -1.0
# ax2.hist(tofs, bins=bins, label='after')
# fig.savefig('hist.pdf')
# exit()
# Then process each frame
for i in range(len(self.frame_parameters)//2):
print(self.frame_parameters[i*2], self.frame_parameters[i*2+1], self.frame_shifts[i])
selection = np.where(np.logical_and(tofs > self.frame_parameters[i*2], tofs < self.frame_parameters[i*2+1]))
tofs[selection] += self.frame_shifts[i]
ax2.hist(tofs, bins=bins, label='after')
fig.savefig('hist.pdf')
exit()
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