From 25d20daa1916d615988c3936843a96f24934e688 Mon Sep 17 00:00:00 2001
From: Marina Ganeva <m.ganeva@fz-juelich.de>
Date: Fri, 9 Mar 2018 14:58:20 +0100
Subject: [PATCH] Refs #21293 LoadDNSSCD documentation.

---
 Framework/MDAlgorithms/src/LoadDNSSCD.cpp    |  12 +-
 Framework/MDAlgorithms/test/LoadDNSSCDTest.h |   2 +-
 docs/source/algorithms/LoadDNSSCD-v1.rst     | 221 +++++++++++++++++++
 3 files changed, 228 insertions(+), 7 deletions(-)
 create mode 100644 docs/source/algorithms/LoadDNSSCD-v1.rst

diff --git a/Framework/MDAlgorithms/src/LoadDNSSCD.cpp b/Framework/MDAlgorithms/src/LoadDNSSCD.cpp
index ffc471e2b30..e547aa66c11 100644
--- a/Framework/MDAlgorithms/src/LoadDNSSCD.cpp
+++ b/Framework/MDAlgorithms/src/LoadDNSSCD.cpp
@@ -179,8 +179,8 @@ void LoadDNSSCD::init() {
                   "if the goniometer is at zero.");
   declareProperty(
        Kernel::make_unique<ArrayProperty<double>>("hkl1", u0, mustBe3D),
-       "Indices of the vector in reciprocal space in the horizontal plane at angle Omegaoffset,"
-       "if the goniometer is at zero (considered absolute true in UB calculation)");
+       "Indices of the vector in reciprocal space in the horizontal plane at angle Omegaoffset, "
+       "if the goniometer is at zero.");
 
   declareProperty(
        Kernel::make_unique<ArrayProperty<double>>("hkl2", v0, mustBe3D),
@@ -189,14 +189,14 @@ void LoadDNSSCD::init() {
   std::vector<double> ttl(2, 0);
   ttl[1] = 180.0;
   declareProperty(
-       Kernel::make_unique<ArrayProperty<double>>("2ThetaLimits", ttl, mustBe2D),
-       "Range (min, max) of scattering angles (2theta, degrees) to consider."
+       Kernel::make_unique<ArrayProperty<double>>("TwoThetaLimits", ttl, mustBe2D),
+       "Range (min, max) of scattering angles (2theta, in degrees) to consider. "
        "Everything out of this range will be cut.");
 
   declareProperty(
         Kernel::make_unique<WorkspaceProperty<API::ITableWorkspace>>(
             "LoadHuberFrom", "", Direction::Input, PropertyMode::Optional),
-        "A table workspace to load a list of raw sample rotation angles."
+        "A table workspace to load a list of raw sample rotation angles. "
         "Huber angles given in the data files will be ignored.");
 
   declareProperty(
@@ -445,7 +445,7 @@ void LoadDNSSCD::fillOutputWorkspace(double wavelength) {
   MDEventInserter<MDEventWorkspace<MDEvent<3>, 3>::sptr> norm_inserter(normws_mdevt_3);
 
   // scattering angle limits
-  std::vector<double> tth_limits = getProperty("2ThetaLimits");
+  std::vector<double> tth_limits = getProperty("TwoThetaLimits");
   double theta_min = tth_limits[0]*deg2rad/2.0;
   double theta_max = tth_limits[1]*deg2rad/2.0;
 
diff --git a/Framework/MDAlgorithms/test/LoadDNSSCDTest.h b/Framework/MDAlgorithms/test/LoadDNSSCDTest.h
index d266b538732..cda7a127593 100644
--- a/Framework/MDAlgorithms/test/LoadDNSSCDTest.h
+++ b/Framework/MDAlgorithms/test/LoadDNSSCDTest.h
@@ -553,7 +553,7 @@ public:
     TS_ASSERT_THROWS_NOTHING(alg.setProperty("OmegaOffset", -43.0));
     TS_ASSERT_THROWS_NOTHING(alg.setProperty("hkl1", "1,1,0"));
     TS_ASSERT_THROWS_NOTHING(alg.setProperty("hkl2", "0,0,1"));
-    TS_ASSERT_THROWS_NOTHING(alg.setProperty("2ThetaLimits", "20.0,55.0"));
+    TS_ASSERT_THROWS_NOTHING(alg.setProperty("TwoThetaLimits", "20.0,55.0"));
     TS_ASSERT_THROWS_NOTHING(alg.execute(););
     TS_ASSERT(alg.isExecuted());
 
diff --git a/docs/source/algorithms/LoadDNSSCD-v1.rst b/docs/source/algorithms/LoadDNSSCD-v1.rst
new file mode 100644
index 00000000000..763f8bbe8fd
--- /dev/null
+++ b/docs/source/algorithms/LoadDNSSCD-v1.rst
@@ -0,0 +1,221 @@
+.. algorithm::
+
+.. summary::
+
+.. alias::
+
+.. properties::
+
+Description
+-----------
+
+.. warning::
+
+   This algorithm does not perform any consistency check of the input data. This is the user responsibility to choose physically reasonable dataset.
+
+This algorithm loads a list  of DNS `.d_dat` data files into a `MDEventWorkspace <http://www.mantidproject.org/MDEventWorkspace>`_. If algorithm fails to process the file, this file will be ignored. In this case algorithm produces a warning and continues to process further files. Only in that case if no valid files are provided, algorithm terminates with an error message.
+
+This algorithm is meant to replace the :ref:`algm-LoadDNSLegacy` for single crysral diffraction data.
+
+**Output**
+
+As a result, two workspaces are created:
+
+- `OutputWorkspace` contains raw neutron counts.
+
+- `NormalizationWorkspace` contains the choosen normalization data (either monitor counts or experiment duration time).
+
+Both workspaces have :math:`(H,K,L)` dimensions. The metadata are loaded into time series sample logs.
+
+.. note::
+
+   For the further data reduction :ref:`algm-BinMD` should be used to bin the data.
+
+Restrictions
+------------
+
+- This algorithm only supports *DNS* instrument in its configuration with one detector bank (polarisation analysis).
+
+- This algorithm does not support DNS TOF mode data. It is meant only for single crystal diffraction experiments with 1 TOF channel.
+
+
+Data replication
+________________
+
+For standard data (vanadium, NiCr, background) the sample rotation angle assumed to be not important. These data are typically measured only for one sample rotation angle. The algorithm can replicate these data for the same sample rotation angles as a single crystal sample has been measured. For this purpose optional input fields *SaveHuberTo* and *LoadHuberFrom* can be used.
+
+- *SaveHuberTo* should contain a name of the `TableWorkspace <http://www.mantidproject.org/TableWorkspace>`_ where sample rotation angles (Huber) read from the data files will be saved. If the specified workspace exists, it will be overwritten.
+
+- *LoadHuberFrom* should contain a name of the `TableWorkspace <http://www.mantidproject.org/TableWorkspace>`_. The workspace must exist and contain one column with the name *Huber(degrees)*, where the sample rotation angles are specified.
+
+.. note::
+
+   If *LoadHuberFrom* option is applied, sample rotation angles in the data files will be ignored. Only sample rotation angles from the table will be considered.
+
+Usage
+-----
+
+**Example 1 - Load a DNS .d_dat file to MDEventWorkspace:**
+
+.. testcode:: LoadDNSSCDEx1
+
+   # data file.
+   filename = "dn134011vana.d_dat"
+
+   # lattice parameters
+   a = 5.0855
+   b = 5.0855
+   c = 14.0191
+   omega_offset = 225.0
+   hkl1="1,0,0"
+   hkl2="0,0,1"
+   alpha=90.0
+   beta=90.0
+   gamma=120.0
+
+   # load data to MDEventWorkspace
+   ws, ws_norm, huber_ws = LoadDNSSCD(FileNames=filename, NormalizationWorkspace='ws_norm',
+                                      Normalization='monitor', a=a, b=b, c=c, alpha=alpha, beta=beta, gamma=gamma,
+                                      OmegaOffset=omega_offset, hkl1=hkl1, hkl2=hkl2, SaveHuberTo='huber_ws')
+
+   # print output workspace information
+   print("Output Workspace Type is:  {}".format(ws.id()))
+   print("It has {0} events and {1} dimensions:".format(ws.getNEvents(), ws.getNumDims()))
+   for i in range(ws.getNumDims()):
+       dimension = ws.getDimension(i)
+       print("Dimension {0} has name: {1}, id: {2}, Range: {3:.2f} to {4:.2f} {5}".format(i,
+             dimension.getDimensionId(),
+             dimension.name,
+             dimension.getMinimum(),
+             dimension.getMaximum(),
+             dimension.getUnits()))
+
+   # print information about the table workspace
+   print ("TableWorkspace '{0}' has {1} row in the column '{2}'.".format(huber_ws.getName(),
+                                                                         huber_ws.rowCount(),
+                                                                         huber_ws.getColumnNames()[0]))
+   print("It contains sample rotation angle {} degrees".format(huber_ws.cell(0, 0)))
+
+**Output:**
+
+.. testoutput:: LoadDNSSCDEx1
+
+    Output Workspace Type is:  MDEventWorkspace<MDEvent,3>
+    It has 24 events and 3 dimensions:
+    Dimension 0 has name: H, id: H, Range: -15.22 to 15.22 r.l.u
+    Dimension 1 has name: K, id: K, Range: -15.22 to 15.22 r.l.u
+    Dimension 2 has name: L, id: L, Range: -41.95 to 41.95 r.l.u
+    TableWorkspace 'huber_ws' has 1 row in the column 'Huber(degrees)'.
+    It contains sample rotation angle 79.0 degrees
+
+
+**Example 2 - Specify scattering angle limits:**
+
+.. testcode:: LoadDNSSCDEx2
+
+   # data file.
+   filename = "dn134011vana.d_dat"
+
+   # lattice parameters
+   a = 5.0855
+   b = 5.0855
+   c = 14.0191
+   omega_offset = 225.0
+   hkl1="1,0,0"
+   hkl2="0,0,1"
+   alpha=90.0
+   beta=90.0
+   gamma=120.0
+
+   # scattering angle limits, degrees
+   tth_limits = "20,70"
+
+   # load data to MDEventWorkspace
+   ws, ws_norm, huber_ws = LoadDNSSCD(FileNames=filename, NormalizationWorkspace='ws_norm',
+                                      Normalization='monitor', a=a, b=b, c=c, alpha=alpha, beta=beta, gamma=gamma,
+                                      OmegaOffset=omega_offset, hkl1=hkl1, hkl2=hkl2, TwoThetaLimits=tth_limits)
+
+   # print output workspace information
+   print("Output Workspace Type is:  {}".format(ws.id()))
+   print("It has {0} events and {1} dimensions.".format(ws.getNEvents(), ws.getNumDims()))
+
+   # print normalization workspace information
+   print("Normalization Workspace Type is:  {}".format(ws_norm.id()))
+   print("It has {0} events and {1} dimensions.".format(ws_norm.getNEvents(), ws_norm.getNumDims()))
+
+**Output:**
+
+.. testoutput:: LoadDNSSCDEx2
+
+    Output Workspace Type is:  MDEventWorkspace<MDEvent,3>
+    It has 10 events and 3 dimensions.
+    Normalization Workspace Type is:  MDEventWorkspace<MDEvent,3>
+    It has 10 events and 3 dimensions.
+
+**Example 3 - Load sample rotation angles from the table**
+
+.. testcode:: LoadDNSSCDEx3
+
+   # data file.
+   filename = "dn134011vana.d_dat"
+
+   # construct table workspace with 10 raw sample rotation angles from 70 to 170 degrees
+   table = CreateEmptyTableWorkspace()
+   table.addColumn( "double", "Huber(degrees)")
+   for huber in range(70, 170, 10):
+       table.addRow([huber])
+
+   # lattice parameters
+   a = 5.0855
+   b = 5.0855
+   c = 14.0191
+   omega_offset = 225.0
+   hkl1="1,0,0"
+   hkl2="0,0,1"
+   alpha=90.0
+   beta=90.0
+   gamma=120.0
+
+   # load data to MDEventWorkspace
+   ws, ws_norm, huber_ws = LoadDNSSCD(FileNames=filename, NormalizationWorkspace='ws_norm',
+                                      Normalization='monitor', a=a, b=b, c=c, alpha=alpha, beta=beta, gamma=gamma,
+                                      OmegaOffset=omega_offset, hkl1=hkl1, hkl2=hkl2, LoadHuberFrom=table)
+
+   # print output workspace information
+   print("Output Workspace Type is:  {}".format(ws.id()))
+   print("It has {0} events and {1} dimensions.".format(ws.getNEvents(), ws.getNumDims()))
+
+   # setting for the BinMD algorithm
+   bvec0 = '[100],unit,1,0,0'
+   bvec1 = '[001],unit,0,0,1'
+   bvec2 = '[010],unit,0,1,0'
+   extents = '-2,1.5,-0.2,6.1,-10,10'
+   bins = '10,10,1'
+   # bin the data
+   data_raw = BinMD(ws, AxisAligned='0', BasisVector0=bvec0, BasisVector1=bvec1,
+                    BasisVector2=bvec2, OutputExtents=extents, OutputBins=bins, NormalizeBasisVectors='0')
+   # bin normalization
+   data_norm = BinMD(ws_norm, AxisAligned='0', BasisVector0=bvec0, BasisVector1=bvec1,
+                     BasisVector2=bvec2, OutputExtents=extents, OutputBins=bins, NormalizeBasisVectors='0')
+   # normalize data
+   data = data_raw/data_norm
+
+   # print reduced workspace information
+   print("Reduced Workspace Type is:  {}".format(data.id()))
+   print("It has {} dimensions.".format(data.getNumDims()))
+   s =  data.getSignalArray()
+   print("Signal at some points: {0:.4f}, {1:.4f}, {2:.4f}".format(s[7,1][0], s[7,2][0], s[7,3][0]))
+
+**Output:**
+
+.. testoutput:: LoadDNSSCDEx3
+
+    Output Workspace Type is:  MDEventWorkspace<MDEvent,3>
+    It has 240 events and 3 dimensions.
+    Reduced Workspace Type is:  MDHistoWorkspace
+    It has 3 dimensions.
+    Signal at some points: 0.0035, 0.0033, 0.0035
+
+.. categories::
+
+.. sourcelink::
-- 
GitLab