Skip to content

Commit 81efe72

Browse files
committed
Add Algorithm Documentation
1 parent 132d8ec commit 81efe72

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

Framework/Algorithms/src/CreateMonteCarloWorkspace.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
#include <vector>
1414

1515
#include "MantidAPI/MatrixWorkspace.h"
16+
#include "MantidAPI/Progress.h"
1617
#include "MantidAPI/Workspace.h"
1718
#include "MantidAPI/WorkspaceFactory.h"
1819
#include "MantidAlgorithms/CreateMonteCarloWorkspace.h"
1920
#include "MantidKernel/BoundedValidator.h"
2021
#include "MantidKernel/Logger.h"
21-
#include "MantidAPI/Progress.h"
2222

2323
namespace {
2424
Mantid::Kernel::Logger g_log("CreateMonteCarloWorkspace");
@@ -41,10 +41,12 @@ const std::string CreateMonteCarloWorkspace::name() const { return "CreateMonteC
4141
int CreateMonteCarloWorkspace::version() const { return 1; }
4242

4343
/// Algorithm's category for identification. @see Algorithm::category
44-
const std::string CreateMonteCarloWorkspace::category() const { return "TODO: FILL IN A CATEGORY"; }
44+
const std::string CreateMonteCarloWorkspace::category() const { return "Simulation"; }
4545

4646
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
47-
const std::string CreateMonteCarloWorkspace::summary() const { return "TODO: FILL IN A SUMMARY"; }
47+
const std::string CreateMonteCarloWorkspace::summary() const {
48+
return "Creates a randomly simulated workspace by sampling from the probability distribution of input data.";
49+
}
4850

4951
//----------------------------------------------------------------------------------------------
5052
/** Initialize the algorithm's properties.
@@ -55,7 +57,8 @@ void CreateMonteCarloWorkspace::init() {
5557

5658
declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
5759
"Input Workspace containing data to be fitted");
58-
declareProperty("Seed", 32, mustBePositive, "Integer that initializes a random-number generator");
60+
declareProperty("Seed", 32, mustBePositive,
61+
"Integer that initializes a random-number generator, good for reproducibility");
5962
declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("OutputWorkspace", "", Direction::Output),
6063
"Name of output workspace.");
6164
}
@@ -105,7 +108,6 @@ void CreateMonteCarloWorkspace::exec() {
105108
int numSteps = 7;
106109
API::Progress progress(this, 0.0, 1.0, numSteps);
107110

108-
109111
MatrixWorkspace_sptr instWs = getProperty("InputWorkspace");
110112
int seed_input = getProperty("Seed");
111113
progress.report();

docs/source/algorithms/CreateMonteCarloWorkspace-v1.rst

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
.. algorithm::
32

43
.. summary::
@@ -9,36 +8,46 @@
98

109
Description
1110
-----------
12-
13-
TODO: Enter a full rst-markup description of your algorithm here.
14-
11+
The algorithm generates a simulated workspace by sampling from the probability
12+
distribution of input data, useful for testing of fitting functions and modeling.
13+
By generating a simulated dataset that mirrors the probability
14+
distribution of existing data.
1515

1616
Usage
1717
-----
18-
.. Try not to use files in your examples,
19-
but if you cannot avoid it then the (small) files must be added to
20-
autotestdata\UsageData and the following tag unindented
21-
.. include:: ../usagedata-note.txt
2218

2319
**Example - CreateMonteCarloWorkspace**
2420

25-
.. testcode:: CreateMonteCarloWorkspaceExample
21+
.. testcode:: Create simulation and compare
2622

27-
# Create a host workspace
28-
ws = CreateWorkspace(DataX=range(0,3), DataY=(0,2))
29-
or
30-
ws = CreateSampleWorkspace()
23+
from mantid.api import AnalysisDataService as ADS
3124

32-
wsOut = CreateMonteCarloWorkspace()
25+
# Create Sample Workspace and Run Simulation
26+
ws = CreateSampleWorkspace(Random= True)
27+
wsOut = CreateMonteCarloWorkspace(InputWorkspace= 'ws', Seed= 32, OutputWorkspace= "New")
3328

34-
# Print the result
35-
print "The output workspace has %%i spectra" %% wsOut.getNumberHistograms()
29+
# Plot both of the above
30+
fig, axes = plt.subplots(edgecolor='#ffffff', num='New', subplot_kw={'projection': 'mantid'})
31+
for data, color, label in [(ADS.retrieve('New'), '#1f77b4', 'New: spec 1'),
32+
(ADS.retrieve('ws'), '#ff7f0e', 'ws: spec 1')]:
33+
axes.plot(data, color=color, label=label, wkspIndex=0)
3634

37-
Output:
35+
axes.tick_params(axis='both', which='major', size=6, tickdir='out', width=1, gridOn=False, label1On=True)
36+
axes.set(title='New', xlabel='Time-of-flight ($\\mu s$)', ylabel='Counts ($\\mu s$)$^{-1}$', ylim=[-0.00225, 0.04725])
37+
axes.legend(fontsize=8.0).set_draggable(True)
3838

39-
.. testoutput:: CreateMonteCarloWorkspaceExample
39+
fig.show()
4040

41-
The output workspace has ?? spectra
41+
Output:
42+
A histogram similar to the original but generated in a random way.
43+
44+
.. image:: ../../../images/New.png
45+
:alt: Overplot of simulated data over input data
46+
:width: 500px
47+
:height: 400px
48+
:scale: 100%
49+
:align: center
50+
:class: custom-class
4251

4352
.. categories::
4453

images/New.png

40.5 KB
Loading

0 commit comments

Comments
 (0)