Skip to content

Commit

Permalink
Merge branch 'feature/8455_correct_sample_geom_cor' into feature/8444…
Browse files Browse the repository at this point in the history
…_multiperiod_data
  • Loading branch information
gesnerpassos committed Nov 18, 2013
2 parents 80ed3a6 + 4a28c18 commit 6f8718c
Show file tree
Hide file tree
Showing 11 changed files with 394 additions and 295 deletions.
Expand Up @@ -156,9 +156,9 @@ class SANSRunWindow : public MantidQt::API::UserSubWindow
/// Create a mask string
void addUserMaskStrings(QString & exec_script,const QString& importCommand,enum MaskType mType);
/// Set geometry details
void setGeometryDetails(const QString & sample_logs, const QString & can_logs);
void setGeometryDetails();
/// Set the SANS2D geometry
void setSANS2DGeometry(boost::shared_ptr<Mantid::API::MatrixWorkspace> workspace, const QString & logs, int wscode);
void setSANS2DGeometry(boost::shared_ptr<Mantid::API::MatrixWorkspace> workspace, int wscode);
/// Set LOQ geometry
void setLOQGeometry(boost::shared_ptr<Mantid::API::MatrixWorkspace> workspace, int wscode);
/// Mark an error on a label
Expand All @@ -168,7 +168,7 @@ class SANSRunWindow : public MantidQt::API::UserSubWindow
/// Run an assign command
bool runAssign(int key, QString & logs);
/// Load a scatter sample file or can run via Python objects using the passed Python command
bool assignDetBankRun(MantidWidgets::MWRunFiles & runFile, const QString & assignFn, QString & logs);
bool assignDetBankRun(MantidWidgets::MWRunFiles & runFile, const QString & assignFn);
/// runs that contain only monitor counts can be direct or transmission runs
bool assignMonitorRun(MantidWidgets::MWRunFiles & trans, MantidWidgets::MWRunFiles & direct, const QString & assignFn);
/// Get the detectors' names
Expand Down
95 changes: 37 additions & 58 deletions Code/Mantid/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
Expand Up @@ -1422,7 +1422,7 @@ void SANSRunWindow::applyMask(const QString& wsName,bool time_pixel)
/**
* Set the information about component distances on the geometry tab
*/
void SANSRunWindow::setGeometryDetails(const QString & sample_logs, const QString & can_logs)
void SANSRunWindow::setGeometryDetails()
{
resetGeometryDetailsBox();

Expand Down Expand Up @@ -1506,7 +1506,7 @@ void SANSRunWindow::setGeometryDetails(const QString & sample_logs, const QStrin
}

//SANS2D - Sample
setSANS2DGeometry(sample_workspace, sample_logs, 0);
setSANS2DGeometry(sample_workspace, 0);
//Get the can workspace if there is one
QString can = m_experCan;
if( can.isEmpty() )
Expand All @@ -1530,7 +1530,7 @@ void SANSRunWindow::setGeometryDetails(const QString & sample_logs, const QStrin
can_workspace = getGroupMember(workspace_ptr, 1);
}

setSANS2DGeometry(can_workspace, can_logs, 1);
setSANS2DGeometry(can_workspace, 1);

//Check for discrepancies
bool warn_user(false);
Expand Down Expand Up @@ -1569,10 +1569,9 @@ void SANSRunWindow::setGeometryDetails(const QString & sample_logs, const QStrin
/**
* Set SANS2D geometry info
* @param workspace :: The workspace
* @param logs :: The log information
* @param wscode :: ?????
* @param wscode :: 0 for sample, 1 for can, others not defined
*/
void SANSRunWindow::setSANS2DGeometry(boost::shared_ptr<Mantid::API::MatrixWorkspace> workspace, const QString & logs, int wscode)
void SANSRunWindow::setSANS2DGeometry(boost::shared_ptr<Mantid::API::MatrixWorkspace> workspace, int wscode)
{
double unitconv = 1000.;

Expand All @@ -1596,33 +1595,30 @@ void SANSRunWindow::setSANS2DGeometry(boost::shared_ptr<Mantid::API::MatrixWorks
dist_label = m_uiForm.dist_bkgd_ms_s2d;
}
dist_label->setText(formatDouble(distance, "black", 'f', 1));

// get the tuple of log values and convert to a list of
QString code_to_run = QString("print ','.join([str(a) for a in i.ReductionSingleton().instrument.getDetValues('%1')])").arg(QString::fromStdString(workspace->name()));

// Detectors
QStringList det_info = logs.split(",");
QStringListIterator itr(det_info);
while( itr.hasNext() )
{
QString line = itr.next();
QStringList values = line.split(":");
QString detname = values[0].trimmed();
QString distance = values[1].trimmed();
trimPyMarkers(detname);

// instrument scientists wants distances printed
// out with just one digit
try
{
double d = distance.toDouble();
distance = QString::number(d, 'f', 1);
}
catch(...)
{
// if distance is not a double for some reason
// for now just proceed
}
QStringList logvalues = runReduceScriptFunction(code_to_run).split(",");

QLabel *lbl = m_s2d_detlabels[wscode].value(detname);
if( lbl ) lbl->setText(distance);
QStringList dets_names;
dets_names << "Front_Det_Z"
<< "Front_Det_X"
<< "Front_Det_Rot"
<< "Rear_Det_Z"
<< "Rear_Det_X";
int index = 0;
foreach(QString detname, dets_names){
QString distance = logvalues[index];
try{
double d = distance.toDouble();
distance = QString::number(d, 'f', 1);
}catch(...){
// if distance is not a double, for now just proceed
}
QLabel * lbl = m_s2d_detlabels[wscode].value(detname);
if (lbl) lbl->setText(distance);
index += 1;
}
}

Expand Down Expand Up @@ -1818,20 +1814,19 @@ bool SANSRunWindow::handleLoadButtonClick()
// set the detector just before loading so to correctly move the instrument
runReduceScriptFunction("\ni.ReductionSingleton().instrument.setDetector('" +
m_uiForm.detbank_sel->currentText() + "')");
QString sample_logs, can_logs;
QString sample = m_uiForm.scatterSample->getFirstFilename();
try
{//preliminarly error checking is over try to load that data
is_loaded &= assignDetBankRun(*(m_uiForm.scatterSample), "AssignSample", sample_logs);
is_loaded &= assignDetBankRun(*(m_uiForm.scatterSample), "AssignSample");
readNumberOfEntries("get_sample().loader", m_uiForm.scatterSample);
if (m_uiForm.scatCan->isEmpty())
{
m_experCan = "";
}
else
{
is_loaded &= assignDetBankRun(*(m_uiForm.scatCan), "AssignCan", can_logs);
readNumberOfEntries("background_subtracter", m_uiForm.scatCan);
is_loaded &= assignDetBankRun(*(m_uiForm.scatCan), "AssignCan");
readNumberOfEntries("get_can().loader", m_uiForm.scatCan);
}
if ( ( ! m_uiForm.transmis->isEmpty() ) && ( ! m_uiForm.direct->isEmpty() ) )
{
Expand All @@ -1858,28 +1853,15 @@ bool SANSRunWindow::handleLoadButtonClick()
g_log.error() << "Problem loading file\n";
is_loaded = false;
}
if( m_uiForm.inst_opt->currentText() == "SANS2D" && sample_logs.isEmpty() )
{
is_loaded = false;
showInformationBox("Error: Cannot find log file for sample run, cannot continue.");
}
if (!is_loaded)
{
setProcessingState(NoSample);
m_uiForm.load_dataBtn->setText("Load Data");
return false;
}
if( m_uiForm.inst_opt->currentText() == "SANS2D" && can_logs.isEmpty() )
{
if ( ! m_uiForm.scatCan->isEmpty() )
{
can_logs = sample_logs;
showInformationBox("Warning: Cannot find log file for can run, using sample values.");
}
}

// Sort out the log information
setGeometryDetails(sample_logs, can_logs);
setGeometryDetails();

Mantid::API::Workspace_sptr baseWS =
Mantid::API::AnalysisDataService::Instance().retrieve(m_experWksp.toStdString());
Expand Down Expand Up @@ -2601,6 +2583,8 @@ void SANSRunWindow::handleDefSaveClick()
saveCommand += "'front-detector, rear-detector'";
if ( matrix_workspace->getInstrument()->getName() == "LOQ" )
saveCommand += "'HAB, main-detector-bank'";
if ( matrix_workspace->getInstrument()->getName() == "LARMOR")
saveCommand += "'" + m_uiForm.detbank_sel->currentText()+"'";

/* From v2, SaveCanSAS1D is able to save the Transmission workspaces related to the
reduced data. The name of workspaces of the Transmission are available at the
Expand Down Expand Up @@ -3098,10 +3082,9 @@ bool SANSRunWindow::assignMonitorRun(MantidWidgets::MWRunFiles & trans, MantidWi
* Load a scatter sample file or can run via Python objects using the passed Python command
* @param[in] runFile name of file to load
* @param[in] assignFn the Python command to run
* @param[out] logs information loaded from the file
* @return true if there were no Python errors, false otherwise
*/
bool SANSRunWindow::assignDetBankRun(MantidWidgets::MWRunFiles & runFile, const QString & assignFn, QString & logs)
bool SANSRunWindow::assignDetBankRun(MantidWidgets::MWRunFiles & runFile, const QString & assignFn)
{
//need something to place between names printed by Python that won't be intepreted as the names or removed as white space
const static QString PYTHON_SEP("C++assignDetBankRunC++");
Expand All @@ -3125,7 +3108,9 @@ bool SANSRunWindow::assignDetBankRun(MantidWidgets::MWRunFiles & runFile, const
.arg( m_uiForm.rear_beam_y->text())
.arg( m_uiForm.front_beam_x->text())
.arg( m_uiForm.front_beam_y->text());
run_info += "SCATTER_SAMPLE, logvalues = " + assignCom+";print '"+PYTHON_SEP+"',SCATTER_SAMPLE,'"+PYTHON_SEP+"',logvalues";
run_info += "SCATTER_SAMPLE = " + assignCom;
run_info += ";ws_name = SCATTER_SAMPLE if not isinstance(SCATTER_SAMPLE, tuple) else SCATTER_SAMPLE[0]";
run_info += ";print '"+PYTHON_SEP+"',ws_name";
run_info = runReduceScriptFunction(run_info);
if (run_info.startsWith("error", Qt::CaseInsensitive))
{
Expand All @@ -3134,12 +3119,6 @@ bool SANSRunWindow::assignDetBankRun(MantidWidgets::MWRunFiles & runFile, const
//read the informtion returned from Python
QString base_workspace = run_info.section(PYTHON_SEP, 1, 1).trimmed();

logs = run_info.section(PYTHON_SEP, 2);
if( !logs.isEmpty() )
{
trimPyMarkers(logs);
}

if ( assignFn.contains("can", Qt::CaseInsensitive) )
{
m_experCan = base_workspace;
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/instrument/Facilities.xml
Expand Up @@ -76,6 +76,7 @@

<instrument name="LARMOR">
<technique>Small Angle Scattering</technique>
<zeropadding size="8"/>
<livedata address="NDXLARMOR:6789" />
</instrument>

Expand Down
55 changes: 55 additions & 0 deletions Code/Mantid/instrument/LARMOR_Parameters.xml
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8" ?>
<parameter-file instrument = "LARMOR" valid-from = "2013-11-06T00:00:00">

<component-link name = "LARMOR">

<parameter name="low-angle-detector-name" type="string">
<value val="DetectorBench"/>
</parameter>

<parameter name="low-angle-detector-short-name" type="string">
<value val="rear"/>
</parameter>

<parameter name="default-incident-monitor-spectrum">
<value val="2"/>
</parameter>

<parameter name="default-transmission-monitor-spectrum">
<value val="3"/>
</parameter>

<parameter name="low-angle-detector-num-rows">
<value val="512"/>
</parameter>

<parameter name="low-angle-detector-num-columns">
<value val="80"/>
</parameter>


<parameter name="high-angle-detector-num-columns">
<value val="0"/>
</parameter>

<parameter name="high-angle-detector-num-rows">
<value val="0"/>
</parameter>

<parameter name="high-angle-detector-name" type="string">
<value val="front-detector"/>
</parameter>

<parameter name="high-angle-detector-short-name" type="string">
<value val="front"/>
</parameter>


<parameter name="centre-finder-step-size">
<!-- this is the initial step for the beam centre finder in metres -->
<value val="0.005"/>
</parameter>

</component-link>

</parameter-file>
61 changes: 43 additions & 18 deletions Code/Mantid/scripts/SANS/ISISCommandInterface.py
Expand Up @@ -100,6 +100,21 @@ def LOQ():
except:
return False
return True

def LARMOR():
"""
Initialises the instrument settings for LARMOR
@return True on success
"""
_printMessage('LARMOR()')
try:
instrument = isis_instrument.LARMOR()

ReductionSingleton().set_instrument(instrument)
config['default.instrument']='LARMOR'
except:
return False
return True

def Detector(det_name):
"""
Expand Down Expand Up @@ -208,6 +223,20 @@ def TransWorkspace(sample, can = None):
ReductionSingleton().transmission_calculator.calculated_samp = sample
ReductionSingleton().transmission_calculator.calculated_can = can

def _return_old_compatibility_assign_methods(ws_name):
"""For backward compatibility, AssignCan and AssignSample returns a tuple
with workspace name and the log entry if available.
In the future, those methods should return just workspace name
"""
logs = ""
if isinstance(ReductionSingleton().instrument, isis_instrument.SANS2D):
try:
logs = ReductionSingleton().instrument.get_detector_log(ws_name)
except:
pass
return ws_name, logs

def AssignCan(can_run, reload = True, period = isis_reduction_steps.LoadRun.UNSET_PERIOD):
"""
The can is a scattering run under the same conditions as the experimental run but the
Expand All @@ -225,18 +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
logs = ReductionSingleton().background_subtracter.assign_can(
ReductionSingleton())
return ReductionSingleton().background_subtracter.workspace.wksp_name, logs

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

def TransmissionSample(sample, direct, reload = True, period_t = -1, period_d = -1):
"""
Expand Down Expand Up @@ -285,8 +306,7 @@ def AssignSample(sample_run, reload = True, period = isis_reduction_steps.LoadRu

global LAST_SAMPLE
LAST_SAMPLE = ReductionSingleton().get_sample().wksp_name
return ReductionSingleton().get_sample().wksp_name, \
ReductionSingleton().get_sample().log
return _return_old_compatibility_assign_methods(LAST_SAMPLE)

def SetCentre(xcoord, ycoord, bank = 'rear'):
"""
Expand All @@ -311,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 @@ -426,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

0 comments on commit 6f8718c

Please sign in to comment.