Skip to content
Snippets Groups Projects
Commit 141ee44d authored by Savici, Andrei T.'s avatar Savici, Andrei T.
Browse files

More documentation and sphinx fixes

parent c26fc8f6
No related branches found
No related tags found
No related merge requests found
...@@ -56,8 +56,7 @@ public: ...@@ -56,8 +56,7 @@ public:
} }
/// See also /// See also
const std::vector<std::string> seeAlso() const override { const std::vector<std::string> seeAlso() const override {
return {"MuonProcess", "ApplyMuonDetectorGrouping", return {"MuonProcess", "ApplyMuonDetectorGrouping"};
"LoadAndApplyMuonDetectorGrouping"};
} }
/// Perform validation of inputs to the algorithm /// Perform validation of inputs to the algorithm
std::map<std::string, std::string> validateInputs() override; std::map<std::string, std::string> validateInputs() override;
......
...@@ -42,6 +42,7 @@ def get_distribution(workspace, **kwargs): ...@@ -42,6 +42,7 @@ def get_distribution(workspace, **kwargs):
""" """
Determine whether or not the data is a distribution. The value in Determine whether or not the data is a distribution. The value in
the kwargs wins. Applies to Matrix workspaces only the kwargs wins. Applies to Matrix workspaces only
:param workspace: :class:`mantid.api.MatrixWorkspace` to extract the data from :param workspace: :class:`mantid.api.MatrixWorkspace` to extract the data from
""" """
distribution = kwargs.pop('distribution', workspace.isDistribution()) distribution = kwargs.pop('distribution', workspace.isDistribution())
...@@ -53,6 +54,7 @@ def get_normalization(md_workspace, **kwargs): ...@@ -53,6 +54,7 @@ def get_normalization(md_workspace, **kwargs):
Gets the normalization flag of an MDHistoWorkspace. For workspaces Gets the normalization flag of an MDHistoWorkspace. For workspaces
derived similar to MSlice/Horace, one needs to average data, the so-called derived similar to MSlice/Horace, one needs to average data, the so-called
"number of events" normalization. "number of events" normalization.
:param md_workspace: :class:`mantid.api.IMDHistoWorkspace` to extract the data from :param md_workspace: :class:`mantid.api.IMDHistoWorkspace` to extract the data from
""" """
normalization = kwargs.pop('normalization', md_workspace.displayNormalizationHisto()) normalization = kwargs.pop('normalization', md_workspace.displayNormalizationHisto())
...@@ -62,6 +64,7 @@ def get_normalization(md_workspace, **kwargs): ...@@ -62,6 +64,7 @@ def get_normalization(md_workspace, **kwargs):
def points_from_boundaries(input_array): def points_from_boundaries(input_array):
""" """
The function returns bin centers from bin boundaries The function returns bin centers from bin boundaries
:param input_array: a :class:`numpy.ndarray` of bin boundaries :param input_array: a :class:`numpy.ndarray` of bin boundaries
""" """
assert isinstance(input_array, numpy.ndarray), 'Not a numpy array' assert isinstance(input_array, numpy.ndarray), 'Not a numpy array'
...@@ -73,6 +76,7 @@ def points_from_boundaries(input_array): ...@@ -73,6 +76,7 @@ def points_from_boundaries(input_array):
def _dim2array(d): def _dim2array(d):
""" """
Create a numpy array containing bin centers along the dimension d Create a numpy array containing bin centers along the dimension d
:param d: an :class:`mantid.geometry.IMDDimension` object :param d: an :class:`mantid.geometry.IMDDimension` object
returns: bin boundaries for dimension d returns: bin boundaries for dimension d
...@@ -138,12 +142,14 @@ def get_md_data1d(workspace, normalization): ...@@ -138,12 +142,14 @@ def get_md_data1d(workspace, normalization):
def get_md_data(workspace, normalization, withError=False): def get_md_data(workspace, normalization, withError=False):
""" """
Generic function to extract data from an MDHisto workspace Generic function to extract data from an MDHisto workspace
:param workspace: :class:`mantid.api.IMDHistoWorkspace` containing data :param workspace: :class:`mantid.api.IMDHistoWorkspace` containing data
:param normalization: if :class:`mantid.api.MDNormalization.NumEventsNormalization` :param normalization: if :class:`mantid.api.MDNormalization.NumEventsNormalization`
it will divide intensity by the number of corresponding MDEvents it will divide intensity by the number of corresponding MDEvents
:param withError: flag for if the error is calculated. If False, err is returned as None
returns a tuple containing bin boundaries for each dimension, the (maybe normalized) returns a tuple containing bin boundaries for each dimension, the (maybe normalized)
signal and error arrays signal and error arrays
:param withError: flag for if the error is calculated. If False, err is returned as None
""" """
dims = workspace.getNonIntegratedDimensions() dims = workspace.getNonIntegratedDimensions()
dim_arrays = [_dim2array(d) for d in dims] dim_arrays = [_dim2array(d) for d in dims]
...@@ -169,6 +175,7 @@ def get_md_data(workspace, normalization, withError=False): ...@@ -169,6 +175,7 @@ def get_md_data(workspace, normalization, withError=False):
def get_spectrum(workspace, wkspIndex, distribution, withDy=False, withDx=False): def get_spectrum(workspace, wkspIndex, distribution, withDy=False, withDx=False):
""" """
Extract a single spectrum and process the data into a frequency Extract a single spectrum and process the data into a frequency
:param workspace: a Workspace2D or an EventWorkspace :param workspace: a Workspace2D or an EventWorkspace
:param wkspIndex: workspace index :param wkspIndex: workspace index
:param distribution: flag to divide the data by bin width. It happens only :param distribution: flag to divide the data by bin width. It happens only
...@@ -176,9 +183,11 @@ def get_spectrum(workspace, wkspIndex, distribution, withDy=False, withDx=False) ...@@ -176,9 +183,11 @@ def get_spectrum(workspace, wkspIndex, distribution, withDy=False, withDx=False)
the mantid configuration is set up to divide such workspaces by bin the mantid configuration is set up to divide such workspaces by bin
width. The same effect can be obtained by running the width. The same effect can be obtained by running the
:ref:`algm-ConvertToDistribution` algorithm :ref:`algm-ConvertToDistribution` algorithm
:param withDy: if True, it will return the error in the "counts", otherwise None :param withDy: if True, it will return the error in the "counts", otherwise None
:param with Dx: if True, and workspace has them, it will return errors :param with Dx: if True, and workspace has them, it will return errors
in the x coordinate, otherwise None in the x coordinate, otherwise None
Note that for workspaces containing bin boundaries, this function will return Note that for workspaces containing bin boundaries, this function will return
the bin centers for x. the bin centers for x.
To be used in 1D plots (plot, scatter, errorbar) To be used in 1D plots (plot, scatter, errorbar)
...@@ -210,7 +219,8 @@ def get_md_data2d_bin_bounds(workspace, normalization): ...@@ -210,7 +219,8 @@ def get_md_data2d_bin_bounds(workspace, normalization):
Function to transform data in an MDHisto workspace with exactly Function to transform data in an MDHisto workspace with exactly
two non-integrated dimension into arrays of bin boundaries in each two non-integrated dimension into arrays of bin boundaries in each
dimension, and data. To be used in 2D plots (pcolor, pcolorfast, pcolormesh) dimension, and data. To be used in 2D plots (pcolor, pcolorfast, pcolormesh)
Note return coordinates are 1d vectors. Use numpy.meshgrid to generate 2d versions
Note: return coordinates are 1d vectors. Use numpy.meshgrid to generate 2d versions
""" """
coordinate, data, _ = get_md_data(workspace, normalization, withError=False) coordinate, data, _ = get_md_data(workspace, normalization, withError=False)
assert len(coordinate) == 2, 'The workspace is not 2D' assert len(coordinate) == 2, 'The workspace is not 2D'
...@@ -223,7 +233,8 @@ def get_md_data2d_bin_centers(workspace, normalization): ...@@ -223,7 +233,8 @@ def get_md_data2d_bin_centers(workspace, normalization):
two non-integrated dimension into arrays of bin centers in each two non-integrated dimension into arrays of bin centers in each
dimension, and data. To be used in 2D plots (contour, contourf, dimension, and data. To be used in 2D plots (contour, contourf,
tricontour, tricontourf, tripcolor) tricontour, tricontourf, tripcolor)
Note return coordinates are 1d vectors. Use numpy.meshgrid to generate 2d versions
Note: return coordinates are 1d vectors. Use numpy.meshgrid to generate 2d versions
""" """
x, y, data = get_md_data2d_bin_bounds(workspace, normalization) x, y, data = get_md_data2d_bin_bounds(workspace, normalization)
x = points_from_boundaries(x) x = points_from_boundaries(x)
...@@ -234,6 +245,7 @@ def get_md_data2d_bin_centers(workspace, normalization): ...@@ -234,6 +245,7 @@ def get_md_data2d_bin_centers(workspace, normalization):
def boundaries_from_points(input_array): def boundaries_from_points(input_array):
"""" """"
The function tries to guess bin boundaries from bin centers The function tries to guess bin boundaries from bin centers
:param input_array: a :class:`numpy.ndarray` of bin centers :param input_array: a :class:`numpy.ndarray` of bin centers
""" """
assert isinstance(input_array, numpy.ndarray), 'Not a numpy array' assert isinstance(input_array, numpy.ndarray), 'Not a numpy array'
...@@ -257,12 +269,15 @@ def get_matrix_2d_data(workspace, distribution, histogram2D=False): ...@@ -257,12 +269,15 @@ def get_matrix_2d_data(workspace, distribution, histogram2D=False):
''' '''
Get all data from a Matrix workspace that has the same number of bins Get all data from a Matrix workspace that has the same number of bins
in every spectrum. It is used for 2D plots in every spectrum. It is used for 2D plots
:param workspace: Matrix workspace to extract the data from :param workspace: Matrix workspace to extract the data from
:param distribution: if False, and the workspace contains histogram data, :param distribution: if False, and the workspace contains histogram data,
the intensity will be divided by the x bin width the intensity will be divided by the x bin width
:param histogram2D: flag that specifies if the coordinates in the output are :param histogram2D: flag that specifies if the coordinates in the output are
-bin centers (such as for contour) for False, or -bin centers (such as for contour) for False, or
-bin edges (such as for pcolor) for True. -bin edges (such as for pcolor) for True.
Returns x,y,z 2D arrays Returns x,y,z 2D arrays
''' '''
try: try:
...@@ -305,9 +320,11 @@ def get_uneven_data(workspace, distribution): ...@@ -305,9 +320,11 @@ def get_uneven_data(workspace, distribution):
''' '''
Function to get data for uneven workspace2Ds, such as Function to get data for uneven workspace2Ds, such as
that pcolor, pcolorfast, and pcolormesh will plot axis aligned rectangles that pcolor, pcolorfast, and pcolormesh will plot axis aligned rectangles
:param workspace: a workspace2d :param workspace: a workspace2d
:param distribution: if False, and the workspace contains histogram data, :param distribution: if False, and the workspace contains histogram data,
the intensity will be divided by the x bin width the intensity will be divided by the x bin width
Returns three lists. Each element in the x list is an array of boundaries Returns three lists. Each element in the x list is an array of boundaries
for a spectra. Each element in the y list is a 2 element array with the extents for a spectra. Each element in the y list is a 2 element array with the extents
of a particular spectra. The z list contains arrays of intensities at bin centers of a particular spectra. The z list contains arrays of intensities at bin centers
...@@ -340,7 +357,9 @@ def get_data_uneven_flag(workspace, **kwargs): ...@@ -340,7 +357,9 @@ def get_data_uneven_flag(workspace, **kwargs):
:meth:`matplotlib.axes.Axes.pcolorfast`, and :meth:`matplotlib.axes.Axes.pcolormesh` :meth:`matplotlib.axes.Axes.pcolorfast`, and :meth:`matplotlib.axes.Axes.pcolormesh`
to plot rectangles parallel to the axes even if the data is not to plot rectangles parallel to the axes even if the data is not
on a regular grid. on a regular grid.
:param workspace: a workspace2d :param workspace: a workspace2d
if axisaligned keyword is available and True or if the workspace does if axisaligned keyword is available and True or if the workspace does
not have a constant number of bins, it will return true, otherwise false not have a constant number of bins, it will return true, otherwise false
''' '''
...@@ -396,6 +415,7 @@ def get_axes_labels(workspace): ...@@ -396,6 +415,7 @@ def get_axes_labels(workspace):
Returns a tuple. The first element is the quantity label, such as "Intensity" or "Counts". Returns a tuple. The first element is the quantity label, such as "Intensity" or "Counts".
All other elements in the tuple are labels for axes. All other elements in the tuple are labels for axes.
Some of them are latex formatted already. Some of them are latex formatted already.
:param workspace: :class:`mantid.api.MatrixWorkspace` or :class:`mantid.api.IMDHistoWorkspace` :param workspace: :class:`mantid.api.MatrixWorkspace` or :class:`mantid.api.IMDHistoWorkspace`
""" """
if isinstance(workspace, MDHistoWorkspace): if isinstance(workspace, MDHistoWorkspace):
......
...@@ -258,4 +258,11 @@ Functions to use when **mantid3d** projection is not available ...@@ -258,4 +258,11 @@ Functions to use when **mantid3d** projection is not available
Helper functions Helper functions
---------------- ----------------
.. automodule:: mantid.plots.helperfunctions .. automodule:: mantid.plots.helperfunctions
:members: get_distribution, get_normalization,
points_from_boundaries, boundaries_from_points,
get_wksp_index_dist_and_label, get_md_data, get_md_data1d,
get_md_data2d_bin_bounds, get_md_data2d_bin_centers,
get_spectrum, get_matrix_2d_data,get_uneven_data,
get_sample_log, get_axes_labels
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment