Skip to content

Commit

Permalink
Fixed background calculation and started to remove old unused code. T…
Browse files Browse the repository at this point in the history
…his refs #4303
  • Loading branch information
JeanBilheux committed Mar 8, 2012
1 parent c2c411b commit f8f6d5a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 173 deletions.
16 changes: 12 additions & 4 deletions Code/Mantid/Framework/PythonAPI/PythonAlgorithms/RefLReduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,14 @@ def PyExec(self):

ws_data_bck = "_DataBckWks"
ws_data_bck_1 = ws_data_bck + "_1"
Transpose(InputWorkspace=ws_transposed,
# Transpose(InputWorkspace=ws_transposed,
# OutputWorkspace=ws_data_bck_1)
Transpose(InputWorkspace=ws_transposed_1,
OutputWorkspace=ws_data_bck_1)
ws_data_bck_2 = ws_data_bck + "_2"
Transpose(InputWorkspace=ws_transposed,
# Transpose(InputWorkspace=ws_transposed,
# OutputWorkspace=ws_data_bck_2)
Transpose(InputWorkspace=ws_transposed_2,
OutputWorkspace=ws_data_bck_2)

ConvertToHistogram(ws_data_bck_1, OutputWorkspace=ws_data_bck_1)
Expand Down Expand Up @@ -365,7 +369,9 @@ def PyExec(self):
EndX=norm_peak[0],
OutputMode="Return Background")

Transpose(InputWorkspace=ws_transposed,
# Transpose(InputWorkspace=ws_transposed,
# OutputWorkspace=ws_data_bck_1)
Transpose(InputWorkspace=ws_transposed_1,
OutputWorkspace=ws_data_bck_1)

FlatBackground(InputWorkspace=ws_transposed,
Expand All @@ -375,7 +381,9 @@ def PyExec(self):
EndX=BacktoYpixel,
OutputMode="Return Background")

Transpose(InputWorkspace=ws_transposed,
# Transpose(InputWorkspace=ws_transposed,
# OutputWorkspace=ws_data_bck_2)
Transpose(InputWorkspace=ws_transposed_2,
OutputWorkspace=ws_data_bck_2)

ConvertToHistogram(InputWorkspace=ws_data_bck_1,
Expand Down
227 changes: 58 additions & 169 deletions Code/Mantid/scripts/reduction/instruments/reflectometer/wks_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,115 +222,8 @@ def convertWorkspaceToQ(ws_data,

#replace the _q_axis of the yrange of interest by the new
#individual _q_axis

y_size = toYpixel - fromYpixel + 1
y_range = arange(y_size) + fromYpixel


# #start of old code
# _y_axis = zeros((maxY, len(_tof_axis) - 1))
# _y_error_axis = zeros((maxY, len(_tof_axis) - 1))
#
# for y in y_range:
# _y_axis[int(y), :] = mt1.readY(int(y))[:]
# _y_error_axis[int(y), :] = mt1.readE(int(y))[:]
#
# for _q_index in range(y_size):
#
# _tmp_q_axis = _q_axis[_q_index]
# q_axis = _tmp_q_axis[::-1] #reverse the axis (now increasing order)
#
# _y_axis_tmp = _y_axis[yrange[_q_index],:]
# _y_axis_tmp = _y_axis_tmp.flatten()
#
# _y_error_axis_tmp = _y_error_axis[yrange[_q_index],:]
## _y_error_axis_tmp = numpy.sqrt(_y_error_axis_tmp)
# _y_error_axis_tmp = _y_error_axis_tmp.flatten()
#
# #keep only the overlap region of Qs
# _q_min = _q_axis_min_max_index[_q_index,0]
# if (_q_min != 0):
# _y_axis_tmp[0:_q_min] = 0
# _y_error_axis_tmp[0:_q_min] = 0
#
# _q_max = _q_axis_min_max_index[_q_index,1]
# if (_q_max != shape(_y_axis_tmp)[0]):
# _y_axis_tmp[_q_max:-1] = 0
# _y_error_axis_tmp[_q_max:-1] = 0
#
# _y_axis_tmp = _y_axis_tmp[::-1]
# _y_error_axis_tmp = _y_error_axis_tmp[::-1]
#
# _outputWorkspace = 'tmpOWks_' + str(_q_index)
# CreateWorkspace(OutputWorkspace=_outputWorkspace,
# DataX=q_axis,
# DataY=_y_axis_tmp,
# DataE=_y_error_axis_tmp,
# Nspec=1,
# UnitX="MomentumTransfer")
#
# if _q_index == 0:
# mt_tmp = mtd[_outputWorkspace]
#
# _outputWorkspace_rebin = 'tmpOWks_' + str(_q_index)
#
# Rebin(InputWorkspace=_outputWorkspace,
# OutputWorkspace=_outputWorkspace_rebin,
# Params=str(_q_bin_width))
#
# if _q_index == 0:
# mt_tmp = mtd[_outputWorkspace_rebin]
#
# _mt = mtd['tmpOWks_0']
# _x_array = _mt.readX(0)[:]
#
# #create big y_array of the all the pixel of interest (yrange)
# big_y_array = zeros((maxY, len(_x_array)))
# big_y_error_array = zeros((maxY, len(_x_array)))
## big_y_array = zeros((y_size, len(_x_array)))
## big_y_error_array = zeros((y_size, len(_x_array)))
#
# for _q_index in range(y_size):
#
# _wks = 'tmpOWks_' + str(_q_index)
# _mt = mtd[_wks]
# _tmp_y = _mt.readY(0)[:]
# _tmp_y_error = _mt.readE(0)[:]
#
# _index = y_range[_q_index]
#
# big_y_array[_index,:] = _tmp_y
# big_y_error_array[_index,:] = _tmp_y_error
#
## big_y_array[int(_q_index),:] = _tmp_y
## big_y_error_array[int(_q_index),:] = _tmp_y_error
#
## mtd.deleteWorkspace(_wks)
#
# _x_axis = _x_array.flatten()
# _y_axis = big_y_array.flatten()
# _y_error_axis = big_y_error_array.flatten()
#
# nbr_pixel_in_peak = y_size
#
# print 'in with geometry correction'
# print 'shape(_x_axis):'
# print shape(_x_axis)
# print 'shape(_y_axis):'
# print shape(_y_axis)
# print 'nbr_pixel_in_peak: '
# print nbr_pixel_in_peak
#
# CreateWorkspace(OutputWorkspace=outputWorkspace,
# DataX=_x_axis,
# DataY=_y_axis,
# DataE=_y_error_axis,
## Nspec=nbr_pixel_in_peak,
# Nspec=maxY,
# UnitX="MomentumTransfer",
# ParentWorkspace=mt1)
#
# #end of old code

_y_axis = zeros((y_size, len(_tof_axis) - 1))
_y_error_axis = zeros((y_size, len(_tof_axis) - 1))
Expand Down Expand Up @@ -495,68 +388,64 @@ def convertToThetaVsLambda(_tof_axis,

return dico

def _convertToRvsQ(_tof_axis,
_pixel_axis_of_peak,
data_of_peak,
central_pixel,
pixel_size=0.0007,
theta= -1,
dSD= -1,
dMD= -1):
"""
This function converts the pixel/tof array to the R(Q) array
"""

h = 6.626e-34 #m^2 kg s^-1
m = 1.675e-27 #kg

##convert tof_axis into seconds
#_tof_axis = _tof_axis * 1e-6

# vel_array = dMD / _tof_axis #mm/ms = m/s
# _lambda = h / (m * vel_array) #m
# _lambda = _lambda * 1e10 #angstroms

d_vec = (_pixel_axis_of_peak - central_pixel) * pixel_size
theta_vec = arctan2(d_vec, dSD) + theta

#create Q axis
nbr_pixel = shape(_pixel_axis_of_peak)[0]
nbr_tof = shape(_tof_axis)[0]
q_array = zeros(nbr_tof)

# print 'dMD: ' , dMD
_const = float(4) * math.pi * m * dMD / h
# print '_const: ' , _const
# print 'theta: ' , theta
# print _tof_axis

for t in range(nbr_tof):
_Q = _const * sin(theta) / _tof_axis[t]
q_array[t] = _Q

return q_array

def convertToRvsQ(dMD= -1, theta= -1, tof=None):
"""
This function converts the pixel/TOF array to the R(Q) array
using Q = (4.Pi.Mn)/h * L.sin(theta/2)/TOF
with L: distance central_pixel->source
TOF: TOF of pixel
theta: angle of detector
"""
_const = float(4) * math.pi * m * dMD / h
sz_tof = numpy.shape(tof)[0]
q_array = zeros(sz_tof - 1)
for t in range(sz_tof - 1):
tof1 = tof[t]
tof2 = tof[t + 1]
tofm = (tof1 + tof2) / 2.
_Q = _const * math.sin(theta) / (tofm * 1e-6)
q_array[t] = _Q * 1e-10

return q_array
#def _convertToRvsQ(_tof_axis,
# _pixel_axis_of_peak,
# data_of_peak,
# central_pixel,
# pixel_size=0.0007,
# theta= -1,
# dSD= -1,
# dMD= -1):
# """
# This function converts the pixel/tof array to the R(Q) array
#
# """
#
# h = 6.626e-34 #m^2 kg s^-1
# m = 1.675e-27 #kg
#
# ##convert tof_axis into seconds
# #_tof_axis = _tof_axis * 1e-6
#
## vel_array = dMD / _tof_axis #mm/ms = m/s
## _lambda = h / (m * vel_array) #m
## _lambda = _lambda * 1e10 #angstroms
#
# d_vec = (_pixel_axis_of_peak - central_pixel) * pixel_size
# theta_vec = arctan2(d_vec, dSD) + theta
#
# #create Q axis
# nbr_pixel = shape(_pixel_axis_of_peak)[0]
# nbr_tof = shape(_tof_axis)[0]
# q_array = zeros(nbr_tof)
#
# _const = float(4) * math.pi * m * dMD / h
#
# for t in range(nbr_tof):
# _Q = _const * sin(theta) / _tof_axis[t]
# q_array[t] = _Q
#
# return q_array

#def convertToRvsQ(dMD= -1, theta= -1, tof=None):
# """
# This function converts the pixel/TOF array to the R(Q) array
# using Q = (4.Pi.Mn)/h * L.sin(theta/2)/TOF
# with L: distance central_pixel->source
# TOF: TOF of pixel
# theta: angle of detector
# """
# _const = float(4) * math.pi * m * dMD / h
# sz_tof = numpy.shape(tof)[0]
# q_array = zeros(sz_tof - 1)
# for t in range(sz_tof - 1):
# tof1 = tof[t]
# tof2 = tof[t + 1]
# tofm = (tof1 + tof2) / 2.
# _Q = _const * math.sin(theta) / (tofm * 1e-6)
# q_array[t] = _Q * 1e-10
#
# return q_array

def convertToRvsQWithCorrection(mt, dMD= -1, theta= -1, tof=None, yrange=None, cpix=None):
"""
Expand Down

0 comments on commit f8f6d5a

Please sign in to comment.