Skip to content

Commit

Permalink
Added grouping workspace to indirect energy conversion tab
Browse files Browse the repository at this point in the history
Refs #10085
  • Loading branch information
DanNixon committed Aug 18, 2014
1 parent 188df16 commit d17a494
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
Expand Up @@ -647,15 +647,11 @@ namespace CustomInterfaces
{
using namespace Mantid::API;

QString groupFile = m_uiForm.cbInst->itemData(m_uiForm.cbInst->currentIndex()).toString().toLower()
+ "_" + m_uiForm.cbAnalyser->currentText() + m_uiForm.cbReflection->currentText()
+ "_" + groupType + ".map";

QString specRange = m_uiForm.leSpectraMin->text() + "," + m_uiForm.leSpectraMax->text();

if(groupType == "File")
{
groupFile = m_uiForm.ind_mapFile->getFirstFilename();
QString groupFile = m_uiForm.ind_mapFile->getFirstFilename();
if(groupFile == "")
{
emit showMessageBox("You must enter a path to the .map file.");
Expand All @@ -664,16 +660,19 @@ namespace CustomInterfaces
}
else if(groupType == "Groups")
{
IAlgorithm_sptr mappingAlg = AlgorithmManager::Instance().create("CreateMappingFile");
mappingAlg->initialize();
QString groupWS = "__Grouping";

mappingAlg->setProperty("Filename", groupFile.toStdString());
mappingAlg->setProperty("GroupCount", m_uiForm.leNoGroups->text().toStdString());
mappingAlg->setProperty("SpectraRange", specRange.toStdString());
IAlgorithm_sptr groupingAlg = AlgorithmManager::Instance().create("CreateGroupingWorkspace");
groupingAlg->initialize();

mappingAlg->execute();
groupingAlg->setProperty("FixedGroupCount", m_uiForm.leNoGroups->text().toInt());
groupingAlg->setProperty("InstrumentName", m_uiForm.cbInst->currentText().toStdString());
groupingAlg->setProperty("ComponentName", m_uiForm.cbAnalyser->currentText().toStdString());
groupingAlg->setProperty("OutputWorkspace", groupWS.toStdString());

return groupFile;
groupingAlg->execute();

return groupWS;
}
else
{
Expand Down
39 changes: 27 additions & 12 deletions Code/Mantid/scripts/Inelastic/inelastic_indirect_reduction_steps.py
Expand Up @@ -947,25 +947,40 @@ def _group_data(self, workspace):
for i in range(0, nhist):
if i not in self._masking_detectors:
wslist.append(i)
GroupDetectors(InputWorkspace=workspace,OutputWorkspace= workspace,
GroupDetectors(InputWorkspace=workspace, OutputWorkspace=workspace,
WorkspaceIndexList=wslist, Behaviour='Average')
else:
# Assume we have a grouping file.
# First lets, find the file...
if (os.path.isfile(grouping)):
grouping_filename = grouping
else:
grouping_filename = os.path.join(config.getString('groupingFiles.directory'),
grouping)
# We may have either a workspace name or a mapping file name here
grouping_workspace = None
grouping_filename = None

# See if it a workspace in ADS
# If not assume it is a mapping file
try:
grouping_workspace = mtd[grouping]
except KeyError:
logger.notice("Cannot find group workspace " + grouping + ", attempting to find as file")

# See if it is an absolute path
# Otherwise check in the default group files directory
if (os.path.isfile(grouping)):
grouping_filename = grouping
else:
grouping_filename = os.path.join(config.getString('groupingFiles.directory'), grouping)

#mask detectors before grouping if we need to
# Mask detectors before grouping if we need to
if len(self._masking_detectors) > 0:
MaskDetectors(workspace, WorkspaceIndexList=self._masking_detectors)

# Final check that the Mapfile exists, if not don't run the alg.
if os.path.isfile(grouping_filename):
GroupDetectors(InputWorkspace=workspace,OutputWorkspace=workspace, MapFile=grouping_filename,
# Run GroupDetectors with a workspace if we have one
# Otherwise try to run it with a mapping file
if grouping_workspace is not None:
GroupDetectors(InputWorkspace=workspace, OutputWorkspace=workspace, CopyGroupingFromWorkspace=grouping_workspace,
Behaviour='Average')
elif os.path.isfile(grouping_filename):
GroupDetectors(InputWorkspace=workspace, OutputWorkspace=workspace, MapFile=grouping_filename,
Behaviour='Average')

return workspace

class SaveItem(ReductionStep):
Expand Down

0 comments on commit d17a494

Please sign in to comment.