Skip to content

Commit

Permalink
refs #6667 Hard Mask only works
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts committed Jul 5, 2013
1 parent ad59da8 commit 2ac4bc0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
48 changes: 38 additions & 10 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,30 @@ def diagnose(self, white, **kwargs):
arg = par.lstrip('diag_')
if arg not in kwargs:
kwargs[arg] = getattr(self, arg)
# If we have a hard_mask, check the instrument name is defined
if 'hard_mask' in kwargs:
if 'instrument_name' not in kwargs:
kwargs['instrument_name'] = self.instr_name

if 'use_hard_mask_only' in kwargs :
if mtd.doesExist('hard_mask_ws'):
diag_mask = mtd['hard_mask_ws']
else: # build hard mask
# in this peculiar way we can obtain working mask which accounts for initial data grouping in the data file.
# SNS or 1 to 1 maps may probably awoid this stuff and load masks directly
whitews_name = common.create_resultname(white, suffix='-white')
if whitews_name in mtd:
DeleteWorkspace(Workspace=whitews_name)
# Load
white_data = self.load_data(white,whitews_name)

diag_mask= LoadMask(Instrument=self.instr_name,InputFile=kwargs['hard_mask'],
OutputWorkspace='hard_mask_ws')
MaskDetectors(Workspace=white_data, MaskedWorkspace=diag_mask)
diag_mask,masked_list = ExtractMask(InputWorkspace=white_data)
DeleteWorkspace(Workspace=whitews_name)

return diag_mask

# Get the white beam vanadium integrals
whiteintegrals = self.do_white(white, None, None,None) # No grouping yet
Expand Down Expand Up @@ -151,11 +175,6 @@ def diagnose(self, white, **kwargs):
kwargs['background_int'] = background_int
kwargs['sample_counts'] = total_counts

# If we have a hard_mask, check the instrument name is defined
if 'hard_mask' in kwargs:
if 'instrument_name' not in kwargs:
kwargs['instrument_name'] = self.instr_name

# Check how we should run diag
if self.diag_spectra is None:
# Do the whole lot at once
Expand Down Expand Up @@ -695,7 +714,7 @@ def save_results(self, workspace, save_path, formats = None):
# if ext is none, no need to write anything
if len(ext) == 1 and ext[0] == None :
return
#self.psi = 1000000; # for test
self.psi = 1000000; # for test
save_path = os.path.splitext(save_path)[0]
for ext in formats:
if ext in self.__save_formats :
Expand All @@ -706,12 +725,14 @@ def save_results(self, workspace, save_path, formats = None):


#-------------------------------------------------------------------------------
def load_data(self, runs):
def load_data(self, runs,new_ws_name=None):
"""
Load a run or list of runs. If a list of runs is given then
they are summed into one.
"""
result_ws = common.load_runs(runs, sum=True)
if new_ws_name != None :
result_ws = RenameWorkspace(InputWorkspace=result_ws,OutputWorkspace=new_ws_name)
self.setup_mtd_instrument(result_ws)
return result_ws

Expand Down Expand Up @@ -742,7 +763,15 @@ def __init__(self, instr_name=None):
#----------------------------------------------------------------------------------
@property
def van_rmm(self):
return self.__van_rmm
"""The rmm of Vanadium is a constant, should not be instrument parameter. Atom not exposed to python :( """
return 50.9415
@van_rmm.setter
def van_rmm(self):
pass
@van_rmm.deleter
def van_rmm(self):
pass


@property
def save_format(self):
Expand Down Expand Up @@ -899,8 +928,7 @@ def init_idf_params(self, reload_instrument=False):
# Option to move detector positions based on the information
self.relocate_dets = False

#The rmm of Vanadium is a constant, should not be instrument parameter. Atom not exposed to python :(
self.__van_rmm = 50.9415


# special property -- synonims -- how to treat external parameters.
try:
Expand Down
24 changes: 16 additions & 8 deletions Code/Mantid/scripts/Inelastic/dgreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No
print '########### Run diagnose for monochromatic vanadium run ##############'
masking2 = Reducer.diagnose(wb_for_monovanadium,sample=monovan_run,
second_white = None,variation=1.1,print_results=True)

masking += masking2
if not Reducer.use_hard_mask_only : # in this case the masking2 is different but points to the same workspace
masking += masking2


else: # if Reducer.mono_correction_factor != None :
Expand All @@ -259,7 +259,8 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No
# estimate and report the number of failing detectors
failed_sp_list,nSpectra = get_failed_spectra_list_from_masks(masking)
nMaskedSpectra = len(failed_sp_list)
print 'Diag processed workspace with {0:d} spectra and found {1:d} bad spectra'.format(nSpectra,nMaskedSpectra)
# this tells turkey in case of hard mask only but everythin else semems work fine
print 'Diag processed workspace with {0:d} spectra and masked {1:d} bad spectra'.format(nSpectra,nMaskedSpectra)
#Run the conversion first on the sample
deltaE_wkspace_sample = Reducer.convert_to_energy(sample_run, ei_guess, wb_run)

Expand Down Expand Up @@ -427,11 +428,18 @@ def apply_absolute_normalization(Reducer,deltaE_wkspace_sample,monovan_run,ei_gu
Reducer.log('##### Evaluate the integral from the monovan run and calculate the correction factor ######')
Reducer.log(' Using absolute units vanadium integration range : '+str(Reducer.monovan_integr_range))
#now on the mono_vanadium run swap the mapping file
map_file = Reducer.map_file;
Reducer.map_file = Reducer.monovan_mapfile;
Reducer.save_format = None;
deltaE_wkspace_monovan = Reducer.convert_to_energy(monovan_run, ei_guess, wb_mono)
Reducer.map_file = map_file
result_ws_name = common.create_resultname(monovan_run)
# check the case when the sample is monovan itself (for testing purposes)
if result_ws_name == deltaE_wkspace_sample.name() :
deltaE_wkspace_monovan = CloneWorkspace(InputWorkspace=deltaE_wkspace_sample,OutputWorkspace=result_ws_name+'-monovan');
deltaE_wkspace_monovan=Reducer.remap(deltaE_wkspace_monovan,None,Reducer.monovan_mapfile)
else:
# convert to monovan to energy
map_file = Reducer.map_file;
Reducer.map_file = Reducer.monovan_mapfile;
deltaE_wkspace_monovan = Reducer.convert_to_energy(monovan_run, ei_guess, wb_mono)
Reducer.map_file = map_file

ei_monovan = deltaE_wkspace_monovan.getRun().getLogData("Ei").value
Reducer.log(' Incident energy found for monovanadium run: '+str(ei_monovan)+' meV')

Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/Inelastic/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def diagnose(white_int, **kwargs):
test_results[0][0] = os.path.basename(parser.hard_mask)
test_results[0][1] = len(masked_list)

if not kwargs.get('hard_mask_only', False):
if not parser.use_hard_mask_only :
# White beam Test
__white_masks, num_failed = do_white_test(white_int, parser.tiny, parser.huge,
parser.van_out_lo, parser.van_out_hi,
Expand Down

0 comments on commit 2ac4bc0

Please sign in to comment.