diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/CMakeLists.txt b/Code/Mantid/Framework/WorkflowAlgorithms/CMakeLists.txt index 7809c4acfe1cd38deeeb73097ff49161457265cd..66608b1282f9ed33659e09e0cf1a8b1efbe74d90 100644 --- a/Code/Mantid/Framework/WorkflowAlgorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/WorkflowAlgorithms/CMakeLists.txt @@ -14,7 +14,6 @@ set ( SRC_FILES src/EQSANSMonitorTOF.cpp src/EQSANSPatchSensitivity.cpp src/EQSANSQ2D.cpp - src/EQSANSReduce.cpp src/HFIRDarkCurrentSubtraction.cpp src/HFIRInstrument.cpp src/HFIRLoad.cpp diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/src/EQSANSReduce.cpp b/Code/Mantid/Framework/WorkflowAlgorithms/src/EQSANSReduce.cpp deleted file mode 100644 index d8b5b9ce9bb07703be203957171253e3d6461aef..0000000000000000000000000000000000000000 --- a/Code/Mantid/Framework/WorkflowAlgorithms/src/EQSANSReduce.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/*WIKI* -Perform EQSANS reduction. This algorithm is used for live reduction -and can handle MPI. -*WIKI*/ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidWorkflowAlgorithms/EQSANSReduce.h" -#include "MantidAPI/FileProperty.h" -#include "MantidAPI/PropertyManagerDataService.h" -#include "MantidKernel/PropertyManager.h" -#include "MantidKernel/EnabledWhenProperty.h" -#include "MantidAPI/MatrixWorkspace.h" - -namespace Mantid -{ -namespace WorkflowAlgorithms -{ - -// Register the algorithm into the AlgorithmFactory -DECLARE_ALGORITHM(EQSANSReduce) - -/// Sets documentation strings for this algorithm -void EQSANSReduce::initDocs() -{ - this->setWikiSummary("Workflow to perform EQSANS reduction."); - this->setOptionalMessage("Workflow to perform EQSANS reduction."); -} - -using namespace Kernel; -using namespace API; -using namespace Geometry; - -void EQSANSReduce::init() -{ - declareProperty(new API::FileProperty("Filename", "", API::FileProperty::OptionalLoad, "_event.nxs"), - "File containing the data to reduce"); - declareProperty(new WorkspaceProperty<>("InputWorkspace", "", Direction::Input, PropertyMode::Optional), - "Workspace to be reduced"); - declareProperty("ReductionProcess", true, - "If true, both the reduction and the post-processing will be run"); - - setPropertySettings("Filename", new EnabledWhenProperty("ReductionProcess", IS_EQUAL_TO, "1") ); - - declareProperty("PostProcess", false, - "If true, I(q) will be computed from the input workspace"); - declareProperty(new API::FileProperty("LogDataFile", "", API::FileProperty::OptionalLoad, ".nxs"), - "For testing: optional file containing the sample logs"); - setPropertySettings("LogDataFile", new EnabledWhenProperty("ReductionProcess", IS_EQUAL_TO, "1") ); - - declareProperty("ReductionProperties", "__eqsans_reduction_properties", Direction::Input); - - declareProperty(new WorkspaceProperty<>("OutputWorkspace", "", Direction::Output), - "Workspace containing the sensitivity correction."); - declareProperty(new FileProperty("OutputFile", "", FileProperty::OptionalSave, ".nxs"), - "File path for the output nexus file"); -} - -/** - * Determine whether the input data is a file or a workspace and load it. - */ -Workspace_sptr EQSANSReduce::loadInputData() -{ - setLoadAlg("LoadEventNexus"); - Workspace_sptr inputWS; - - std::string inputData = getPropertyValue("Filename"); - const std::string inputWSName = getPropertyValue("InputWorkspace"); - if (!inputWSName.empty() && !inputData.empty()) - throw std::runtime_error("EQSANSReduce: Either the Filename property or InputWorkspace property must be provided, NOT BOTH"); - else if (!inputWSName.empty()) - inputWS = load(inputWSName); - else if (!inputData.empty()) - inputWS = load(inputData); - else - throw std::runtime_error("EQSANSReduce: Either the Filename property or InputWorkspace property must be provided"); - - return inputWS; -} - -/** - * Perform the reduction process on the given workspace. - * @param workspace :: name of the workspace to reduce - */ -void EQSANSReduce::performReduction(Workspace_sptr workspace) -{ - if (!workspace) - throw std::runtime_error("EQSANSReduce.performReduction was passed a pointer to no workspace"); - - // For testing the live reduction, we may need to load some - // logs from another file - const std::string logFile = getPropertyValue("LogDataFile"); - if (!logFile.empty()) - { - IAlgorithm_sptr alg = this->createChildAlgorithm("LoadNexusLogs"); - alg->setLogging(false); - alg->setProperty("Workspace", workspace); - alg->setPropertyValue("Filename", logFile); - alg->setProperty("OverwriteLogs", true); - alg->execute(); - } - - // Write the Reducer python script to be executed - std::string script = "import reduction.instruments.sans.sns_command_interface as cmd\n"; - script += "cmd.AppendDataFile([\"" + workspace->name() + "\"])\n"; - script += "cmd.Reduce1D()\n"; - - // Run a snippet of python - IAlgorithm_sptr alg = this->createChildAlgorithm("RunOldPythonScript"); - alg->setLogging(true); - alg->setPropertyValue("Code", script); - alg->execute(); -} - -/** - * Perform post-processing (I(q) calculation) on the reduced workspace. - * In the case of MPI jobs, the post-processing is done on the assemble workspace. - * @param workspace :: name of the workspace to process - */ -Workspace_sptr EQSANSReduce::postProcess(Workspace_sptr workspace) -{ - // Construct the script's output workspace name - const std::string outputIq = workspace->name() + "_Iq"; - - // Write the Reducer python script to be executed - std::string script = "import reduction.instruments.sans.sns_command_interface as cmd\n"; - script += "from reduction.instruments.sans.sns_reduction_steps import AzimuthalAverageByFrame\n"; - script += "averager = AzimuthalAverageByFrame()\n"; - script += "output = \"" + outputIq + "\"\n"; - script += "averager.execute(cmd.ReductionSingleton(),\"" + workspace->name() + "\")\n"; - - // Run a snippet of python - IAlgorithm_sptr scriptAlg = this->createChildAlgorithm("RunOldPythonScript"); - scriptAlg->setLogging(true); - scriptAlg->setPropertyValue("Code", script); - scriptAlg->setPropertyValue("OutputWorkspace", outputIq); - scriptAlg->execute(); - - Workspace_sptr outputWS = AnalysisDataService::Instance().retrieve(outputIq); - - MatrixWorkspace_sptr matrixWS = boost::dynamic_pointer_cast<MatrixWorkspace>(outputWS); - matrixWS *= getNThreads(); - - return outputWS; -} - -void EQSANSReduce::exec() -{ - // Check the validity of the input data and load as appropriate - Workspace_sptr workspace = loadInputData(); - - // Reduce the data - const bool doReduction = getProperty("ReductionProcess"); - const bool doPostProcessing = getProperty("PostProcess"); - const std::string outputFile = getPropertyValue("OutputFile"); - - if (doReduction) performReduction(workspace); - - // Assemble parts (MPI jobs only) - std::string outputWSName = workspace->name(); - Workspace_sptr assembledWS = assemble(outputWSName, outputWSName); - - if (doPostProcessing) - { - if (isMainThread()) - { - workspace = postProcess(assembledWS); - saveNexus(workspace->name(), outputFile); - } - setProperty("OutputWorkspace", workspace); - } - else if (doReduction) - { - setProperty("OutputWorkspace", workspace); - } - else - g_log.error() << "EQSANSReduce: The ReductionProcess and PostProcess properties are set to false: nothing to do" << std::endl; - -} - -} // namespace WorkflowAlgorithms -} // namespace Mantid - diff --git a/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupEQSANSReduction.cpp b/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupEQSANSReduction.cpp index 31c9650d4bee1d42126bcd05a268fd31e8f9c914..3e39ddb494f3e7a0c581e89105ddc4246d854d90 100644 --- a/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupEQSANSReduction.cpp +++ b/Code/Mantid/Framework/WorkflowAlgorithms/src/SetupEQSANSReduction.cpp @@ -450,10 +450,6 @@ void SetupEQSANSReduction::init() setPropertyGroup("AbsoluteScalingAttenuatorTrans", abs_scale_grp); setPropertyGroup("AbsoluteScalingApplySensitivity", abs_scale_grp); - - // Setup the version 1 reducer - declareProperty("SetupReducer",false, "If true, a Reducer object will be created"); - // I(Q) calculation std::string iq1d_grp = "I(q) Calculation"; declareProperty("DoAzimuthalAverage", true); @@ -760,154 +756,6 @@ void SetupEQSANSReduction::exec() reductionManager->declareProperty(algProp); } setPropertyValue("OutputMessage", "EQSANS reduction options set"); - - // Create a python reduction singleton as needed - const bool setupReducer = getProperty("SetupReducer"); - if (setupReducer) initializeReduction(reductionManager); -} - -/* - * For backward compatibility, we have the option of creating a - * python ReductionSingleton object. - */ -void SetupEQSANSReduction::initializeReduction(boost::shared_ptr<PropertyManager> reductionManager) -{ - // Write the Reducer python script to be executed - std::string script = "import reduction.instruments.sans.sns_command_interface as cmd\n"; - const std::string reductionManagerName = getProperty("ReductionProperties"); - const bool preserveEvents = getProperty("PreserveEvents"); - - // - beam center - double center_x = 0.0; - double center_y = 0.0; - if (reductionManager->existsProperty("LatestBeamCenterX") - && reductionManager->existsProperty("LatestBeamCenterY")) - { - center_x = reductionManager->getProperty("LatestBeamCenterX"); - center_y = reductionManager->getProperty("LatestBeamCenterY"); - } - else - throw std::runtime_error("EQSANSReduce not yet compatible with beam finder: enter beam center coordinates"); - - if (preserveEvents) - script += "cmd.EQSANS(True, \"" + reductionManagerName + "\")\n"; - else - script += "cmd.EQSANS(False, \"" + reductionManagerName + "\")\n"; - script += "cmd.SetBeamCenter(" + Poco::NumberFormatter::format(center_x, 2) - + ", " + Poco::NumberFormatter::format(center_y, 2) + ")\n"; - - // - sensitivity file - if (reductionManager->existsProperty("SensitivityAlgorithm")) - { - IAlgorithm_sptr effAlg = reductionManager->getProperty("SensitivityAlgorithm"); - const std::string fileName = effAlg->getPropertyValue("Filename"); - if (fileName.size()>0) - script += "cmd.SensitivityCorrection(\"" + fileName + "\")\n"; - } - - // - load options - const bool useConfig = getProperty("UseConfig"); - if (useConfig) - script += "cmd.UseConfig(True)\n"; - else - script += "cmd.UseConfig(False)\n"; - - if (reductionManager->existsProperty("LoadAlgorithm")) - { - IAlgorithm_sptr loadAlg = reductionManager->getProperty("LoadAlgorithm"); - - // Correct for flight path? - const bool tofCorr = loadAlg->getProperty("CorrectForFlightPath"); - if (tofCorr) - script += "cmd.PerformFlightPathCorrection(True)\n"; - else - script += "cmd.PerformFlightPathCorrection(False)\n"; - - // Use TOF cut from config file? - const bool confTOF = loadAlg->getProperty("UseConfigTOFCuts"); - if (confTOF) - script += "cmd.UseConfigTOFTailsCutoff(use_config=True)\n"; - else - { - script += "cmd.UseConfigTOFTailsCutoff(use_config=False)\n"; - // Manual TOF cut - const double lowTOF = loadAlg->getProperty("LowTOFCut"); - const double highTOF = loadAlg->getProperty("HighTOFCut"); - script += "cmd.SetTOFTailsCutoff(low_cut=" + Poco::NumberFormatter::format(lowTOF, 2) - + ", high_cut=" + Poco::NumberFormatter::format(highTOF, 2) + ")\n"; - } - - // Use config mask? - const bool confMask = loadAlg->getProperty("UseConfigMask"); - if (confMask) - script += "cmd.UseConfigMask(use_config=True)\n"; - else - script += "cmd.UseConfigMask(use_config=False)\n"; - } - - // - Solid angle correction - const bool solidAngle = getProperty("SolidAngleCorrection"); - if (solidAngle) - script += "cmd.SolidAngle()\n"; - else - script += "cmd.NoSolidAngle()\n"; - - // - Dark current - const std::string darkCurrentFile = getPropertyValue("DarkCurrentFile"); - if (darkCurrentFile.size() > 0) - { - script += "cmd.DarkCurrent(\"" + darkCurrentFile + "\")\n"; - } - - // - Normalization options - if (reductionManager->existsProperty("NormaliseAlgorithm")) - { - IAlgorithm_sptr normAlg = reductionManager->getProperty("NormaliseAlgorithm"); - const bool normaliseToBeam = normAlg->getProperty("NormaliseToBeam"); - const bool normaliseToMonitor = normAlg->getProperty("NormaliseToMonitor"); - const std::string fileName = normAlg->getPropertyValue("BeamSpectrumFile"); - if (normaliseToMonitor) - { - script += "cmd.BeamMonitorNormalization(\"" + fileName + "\")\n"; - } else { - if (normaliseToBeam) - script += "cmd.TotalChargeNormalization(normalize_to_beam=True)\n"; - else - script += "cmd.TotalChargeNormalization(normalize_to_beam=False)\n"; - } - } - - // - Transmission - const double trans = getProperty("TransmissionValue"); - const bool thetaDependent = getProperty("ThetaDependentTransmission"); - if (isEmpty(trans)) - { - const std::string directBeam = getPropertyValue("TransmissionDirectBeam"); - const std::string emptyBeam = getPropertyValue("TransmissionEmptyBeam"); - - script += "cmd.DirectBeamTransmission(\"" + directBeam - + "\", \"" + emptyBeam + "\")\n"; - if (thetaDependent) - script += "cmd.ThetaDependentTransmission(True)\n"; - else - script += "cmd.ThetaDependentTransmission(False)\n"; - } - else - { - if (thetaDependent) - script += "cmd.SetTransmission(" + Poco::NumberFormatter::format(trans, 2) + ", 0.0, True)\n"; - else - script += "cmd.SetTransmission(" + Poco::NumberFormatter::format(trans, 2) + ", 0.0, False)\n"; - } - script += "cmd.ReductionSingleton().set_azimuthal_averager(None)\n"; - - g_log.information() << "Reducer script:\n" << script << std::endl; - - // Run a snippet of python - IAlgorithm_sptr alg = this->createChildAlgorithm("RunOldPythonScript"); - alg->setLogging(false); - alg->setPropertyValue("Code", script); - alg->execute(); } void SetupEQSANSReduction::setupSensitivity(boost::shared_ptr<PropertyManager> reductionManager)