diff --git a/Framework/DataHandling/CMakeLists.txt b/Framework/DataHandling/CMakeLists.txt index f9752115822b..e0f66ec3a078 100644 --- a/Framework/DataHandling/CMakeLists.txt +++ b/Framework/DataHandling/CMakeLists.txt @@ -176,7 +176,6 @@ set(SRC_FILES src/SaveDaveGrp.cpp src/SaveDetectorsGrouping.cpp src/SaveDiffCal.cpp - src/SaveDiffFittingAscii.cpp src/SaveDspacemap.cpp src/SaveFITS.cpp src/SaveFocusedXYE.cpp @@ -398,7 +397,6 @@ set(INC_FILES inc/MantidDataHandling/SaveDaveGrp.h inc/MantidDataHandling/SaveDetectorsGrouping.h inc/MantidDataHandling/SaveDiffCal.h - inc/MantidDataHandling/SaveDiffFittingAscii.h inc/MantidDataHandling/SaveDspacemap.h inc/MantidDataHandling/SaveFITS.h inc/MantidDataHandling/SaveFocusedXYE.h diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveAscii2.h b/Framework/DataHandling/inc/MantidDataHandling/SaveAscii2.h index cf1fcaf47df4..c36ed4f44f92 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/SaveAscii2.h +++ b/Framework/DataHandling/inc/MantidDataHandling/SaveAscii2.h @@ -53,8 +53,7 @@ class MANTID_DATAHANDLING_DLL SaveAscii2 final : public API::Algorithm { /// Algorithm's version for identification overriding a virtual method int version() const override { return 2; } const std::vector seeAlso() const override { - return {"LoadAscii", "SaveCSV", "SaveDiffFittingAscii", "SaveReflectometryAscii", - "SaveOpenGenieAscii", "SaveGSS", "SaveFocusedXYE"}; + return {"LoadAscii", "SaveCSV", "SaveReflectometryAscii", "SaveOpenGenieAscii", "SaveGSS", "SaveFocusedXYE"}; } /// Algorithm's category for identification overriding a virtual method const std::string category() const override { return "DataHandling\\Text"; } diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveDiffFittingAscii.h b/Framework/DataHandling/inc/MantidDataHandling/SaveDiffFittingAscii.h deleted file mode 100644 index 617833bb475d..000000000000 --- a/Framework/DataHandling/inc/MantidDataHandling/SaveDiffFittingAscii.h +++ /dev/null @@ -1,77 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" -#include "MantidAPI/DeprecatedAlgorithm.h" -#include "MantidAPI/ITableWorkspace_fwd.h" -#include "MantidDataHandling/DllConfig.h" - -namespace Mantid { -namespace DataHandling { - -class MANTID_DATAHANDLING_DLL SaveDiffFittingAscii : public Mantid::API::Algorithm, public API::DeprecatedAlgorithm { -public: - /// (Empty) Constructor - SaveDiffFittingAscii(); - - /// Algorithm's name - const std::string name() const override { return "SaveDiffFittingAscii"; } - - /// Summary of algorithms purpose - const std::string summary() const override { - return "Saves the results to ASCII file after carrying out single peak " - "fitting process " - "or running " - "EnggFitPeaks algorithm."; - } - - /// Algorithm's version - int version() const override { return (1); } - const std::vector seeAlso() const override { return {"EnggFitPeaks", "SaveAscii"}; } - - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "DataHandling\\Text"; } - -private: - /// Initialisation code - void init() override; - - /// Execution code - void exec() override; - - /// Process two groups and ensure the Result string is set properly on the - /// final algorithm - bool processGroups() override; - - /// Cross-check properties with each other @see IAlgorithm::validateInputs - std::map validateInputs() override; - - /// Main exec routine, called for group or individual workspace processing. - void processAll(const std::vector &input_ws); - - std::vector splitList(std::string strList); - - void writeInfo(const std::string &runNumber, const std::string &bank, std::ofstream &file); - - void writeHeader(const std::vector &columnHeadings, std::ofstream &file); - - void writeData(const API::ITableWorkspace_sptr &workspace, std::ofstream &file, const size_t columnSize); - - void writeVal(const std::string &val, std::ofstream &file, const bool endline); - - /// the separator - const char m_sep; - - /// table_counter - int m_counter; -}; -} // namespace DataHandling -} // namespace Mantid diff --git a/Framework/DataHandling/src/SaveDiffFittingAscii.cpp b/Framework/DataHandling/src/SaveDiffFittingAscii.cpp deleted file mode 100644 index b8bfad04dea8..000000000000 --- a/Framework/DataHandling/src/SaveDiffFittingAscii.cpp +++ /dev/null @@ -1,290 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "MantidDataHandling/SaveDiffFittingAscii.h" - -#include "MantidAPI/FileProperty.h" -#include "MantidAPI/TableRow.h" -#include "MantidAPI/WorkspaceGroup.h" -#include "MantidDataObjects/TableWorkspace.h" -#include "MantidKernel/ListValidator.h" -#include "MantidKernel/MandatoryValidator.h" -#include "Poco/File.h" -#include -#include - -namespace Mantid::DataHandling { - -using namespace Kernel; -using namespace Mantid::API; - -// Register the algorithm into the algorithm factory -DECLARE_ALGORITHM(SaveDiffFittingAscii) - -/// Empty constructor -SaveDiffFittingAscii::SaveDiffFittingAscii() : Mantid::API::Algorithm(), m_sep(','), m_counter(0) { - useAlgorithm("EnggSaveSinglePeakFitResultsToHDF5", 1); -} - -/// Initialisation method. -void SaveDiffFittingAscii::init() { - - declareProperty(std::make_unique>("InputWorkspace", "", Direction::Input), - "The name of the workspace containing the data you want to " - "save to a TBL file"); - - // Declare required parameters, filename with ext {.his} and input - // workspace - const std::vector exts{".txt", ".csv", ""}; - declareProperty(std::make_unique("Filename", "", API::FileProperty::Save, exts), - "The filename to use for the saved data"); - - declareProperty("RunNumber", "", - "Run number list of the focused files, which is used to generate the " - "parameters table workspace"); - - declareProperty("Bank", "", - "Bank number list of the focused files, which is used to generate " - "the parameters table workspace"); - - std::vector formats; - - formats.emplace_back("AppendToExistingFile"); - formats.emplace_back("OverwriteFile"); - declareProperty("OutMode", "AppendToExistingFile", std::make_shared(formats), - "Over write the file or append data to existing file"); -} - -/** - * Executes the algorithm. - */ -void SaveDiffFittingAscii::exec() { - - // Retrieve the input workspace - /// Workspace - const ITableWorkspace_sptr tbl_ws = getProperty("InputWorkspace"); - if (!tbl_ws) - throw std::runtime_error("Please provide an input table workspace to be saved."); - - std::vector input_ws; - input_ws.emplace_back(std::dynamic_pointer_cast(tbl_ws)); - - processAll(input_ws); -} - -bool SaveDiffFittingAscii::processGroups() { - - try { - - std::string wsName = getPropertyValue("InputWorkspace"); - - WorkspaceGroup_sptr inputGroup = AnalysisDataService::Instance().retrieveWS(wsName); - - std::vector input_ws; - input_ws.reserve(inputGroup->getNumberOfEntries()); - for (int i = 0; i < inputGroup->getNumberOfEntries(); ++i) { - input_ws.emplace_back(std::dynamic_pointer_cast(inputGroup->getItem(i))); - } - - processAll(input_ws); - } catch (std::runtime_error &rexc) { - g_log.error(std::string("Error while processing a group of workspaces. Details: ") + rexc.what() + '\n'); - } - - return true; -} - -void SaveDiffFittingAscii::processAll(const std::vector &input_ws) { - - const std::string filename = getProperty("Filename"); - const std::string outMode = getProperty("OutMode"); - std::string runNumList = getProperty("RunNumber"); - std::string bankList = getProperty("Bank"); - - Poco::File pFile = (filename); - bool exist = pFile.exists(); - - bool appendToFile = false; - if (outMode == "AppendToExistingFile") - appendToFile = true; - - // Initialize the file stream - std::ofstream file(filename.c_str(), (appendToFile ? std::ios::app : std::ios::out)); - - if (!file) { - throw Exception::FileError("Unable to create file: ", filename); - } - - if (exist && !appendToFile) { - g_log.warning() << "File " << filename << " exists and will be overwritten." - << "\n"; - } - - if (exist && appendToFile) { - file << "\n"; - } - - // reset counter - m_counter = 0; - - std::vector splitRunNum = splitList(runNumList); - std::vector splitBank = splitList(bankList); - - // Create a progress reporting object - Progress progress(this, 0.0, 1.0, input_ws.size()); - - size_t breaker = input_ws.size(); - if (outMode == "AppendToExistingFile" && input_ws.size() == 1) - breaker = 1; - - for (size_t i = 0; i < breaker; ++i) { - - std::string runNum = splitRunNum[m_counter]; - std::string bank = splitBank[m_counter]; - - if (!runNum.empty() || !bank.empty()) - writeInfo(runNum, bank, file); - - // write header - std::vector columnHeadings = input_ws[i]->getColumnNames(); - writeHeader(columnHeadings, file); - - // write out the data form the table workspace - size_t columnSize = columnHeadings.size(); - writeData(input_ws[i], file, columnSize); - - if (input_ws.size() > 1 && (i + 1) != input_ws.size()) { - file << '\n'; - } - } - progress.report(); -} - -std::vector SaveDiffFittingAscii::splitList(std::string strList) { - std::vector splitList; - strList.erase(std::remove(strList.begin(), strList.end(), ' '), strList.end()); - boost::split(splitList, strList, boost::is_any_of(",")); - - return splitList; -} - -void SaveDiffFittingAscii::writeInfo(const std::string &runNumber, const std::string &bank, std::ofstream &file) { - - file << "run number: " << runNumber << '\n'; - file << "bank: " << bank << '\n'; - m_counter++; -} - -void SaveDiffFittingAscii::writeHeader(const std::vector &columnHeadings, std::ofstream &file) { - for (const auto &heading : columnHeadings) { - // if last header in the table workspace, put eol - if (&heading == &columnHeadings.back()) { - writeVal(heading, file, true); - } else { - writeVal(heading, file, false); - } - } -} - -void SaveDiffFittingAscii::writeData(const API::ITableWorkspace_sptr &workspace, std::ofstream &file, - const size_t columnSize) { - - for (size_t rowIndex = 0; rowIndex < workspace->rowCount(); ++rowIndex) { - TableRow row = workspace->getRow(rowIndex); - for (size_t columnIndex = 0; columnIndex < columnSize; columnIndex++) { - - const auto row_str = boost::lexical_cast(row.Double(columnIndex)); - g_log.debug() << row_str << std::endl; - - if (columnIndex == columnSize - 1) - writeVal(row_str, file, true); - else - writeVal(row_str, file, false); - } - } -} - -void SaveDiffFittingAscii::writeVal(const std::string &val, std::ofstream &file, const bool endline) { - std::string valStr = boost::lexical_cast(val); - - // checking if it needs to be surrounded in - // quotes due to a comma being included - size_t comPos = valStr.find(','); - if (comPos != std::string::npos) { - file << '"' << val << '"'; - } else { - file << boost::lexical_cast(val); - } - - if (endline) { - file << '\n'; - } else { - file << m_sep; - } -} - -std::map SaveDiffFittingAscii::validateInputs() { - std::map errors; - - bool is_grp = true; - - // check for null pointers - this is to protect against workspace groups - const std::string inputWS = getProperty("InputWorkspace"); - - WorkspaceGroup_sptr inWks = AnalysisDataService::Instance().retrieveWS(inputWS); - API::WorkspaceGroup_const_sptr inGrp = std::dynamic_pointer_cast(inWks); - - const ITableWorkspace_sptr tbl_ws = getProperty("InputWorkspace"); - if (tbl_ws) { - is_grp = false; - } - - if (!inGrp && !tbl_ws) { - std::string message = "The current version of this algorithm only " - "supports input workspaces of type TableWorkspace and WorkspaceGroup"; - errors["InputWorkspace"] = message; - } - - const std::string file = getProperty("Filename"); - if (file.empty()) { - errors["Filename"] = "File name directory cannot be empty"; - } - - std::string runNumber = getPropertyValue("RunNumber"); - std::vector splitRunNum = splitList(runNumber); - - std::string bankNumber = getPropertyValue("Bank"); - std::vector splitBank = splitList(bankNumber); - - if (bankNumber.empty()) { - if (!runNumber.empty()) - errors["Bank"] = "Please provide a valid bank list"; - } else if (runNumber.empty()) { - errors["RunNumber"] = "Please provide a valid run number list"; - } else if (!is_grp) { - if (splitRunNum.size() > 1) { - errors["RunNumber"] = "One run number should be provided when a Table" - "workspace is selected"; - } - if (splitBank.size() > 1) { - errors["Bank"] = "One bank should be provided when a Table" - "Workspace is selected"; - } - } else { - if (splitRunNum.size() != inGrp->size()) { - errors["RunNumber"] = "Run number list size should match the number of " - "TableWorkspaces in the GroupWorkspace selected"; - } - if (splitBank.size() != inGrp->size()) { - errors["Bank"] = "Bank list size should match the number of " - "TableWorkspaces in the GroupWorkspace selected"; - } - } - - return errors; -} - -} // namespace Mantid::DataHandling diff --git a/docs/source/algorithms/SaveDiffFittingAscii-v1.rst b/docs/source/algorithms/SaveDiffFittingAscii-v1.rst deleted file mode 100644 index 5997581c202f..000000000000 --- a/docs/source/algorithms/SaveDiffFittingAscii-v1.rst +++ /dev/null @@ -1,120 +0,0 @@ -.. algorithm:: - -.. summary:: - -.. relatedalgorithms:: - -.. properties:: - -Description ------------ - -Saves a TableWorkspace containing Diffraction Fitting results as an ASCII file. -All of the columns must be typed as 'double' in order to successfully save it as an ASCII file. -A GroupWorkspace of TableWorkspace can also be saved where the run number and bank is provided -manually as a list in the correct order. - - -The following TableWorkspace: - - -+----------+----------+---------+--------------+----------+---------+----------+---------+----------+---------+----------+---------+----------+---------+----------+----------+ -|dSpacing |A0 |A0_Err | A1 | A1_Err |X0 | X0_Err |A |A_Err |B |B_Err |S |S_Err |I |I_Err |Chi | -+==========+==========+=========+==============+==========+=========+==========+=========+==========+=========+==========+=========+==========+=========+==========+==========+ -|1.6092 |0.015160 |5.41233 |-1.93673e-06 |0.00018 |0.00018 |5.8782518 |0.021762 |0.003330 |0.023050 |0.0035287 |21.99236 |7.1390246 |521.0432 |27.212413 |3.0258827 | -+----------+----------+---------+--------------+----------+---------+----------+---------+----------+---------+----------+---------+----------+---------+----------+----------+ -|1.6834 |0.177540 |5.41233 |3.9826001041 |0.00012 |0.00018 |30963.562 |0.021762 |94.09466 |0.104790 |44.493605 |0.060733 |24.092391 |801.0639 |23.93961 |3.0258827 | -+----------+----------+---------+--------------+----------+---------+----------+---------+----------+---------+----------+---------+----------+---------+----------+----------+ -|-0.05474 |7.0641652 |1.04e-05 |-1.93673e-06 |0.000194 |36280.22 |7.9724626 |0.074861 |0.0398539 |0.022008 |0.0009267 |38.47428 |5.1456557 |6386.304 |63.73136 |3.2363716 | -+----------+----------+---------+--------------+----------+---------+----------+---------+----------+---------+----------+---------+----------+---------+----------+----------+ - - -becomes: - -:: - - run number: 23424 - bank: 1 - dSpacing,A0,A0_Err,A1,A1_Err,X0,X0_Err,A,A_Err,B,B_Err,S,S_Err,I,I_Err,Chi - 1.6092,0.01516,5.4123299999999999,-1.93673e-06,0.00018000000000000001,0.00018000000000000001,5.8782518000000001,0.021762,0.0033300000000000001,0.023050000000000001,0.0035287000000000001,21.992360000000001,7.1390245999999999,521.04319999999996,27.212413000000002,3.0258826999999999 - 1.6834,0.17754,5.4123299999999999,3.9826001040999999,0.00012,0.00018000000000000001,30963.562000000002,0.021762,4.0946689999999997,0.10478999999999999,44.493605000000002,0.060733000000000002,24.092390999999999,801.06389999999999,23.939609999999998,3.0258826999999999 - -0.054739999999999997,7.0641651999999997,1.04e-05,-1.93673e-06,0.000194,36280.220000000001,7.9724626000000001,0.074860999999999997,0.039853899999999998,0.022008,0.00092670000000000003,38.47428,5.1456556999999998,6386.3040000000001,63.731360000000002,3.2363716 - -*This is just an example table, the values may not be valid.* - -Limitations -########### - -The Algorithm will fail if any of the columns is not of type 'double'. - -Usage ------ - -**Example - Save a TableWorkspace in Diffraction Fitting Table format** - -.. testcode:: ExSaveDiffFittingAscii - - #import the os path libraries for directory functions - import os - - # Create a table workspace with data to save. - ws = CreateEmptyTableWorkspace() - ws.addColumn("double", "dSpacing"); - ws.addColumn("double", "A0"); - ws.addColumn("double", "A0_Err"); - ws.addColumn("double", "A1"); - ws.addColumn("double", "A1_Err"); - ws.addColumn("double", "X0"); - ws.addColumn("double", "X0_Err"); - ws.addColumn("double", "A"); - ws.addColumn("double", "A_Err"); - ws.addColumn("double", "B"); - ws.addColumn("double", "B_Err"); - ws.addColumn("double", "S"); - ws.addColumn("double", "S_Err"); - ws.addColumn("double", "I"); - ws.addColumn("double", "I_Err"); - ws.addColumn("double", "Chi"); - - nextRow = {'dSpacing': 1.6092, 'A0': 0.015160, 'A0_Err': 5.41233, 'A1': -1.93673e-06, 'A1_Err': 0.00018, - 'X0': 0.00018, 'X0_Err': 5.8782518, 'A': 0.021762, 'A_Err': 0.003330, 'B': 0.023050, - 'B_Err': 0.0035287, 'S': 21.99236, 'S_Err': 7.1390246, 'I': 521.0432, 'I_Err': 27.212413, - 'Chi': 3.0258827} - ws.addRow(nextRow) - - nextRow = {'dSpacing': 1.6834, 'A0': 0.177540, 'A0_Err': 5.41233, 'A1': 3.9826001041, 'A1_Err': 0.00012, - 'X0': 0.00018, 'X0_Err': 30963.562, 'A': 0.021762, 'A_Err': 4.094669, 'B': 0.104790, - 'B_Err': 44.493605, 'S': 0.060733, 'S_Err': 24.092391, 'I': 801.0639, 'I_Err': 23.93961, - 'Chi': 3.0258827} - ws.addRow(nextRow) - - nextRow = {'dSpacing': -0.05474, 'A0': 7.0641652, 'A0_Err': 1.04e-05, 'A1': -1.93673e-06, 'A1_Err': 0.000194, - 'X0': 36280.22, 'X0_Err': 7.9724626, 'A': 0.074861, 'A_Err': 0.0398539, 'B': 0.022008, - 'B_Err': 0.0009267, 'S': 38.47428, 'S_Err': 5.1456557, 'I': 6386.304, 'I_Err': 63.73136, - 'Chi': 3.2363716} - ws.addRow(nextRow) - - - #Create an absolute path by joining the proposed filename to a directory - #os.path.expanduser("~") used in this case returns the home directory of the current user - savefile = os.path.join(os.path.expanduser("~"), "FittingResults.txt") - - # perform the algorithm - SaveDiffFittingAscii(InputWorkspace = ws, Filename=savefile, RunNumber="21344", Bank = "1", - OutMode = "AppendToExistingFile") - - print("File Exists: {}".format(os.path.exists(savefile))) - -Output: - -.. testoutput:: ExSaveDiffFittingAscii - - File Exists: True - -.. testcleanup:: ExSaveDiffFittingAscii - - os.remove(savefile) - -.. categories:: - -.. sourcelink:: diff --git a/docs/source/release/v3.8.0/diffraction.rst b/docs/source/release/v3.8.0/diffraction.rst index 2a5deb559163..3204550c92e8 100644 --- a/docs/source/release/v3.8.0/diffraction.rst +++ b/docs/source/release/v3.8.0/diffraction.rst @@ -59,13 +59,13 @@ Engineering Diffraction - EnggFocus: bins are now masked at the beginning of the workflow (when using the option MaskBinsXMins) -- :ref:`SaveDiffFittingAscii ` an algorithm which saves a TableWorkspace containing +- SaveDiffFittingAscii an algorithm which saves a TableWorkspace containing diffraction fitting results as an ASCII file - New *Fit All* button on the Fitting Tab will enable user to batch-process all the runs and banks when a range of run number is given. During the Fit process, - :ref:`SaveDiffFittingAscii ` algorithm + SaveDiffFittingAscii algorithm will be utilised to save *engggui_fitting_fitpeaks_param* TableWorkspace as a `csv` file. diff --git a/docs/source/release/v3.8.0/framework.rst b/docs/source/release/v3.8.0/framework.rst index dba3b3e93659..28cb6a31a08a 100644 --- a/docs/source/release/v3.8.0/framework.rst +++ b/docs/source/release/v3.8.0/framework.rst @@ -46,7 +46,7 @@ New that the user has chosen and creates a background workspace out of them. It interpolates the points so the resulting background can be subtracted from the original data. -- :ref:`SaveDiffFittingAscii ` an algorithm which saves a TableWorkspace containing +- SaveDiffFittingAscii an algorithm which saves a TableWorkspace containing diffraction fitting results as an ASCII file - :ref:`UnwrapMonitorsInTOF ` handles the data which was collected beyond the end of a frame. diff --git a/docs/source/release/v6.11.0/Framework/Algorithms/Removed/37886.rst b/docs/source/release/v6.11.0/Framework/Algorithms/Removed/37886.rst new file mode 100644 index 000000000000..d680b91f4b8b --- /dev/null +++ b/docs/source/release/v6.11.0/Framework/Algorithms/Removed/37886.rst @@ -0,0 +1 @@ +- The SaveDiffFittingAscii algorithm was deprecated in :ref:`Release 3.13.0 ` and has now been removed. Use :ref:`EnggSaveSinglePeakFitResultsToHDF5 ` instead. \ No newline at end of file