Skip to content

Commit

Permalink
Fix LoadVesuvio run finder when extension is provided.
Browse files Browse the repository at this point in the history
Refs #18843
  • Loading branch information
martyngigg committed Feb 20, 2017
1 parent cdb86e7 commit ce56023
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 16 deletions.
39 changes: 26 additions & 13 deletions Framework/PythonInterface/plugins/algorithms/LoadVesuvio.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import copy
import numpy as np
import re
import six

RUN_PROP = "Filename"
WKSP_PROP = "OutputWorkspace"
Expand All @@ -18,6 +20,8 @@
LOAD_MON = "LoadMonitors"
WKSP_PROP_LOAD_MON= "OutputMonitorWorkspace"

FILENAME_RE = re.compile(r'^([0-9]+)(\.[a-zA-z]+)?$')

# Raw workspace names which are necessary at the moment
SUMMED_WS = "__loadraw_evs"
# Enumerate the indexes for the different foil state sums
Expand Down Expand Up @@ -315,22 +319,13 @@ def _exec_single_foil_state_mode(self):
"""

runs = self._get_runs()

all_spectra = [item for sublist in self._spectra for item in sublist]

if len(runs) > 1:
self._set_spectra_type(all_spectra[0])
self._setup_raw(all_spectra)
else:
isis = config.getFacility("ISIS")
vesuvio = isis.instrument("VESUVIO")
run_no = runs[0]
run_str = vesuvio.filePrefix(int(run_no)) + run_no

self._raise_error_period_scatter(run_str, self._back_scattering)
all_spectra = [item for sublist in self._spectra for item in sublist]

self._load_single_run_spec_and_mon(all_spectra, run_str)
self._load_single_run_spec_and_mon(all_spectra, self._get_filename(runs[0]))

raw_group = mtd[SUMMED_WS]
self._nperiods = raw_group.size()
Expand Down Expand Up @@ -408,7 +403,27 @@ def _exec_single_foil_state_mode(self):

#----------------------------------------------------------------------------------------

def _get_filename(self, run_or_filename):
"""Given a string containing either a filename/partial filename or run number find the correct
file prefix"""
isis = config.getFacility("ISIS")
vesuvio = isis.instrument("VESUVIO")
if isinstance(run_or_filename, six.integer_types):
run_no = run_or_filename
return vesuvio.filePrefix(int(run_no)) + str(run_or_filename)
else:
match = FILENAME_RE.match(run_or_filename)
if match:
run_no = match.group(1)
return vesuvio.filePrefix(int(run_no)) + str(run_or_filename)
else:
# Assume file is okay and give it a go with Load
return run_or_filename

#----------------------------------------------------------------------------------------

def _load_single_run_spec_and_mon(self, all_spectra, run_str):
self._raise_error_period_scatter(run_str, self._back_scattering)
# check if the monitor spectra are already in the spectra list
filtered_spectra = sorted([i for i in all_spectra if i <= self._mon_spectra[-1]])
mons_in_ws = False
Expand Down Expand Up @@ -579,15 +594,13 @@ def _load_and_sum_runs(self, spectra):
@param spectra :: The list of spectra to load
@returns a tuple of length 2 containing (main_detector_ws, monitor_ws)
"""
isis = config.getFacility("ISIS")
vesuvio = isis.instrument("VESUVIO")
runs = self._get_runs()

self.summed_ws, self.summed_mon = "__loadraw_evs", "__loadraw_evs_monitors"
spec_inc_mon = self._mon_spectra
spec_inc_mon.extend(spectra)
for index, run in enumerate(runs):
filename = vesuvio.filePrefix(int(run)) + str(run)
filename = self._get_filename(run)
self._raise_error_period_scatter(filename, self._back_scattering)
if index == 0:
out_name, out_mon = SUMMED_WS, SUMMED_WS + '_monitors'
Expand Down
21 changes: 20 additions & 1 deletion Testing/SystemTests/tests/analysis/LoadVesuvioTest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pylint: disable=invalid-name,no-init,too-many-public-methods,too-many-arguments
import stresstesting

from mantid.api import MatrixWorkspace, mtd
from mantid.api import FileFinder, MatrixWorkspace, mtd
import mantid.simpleapi as ms

import math
Expand Down Expand Up @@ -46,6 +46,25 @@ def test_spectrum_list_comma_separated_ranges(self):

#================== Success cases ================================

def test_filename_accepts_full_filepath(self):
diff_mode = "FoilOut"
rawfile = FileFinder.getFullPath("EVS14188.raw")
self._run_load(rawfile, "3", diff_mode)
self.assertTrue(mtd.doesExist('evs_raw'))
self.assertEquals(mtd['evs_raw'].getNumberHistograms(), 1)

def test_filename_accepts_filename_no_path(self):
diff_mode = "FoilOut"
self._run_load("EVS14188.raw", "3", diff_mode)
self.assertTrue(mtd.doesExist('evs_raw'))
self.assertEquals(mtd['evs_raw'].getNumberHistograms(), 1)

def test_filename_accepts_run_and_ext(self):
diff_mode = "FoilOut"
self._run_load("14188.raw", "3", diff_mode)
self.assertTrue(mtd.doesExist('evs_raw'))
self.assertEquals(mtd['evs_raw'].getNumberHistograms(), 1)

def test_load_with_back_scattering_spectra_produces_correct_workspace_using_double_difference(self):
diff_mode = "DoubleDifference"
self._run_load("14188", "3-134", diff_mode)
Expand Down
4 changes: 2 additions & 2 deletions scripts/Inelastic/IndirectReductionCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def load_files(data_files, ipf_filename, spec_min, spec_max, sum_files=False, lo
logger.debug('Loading file %s as workspace %s' % (filename, ws_name))

if 'VESUVIO' in ipf_filename:
evs_filename = os.path.basename(str(filename)).replace('EVS', '')
LoadVesuvio(Filename=evs_filename,
# Load all spectra. They are cropped later
LoadVesuvio(Filename=filename,
OutputWorkspace=ws_name,
SpectrumList='1-198',
**load_opts)
Expand Down

0 comments on commit ce56023

Please sign in to comment.