From 001b5733ce91f117ceaab6354b251aae4ec471da Mon Sep 17 00:00:00 2001
From: Conor Finn <conor.finn@stfc.ac.uk>
Date: Thu, 3 Oct 2019 16:46:50 +0100
Subject: [PATCH] RE #26846 Added code documentation

---
 .../PythonInterface/mantid/kernel/_aliases.py |  2 +-
 .../engineering_diffraction.py                |  2 +-
 .../tabs/calibration/model.py                 | 46 +++++++++++++++++--
 .../tabs/calibration/presenter.py             | 13 ++++--
 .../tabs/calibration/test/test_model.py       |  2 +-
 .../tabs/calibration/test/test_presenter.py   |  2 +-
 .../tabs/calibration/view.py                  |  2 +-
 7 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/Framework/PythonInterface/mantid/kernel/_aliases.py b/Framework/PythonInterface/mantid/kernel/_aliases.py
index 11e69e16a28..b6ac466b9d7 100644
--- a/Framework/PythonInterface/mantid/kernel/_aliases.py
+++ b/Framework/PythonInterface/mantid/kernel/_aliases.py
@@ -1,4 +1,4 @@
-# Mantid Repository : https://github.com/mantidproject/mantmatrixWorkspaceid
+# Mantid Repository : https://github.com/mantidproject/mantid
 #
 # Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
 #     NScD Oak Ridge National Laboratory, European Spallation Source
diff --git a/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py b/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py
index db15335bc5f..6b38972c87c 100644
--- a/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py
+++ b/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py
@@ -1,6 +1,6 @@
 # Mantid Repository : https://github.com/mantidproject/mantid
 #
-# Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
+# Copyright &copy; 2019 ISIS Rutherford Appleton Laboratory UKRI,
 #     NScD Oak Ridge National Laboratory, European Spallation Source
 #     & Institut Laue - Langevin
 # SPDX - License - Identifier: GPL - 3.0 +
diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py
index 26e0d00a54f..bc3bc62a21f 100644
--- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py
+++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py
@@ -1,6 +1,6 @@
 # Mantid Repository : https://github.com/mantidproject/mantid
 #
-# Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
+# Copyright &copy; 2019 ISIS Rutherford Appleton Laboratory UKRI,
 #     NScD Oak Ridge National Laboratory, European Spallation Source
 #     & Institut Laue - Langevin
 # SPDX - License - Identifier: GPL - 3.0 +
@@ -31,6 +31,15 @@ class CalibrationModel(object):
                                plot_output,
                                instrument,
                                rb_num=None):
+        """
+        Create a new calibration from a vanadium run and ceria run
+        :param vanadium_path: Path to vanadium data file.
+        :param ceria_path: Path to ceria data file
+        :param plot_output: Whether the output should be plotted.
+        :param instrument: The instrument the data relates to.
+        :param rb_num: The RB number for file creation.
+        """
+
         vanadium_corrections = self.calculate_vanadium_correction(vanadium_path)
         van_integration = vanadium_corrections[0]
         van_curves = vanadium_corrections[1]
@@ -125,6 +134,13 @@ class CalibrationModel(object):
             raise RuntimeError
 
     def run_calibration(self, ceria_ws, van_integration, van_curves):
+        """
+        Runs the main Engineering calibration algorithm.
+        :param ceria_ws: The workspace with the ceria data.
+        :param van_integration: The integration values from the vanadium corrections
+        :param van_curves: The curves from the vanadium corrections.
+        :return: The output of the algorithm.
+        """
         output = [None] * 2
         for i in range(2):
             table_name = self._generate_table_workspace_name(i)
@@ -136,13 +152,18 @@ class CalibrationModel(object):
                                       OutputParametersTableName=table_name)
         return output
 
-    def calculate_vanadium_correction(self, vanadium_run_no):
+    def calculate_vanadium_correction(self, vanadium_path):
+        """
+        Runs the vanadium correction algorithm.
+        :param vanadium_path: The path to the vanadium data.
+        :return: The integrated workspace and the curves generated by the algorithm.
+        """
         try:
-            Load(Filename=vanadium_run_no, OutputWorkspace=self.VANADIUM_INPUT_WORKSPACE_NAME)
+            Load(Filename=vanadium_path, OutputWorkspace=self.VANADIUM_INPUT_WORKSPACE_NAME)
         except Exception as e:
             logger.error("Error when loading vanadium sample data. "
                          "Could not run Load algorithm with vanadium run number: " +
-                         str(vanadium_run_no) + ". Error description: " + str(e))
+                         str(vanadium_path) + ". Error description: " + str(e))
             raise RuntimeError
         EnggVanadiumCorrections(VanadiumWorkspace=self.VANADIUM_INPUT_WORKSPACE_NAME,
                                 OutIntegrationWorkspace=self.INTEGRATED_WORKSPACE_NAME,
@@ -154,6 +175,15 @@ class CalibrationModel(object):
 
     def create_output_files(self, calibration_dir, difc, tzero, ceria_path, vanadium_path,
                             instrument):
+        """
+        Create output files from the algorithms in the specified directory
+        :param calibration_dir: The directory to save the files into.
+        :param difc: DIFC values from the calibration algorithm.
+        :param tzero: TZERO values from the calibration algorithm.
+        :param ceria_path: The path to the ceria data file.
+        :param vanadium_path: The path to the vanadium data file.
+        :param instrument: The instrument (ENGINX or IMAT)
+        """
         if not path.exists(calibration_dir):
             makedirs(calibration_dir)
         filename, vanadium_no, ceria_no = self._generate_output_file_name(vanadium_path,
@@ -190,6 +220,14 @@ class CalibrationModel(object):
 
     @staticmethod
     def _generate_output_file_name(vanadium_path, ceria_path, instrument, bank):
+        """
+        Generate an output filename in the form INSTRUMENT_VanadiumRunNo_CeriaRunCo_BANKS
+        :param vanadium_path: Path to vanadium data file
+        :param ceria_path: Path to ceria data file
+        :param instrument: The instrument in use.
+        :param bank: The bank being saved.
+        :return: The filename, the vanadium run number, and ceria run number.
+        """
         vanadium_no = path.splitext(basename(vanadium_path))[0].replace(instrument, '').lstrip('0')
         ceria_no = path.splitext(basename(ceria_path))[0].replace(instrument, '').lstrip('0')
         filename = instrument + "_" + vanadium_no + "_" + ceria_no + "_"
diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/presenter.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/presenter.py
index 63c87939005..5515a5f5c5d 100644
--- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/presenter.py
+++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/presenter.py
@@ -1,6 +1,6 @@
 # Mantid Repository : https://github.com/mantidproject/mantid
 #
-# Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
+# Copyright &copy; 2019 ISIS Rutherford Appleton Laboratory UKRI,
 #     NScD Oak Ridge National Laboratory, European Spallation Source
 #     & Institut Laue - Langevin
 # SPDX - License - Identifier: GPL - 3.0 +
@@ -31,8 +31,15 @@ class CalibrationPresenter(object):
         plot_output = self.view.get_plot_output()
         self.start_calibration_worker(vanadium_no, calib_no, plot_output, self.rb_num)
 
-    def start_calibration_worker(self, vanadium_no, calib_no, plot_output, rb_num):
-        self.worker = AsyncTask(self.model.create_new_calibration, (vanadium_no, calib_no),
+    def start_calibration_worker(self, vanadium_path, calib_path, plot_output, rb_num):
+        """
+        Calibrate the data in a separate thread so as to not freeze the GUI.
+        :param vanadium_path: Path to vanadium data file.
+        :param calib_path: Path to calibration data file.
+        :param plot_output: Whether to plot the output.
+        :param rb_num: The current RB number set in the GUI.
+        """
+        self.worker = AsyncTask(self.model.create_new_calibration, (vanadium_path, calib_path),
                                 {"plot_output": plot_output, "instrument": self.instrument, "rb_num": rb_num},
                                 error_cb=self._on_error, finished_cb=self.enable_calibrate_buttons)
         self.worker.start()
diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_model.py
index 80834066382..ba57bc8aeac 100644
--- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_model.py
+++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_model.py
@@ -1,6 +1,6 @@
 # Mantid Repository : https://github.com/mantidproject/mantid
 #
-# Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
+# Copyright &copy; 2019 ISIS Rutherford Appleton Laboratory UKRI,
 #     NScD Oak Ridge National Laboratory, European Spallation Source
 #     & Institut Laue - Langevin
 # SPDX - License - Identifier: GPL - 3.0 +
diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_presenter.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_presenter.py
index ae0b2aa52a2..9a5e0100d71 100644
--- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_presenter.py
+++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/test/test_presenter.py
@@ -1,6 +1,6 @@
 # Mantid Repository : https://github.com/mantidproject/mantid
 #
-# Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
+# Copyright &copy; 2019 ISIS Rutherford Appleton Laboratory UKRI,
 #     NScD Oak Ridge National Laboratory, European Spallation Source
 #     & Institut Laue - Langevin
 # SPDX - License - Identifier: GPL - 3.0 +
diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/view.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/view.py
index 6494b21667f..c3251f1e8a9 100644
--- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/view.py
+++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/view.py
@@ -1,6 +1,6 @@
 # Mantid Repository : https://github.com/mantidproject/mantid
 #
-# Copyright &copy; 2018 ISIS Rutherford Appleton Laboratory UKRI,
+# Copyright &copy; 2019 ISIS Rutherford Appleton Laboratory UKRI,
 #     NScD Oak Ridge National Laboratory, European Spallation Source
 #     & Institut Laue - Langevin
 # SPDX - License - Identifier: GPL - 3.0 +
-- 
GitLab