Skip to content

Commit

Permalink
refs #6667 Attempted to implement masks reuse.
Browse files Browse the repository at this point in the history
Which does not work because of the way xml mask interacts with workspace. left for the time being.
  • Loading branch information
abuts committed Jul 5, 2013
1 parent 0aa884c commit 5dc8cbb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 32 deletions.
19 changes: 14 additions & 5 deletions Code/Mantid/instrument/MAPS_Parameters.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
<parameter name="hard_mask_file" type="string">
<value val="None"/>
</parameter>
<!-- The if true, use only hard mask file specified above and do not run diagnostics procedures -->
<parameter name="use_hard_mask_only" type="bool">
<value val="False"/>
</parameter>
<!-- The map file used when calculating absolute units conversion integrals
This map usually groups together large areas of detectors to obtain proper vanadium statistics -->
<parameter name="monovan_mapfile" type="string">
Expand Down Expand Up @@ -323,6 +319,19 @@
<value val="True"/>
</parameter>

<!-- The if true, use only hard mask file specified above and do not run diagnostics procedures -->
<parameter name="use_hard_mask_only" type="bool">
<value val="False"/>
</parameter>

<!-- If this parameter is set to true, dgreduce will try to load mask from the mask file
correspondent to the run if finds it and uses this mask as hard mask only (does not run diagnostics).
If such file has not been found, it will run diagnostics and save the masks into mask file for reuse
Hard Mask file, provided separately or as additional hard mask file is ignored in this case -->
<parameter name="save_and_reuse_masks" type="bool">
<value val="False"/>
</parameter>


<!-- List of the words which can be used as a command line arguments to define reducer keywords
the form is reducer_keword1=synonim1=synonim2=synonim3;reducer_keword1=synonim1a, so,
Expand All @@ -343,7 +352,7 @@
monovan_hi_value = monovan-integr-max;
use_hard_mask_only=hardmaskOnly;
bkgd_range = background_range;
hard_mask = hard_mask_file=hardmaskPlus;
hard_mask_file=hard_mask = =hardmaskPlus;
van_out_lo = diag_van_median_rate_limit_lo=diag_van_out_lo;
van_out_hi = diag_van_median_rate_limit_hi=diag_van_out_hi;
van_lo = diag_van_median_sigma_lo=diag_van_lo;
Expand Down
16 changes: 9 additions & 7 deletions Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def diagnose(self, white, **kwargs):
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 'hard_mask_file' in kwargs:
if 'instrument_name' not in kwargs:
kwargs['instrument_name'] = self.instr_name

Expand All @@ -122,14 +122,14 @@ def diagnose(self, white, **kwargs):
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
# SNS or 1 to 1 maps may probably awoid this stuff and can 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'],
diag_mask= LoadMask(Instrument=self.instr_name,InputFile=kwargs['hard_mask_file'],
OutputWorkspace='hard_mask_ws')
MaskDetectors(Workspace=white_data, MaskedWorkspace=diag_mask)
diag_mask,masked_list = ExtractMask(InputWorkspace=white_data)
Expand Down Expand Up @@ -350,12 +350,12 @@ def _do_mono(self, data_ws, monitor_ws, result_name, ei_guess,
mon1_peak = 0.0
# apply T0 shift
ChangeBinOffset(InputWorkspace=data_ws,OutputWorkspace= result_name,Offset=-tzero)
self.ei_guess = ei_value
self.incident_en = ei_value
else:
# Do ISIS stuff for Ei
# Both are these should be run properties really
ei_value, mon1_peak = self.get_ei(monitor_ws, result_name, ei_guess)
self.ei_guess = ei_value
self.incident_en = ei_value

# As we've shifted the TOF so that mon1 is at t=0.0 we need to account for this in FlatBackground and normalisation
bin_offset = -mon1_peak
Expand Down Expand Up @@ -477,7 +477,7 @@ def convert_to_energy(self, mono_run, ei, white_run=None, mono_van=None,\
"""
One-shot function to convert the given runs to energy
"""
self.ei_guess = ei;
self.incident_en = ei;
# Check if we need to perform the absolute normalisation first
if not mono_van is None:
if abs_ei is None:
Expand Down Expand Up @@ -556,11 +556,13 @@ def get_ei(self, input_ws, resultws_name, ei_guess):
else:
raise TypeError('Unknown option passed to get_ei "%s"' % fix_ei)

self.incident_en= ei_guess
# Calculate the incident energy
ei,mon1_peak,mon1_index,tzero = \
GetEi(InputWorkspace=input_ws, Monitor1Spec=int(self.ei_mon_spectra[0]), Monitor2Spec=int(self.ei_mon_spectra[1]),
EnergyEstimate=ei_guess,FixEi=self.fix_ei)

self.incident_en = ei
# Adjust the TOF such that the first monitor peak is at t=0
ChangeBinOffset(InputWorkspace=input_ws,OutputWorkspace= resultws_name,Offset= -float(str(mon1_peak)))
mon1_det = input_ws.getDetector(mon1_index)
Expand Down Expand Up @@ -921,7 +923,7 @@ def init_idf_params(self, reload_instrument=False):
# and tries to get rest from the correspondent dgreduced attributes
self.__diag_params = ['diag_tiny', 'diag_huge', 'diag_samp_zero', 'diag_samp_lo', 'diag_samp_hi','diag_samp_sig',\
'diag_van_out_lo', 'diag_van_out_hi', 'diag_van_lo', 'diag_van_hi', 'diag_van_sig', 'diag_variation',\
'diag_bleed_test','diag_bleed_pixels','diag_bleed_maxrate','diag_hard_mask','diag_use_hard_mask_only','diag_bkgd_range']
'diag_bleed_test','diag_bleed_pixels','diag_bleed_maxrate','diag_hard_mask_file','diag_use_hard_mask_only','diag_bkgd_range']

self.__normalization_methods=['none','monitor-1','current'] # 'monitor-2','uamph', peak -- disabled/unknown at the moment

Expand Down
51 changes: 35 additions & 16 deletions Code/Mantid/scripts/Inelastic/dgreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,36 +231,55 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No
RenameWorkspace(InputWorkspace=accum,OutputWorkspace=inst_name+str(sample_run[0])+'.raw')
sample_run=sample_run[0]

masks_done=False
if Reducer.save_and_reuse_masks :
raise NotImplementedError("Save and reuse masks option is not yet implemented")
mask_file_name = common.create_resultname(str(mask_run),Reducer.instr_name,'_masks.xml')
mask_full_file = FileFinder.getFullPath(mask_file_name)
if len(mask_full_file) > 0 :
masking = LoadMask(Instrument=Reducer.instr_name,InputFile=mask_full_file,OutputWorkspace=mask_file_name)
#Reducer.hard_mask_file = mask_full_file;
#Reducer.use_hard_mask_only = True
masks_done=True
header="Masking loaded "
else:
pass
#-------------------------------------------------------------------------------------------------------------------------------------------------------
# Here we give control to the Reducer
# --------------------------------------------------------------------------------------------------------
# diag the sample and detector vanadium. It will deal with hard mask only if it is set that way
masking = Reducer.diagnose(wb_run,sample = mask_run,
# diag the sample and detector vanadium. It will deal with hard mask only if it is set that way
if not masks_done:
masking = Reducer.diagnose(wb_run,sample = mask_run,
second_white = None,variation=1.1,print_results=True)
header = "Diag Processed "


# Calculate absolute units:
if monovan_run != None :
if Reducer.mono_correction_factor == None :
if Reducer.use_sam_msk_on_monovan == True:
Reducer.log(' Applying sample run mask to mono van')
else:
print '########### Run diagnose for monochromatic vanadium run ##############'
masking2 = Reducer.diagnose(wb_for_monovanadium,sample=monovan_run,
if monovan_run != None :
if Reducer.mono_correction_factor == None :
if Reducer.use_sam_msk_on_monovan == True:
Reducer.log(' Applying sample run mask to mono van')
else:
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)
if not Reducer.use_hard_mask_only : # in this case the masking2 is different but points to the same workspace Should be better soulution for that.
masking += masking2
if not Reducer.use_hard_mask_only : # in this case the masking2 is different but points to the same workspace Should be better soulution for that.
masking += masking2


else: # if Reducer.mono_correction_factor != None :
pass
else: # if Reducer.mono_correction_factor != None :
pass

# save mask if it does not exist and has been already loaded
if Reducer.save_and_reuse_masks and not masks_done:
SaveMask(InputWorkspace=masking,OutputFile = mask_file_name,GroupedDetectors=True)

Reducer.spectra_masks=masking
# estimate and report the number of failing detectors
failed_sp_list,nSpectra = get_failed_spectra_list_from_masks(masking)
nMaskedSpectra = len(failed_sp_list)
# 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)
print '{0} workspace with {1:d} spectra and masked {2:d} bad spectra'.format(header,nSpectra,nMaskedSpectra)
#Run the conversion first on the sample
deltaE_wkspace_sample = Reducer.convert_to_energy(sample_run, ei_guess, wb_run)

Expand All @@ -276,7 +295,7 @@ def arb_units(wb_run,sample_run,ei_guess,rebin,map_file='default',monovan_run=No


#ei= (deltaE_wkspace_sample.getRun().getLogData("Ei").value)
print 'Incident energy found for sample run: ',Reducer.eifixed,' meV'
print 'Incident energy found for sample run: ',Reducer.incident_en,' meV'

end_time=time.time()
print 'Elapsed time =',end_time-start_time, 's'
Expand Down Expand Up @@ -325,7 +344,7 @@ def abs_units(wb_for_run,sample_run,monovan_run,wb_for_monovanadium,samp_rmm,sam
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)
hard_mask_file - 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)
Expand Down
8 changes: 4 additions & 4 deletions Code/Mantid/scripts/Inelastic/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def diagnose(white_int, **kwargs):
If a run/file is given it simply loaded and integrated across the whole range
sample_counts - A workspace containing the total integrated counts from a sample run
second_white - If provided an additional set of tests is performed on this.
hard_mask - A file specifying those spectra that should be masked without testing
hard_mask_file - A file specifying those spectra that should be masked without testing
tiny - Minimum threshold for acceptance
huge - Maximum threshold for acceptance
van_out_lo - Lower bound defining outliers as fraction of median value
Expand Down Expand Up @@ -65,15 +65,15 @@ def diagnose(white_int, **kwargs):
test_results = [ [None, None], [None, None], [None, None], [None, None], [None, None]]

# Hard mask
hardmask_file = kwargs.get('hard_mask', None)
hardmask_file = kwargs.get('hard_mask_file', None)
if hardmask_file is not None:
LoadMask(Instrument=kwargs.get('instrument_name',''),InputFile=parser.hard_mask,
LoadMask(Instrument=kwargs.get('instrument_name',''),InputFile=parser.hard_mask_file,
OutputWorkspace='hard_mask_ws')
MaskDetectors(Workspace=white_int, MaskedWorkspace='hard_mask_ws')
# Find out how many detectors we hard masked
_dummy_ws,masked_list = ExtractMask(InputWorkspace='hard_mask_ws')
DeleteWorkspace('_dummy_ws')
test_results[0][0] = os.path.basename(parser.hard_mask)
test_results[0][0] = os.path.basename(parser.hard_mask_file)
test_results[0][1] = len(masked_list)

if not parser.use_hard_mask_only :
Expand Down

0 comments on commit 5dc8cbb

Please sign in to comment.