Skip to content

Commit

Permalink
refs #4328 #3641. First version working end to end.
Browse files Browse the repository at this point in the history
 Overall algorithm dialog. Can convert workspaces and save them to disk. Merging next.
  • Loading branch information
OwenArnold committed Jan 6, 2012
1 parent 977cb2e commit 4abbbfb
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace MantidQt

void addWorkspaceClicked();

void addRawFileClicked();
void addNexusFileClicked();

void addEventNexusFileClicked();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="btn_add_raw_file">
<widget class="QPushButton" name="btn_add_nexus_file">
<property name="text">
<string>Add Raw File</string>
<string>Add Nexus</string>
</property>
</widget>
</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ class CreateMDWorkspaceAlgDialog : public QDialog
QString getOtherDimensions() const;
QString getMaxExtents() const;
QString getMinExtents() const;
QString getLocation() const;
bool getPreprocessedEvents() const;

private slots:

void outputLocationClicked();

private:

Ui::CreateMDWorkspaceAlgDialog m_uiForm;

QString m_location;

};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>456</width>
<height>205</height>
<height>216</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -17,7 +17,7 @@
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="toolTip">
<string>You can to transfer source workspace dimensions into target worskpace directly (NoQ) or transform into mod(Q) (1 dimension) or QxQyQz (3 dimensions) in Q space</string>
Expand All @@ -27,10 +27,10 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="combo_q_dimensions"/>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="toolTip">
<string>You can analyze neutron energy transfer in direct, indirect or elastic mode. The analysis mode has to correspond to experimenal set up.</string>
Expand All @@ -40,10 +40,10 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QComboBox" name="combo_analysis_mode"/>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string>List(comma separated) of additional to Q (orthogonal) dimensions in the target workspace.</string>
Expand All @@ -53,10 +53,10 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QLineEdit" name="txt_other_dimensions"/>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QCheckBox" name="ck_use_preprocessed_detectors">
<property name="text">
<string>Use Pre-processed detectors</string>
Expand All @@ -66,7 +66,7 @@
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_3">
<property name="toolTip">
<string>An array of size:
Expand Down Expand Up @@ -96,7 +96,7 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="QLineEdit" name="txt_min_values">
<property name="toolTip">
<string>An array of the same size and the same units as MinValues array
Expand All @@ -105,17 +105,17 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="7" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Max Values</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="7" column="1">
<widget class="QLineEdit" name="txt_max_values"/>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -132,6 +132,19 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="btn_output_location">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Set Output Location</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
36 changes: 24 additions & 12 deletions Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void CreateMDWorkspace::initLayout()
m_uiForm.setupUi(this);
connect(m_uiForm.btn_create, SIGNAL(clicked()), this, SLOT(createMDWorkspaceClicked()));
connect(m_uiForm.btn_add_workspace, SIGNAL(clicked()), this, SLOT(addWorkspaceClicked()));
connect(m_uiForm.btn_add_raw_file, SIGNAL(clicked()), this, SLOT(addRawFileClicked()));
connect(m_uiForm.btn_add_nexus_file, SIGNAL(clicked()), this, SLOT(addNexusFileClicked()));
connect(m_uiForm.btn_add_event_nexus_file, SIGNAL(clicked()), this, SLOT(addEventNexusFileClicked()));
connect(m_uiForm.btn_remove_workspace, SIGNAL(clicked()), this, SLOT(removeSelectedClicked()));
connect(m_uiForm.btn_set_ub_matrix, SIGNAL(clicked()), this, SLOT(setUBMatrixClicked()));
Expand Down Expand Up @@ -282,13 +282,13 @@ void CreateMDWorkspace::addUniqueMemento(WorkspaceMemento_sptr candidate)
}

/*
Add a raw file from the ADS
Add a nexus file from the ADS
*/
void CreateMDWorkspace::addRawFileClicked()
void CreateMDWorkspace::addNexusFileClicked()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
"/home",
tr("Raw Files (*.raw)"));
tr("Raw Files (*.nxs)"));

std::string name = fileName.toStdString();
if(!name.empty())
Expand Down Expand Up @@ -415,14 +415,12 @@ int CreateMDWorkspace::runConfirmation(const std::string& message)

void CreateMDWorkspace::createMDWorkspaceClicked()
{
//Launch dialog

//1) Run a top-level dialog similar to ConvertToMDEvents. Extract all required arguments.
CreateMDWorkspaceAlgDialog algDlg;
algDlg.setModal(true);
int result = algDlg.exec();
if(result != QDialog::Accepted)
{
runConfirmation("Aborted by user.");
return;
}

Expand All @@ -432,6 +430,12 @@ void CreateMDWorkspace::createMDWorkspaceClicked()
QString analysisMode = algDlg.getAnalysisMode();
QString otherDimensions = algDlg.getOtherDimensions();
bool preProcessedEvents = algDlg.getPreprocessedEvents();
QString location = algDlg.getLocation();
if(location.isEmpty())
{
runConfirmation("Output location is mandatory. Please start again and enter one.");
return;
}

//2) Run ConvertToMDEvents on each workspace.
for(WorkspaceMementoCollection::size_type i = 0; i < m_data.size(); i++)
Expand All @@ -440,12 +444,20 @@ void CreateMDWorkspace::createMDWorkspaceClicked()
Workspace_sptr ws = currentMemento->applyActions();

//
//QString command = ""
// "";
QString command = "try:\n"
" ConvertToMDEvents(InputWorkspace='%1',OutputWorkspace='%1_md',OtherDimensions='%2',dEAnalysisMode='%3',QDimensions='%4',MinValues='%5',MaxValues='%6')\n"
" SaveMD(InputWorkspace='%1_md', Filename='%7/%1_md.nxs',MakeFileBacked='1')\n"
" mtd.deleteWorkspace('%1_md')\n"
"except:\n"
" print 'FAIL'";

//ConvertToMDEvents
//SaveMD

command = command.arg(QString(currentMemento->getId().c_str()), otherDimensions, analysisMode, qDimension, minExtents, maxExtents, location);
QString pyOutput = runPythonCode(command).trimmed();
if(pyOutput == "FAIL")
{
runConfirmation("Aborted during conversion. See log messages.");
return; //Abort.
}

currentMemento->cleanUp();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
#include <QComboBox>
#include <QLineEdit>
#include <QCheckBox>
#include <QFileDialog>

CreateMDWorkspaceAlgDialog::CreateMDWorkspaceAlgDialog()
{
m_uiForm.setupUi(this);

connect(m_uiForm.btn_output_location, SIGNAL(clicked()), this, SLOT(outputLocationClicked()));
connect(m_uiForm.buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(m_uiForm.buttonBox, SIGNAL(rejected()), this, SLOT(reject()));

m_uiForm.combo_q_dimensions->addItem("|Q|");
m_uiForm.combo_q_dimensions->addItem("QxQyQz");

m_uiForm.combo_analysis_mode->addItem("Direct");
m_uiForm.combo_analysis_mode->addItem("Elastic");
m_uiForm.combo_analysis_mode->addItem("Indirect");
m_uiForm.combo_analysis_mode->addItem("InElastic");


this->setWindowTitle("Set MDWorkspace Creation Parameters");
}

Expand Down Expand Up @@ -50,6 +52,16 @@ bool CreateMDWorkspaceAlgDialog::getPreprocessedEvents() const
return m_uiForm.ck_use_preprocessed_detectors->isChecked();
}

QString CreateMDWorkspaceAlgDialog::getLocation() const
{
return m_location;
}

CreateMDWorkspaceAlgDialog::~CreateMDWorkspaceAlgDialog()
{
}

void CreateMDWorkspaceAlgDialog::outputLocationClicked()
{
this->m_location = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "/home");
}
8 changes: 4 additions & 4 deletions Code/Mantid/MantidQt/CustomInterfaces/src/RawFileMemento.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ namespace MantidQt
*/
RawFileMemento::RawFileMemento(std::string fileName) : m_fileName(fileName)
{
boost::regex pattern("(RAW)$", boost::regex_constants::icase);
boost::regex pattern("(NXS)$", boost::regex_constants::icase);

if(!boost::regex_search(fileName, pattern))
{
std::string msg = "RawFileMemento:: Unknown File extension on: " + fileName;
std::string msg = "NexusFileMemento:: Unknown File extension on: " + fileName;
throw std::invalid_argument(msg);
}

if(!checkStillThere())
{
throw std::runtime_error("RawFileMemento:: File doesn't exist");
throw std::runtime_error("NexusFileMemento:: File doesn't exist");
}

std::vector<std::string> strs;
Expand Down Expand Up @@ -86,7 +86,7 @@ namespace MantidQt
{
checkStillThere();

IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("LoadRaw");
IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("LoadNexus");
alg->initialize();
alg->setRethrows(true);
alg->setProperty("Filename", m_fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class RawFileMementoTest : public CxxTest::TestSuite

static std::string getSuitableFileNamePath()
{
return Mantid::API::FileFinder::Instance().getFullPath("LOQ48127.raw");
return Mantid::API::FileFinder::Instance().getFullPath("LOQ49886.nxs");
}

public:

void testConstructorThrowsWithWrongExtension()
{
std::string badFile = "MAR11001.rrr"; //Fictional extension
std::string badFile = "LOQ49886.nxss"; //Fictional extension
TSM_ASSERT_THROWS("Unknown extension, should throw.", new RawFileMemento(badFile), std::invalid_argument);
}

Expand All @@ -37,7 +37,7 @@ class RawFileMementoTest : public CxxTest::TestSuite

void testConstructThrowsWhenFileDoesntExist()
{
TSM_ASSERT_THROWS("Unknown file, should throw.", new RawFileMemento("MadeUp.raw"), std::runtime_error);
TSM_ASSERT_THROWS("Unknown file, should throw.", new RawFileMemento("MadeUp.nxs"), std::runtime_error);
}

void testFetchItSucceedsWhenFileExists()
Expand Down

0 comments on commit 4abbbfb

Please sign in to comment.