Skip to content

Commit

Permalink
Merge branch 'feature/8505_slicing' into feature/8528_slice_event
Browse files Browse the repository at this point in the history
  • Loading branch information
gesnerpassos committed Nov 29, 2013
2 parents d18e10c + 74cadec commit 12a1b07
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 194 deletions.
25 changes: 10 additions & 15 deletions Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3039,23 +3039,18 @@ bool SANSRunWindow::assignMonitorRun(MantidWidgets::MWRunFiles & trans, MantidWi
assignCom.append(", r'"+direct.getFirstFilename()+"'");

int period = trans.getEntryNum();
//we can only do single period reductions now
if (period == MWRunFiles::ALL_ENTRIES)
if (period != MWRunFiles::ALL_ENTRIES)
{
period = 1;
trans.setEntryNum(period);
assignCom.append(", period_t="+QString::number(period));
}
assignCom.append(", period_t="+QString::number(period));

period = direct.getEntryNum();
//we can only do single period reductions now
if (period == MWRunFiles::ALL_ENTRIES)
if (period != MWRunFiles::ALL_ENTRIES)
{
period = 1;
direct.setEntryNum(period);
assignCom.append(", period_d="+QString::number(period));
}
assignCom.append(", period_d="+QString::number(period)+")");

assignCom.append(")");
//assign the workspace name to a Python variable and read back some details
QString pythonC="t1, t2 = " + assignCom + ";print '"+PYTHON_SEP+"',t1,'"+PYTHON_SEP+"',t2";
QString ws_names = runReduceScriptFunction(pythonC);
Expand Down Expand Up @@ -3092,13 +3087,13 @@ bool SANSRunWindow::assignDetBankRun(MantidWidgets::MWRunFiles & runFile, const
QString assignCom("i."+assignFn+"(r'" + runFile.getFirstFilename() + "'");
assignCom.append(", reload = True");
int period = runFile.getEntryNum();
//we can only do single period reductions now
if (period == MWRunFiles::ALL_ENTRIES)

if (period != MWRunFiles::ALL_ENTRIES)
{
period = 1;
runFile.setEntryNum(period);
assignCom.append(", period = " + QString::number(period));
}
assignCom.append(", period = " + QString::number(period)+")");

assignCom.append(")");

//assign the workspace name to a Python variable and read back some details

Expand Down
84 changes: 34 additions & 50 deletions Code/Mantid/scripts/SANS/ISISCommandInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,30 +330,6 @@ def GetMismatchedDetList():
"""
return ReductionSingleton().instrument.get_marked_dets()

def _setUpPeriod(i):
# it first get the reference to the loaders, then it calls the AssignSample
# (which get rid of the reducer objects (see clean_loaded_data())
# but because we still get the reference, we can use it to query the data file and method.
# ideally, we should not use this _setUpPeriod in the future.

trans_samp = ReductionSingleton().samp_trans_load
can = ReductionSingleton().get_can()
trans_can = ReductionSingleton().can_trans_load
new_sample_workspaces = AssignSample(ReductionSingleton().get_sample().loader._data_file, period=i)[0]
if can:
#replace one thing that gets overwritten
AssignCan(can.loader._data_file, True, period=can.loader.getCorrospondingPeriod(i, ReductionSingleton()))
if trans_samp:
trans = trans_samp.trans
direct = trans_samp.direct
TransmissionSample(trans._data_file, direct._data_file, True, period_t=trans.getCorrospondingPeriod(i, ReductionSingleton()),period_d=direct.getCorrospondingPeriod(i, ReductionSingleton()))
if trans_can:
trans = trans_can.trans
direct = trans_can.direct
TransmissionCan(trans._data_file, direct._data_file, True, period_t=trans.getCorrospondingPeriod(i, ReductionSingleton()),period_d=direct.getCorrospondingPeriod(i, ReductionSingleton()))

return new_sample_workspaces

def WavRangeReduction(wav_start=None, wav_end=None, full_trans_wav=None, name_suffix=None, combineDet=None, resetSetup=True, out_fit_settings = dict()):
"""
Run reduction from loading the raw data to calculating Q. Its optional arguments allows specifics
Expand Down Expand Up @@ -643,36 +619,44 @@ def _WavRangeReduction(name_suffix=None):
"""
Run a reduction that has been set up, from loading the raw data to calculating Q
"""
def _setUpPeriod(period):
assert(ReductionSingleton().get_sample().loader.move2ws(period))
can = ReductionSingleton().get_can()
if can and can.loader.periods_in_file > 1:
can.loader.move2ws(period)

for trans in [ReductionSingleton().samp_trans_load, ReductionSingleton().can_trans_load]:
if trans and trans.direct.periods_in_file > 1 and trans.trans.periods_in_file > 1:
trans.direct.move2ws(period)
trans.trans.move2next(period)
return

def _applySuffix(result, name_suffix):
if name_suffix:
old = result
result += name_suffix
RenameWorkspace(InputWorkspace=old,OutputWorkspace= result)
return result


result = ""
if ReductionSingleton().get_sample().loader.periods_in_file == 1:
result = ReductionSingleton()._reduce()
return _applySuffix(result, name_suffix)

calculated = []
try:
# do a reduction
calculated = [ReductionSingleton()._reduce()]

periods = ReductionSingleton().get_sample().loader.entries
if len(periods) > 1:
run_setup = ReductionSingleton().settings()
for i in periods[1:len(periods)]:
ReductionSingleton.replace(copy.deepcopy(run_setup))
temp_workspaces = _setUpPeriod(i)
# do a reduction for period i
calculated.append(ReductionSingleton()._reduce())
delete_workspaces(temp_workspaces)
result = ReductionSingleton().get_out_ws_name(show_period=False)
all_results = calculated[0]
for name in calculated[1:len(calculated)]:
all_results += ',' + name
GroupWorkspaces(OutputWorkspace=result, InputWorkspaces=all_results)
else:
result = calculated[0]
for period in ReductionSingleton().get_sample().loader.entries:
_setUpPeriod(period)
calculated.append(ReductionSingleton()._reduce())

finally:
f=1 #_refresh_singleton()
if len(calculated) > 0:
allnames = ','.join(calculated)
result = ReductionSingleton().get_out_ws_name(show_period=False)
GroupWorkspaces(OutputWorkspace=result, InputWorkspaces=allnames)

if name_suffix:
old = result
result += name_suffix
RenameWorkspace(InputWorkspace=old,OutputWorkspace= result)

return result
return _applySuffix(result, name_suffix)

def delete_workspaces(workspaces):
"""
Expand Down
31 changes: 22 additions & 9 deletions Code/Mantid/scripts/SANS/SANSUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def getBinsBoundariesFromWorkspace(ws_reference):
return binning

def loadMonitorsFromFile(fileName, monitor_ws_name='monitor_ws'):
monitor = LoadNexus(fileName, SpectrumMax=8, OutputWorkspace=monitor_ws_name)
monitor = LoadNexusMonitors(fileName, OutputWorkspace=monitor_ws_name)
return monitor

def getFilePathFromWorkspace(ws):
Expand All @@ -432,19 +432,32 @@ def getFilePathFromWorkspace(ws):
raise RuntimeError("Can not find the file name for workspace " + str(ws))
return file_path

def getMonitor4event(ws_event):
file_path = getFilePathFromWorkspace(ws_event)
ws_monitor = loadMonitorsFromFile(file_path)
return ws_monitor

def fromEvent2Histogram(ws_event, ws_monitor = None):
if not ws_monitor:
file_path = getFilePathFromWorkspace(ws_event)
ws_monitor = loadMonitorsFromFile(file_path)
"""Transform an event mode workspace into a histogram workspace.
It does conjoin the monitor and the workspace as it is expected from the current
SANS data inside ISIS.
Finally, it copies the parameter map from the workspace to the resulting histogram
in order to preserve the positions of the detectors components inside the workspace.
bins_option = getBinsBoundariesFromWorkspace(ws_monitor)
It will finally, replace the input workspace with the histogram equivalent workspace.
"""
if not ws_monitor:
ws_monitor = getMonitor4event(ws_event)

aux_hist = Rebin(ws_event, bins_option, False)
aux_hist = RebinToWorkspace(ws_event, ws_monitor, False)

monitor_ws_name = ws_monitor.name()
ConjoinWorkspaces(ws_monitor, aux_hist, CheckOverlapping=True)
name = '__monitor_tmp'
ws_monitor.clone(OutputWorkspace=name)
ConjoinWorkspaces(name, aux_hist, CheckOverlapping=True)
CopyInstrumentParameters(ws_event, OutputWorkspace=name)

ws_hist = RenameWorkspace(monitor_ws_name, OutputWorkspace=str(ws_event))
ws_hist = RenameWorkspace(name, OutputWorkspace=str(ws_event))

return ws_hist

Expand Down
28 changes: 21 additions & 7 deletions Code/Mantid/scripts/SANS/isis_reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import reduction.instruments.sans.sans_reduction_steps as sans_reduction_steps
import isis_reduction_steps
from mantid.simpleapi import *
from mantid.api import IEventWorkspace
import os
import copy

Expand Down Expand Up @@ -109,7 +110,8 @@ def _to_steps(self):
"""
Defines the steps that are run and their order
"""
proc_TOF = [self.crop_detector]
proc_TOF = [self.event2hist]
proc_TOF.append(self.crop_detector)
proc_TOF.append(self.mask)
proc_TOF.append(self.to_wavelen)

Expand Down Expand Up @@ -138,7 +140,7 @@ def _init_steps(self):
self._out_name = isis_reduction_steps.GetOutputName()

#except self.prep_normalize all the steps below are used by the reducer
self.crop_detector = isis_reduction_steps.CropDetBank(crop_sample=True)
self.crop_detector = isis_reduction_steps.CropDetBank()
self.mask =self._mask= isis_reduction_steps.Mask_ISIS()
self.to_wavelen = isis_reduction_steps.UnitsConvert('Wavelength')
self.norm_mon = isis_reduction_steps.NormalizeToMonitor()
Expand Down Expand Up @@ -167,6 +169,7 @@ def _clean_loaded_data(self):
self._can_run = Can()
self.samp_trans_load = None
self.can_trans_load = None
self.event2hist = isis_reduction_steps.SliceEvent()

def __init__(self):
SANSReducer.__init__(self)
Expand Down Expand Up @@ -208,6 +211,9 @@ def set_sample(self, run, reload, period):
@param reload: if this sample should be reloaded before the first reduction
@param period: the period within the sample to be analysed
"""
if not self.user_settings.executed:
raise RuntimeError('User settings must be loaded before the sample can be assigned, run UserFile() first')

# ensure that when you set sample, you start with no can, transmission previously used.
self._clean_loaded_data()
self._sample_run.set_run(run, reload, period, self)
Expand All @@ -225,6 +231,13 @@ def get_sample(self):
else:
return self.get_can()

def get_monitor(self, index):
_ws = mtd[self.get_sample().wksp_name]
if isinstance(_ws, IEventWorkspace):
_ws = mtd[self.event2hist.monitor]
__MonitorWs = ExtractSingleSpectrum(_ws, index)
return __MonitorWs

def get_transmissions(self):
""" Get the transmission and direct workspace if they were given
for the can and for the sample"""
Expand Down Expand Up @@ -256,11 +269,8 @@ def get_out_ws_name(self, show_period=True):
"""
sample_obj = self.get_sample().loader
name = str(sample_obj.shortrun_no)
if show_period and sample_obj.periods_in_file > 1:
if sample_obj._period == sample_obj.UNSET_PERIOD:
period = 1
else:
period = sample_obj._period
if show_period and (sample_obj.periods_in_file > 1 or sample_obj._period != -1):
period = sample_obj.curr_period()
name += 'p'+str(period)

name += self.instrument.cur_detector().name('short')
Expand Down Expand Up @@ -311,6 +321,10 @@ def _reduce(self, init=True, post=True, steps=None):

if not steps:
steps = self._reduction_steps

# create the workspace that will be used throughout the reduction
CloneWorkspace(self.get_sample().wksp_name, OutputWorkspace=self.output_wksp)

#the main part of the reduction is done here, go through and execute each step
for item in steps:
if item:
Expand Down

0 comments on commit 12a1b07

Please sign in to comment.