Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/8435_redesign_load_data'
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterParker committed Nov 22, 2013
2 parents 17e23f0 + eb0beb1 commit 9f24f65
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ bool SANSRunWindow::handleLoadButtonClick()
else
{
is_loaded &= assignDetBankRun(*(m_uiForm.scatCan), "AssignCan");
readNumberOfEntries("background_subtracter", m_uiForm.scatCan);
readNumberOfEntries("get_can().loader", m_uiForm.scatCan);
}
if ( ( ! m_uiForm.transmis->isEmpty() ) && ( ! m_uiForm.direct->isEmpty() ) )
{
Expand Down
28 changes: 12 additions & 16 deletions Code/Mantid/scripts/SANS/ISISCommandInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,19 +254,10 @@ def AssignCan(can_run, reload = True, period = isis_reduction_steps.LoadRun.UNSE
mes += ', ' + str(period)
mes += ')'
_printMessage(mes)

if (not can_run) or (isinstance(can_run,str) and can_run.startswith('.')):
ReductionSingleton().background_subtracter = None
return '', None

ReductionSingleton().background_subtracter = \
isis_reduction_steps.CanSubtraction(
can_run, reload=reload, period=period)
#ideally this code should live in a separate load can object
ReductionSingleton().background_subtracter.assign_can(
ReductionSingleton())

ReductionSingleton().set_can(can_run, reload, period)
return _return_old_compatibility_assign_methods(
ReductionSingleton().background_subtracter.workspace.wksp_name)
ReductionSingleton().get_can().wksp_name)

def TransmissionSample(sample, direct, reload = True, period_t = -1, period_d = -1):
"""
Expand Down Expand Up @@ -340,13 +331,18 @@ 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().background_subtracter
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.workspace._data_file, True, period=can.workspace.getCorrospondingPeriod(i, ReductionSingleton()))
AssignCan(can.loader._data_file, True, period=can.loader.getCorrospondingPeriod(i, ReductionSingleton()))
if trans_samp:
trans = trans_samp.trans
direct = trans_samp.direct
Expand Down Expand Up @@ -455,8 +451,8 @@ def WavRangeReduction(wav_start=None, wav_end=None, full_trans_wav=None, name_su
ReductionSingleton().instrument.setDetector('front')
ReductionSingleton()._sample_run.reload(ReductionSingleton())
#reassign can
if ReductionSingleton().background_subtracter:
ReductionSingleton().background_subtracter.assign_can(ReductionSingleton())
if ReductionSingleton().get_can():
ReductionSingleton().get_can().reload(ReductionSingleton())
if ReductionSingleton().samp_trans_load:
#refresh Transmission
ReductionSingleton().samp_trans_load.execute(ReductionSingleton(), None)
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/scripts/SANS/centre_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def SeekCentre(self, setup, trial):

self._group_into_quadrants(setup, 'centre', trial[0], trial[1], suffix='_tmp')

if setup.background_subtracter:
if setup.get_can():
#reduce the can here
setup.reduce_can('centre_can', run_Q=False)

Expand Down Expand Up @@ -100,8 +100,8 @@ def move(self, setup, x, y):
y = -y
MoveInstrumentComponent(Workspace=setup.get_sample().wksp_name,
ComponentName=self.detector, X=x, Y=y, RelativePosition=True)
if setup.background_subtracter:
MoveInstrumentComponent(Workspace=setup.background_subtracter.workspace.wksp_name,
if setup.get_can():
MoveInstrumentComponent(Workspace=setup.get_can().wksp_name,
ComponentName=self.detector, X=x, Y=y, RelativePosition=True)

# Create a workspace with a quadrant value in it
Expand Down
69 changes: 52 additions & 17 deletions Code/Mantid/scripts/SANS/isis_reducer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def _deepcopy_method(x, memo):
current_settings = None

class Sample(object):
ISSAMPLE = True
def __init__(self):
#will contain a LoadSample() object that converts the run number into a file name and loads that file
self.loader = None
Expand Down Expand Up @@ -62,14 +63,21 @@ def set_run(self, run, reload, period, reducer):
self.period_option = period

self.loader = isis_reduction_steps.LoadSample(run, reload, period)
self.loader.execute(reducer, None)

self.geometry.execute(None, self.get_wksp_name())
self.loader.execute(reducer, self.ISSAMPLE)
if self.ISSAMPLE:
self.geometry.execute(None, self.get_wksp_name())

def get_wksp_name(self):
return self.loader.wksp_name

def get_periods_in_file(self):
return self.loader.periods_in_file

wksp_name = property(get_wksp_name, None, None, None)
periods_in_file = property(get_periods_in_file, None, None, None)

class Can(Sample):
ISSAMPLE = False

class ISISReducer(SANSReducer):
"""
Expand Down Expand Up @@ -110,7 +118,7 @@ def _to_steps(self):
proc_wav.append(self._corr_and_scale)
proc_wav.append(self.geometry_correcter)

self._can = [self.background_subtracter]
self._can = [self._background_subtracter]

# self._tidy = [self._zero_error_flags]
self._tidy = [self._rem_nans]
Expand All @@ -131,8 +139,6 @@ def _init_steps(self):

#except self.prep_normalize all the steps below are used by the reducer
self.crop_detector = isis_reduction_steps.CropDetBank(crop_sample=True)
self.samp_trans_load = None
self.can_trans_load = None
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 All @@ -149,18 +155,22 @@ def _init_steps(self):

self.to_Q = isis_reduction_steps.ConvertToQISIS(
self.prep_normalize)
self.background_subtracter = None
self.geometry_correcter = sans_reduction_steps.SampleGeomCor(
self._sample_run.geometry)
self._background_subtracter = isis_reduction_steps.CanSubtraction()
self.geometry_correcter = sans_reduction_steps.SampleGeomCor()
# self._zero_error_flags=isis_reduction_steps.ReplaceErrors()
self._rem_nans = sans_reduction_steps.StripEndNans()

self.set_Q_output_type(self.to_Q.output_type)

def _clean_loaded_data(self):
self._sample_run = Sample()
self._can_run = Can()
self.samp_trans_load = None
self.can_trans_load = None

def __init__(self):
SANSReducer.__init__(self)
self._dark_current_subtracter_class = None
self._sample_run = Sample()
self.output_wksp = None
self.full_trans_wav = False
self._monitor_set = False
Expand All @@ -171,6 +181,7 @@ def __init__(self):
#all workspaces created by this reducer
self._workspace = [self._temporys, self._outputs]

self._clean_loaded_data()
self._init_steps()

#process the background (can) run instead of the sample
Expand All @@ -189,14 +200,20 @@ def __init__(self):
# register the value of transmission can
self.__transmission_can = ""


def set_sample(self, run, reload, period):
"""
Assigns and load the run that this reduction chain will analysis
@param run: the run in a number.raw|nxs format
@param reload: if this sample should be reloaded before the first reduction
@param period: the period within the sample to be analysed
"""
# 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)

def set_can(self, run, reload, period):
self._can_run.set_run(run, reload, period, self)

def get_sample(self):
"""
Expand All @@ -206,7 +223,29 @@ def get_sample(self):
if not self._process_can:
return self._sample_run
else:
return self.background_subtracter
return self.get_can()

def get_transmissions(self):
""" Get the transmission and direct workspace if they were given
for the can and for the sample"""
if self._process_can:
loader = self.can_trans_load
else:
loader = self.samp_trans_load
if loader:
return loader.trans.wksp_name, loader.direct.wksp_name
else:
return "", ""

def get_can(self):
if self._can_run.loader and self._can_run.wksp_name:
return self._can_run
else:
return None

# for compatibility reason, previously, background_subtracter was used to
# query if the can was provided and for the can reduction.
background_subtracter = property(get_can, None, None, None)

def get_out_ws_name(self, show_period=True):
"""
Expand Down Expand Up @@ -373,18 +412,14 @@ def set_trans_fit(self, lambda_min=None, lambda_max=None, fit_method="Log", sele
self.transmission_calculator.set_trans_fit(fit_method, lambda_min, lambda_max, override=True, selector=selector)

def set_trans_sample(self, sample, direct, reload=True, period_t = -1, period_d = -1):
if not issubclass(self.samp_trans_load.__class__, sans_reduction_steps.BaseTransmission):
self.samp_trans_load = isis_reduction_steps.LoadTransmissions(reload=reload)
self.samp_trans_load = isis_reduction_steps.LoadTransmissions(reload=reload)
self.samp_trans_load.set_trans(sample, period_t)
self.samp_trans_load.set_direc(direct, period_d)
self.transmission_calculator.samp_loader = self.samp_trans_load

def set_trans_can(self, can, direct, reload = True, period_t = -1, period_d = -1):
if not issubclass(self.can_trans_load.__class__, sans_reduction_steps.BaseTransmission):
self.can_trans_load = isis_reduction_steps.LoadTransmissions(is_can=True, reload=reload)
self.can_trans_load = isis_reduction_steps.LoadTransmissions(is_can=True, reload=reload)
self.can_trans_load.set_trans(can, period_t)
self.can_trans_load.set_direc(direct, period_d)
self.transmission_calculator.can_loader = self.can_trans_load

def set_monitor_spectrum(self, specNum, interp=False, override=True):
if override:
Expand Down

0 comments on commit 9f24f65

Please sign in to comment.