Skip to content

Commit

Permalink
Replace python function with LoadMask. Refs #4882
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed May 10, 2012
1 parent 5c720da commit 3e69fca
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 53 deletions.
47 changes: 0 additions & 47 deletions Code/Mantid/scripts/Inelastic/CommonFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,50 +161,3 @@ def sum_files(accumulator, files, file_type):
Plus(accumulator, temp, accumulator)
else:
pass

def load_mask(hard_mask):
"""
Load a hard mask file and return the
list of spectra numbers it contains as a string
Each line of the file specifies spectra to be masked by either specifying a range
using a hypen or a single spectra number using a space as a delimiter between fields i.e.
48897 - 49152
50000
60100-60105
"""
mask_file = open(hard_mask)
spectra_list = ""
for line in mask_file:
numbers = line.split()
if len(numbers) == 0:
continue
# Any non-numeric character at the start of the line marks a comment,
# check the first character of the first word
if not numbers[0][0].isdigit():
continue
num_cols = len(numbers)
remainder = num_cols % 3
group_end = num_cols - remainder
# Jump in steps of 3 where there are whole blocks
for index in range(0, group_end, 3):
# Can either have a range specified with a "-" or single numbers
n_i = numbers[index]
n_ip1 = numbers[index+1]
n_ip2 = numbers[index+2]
# If there is a dash it will have to be the middle value
if n_ip1 == '-':
spectra_list += n_i + '-' + n_ip2
else:
spectra_list += n_i + "," + n_ip1 + ',' + n_ip2
spectra_list += ","
# Now deal with the remainder
for index in range(group_end,num_cols):
spectra_list += numbers[index] + ","

if len(spectra_list) < 1:
mantid.sendLogMessage('Only comment lines found in mask file ' + hard_mask)
return ''
# Return everything after the very first comma we added in the line above
return spectra_list.rstrip(',')
7 changes: 6 additions & 1 deletion Code/Mantid/scripts/Inelastic/DirectEnergyConversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ def diagnose(self, white, **kwargs):
diagnostics.normalise_background(background_int, whiteintegrals, kwargs.get('second_white',None))
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
14 changes: 9 additions & 5 deletions Code/Mantid/scripts/Inelastic/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def diagnose(white_int, **kwargs):
simply loaded and integrated. A workspace is assumed to be prepared in it's integrated form
Optional inputs:
instrument_name - The name of the instrument (required for hard_masking)
start_index - The index to start the diag
end_index - The index to finish the diag
background_int - A workspace, run number or filepath of a sample run that has been integrated over the background region.
Expand Down Expand Up @@ -74,12 +75,15 @@ def diagnose(white_int, **kwargs):
# Hard mask
hardmask_file = kwargs.get('hard_mask', None)
if hardmask_file is not None:
hard_mask_spectra = common.load_mask(parser.hard_mask)
test_results[0][0] = os.path.basename(parser.hard_mask)
masking = MaskDetectors(white_int, SpectraList=hard_mask_spectra)
LoadMask(Instrument=kwargs.get('instrument_name',''),InputFile=parser.hard_mask,
OutputWorkspace='hard_mask_ws')
MaskDetectors(white_int, MaskedWorkspace='hard_mask_ws')
# Find out how many detectors we hard masked
hard_mask_spectra = masking['SpectraList'].value
test_results[0][1] = len(hard_mask_spectra)
alg = ExtractMask('hard_mask_ws',OutputWorkspace='_dummy_ws')
DeleteWorkspace('_dummy_ws')
masked_list = alg.getProperty('DetectorList').value
test_results[0][0] = os.path.basename(parser.hard_mask)
test_results[0][1] = len(masked_list)

# White beam Test
__white_masks, num_failed = do_white_test(white_int, parser.tiny, parser.huge,
Expand Down

0 comments on commit 3e69fca

Please sign in to comment.