Skip to content

Commit

Permalink
Re #10803 Unit test that dgreduce still works
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Jan 8, 2015
1 parent 5aa0267 commit 943d22a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 21 deletions.
1 change: 0 additions & 1 deletion Code/Mantid/scripts/Inelastic/Direct/dgreduce.py
Expand Up @@ -6,7 +6,6 @@
from mantid import api
from mantid.kernel import funcreturns

import unittest

# the class which is responsible for data reduction
global Reducer
Expand Down
52 changes: 32 additions & 20 deletions Code/Mantid/scripts/test/DirectEnergyConversionTest.py
@@ -1,9 +1,11 @@
import os, sys
#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
import inspect
import os, sys
from Direct.DirectEnergyConversion import DirectEnergyConversion
import Direct.dgreduce as dgreduce


#-----------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -113,21 +115,6 @@ def test_diagnostics_wb(self):

def test_do_white_wb(self) :
wb_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10000)
# THIS DOES NOT WORK AND THE QUESTION IS WHY?
used_parameters = """<?xml version="1.0" encoding="UTF-8" ?>
<parameter-file instrument="BASIC_RECT" valid-from="2014-01-01 00:00:01">
<component-link name = "BASIC_RECT">
<parameter name="det_cal_file" type="string">
<value val="None"/>
</parameter>
<parameter name="load_monitors_with_workspace" type="bool">
<value val="True"/>
</parameter>
</component-link>
</parameter-file>"""
#LoadParameterFile(Workspace=wb_ws,ParameterXML = used_parameters);
LoadInstrument(wb_ws,InstrumentName='MARI')

Expand All @@ -137,30 +124,55 @@ def test_do_white_wb(self) :
self.assertTrue(white_ws)

def test_get_abs_normalization_factor(self) :
mono_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10000,XUnit='DeltaE',XMin=-5,XMax=15,BinWidth=0.1)
mono_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10000,XUnit='DeltaE',XMin=-5,XMax=15,BinWidth=0.1,function='Flat background')
LoadInstrument(mono_ws,InstrumentName='MARI')

tReducer = DirectEnergyConversion(mono_ws.getInstrument())
tReducer.prop_man.incident_energy = 5.
tReducer.prop_man.monovan_integr_range=[-10,10]

(nf1,nf2,nf3,nf4) = tReducer.get_abs_normalization_factor(mono_ws.getName(),5.)
self.assertAlmostEqual(nf1,0.139349147,7)
self.assertAlmostEqual(nf1,0.58561121802167193,7)
self.assertAlmostEqual(nf1,nf2)
self.assertAlmostEqual(nf2,nf3)
self.assertAlmostEqual(nf3,nf4)

# check warning. WB spectra with 0 signal indicate troubles.
mono_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10000,XUnit='DeltaE',XMin=-5,XMax=15,BinWidth=0.1)
mono_ws = CreateSampleWorkspace(NumBanks=1, BankPixelWidth=4, NumEvents=10000,XUnit='DeltaE',XMin=-5,XMax=15,BinWidth=0.1,function='Flat background')
LoadInstrument(mono_ws,InstrumentName='MARI')
sig = mono_ws.dataY(0);
sig[:]=0;

(nf1,nf2,nf3,nf4) = tReducer.get_abs_normalization_factor(mono_ws.getName(),5.)
self.assertAlmostEqual(nf1,0.139349147,7)
self.assertAlmostEqual(nf1,0.585611218022,7)
self.assertAlmostEqual(nf1,nf2)
self.assertAlmostEqual(nf2,nf3)
self.assertAlmostEqual(nf3,nf4)

def test_dgreduce_works(self):
""" Test for old interface """
run_ws = CreateSampleWorkspace( Function='Multiple Peaks', NumBanks=1, BankPixelWidth=4, NumEvents=10000)
LoadInstrument(run_ws,InstrumentName='MARI')
#mono_ws = CloneWorkspace(run_ws);
wb_ws = CloneWorkspace(run_ws);
#wb_ws=CreateSampleWorkspace( Function='Multiple Peaks', NumBanks=1, BankPixelWidth=4, NumEvents=10000)




dgreduce.setup('MAR');
par = {};
par['ei_mon_spectra']=[4,5]
par['abs_units_van_range']=[-4000,8000]
# overwrite parameters, which are necessary from command line, but we want them to have test values
dgreduce.getReducer().prop_man.map_file=None;
dgreduce.getReducer().prop_man.monovan_mapfile=None;
dgreduce.getReducer().mono_correction_factor = 1
#abs_units(wb_for_run,sample_run,monovan_run,wb_for_monovanadium,samp_rmm,samp_mass,ei_guess,rebin,map_file='default',monovan_mapfile='default',**kwargs):
ws = dgreduce.abs_units(wb_ws,run_ws,None,wb_ws,10,100,8.8,[-10,0.1,7],None,None,**par)
self.assertTrue(isinstance(ws,api.MatrixWorkspace))



##def test_diag_call(self):
## tReducer = self.reducer
Expand Down

0 comments on commit 943d22a

Please sign in to comment.