Skip to content

Commit

Permalink
refs #6667 Small improvements and attempt to use hardmask only
Browse files Browse the repository at this point in the history
unsuccessful attempts
  • Loading branch information
abuts committed Jun 21, 2013
1 parent bd79a0f commit b839450
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 124 deletions.
3 changes: 0 additions & 3 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ def diagnose(self, white, **kwargs):
if 'instrument_name' not in kwargs:
kwargs['instrument_name'] = self.instr_name

logger.debug("------------------------------------------------------------------------------------------------------------")
# Check how we should run diag
if self.diag_spectra is None:
# Do the whole lot at once
Expand All @@ -176,8 +175,6 @@ def diagnose(self, white, **kwargs):
kwargs['start_index'] = bank[0] - 1
kwargs['end_index'] = bank[1] - 1
diagnostics.diagnose(whiteintegrals, **kwargs)
logger.debug("------------------------------------------------------------------------------------------------------------")
#raise AssertionError("Stop here")

if 'sample_counts' in kwargs:
DeleteWorkspace(Workspace='background_int')
Expand Down
267 changes: 146 additions & 121 deletions Code/Mantid/scripts/Inelastic/dgreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,23 +237,30 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file=None,monovan_run=None,**
# --------------------------------------------------------------------------------------------------------
# diag the sample and detector vanadium
if Reducer.use_hard_mask_only: # if it is string, it is treated as bool
totalmask = Reducer.hard_mask_file
totalmask = Reducer.hard_mask

print ' Using hardmask only from: ', totalmask
#next stable version can replace this with loadmask algoritum
specs=diag_load_mask(totalmask)
CloneWorkspace(InputWorkspace=sample_run,OutputWorkspace='mask_wksp')
MaskDetectors(Workspace='mask_wksp',SpectraList=specs)
masking=mtd['mask_wksp']
Reducer.log(' Using hardmask only from: '+totalmask)
#Return masking workspace
masking = LoadMask(Instrument=Reducer.instr_name,InputFile=Reducer.hard_mask)
if Reducer.map_file != None:
masking=GroupDetectors(InputWorkspace=masking,OutputWorkspace=masking,
MapFile= Reducer.map_file, KeepUngroupedSpectra=0, Behaviour='Average')

# load runs and mask them using masking workspace
mask_workspace(wb_run,masking)
mask_workspace(sample_run,masking)
else:
masking = Reducer.diagnose(wb_run,sample = mask_run,
second_white = None,variation=1.1,print_results=True)

# Calculate absolute units:
if monovan_run != None and Reducer.mono_correction_factor == None :

if Reducer.use_sam_msk_on_monovan == True:
print 'applying sample run mask to mono van'
if Reducer.use_sam_msk_on_monovan == True or Reducer.use_hard_mask_only:
Reducer.log(' Applying sample run mask to mono van ')
mask_workspace(monovan_run,masking)
if wb_for_monovanadium != wb_run:
mask_workspace(monovan_run,masking)
else:
print '########### Run diagnose for monochromatic vanadium run ##############'

Expand Down Expand Up @@ -299,6 +306,134 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file=None,monovan_run=None,**
return deltaE_wkspace_sample


def mask_workspace(run_number,mask_ws) :
"""
mask workspace defined by the run number with masks defined in masking workspace
"""
run_ws=common.load_run(run_number)

if Reducer.map_file != None:
run_ws=GroupDetectors(InputWorkspace=run_ws,OutputWorkspace=run_ws,
MapFile= Reducer.map_file, KeepUngroupedSpectra=0, Behaviour='Average')

MaskDetectors(Workspace=run_ws, MaskedWorkspace=mask_ws)

def abs_units(wb_for_run,sample_run,monovan_run,wb_for_monovanadium,samp_rmm,samp_mass,ei_guess,rebin,map_file,monovan_mapfile,**kwargs):
"""
dgreduce.abs_units(wb_run Whitebeam run number or file name or workspace
sample_run Sample run run number or file name or workspace
monovan_run Monochromatic run run number or file name or workspace
wb_mono White beam for Monochromatic run run number or file name or workspace
samp_rmm Mass of forumula unit of sample
samp_mass Actual sample mass
ei_guess Ei guess of run
rebin Rebin parameters for output data
map_file Mapfile for sample run
monovan_mapfile Mapfile for mono van run
keyword arguments Any specified additional keyword arguments
Example with run numbers
abs_units(11001,11002,11003,10098,250.1,5.2,80,'-10,.1,75','mari_res','mari_res')
A detector calibration file must be specified if running the reduction with workspace inputs
Example with workspace inputs
abs_units('wb_run','sam_run','mono_run','wb_for_mono',250.1,5.2,80,'-10,.1,75','mari_res','mari_res',
det_cal_file=10001,diag_remove_zero=False,norm_method='current')
A detector calibration file must be specified if running the reduction with workspace inputs
Available keywords
norm_method =[monitor-1],[monitor-2][Current]
background =False , True
fixei =False , True
save_format =['.spe'],['.nxspe'],'none'
detector_van_range =[20,40] in mev
bkgd_range =[15000,19000] :integration range for background tests
second_white - If provided an additional set of tests is performed on this. (default = None)
hard_mask - A file specifying those spectra that should be masked without testing (default=None)
tiny - Minimum threshold for acceptance (default = 1e-10)
large - Maximum threshold for acceptance (default = 1e10)
bkgd_range - A list of two numbers indicating the background range (default=instrument defaults)
diag_van_median_rate_limit_lo - Lower bound defining outliers as fraction of median value (default = 0.01)
diag_van_median_rate_limit_hi - Upper bound defining outliers as fraction of median value (default = 100.)
diag_van_median_sigma_lo - Fraction of median to consider counting low for the white beam diag (default = 0.1)
diag_van_median_sigma_hi - Fraction of median to consider counting high for the white beam diag (default = 1.5)
diag_van_sig - Error criterion as a multiple of error bar i.e. to fail the test, the magnitude of the
difference with respect to the median value must also exceed this number of error bars (default=0.0)
diag_remove_zero - If true then zeroes in the vanadium data will count as failed (default = True)
diag_samp_samp_median_sigma_lo - Fraction of median to consider counting low for the white beam diag (default = 0)
diag_samp_samp_median_sigma_hi - Fraction of median to consider counting high for the white beam diag (default = 2.0)
diag_samp_sig - Error criterion as a multiple of error bar i.e. to fail the test, the magnitude of the"
difference with respect to the median value must also exceed this number of error bars (default=3.3)
variation -The number of medians the ratio of the first/second white beam can deviate from
the average by (default=1.1)
bleed_test - If true then the CreatePSDBleedMask algorithm is run
bleed_maxrate - If the bleed test is on then this is the maximum framerate allowed in a tube
bleed_pixels - If the bleed test is on then this is the number of pixels ignored within the
bleed test diagnostic
print_results - If True then the results are printed to the screen
diag_remove_zero =True, False (default):Diag zero counts in background range
bleed=True , turn bleed correction on and off on by default for Merlin and LET
sum =True,False(default) , sum multiple files
det_cal_file= a valid detector block file and path or a raw file. Setting this
will use the detector calibraion from the specified file NOT the
input raw file
mask_run = RunNumber to use for diag instead of the input run number
one2one =True, False :Reduction will not use a mapping file
hardmaskPlus=Filename :load a hardmarkfile and apply together with diag mask
hardmaskOnly=Filename :load a hardmask and use as only mask
use_sam_msk_on_monovan=False This will set the total mask to be that of the sample run
abs_units_van_range=[-40,40] integral range for absolute vanadium data
mono_correction_factor=float User specified correction factor for absolute units normalisation
"""

kwargs['monovan_mapfile'] = monovan_mapfile
kwargs['wb_for_monovanadium']= wb_for_monovanadium
kwargs['sample_mass'] = samp_mass
kwargs['sample_rmm'] = samp_rmm

# service property, which tells arb_units that here defaults have changed and no need to check they are changed
kwargs['_defaults_have_changed'] = True
try:
n,r=funcreturns.lhs_info('both')
wksp_out=r[0]

except:
if sample_run == 0:
#deal with the current run being parsed as 0 rather than 00000
sample_run='00000'
wksp_out=Reducer.instr_name+str(sample_run)+'.spe'
if kwargs.has_key('sum') and kwargs.get('sum')==True:
wksp_out=inst_name+str(sample_run[0])+'sum'+'.spe'


results_name = wksp_out
wksp_out = arb_units(wb_for_run,sample_run,ei_guess,rebin,map_file,monovan_run,**kwargs)


if results_name != wksp_out.getName():
RenameWorkspace(InputWorkspace=wksp_out,OutputWorkspace=results_name)

return wksp_out





def apply_absolute_normalization(Reducer,deltaE_wkspace_sample,monovan_run,ei_guess,wb_mono):
""" Function applies absolute normalization factor to the target workspace
and calculates this factor if nececcary
Expand Down Expand Up @@ -492,118 +627,6 @@ def get_abs_normalization_factor(Reducer,deltaE_wkspaceName,ei_monovan) :
DeleteWorkspace(Workspace=data_ws)
return (absnorm_factorLibISIS,absnorm_factorSigSq,absnorm_factorPuason,absnorm_factorTGP)

def abs_units(wb_for_run,sample_run,monovan_run,wb_for_monovanadium,samp_rmm,samp_mass,ei_guess,rebin,map_file,monovan_mapfile,**kwargs):
"""
dgreduce.abs_units(wb_run Whitebeam run number or file name or workspace
sample_run Sample run run number or file name or workspace
monovan_run Monochromatic run run number or file name or workspace
wb_mono White beam for Monochromatic run run number or file name or workspace
samp_rmm Mass of forumula unit of sample
samp_mass Actual sample mass
ei_guess Ei guess of run
rebin Rebin parameters for output data
map_file Mapfile for sample run
monovan_mapfile Mapfile for mono van run
keyword arguments Any specified additional keyword arguments
Example with run numbers
abs_units(11001,11002,11003,10098,250.1,5.2,80,'-10,.1,75','mari_res','mari_res')
A detector calibration file must be specified if running the reduction with workspace inputs
Example with workspace inputs
abs_units('wb_run','sam_run','mono_run','wb_for_mono',250.1,5.2,80,'-10,.1,75','mari_res','mari_res',
det_cal_file=10001,diag_remove_zero=False,norm_method='current')
A detector calibration file must be specified if running the reduction with workspace inputs
Available keywords
norm_method =[monitor-1],[monitor-2][Current]
background =False , True
fixei =False , True
save_format =['.spe'],['.nxspe'],'none'
detector_van_range =[20,40] in mev
bkgd_range =[15000,19000] :integration range for background tests
second_white - If provided an additional set of tests is performed on this. (default = None)
hard_mask - A file specifying those spectra that should be masked without testing (default=None)
tiny - Minimum threshold for acceptance (default = 1e-10)
large - Maximum threshold for acceptance (default = 1e10)
bkgd_range - A list of two numbers indicating the background range (default=instrument defaults)
diag_van_median_rate_limit_lo - Lower bound defining outliers as fraction of median value (default = 0.01)
diag_van_median_rate_limit_hi - Upper bound defining outliers as fraction of median value (default = 100.)
diag_van_median_sigma_lo - Fraction of median to consider counting low for the white beam diag (default = 0.1)
diag_van_median_sigma_hi - Fraction of median to consider counting high for the white beam diag (default = 1.5)
diag_van_sig - Error criterion as a multiple of error bar i.e. to fail the test, the magnitude of the
difference with respect to the median value must also exceed this number of error bars (default=0.0)
diag_remove_zero - If true then zeroes in the vanadium data will count as failed (default = True)
diag_samp_samp_median_sigma_lo - Fraction of median to consider counting low for the white beam diag (default = 0)
diag_samp_samp_median_sigma_hi - Fraction of median to consider counting high for the white beam diag (default = 2.0)
diag_samp_sig - Error criterion as a multiple of error bar i.e. to fail the test, the magnitude of the"
difference with respect to the median value must also exceed this number of error bars (default=3.3)
variation -The number of medians the ratio of the first/second white beam can deviate from
the average by (default=1.1)
bleed_test - If true then the CreatePSDBleedMask algorithm is run
bleed_maxrate - If the bleed test is on then this is the maximum framerate allowed in a tube
bleed_pixels - If the bleed test is on then this is the number of pixels ignored within the
bleed test diagnostic
print_results - If True then the results are printed to the screen
diag_remove_zero =True, False (default):Diag zero counts in background range
bleed=True , turn bleed correction on and off on by default for Merlin and LET
sum =True,False(default) , sum multiple files
det_cal_file= a valid detector block file and path or a raw file. Setting this
will use the detector calibraion from the specified file NOT the
input raw file
mask_run = RunNumber to use for diag instead of the input run number
one2one =True, False :Reduction will not use a mapping file
hardmaskPlus=Filename :load a hardmarkfile and apply together with diag mask
hardmaskOnly=Filename :load a hardmask and use as only mask
use_sam_msk_on_monovan=False This will set the total mask to be that of the sample run
abs_units_van_range=[-40,40] integral range for absolute vanadium data
mono_correction_factor=float User specified correction factor for absolute units normalisation
"""

kwargs['monovan_mapfile'] = monovan_mapfile
kwargs['wb_for_monovanadium']= wb_for_monovanadium
kwargs['sample_mass'] = samp_mass
kwargs['sample_rmm'] = samp_rmm

# service property, which tells arb_units that here defaults have changed and no need to check they are changed
kwargs['_defaults_have_changed'] = True
try:
n,r=funcreturns.lhs_info('both')
wksp_out=r[0]

except:
if sample_run == 0:
#deal with the current run being parsed as 0 rather than 00000
sample_run='00000'
wksp_out=Reducer.instr_name+str(sample_run)+'.spe'
if kwargs.has_key('sum') and kwargs.get('sum')==True:
wksp_out=inst_name+str(sample_run[0])+'sum'+'.spe'


results_name = wksp_out
wksp_out = arb_units(wb_for_run,sample_run,ei_guess,rebin,map_file,monovan_run,**kwargs)


if results_name != wksp_out.getName():
RenameWorkspace(InputWorkspace=wksp_out,OutputWorkspace=results_name)

return wksp_out



def sum_files(accumulator, files):
Expand Down Expand Up @@ -665,6 +688,8 @@ def get_failed_spectra_list_from_masks(masking_wksp):

return (failed_spectra,n_spectra)



class DgreduceTest(unittest.TestCase):
def __init__(self, methodName):
setup("MAPS")
Expand Down

0 comments on commit b839450

Please sign in to comment.