Skip to content

Commit

Permalink
Move the centre_finder to Python V2
Browse files Browse the repository at this point in the history
  • Loading branch information
gesnerpassos committed Mar 5, 2013
1 parent 044b53f commit 1f0d95e
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions Code/Mantid/scripts/SANS/centre_finder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import isis_reducer
import reduction.instruments.sans.sans_reduction_steps as sans_reduction_steps
from mantidsimple import *
from mantid.simpleapi import *
import SANSUtility

class CentreFinder(object):
Expand Down Expand Up @@ -48,17 +48,17 @@ def SeekCentre(self, setup, trial):
setup.reduce_can('centre_can', run_Q=False)

self._group_into_quadrants(setup, 'centre_can', trial[0], trial[1], suffix='_can')
Minus('Left_tmp', 'Left_can', 'Left_tmp')
Minus('Right_tmp', 'Right_can', 'Right_tmp')
Minus('Up_tmp', 'Up_can', 'Up_tmp')
Minus('Down_tmp', 'Down_can', 'Down_tmp')
DeleteWorkspace('Left_can')
DeleteWorkspace('Right_can')
DeleteWorkspace('Up_can')
DeleteWorkspace('Down_can')
DeleteWorkspace('centre_can')
Minus(LHSWorkspace='Left_tmp',RHSWorkspace= 'Left_can',OutputWorkspace= 'Left_tmp')
Minus(LHSWorkspace='Right_tmp',RHSWorkspace= 'Right_can',OutputWorkspace= 'Right_tmp')
Minus(LHSWorkspace='Up_tmp',RHSWorkspace= 'Up_can',OutputWorkspace= 'Up_tmp')
Minus(LHSWorkspace='Down_tmp',RHSWorkspace= 'Down_can',OutputWorkspace= 'Down_tmp')
DeleteWorkspace(Workspace='Left_can')
DeleteWorkspace(Workspace='Right_can')
DeleteWorkspace(Workspace='Up_can')
DeleteWorkspace(Workspace='Down_can')
DeleteWorkspace(Workspace='centre_can')

DeleteWorkspace('centre')
DeleteWorkspace(Workspace='centre')
self._last_pos = trial

#prepare the workspaces for "publication", after they have their standard names calculations will be done on them and they will be plotted
Expand All @@ -68,7 +68,7 @@ def SeekCentre(self, setup, trial):
rem_nans = sans_reduction_steps.StripEndNans()
rem_nans.execute(setup, in_wksp)

RenameWorkspace(in_wksp, out_wksp)
RenameWorkspace(InputWorkspace=in_wksp,OutputWorkspace= out_wksp)

return self._calculate_residue()

Expand Down Expand Up @@ -96,20 +96,20 @@ def move(self, setup, x, y):
"""
x = -x
y = -y
MoveInstrumentComponent(setup.get_sample().wksp_name,
MoveInstrumentComponent(Workspace=setup.get_sample().wksp_name,
ComponentName=self.detector, X=x, Y=y, RelativePosition=True)
if setup.background_subtracter:
MoveInstrumentComponent(setup.background_subtracter.workspace.wksp_name,
MoveInstrumentComponent(Workspace=setup.background_subtracter.workspace.wksp_name,
ComponentName=self.detector, X=x, Y=y, RelativePosition=True)

# Create a workspace with a quadrant value in it
def _create_quadrant(self, setup, reduced_ws, quadrant, xcentre, ycentre, r_min, r_max, suffix):
out_ws = quadrant+suffix
# Need to create a copy because we're going to mask 3/4 out and that's a one-way trip
CloneWorkspace(reduced_ws, out_ws)
CloneWorkspace(InputWorkspace=reduced_ws,OutputWorkspace= out_ws)
objxml = SANSUtility.QuadrantXML([0, 0, 0.0], r_min, r_max, quadrant)
# Mask out everything outside the quadrant of interest
MaskDetectorsInShape(out_ws, objxml)
MaskDetectorsInShape(Workspace=out_ws,ShapeXML= objxml)

setup.to_Q.execute(setup, out_ws)
#Q1D(output,rawcount_ws,output,q_bins,AccountForGravity=GRAVITY)
Expand All @@ -128,42 +128,42 @@ def _calculate_residue(self):
and Down. This assumes that a workspace with one spectrum for each of the quadrants
@return: difference left to right, difference up down
"""
yvalsA = mtd.getMatrixWorkspace('Left').readY(0)
yvalsB = mtd.getMatrixWorkspace('Right').readY(0)
qvalsA = mtd.getMatrixWorkspace('Left').readX(0)
qvalsB = mtd.getMatrixWorkspace('Right').readX(0)
yvalsA = mtd['Left'].readY(0)
yvalsB = mtd['Right'].readY(0)
qvalsA = mtd['Left'].readX(0)
qvalsB = mtd['Right'].readX(0)
qrange = [len(yvalsA), len(yvalsB)]
nvals = min(qrange)
residueX = 0
indexB = 0
for indexA in range(0, nvals):
if qvalsA[indexA] < qvalsB[indexB]:
mantid.sendLogMessage("::SANS::LR1 "+str(indexA)+" "+str(indexB))
logger.notice("::SANS::LR1 "+str(indexA)+" "+str(indexB))
continue
elif qvalsA[indexA] > qvalsB[indexB]:
while qvalsA[indexA] > qvalsB[indexB]:
mantid.sendLogMessage("::SANS::LR2 "+str(indexA)+" "+str(indexB))
logger.notice("::SANS::LR2 "+str(indexA)+" "+str(indexB))
indexB += 1
if indexA > nvals - 1 or indexB > nvals - 1:
break
residueX += pow(yvalsA[indexA] - yvalsB[indexB], 2)
indexB += 1

yvalsA = mtd.getMatrixWorkspace('Up').readY(0)
yvalsB = mtd.getMatrixWorkspace('Down').readY(0)
qvalsA = mtd.getMatrixWorkspace('Up').readX(0)
qvalsB = mtd.getMatrixWorkspace('Down').readX(0)
yvalsA = mtd['Up'].readY(0)
yvalsB = mtd['Down'].readY(0)
qvalsA = mtd['Up'].readX(0)
qvalsB = mtd['Down'].readX(0)
qrange = [len(yvalsA), len(yvalsB)]
nvals = min(qrange)
residueY = 0
indexB = 0
for indexA in range(0, nvals):
if qvalsA[indexA] < qvalsB[indexB]:
mantid.sendLogMessage("::SANS::UD1 "+str(indexA)+" "+str(indexB))
logger.notice("::SANS::UD1 "+str(indexA)+" "+str(indexB))
continue
elif qvalsA[indexA] > qvalsB[indexB]:
while qvalsA[indexA] > qvalsB[indexB]:
mantid.sendLogMessage("::SANS::UD2 "+str(indexA)+" "+str(indexB))
logger.notice("::SANS::UD2 "+str(indexA)+" "+str(indexB))
indexB += 1
if indexA > nvals - 1 or indexB > nvals - 1:
break
Expand Down

0 comments on commit 1f0d95e

Please sign in to comment.