Newer
Older
#ifndef MANTID_MDALGORITHMS_CUTMDTEST_H_
#define MANTID_MDALGORITHMS_CUTMDTEST_H_
#include "MantidMDAlgorithms/CutMD.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/IMDWorkspace.h"
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidAPI/IMDHistoWorkspace.h"
#include "MantidAPI/TableRow.h"
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <cxxtest/TestSuite.h>
using namespace Mantid::MDAlgorithms;
using namespace Mantid::API;
using namespace Mantid::Kernel;
namespace {
const std::string sharedWSName = "__CutMDTest_dataWS";
}
class CutMDTest : public CxxTest::TestSuite {
private:
IMDWorkspace_sptr m_inWS;
public:
CutMDTest() {
FrameworkManager::Instance().exec("CreateMDWorkspace", 10,
"OutputWorkspace", sharedWSName.c_str(),
"Dimensions", "3",
"Extents", "-10,10,-10,10,-10,10",
"Names", "A,B,C",
"Units", "U,U,U");
FrameworkManager::Instance().exec("SetSpecialCoordinates", 4,
"InputWorkspace", sharedWSName.c_str(),
"SpecialCoordinates", "HKL");
FrameworkManager::Instance().exec("SetUB", 14,
"Workspace", sharedWSName.c_str(),
"a", "1",
"b", "1",
"c", "1",
"alpha", "90",
"beta", "90",
"gamma", "90");
FrameworkManager::Instance().exec("FakeMDEventData", 4,
"InputWorkspace", sharedWSName.c_str(),
"PeakParams", "10000,0,0,0,1");
m_inWS =
AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(sharedWSName);
}
virtual ~CutMDTest() { AnalysisDataService::Instance().remove(sharedWSName); }
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static CutMDTest *createSuite() { return new CutMDTest(); }
static void destroySuite(CutMDTest *suite) { delete suite; }
void test_init() {
CutMD alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize())
TS_ASSERT(alg.isInitialized())
}
void test_exec_throws_if_giving_4th_binning_param_when_workspace_is_3d() {
const std::string wsName = "__CutMDTest_4thbinon3dthrows";
FrameworkManager::Instance().exec("CreateMDWorkspace", 10,
"OutputWorkspace", wsName.c_str(),
"Dimensions", "3",
"Extents", "-10,10,-10,10,-10,10",
"Names", "H,K,L",
"Units", "U,U,U");
FrameworkManager::Instance().exec("SetSpecialCoordinates", 4,
"InputWorkspace", wsName.c_str(),
"SpecialCoordinates", "HKL");
auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD");
algCutMD->initialize();
algCutMD->setRethrows(true);
algCutMD->setProperty("InputWorkspace", wsName);
algCutMD->setProperty("OutputWorkspace", wsName);
algCutMD->setProperty("P1Bin", "0.1");
algCutMD->setProperty("P2Bin", "0.1");
algCutMD->setProperty("P3Bin", "0.1");
algCutMD->setProperty("P4Bin", "0.1");
TS_ASSERT_THROWS(algCutMD->execute(), std::runtime_error)
AnalysisDataService::Instance().remove(wsName);
}
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
void test_slice_to_original() {
const std::string wsName = "__CutMDTest_slice_to_original";
auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD");
algCutMD->initialize();
algCutMD->setRethrows(true);
algCutMD->setProperty("InputWorkspace", sharedWSName);
algCutMD->setProperty("OutputWorkspace", wsName);
algCutMD->setProperty("P1Bin", "0.1");
algCutMD->setProperty("P2Bin", "0.1");
algCutMD->setProperty("P3Bin", "0.1");
algCutMD->setProperty("CheckAxes", false);
algCutMD->execute();
TS_ASSERT(algCutMD->isExecuted());
IMDEventWorkspace_sptr outWS =
AnalysisDataService::Instance().retrieveWS<IMDEventWorkspace>(wsName);
TS_ASSERT(outWS.get());
TS_ASSERT_EQUALS(
outWS->getDimension(0)->getMinimum(),
m_inWS->getDimension(0)->getMinimum());
TS_ASSERT_EQUALS(
outWS->getDimension(0)->getMaximum(),
m_inWS->getDimension(0)->getMaximum());
TS_ASSERT_EQUALS(
outWS->getDimension(1)->getMinimum(),
m_inWS->getDimension(1)->getMinimum());
TS_ASSERT_EQUALS(
outWS->getDimension(1)->getMaximum(),
m_inWS->getDimension(1)->getMaximum());
TS_ASSERT_EQUALS(
outWS->getDimension(2)->getMinimum(),
m_inWS->getDimension(2)->getMinimum());
TS_ASSERT_EQUALS(
outWS->getDimension(2)->getMaximum(),
m_inWS->getDimension(2)->getMaximum());
TS_ASSERT_EQUALS("['zeta', 0, 0]", outWS->getDimension(0)->getName());
TS_ASSERT_EQUALS("[0, 'eta', 0]", outWS->getDimension(1)->getName());
TS_ASSERT_EQUALS("[0, 0, 'xi']", outWS->getDimension(2)->getName());
AnalysisDataService::Instance().remove(wsName);
}
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
void test_recalculate_extents_with_3_bin_arguments() {
const std::string wsName = "__CutMDTest_recalc_extents_with_3_bin_args";
auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD");
algCutMD->initialize();
algCutMD->setRethrows(true);
algCutMD->setProperty("InputWorkspace", sharedWSName);
algCutMD->setProperty("OutputWorkspace", wsName);
algCutMD->setProperty("P1Bin", "0,0.3,0.8");
algCutMD->setProperty("P2Bin", "0.1");
algCutMD->setProperty("P3Bin", "0.1");
algCutMD->setProperty("CheckAxes", false);
algCutMD->setProperty("NoPix", true);
algCutMD->execute();
TS_ASSERT(algCutMD->isExecuted());
IMDWorkspace_sptr outWS =
AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(wsName);
TS_ASSERT(outWS.get());
TS_ASSERT_DELTA(outWS->getDimension(0)->getMinimum(), 0.0, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(0)->getMaximum(), 0.6, 1E-6);
TS_ASSERT_EQUALS(outWS->getDimension(0)->getNBins(), 2);
AnalysisDataService::Instance().remove(wsName);
}
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
void test_truncate_extents() {
const std::string wsName = "__CutMDTest_truncate_extents";
auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD");
algCutMD->initialize();
algCutMD->setRethrows(true);
algCutMD->setProperty("InputWorkspace", sharedWSName);
algCutMD->setProperty("OutputWorkspace", wsName);
algCutMD->setProperty("P1Bin", "0,1.1,1");
algCutMD->setProperty("P2Bin", "21");
algCutMD->setProperty("P3Bin", "0.1");
algCutMD->setProperty("CheckAxes", false);
algCutMD->setProperty("NoPix", true);
algCutMD->execute();
TS_ASSERT(algCutMD->isExecuted());
IMDWorkspace_sptr outWS =
AnalysisDataService::Instance().retrieveWS<IMDWorkspace>(wsName);
TS_ASSERT(outWS.get());
TS_ASSERT_EQUALS(outWS->getDimension(0)->getNBins(), 1);
TS_ASSERT_EQUALS(outWS->getDimension(1)->getNBins(), 1);
AnalysisDataService::Instance().remove(wsName);
}
void test_wrong_proj_format_columns() {
const std::string wsName = "__CutMDTest_wrong_proj_columns";
ITableWorkspace_sptr proj = WorkspaceFactory::Instance().createTable();
proj->addColumn("str", "name");
auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD");
algCutMD->initialize();
algCutMD->setRethrows(true);
algCutMD->setProperty("InputWorkspace", sharedWSName);
algCutMD->setProperty("OutputWorkspace", wsName);
algCutMD->setProperty("Projection", proj);
algCutMD->setProperty("P1Bin", "0.1");
algCutMD->setProperty("P2Bin", "0.2");
algCutMD->setProperty("P3Bin", "0.1");
algCutMD->setProperty("CheckAxes", false);
TS_ASSERT_THROWS(algCutMD->execute(), std::runtime_error);
}
void test_wrong_proj_format_rows() {
const std::string wsName = "__CutMDTest_wrong_proj_rows";
// Correct columns
ITableWorkspace_sptr proj = WorkspaceFactory::Instance().createTable();
proj->addColumn("str", "name");
proj->addColumn("str", "value");
proj->addColumn("double", "offset");
proj->addColumn("str", "type");
// ...but no rows
auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD");
algCutMD->initialize();
algCutMD->setRethrows(true);
algCutMD->setProperty("InputWorkspace", sharedWSName);
algCutMD->setProperty("OutputWorkspace", wsName);
algCutMD->setProperty("Projection", proj);
algCutMD->setProperty("P1Bin", "0.1");
algCutMD->setProperty("P2Bin", "0.2");
algCutMD->setProperty("P3Bin", "0.1");
algCutMD->setProperty("CheckAxes", false);
TS_ASSERT_THROWS(algCutMD->execute(), std::runtime_error);
}
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
void test_orthogonal_slice_with_scaling() {
const std::string wsName = "__CutMDTest_orthog_slice_with_scaling";
FrameworkManager::Instance().exec("CreateMDWorkspace", 10,
"OutputWorkspace", wsName.c_str(),
"Dimensions", "3",
"Extents", "-1,1,-1,1,-1,1",
"Names", "H,K,L",
"Units", "U,U,U");
FrameworkManager::Instance().exec("SetUB", 14,
"Workspace", wsName.c_str(),
"a", "1", "b", "1", "c", "1",
"alpha", "90", "beta", "90", "gamma", "90");
FrameworkManager::Instance().exec("SetSpecialCoordinates", 4,
"InputWorkspace", wsName.c_str(),
"SpecialCoordinates", "HKL");
ITableWorkspace_sptr proj = WorkspaceFactory::Instance().createTable();
proj->addColumn("str", "name");
proj->addColumn("str", "value");
proj->addColumn("double", "offset");
proj->addColumn("str", "type");
TableRow uRow = proj->appendRow();
TableRow vRow = proj->appendRow();
TableRow wRow = proj->appendRow();
uRow << "u" << "1,0,0" << 0.0 << "r";
vRow << "v" << "0,1,0" << 0.0 << "r";
wRow << "w" << "0,0,1" << 0.0 << "r";
auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD");
algCutMD->initialize();
algCutMD->setRethrows(true);
algCutMD->setProperty("InputWorkspace", wsName);
algCutMD->setProperty("OutputWorkspace", wsName);
algCutMD->setProperty("Projection", proj);
algCutMD->setProperty("P1Bin", "-0.5,0.5");
algCutMD->setProperty("P2Bin", "-0.1,0.1");
algCutMD->setProperty("P3Bin", "-0.3,0.3");
algCutMD->setProperty("NoPix", true);
algCutMD->execute();
TS_ASSERT(algCutMD->isExecuted());
IMDHistoWorkspace_sptr outWS =
AnalysisDataService::Instance().retrieveWS<IMDHistoWorkspace>(wsName);
TS_ASSERT(outWS.get());
TS_ASSERT_DELTA(outWS->getDimension(0)->getMinimum(), -0.5, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(0)->getMaximum(), 0.5, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(1)->getMinimum(), -0.1, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(1)->getMaximum(), 0.1, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(2)->getMinimum(), -0.3, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(2)->getMaximum(), 0.3, 1E-6);
TS_ASSERT_EQUALS("['zeta', 0, 0]", outWS->getDimension(0)->getName());
TS_ASSERT_EQUALS("[0, 'eta', 0]", outWS->getDimension(1)->getName());
TS_ASSERT_EQUALS("[0, 0, 'xi']", outWS->getDimension(2)->getName());
AnalysisDataService::Instance().remove(wsName);
}
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
void test_non_orthogonal_slice() {
const std::string wsName = "__CutMDTest_non_orthog_slice";
FrameworkManager::Instance().exec("CreateMDWorkspace", 10,
"OutputWorkspace", wsName.c_str(),
"Dimensions", "3",
"Extents", "-1,1,-1,1,-1,1",
"Names", "H,K,L",
"Units", "U,U,U");
FrameworkManager::Instance().exec("SetUB", 14,
"Workspace", wsName.c_str(),
"a", "1", "b", "1", "c", "1",
"alpha", "90", "beta", "90", "gamma", "90");
FrameworkManager::Instance().exec("SetSpecialCoordinates", 4,
"InputWorkspace", wsName.c_str(),
"SpecialCoordinates", "HKL");
ITableWorkspace_sptr proj = WorkspaceFactory::Instance().createTable();
proj->addColumn("str", "name");
proj->addColumn("str", "value");
proj->addColumn("double", "offset");
proj->addColumn("str", "type");
TableRow uRow = proj->appendRow();
TableRow vRow = proj->appendRow();
TableRow wRow = proj->appendRow();
uRow << "u" << "1,1,0" << 0.0 << "r";
vRow << "v" << "-1,1,0" << 0.0 << "r";
wRow << "w" << "0,0,1" << 0.0 << "r";
auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD");
algCutMD->initialize();
algCutMD->setRethrows(true);
algCutMD->setProperty("InputWorkspace", wsName);
algCutMD->setProperty("OutputWorkspace", wsName);
algCutMD->setProperty("Projection", proj);
algCutMD->setProperty("P1Bin", "0.1");
algCutMD->setProperty("P2Bin", "0.1");
algCutMD->setProperty("P3Bin", "0.1");
algCutMD->setProperty("NoPix", true);
algCutMD->execute();
TS_ASSERT(algCutMD->isExecuted());
IMDHistoWorkspace_sptr outWS =
AnalysisDataService::Instance().retrieveWS<IMDHistoWorkspace>(wsName);
TS_ASSERT(outWS.get());
TS_ASSERT_EQUALS(outWS->getDimension(0)->getMinimum(), -1);
TS_ASSERT_EQUALS(outWS->getDimension(0)->getMaximum(), 1);
TS_ASSERT_EQUALS(outWS->getDimension(1)->getMinimum(), -1);
TS_ASSERT_EQUALS(outWS->getDimension(1)->getMaximum(), 1);
TS_ASSERT_EQUALS(outWS->getDimension(2)->getMinimum(), -1);
TS_ASSERT_EQUALS(outWS->getDimension(2)->getMaximum(), 1);
TS_ASSERT_EQUALS("['zeta', 'zeta', 0]", outWS->getDimension(0)->getName());
TS_ASSERT_EQUALS("['-eta', 'eta', 0]", outWS->getDimension(1)->getName());
TS_ASSERT_EQUALS("[0, 0, 'xi']", outWS->getDimension(2)->getName());
AnalysisDataService::Instance().remove(wsName);
}
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
void test_orthogonal_slice_with_cropping() {
const std::string wsName = "__CutMDTest_orthog_slice_crop";
FrameworkManager::Instance().exec("CreateMDWorkspace", 10,
"OutputWorkspace", wsName.c_str(),
"Dimensions", "3",
"Extents", "-1,1,-1,1,-1,1",
"Names", "H,K,L",
"Units", "U,U,U");
FrameworkManager::Instance().exec("SetUB", 14,
"Workspace", wsName.c_str(),
"a", "1", "b", "1", "c", "1",
"alpha", "90", "beta", "90", "gamma", "90");
FrameworkManager::Instance().exec("SetSpecialCoordinates", 4,
"InputWorkspace", wsName.c_str(),
"SpecialCoordinates", "HKL");
ITableWorkspace_sptr proj = WorkspaceFactory::Instance().createTable();
proj->addColumn("str", "name");
proj->addColumn("str", "value");
proj->addColumn("double", "offset");
proj->addColumn("str", "type");
TableRow uRow = proj->appendRow();
TableRow vRow = proj->appendRow();
TableRow wRow = proj->appendRow();
uRow << "u" << "1,0,0" << 0.0 << "r";
vRow << "v" << "0,1,0" << 0.0 << "r";
wRow << "w" << "0,0,1" << 0.0 << "r";
auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD");
algCutMD->initialize();
algCutMD->setRethrows(true);
algCutMD->setProperty("InputWorkspace", wsName);
algCutMD->setProperty("OutputWorkspace", wsName);
algCutMD->setProperty("Projection", proj);
algCutMD->setProperty("P1Bin", "-0.5,0.5");
algCutMD->setProperty("P2Bin", "-0.1,0.1");
algCutMD->setProperty("P3Bin", "-0.3,0.3");
algCutMD->setProperty("NoPix", true);
algCutMD->execute();
TS_ASSERT(algCutMD->isExecuted());
IMDHistoWorkspace_sptr outWS =
AnalysisDataService::Instance().retrieveWS<IMDHistoWorkspace>(wsName);
TS_ASSERT(outWS.get());
TS_ASSERT_DELTA(outWS->getDimension(0)->getMinimum(), -0.5, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(0)->getMaximum(), 0.5, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(1)->getMinimum(), -0.1, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(1)->getMaximum(), 0.1, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(2)->getMinimum(), -0.3, 1E-6);
TS_ASSERT_DELTA(outWS->getDimension(2)->getMaximum(), 0.3, 1E-6);
TS_ASSERT_EQUALS("['zeta', 0, 0]", outWS->getDimension(0)->getName());
TS_ASSERT_EQUALS("[0, 'eta', 0]", outWS->getDimension(1)->getName());
TS_ASSERT_EQUALS("[0, 0, 'xi']", outWS->getDimension(2)->getName());
AnalysisDataService::Instance().remove(wsName);
}
};
#endif /* MANTID_MDALGORITHMS_CUTMDTEST_H_ */