Skip to content

Commit

Permalink
Re #10684 Initial commit (attempt to construct a unit test for later
Browse files Browse the repository at this point in the history
rebinning). Nothing still works
  • Loading branch information
abuts committed Jan 30, 2015
1 parent 9700712 commit a6f046f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
30 changes: 16 additions & 14 deletions Code/Mantid/scripts/Inelastic/Direct/DirectEnergyConversion.py
Expand Up @@ -3,8 +3,7 @@
from mantid import geometry

import time as time
import os.path
import copy
import os.path, copy

import Direct.CommonFunctions as common
import Direct.diagnostics as diagnostics
Expand Down Expand Up @@ -320,7 +319,7 @@ def convert_to_energy(self,wb_run=None,sample_run=None,ei_guess=None,rebin=None,
if len(workspace_defined_prop) > 0:
prop_man.log("****************************************************************")
prop_man.log('*** Sample run {0} properties change default reduction properties: '.\
format(PropertyManager.sample_run.get_ws_name()))
format(PropertyManager.sample_run.get_ws_name()))
prop_man.log_changed_values('notice',False,oldChanges)
prop_man.log("****************************************************************")

Expand Down Expand Up @@ -552,10 +551,12 @@ def get_ei(self, data_run, ei_guess):
mon1_det = monitor_ws.getDetector(spec_num)
mon1_pos = mon1_det.getPos()
src_name = data_ws.getInstrument().getSource().getName()
MoveInstrumentComponent(Workspace=resultws_name,ComponentName= src_name, X=mon1_pos.getX(), Y=mon1_pos.getY(), Z=mon1_pos.getZ(), RelativePosition=False)
MoveInstrumentComponent(Workspace=resultws_name,ComponentName= src_name, X=mon1_pos.getX(),
Y=mon1_pos.getY(), Z=mon1_pos.getZ(), RelativePosition=False)
#
if separate_monitors:
MoveInstrumentComponent(Workspace=result_mon_name,ComponentName= src_name, X=mon1_pos.getX(), Y=mon1_pos.getY(), Z=mon1_pos.getZ(), RelativePosition=False)
MoveInstrumentComponent(Workspace=result_mon_name,ComponentName= src_name, X=mon1_pos.getX(),
Y=mon1_pos.getY(), Z=mon1_pos.getZ(), RelativePosition=False)

data_run.synchronize_ws(mtd[resultws_name])
return ei, mon1_peak
Expand Down Expand Up @@ -834,6 +835,8 @@ def __init__(self, instr_name=None,reload_instrument=False):
# shifting the instrument
object.__setattr__(self,'_mon2_norm_time_range',None)
object.__setattr__(self,'_debug_mode',False)
# method used in debug mode and requesting
object.__setattr__(self,'_do_early_rebinning',False)

all_methods = dir(self)
# define list of all existing properties, which have descriptors
Expand Down Expand Up @@ -1104,14 +1107,6 @@ def get_abs_normalization_factor(self,deltaE_wkspaceName,ei_monovan):
DeleteWorkspace(Workspace=deltaE_wkspaceName)
DeleteWorkspace(Workspace=data_ws)
return (norm_factor['LibISIS'],norm_factor['SigSq'],norm_factor['Poisson'],norm_factor['TGP'])
#-------------------------------------------------------------------------------

def _build_white_tag(self):
""" build tag indicating wb-integration ranges """
low,upp = self.wb_integr_range
white_tag = 'NormBy:{0}_IntergatedIn:{1:0>10.2f}:{2:0>10.2f}'.format(self.normalise_method,low,upp)
return white_tag

# -------------------------------------------------------------------------------------------
# This actually does the conversion for the mono-sample and
# mono-vanadium runs
Expand All @@ -1120,7 +1115,8 @@ def _build_white_tag(self):
def _do_mono_SNS(self, data_ws, result_name, ei_guess,
white_run=None, map_file=None, spectra_masks=None, Tzero=None):
# does not work -- retrieve from repo and fix
raise NotImplementedError("Non currently implemented. Retrieve from repository if necessary")
raise NotImplementedError("Non currently implemented. Retrieve from repository"
" if necessary and fix")
return
#-------------------------------------------------------------------------------
def _do_mono_ISIS(self, data_run, ei_guess,
Expand Down Expand Up @@ -1277,6 +1273,12 @@ def _get_wb_inegrals(self,run):
else:
result = run.get_workspace()
return result
#-------------------------------------------------------------------------------
def _build_white_tag(self):
""" build tag indicating wb-integration ranges """
low,upp = self.wb_integr_range
white_tag = 'NormBy:{0}_IntergatedIn:{1:0>10.2f}:{2:0>10.2f}'.format(self.normalise_method,low,upp)
return white_tag

#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
Expand Down
37 changes: 36 additions & 1 deletion Code/Mantid/scripts/test/DirectEnergyConversionTest.py
@@ -1,5 +1,5 @@
import os, sys
#os.environ["PATH"] = r"c:/Mantid/Code/builds/br_master/bin/Release;"+os.environ["PATH"]
os.environ["PATH"] = r"c:/Mantid/Code/builds/br_master/bin/Release;"+os.environ["PATH"]
from mantid.simpleapi import *
from mantid import api
import unittest
Expand Down Expand Up @@ -252,6 +252,41 @@ def test_energy_to_TOF_range(self):
eni = EnWs.dataX(0)
for samp,rez in zip(eni,en_range): self.assertAlmostEqual(samp,rez)

def test_late_rebinning(self):
run_ws = CreateSampleWorkspace( Function='Multiple Peaks',WorkspaceType='Event',NumBanks=10, BankPixelWidth=4, NumEvents=10000)
LoadInstrument(run_ws,InstrumentName='MARI')
#mono_ws = CloneWorkspace(run_ws)
wb_ws = CloneWorkspace(run_ws)
tReducer = DirectEnergyConversion(run_ws.getInstrument())
#un_ws = CreateSampleWorkspace( Function='Multiple Peaks',WorkspaceType='Event',NumBanks=10, BankPixelWidth=4, NumEvents=10000)
# ...: LoadInstrument(run_ws,InstrumentName='MARI')
# ...:
#Out[15]: array([1, 2, 3])

#In [16]: run_ws = CreateSampleWorkspace( Function='Multiple Peaks',WorkspaceType='Event',NumBanks=10, BankPixelWidth=4, NumEvents=10000)
# ...: LoadInstrument(run_ws,InstrumentName='MARI')
# ...: bws = Rebin(run_ws,Params='0,100,20000')
# ...:

#In [17]: ews=ConvertUnits(bws,'Energy','Elastic')

#In [18]: tws = CreateSampleWorkspace( Function='Multiple Peaks',NumBanks=10, BankPixelWidth=4, NumEvents=10000,XUnit='Energy',XMin=-10,xMax=20,BinWidth=0.1)

#In [19]: LoadInstrument(tws,InstrumentName='MARI')
#Out[19]: array([1, 2, 3])

#In [20]: etws=ConvertUnits(tws,'TOF','Elastic')

#In [21]: mon_ws = CreateSampleWorkspace( Function='Multiple Peaks',NumBanks=3, BankPixelWidth=1, NumEvents=10000,XUnit='Energy',XMin=-10,xMax=20,BinWidth=0.1)

#In [22]: LoadInsturment(mon_ws,InstrumentName='MARI')

#ref_ws = Rebin(

mono_s = tRedcucet._do_mono(mono_run, ei_guess,
white_run, map_file, spectra_masks, Tzero)





Expand Down

0 comments on commit a6f046f

Please sign in to comment.