forked from BAMresearch/McSAS3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_McData2D_unittest.py
132 lines (112 loc) · 5.31 KB
/
test_McData2D_unittest.py
1
2
3
4
5
6
7
8
9
10
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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
import unittest
# these need to be loaded at the beginning to avoid errors related to relative imports (ImportWarning in h5py)
# might be related to the change of import style for Python 3.5+. Tested on Python 3.7 at 20200417
import sys, os, pandas, scipy
import numpy as np
from pathlib import Path
# these packages are failing to import in McHat if they are not loaded here:
import h5py
# %matplotlib inline
# import matplotlib.pyplot as plt
from mcsas3 import McData2D
import shutil # for copy
# import warnings
# warnings.filterwarnings('error')
class testMcData2D(unittest.TestCase):
def test_mcdata2d_instantiated(self):
md = McData2D.McData2D()
md.from_nexus(filename=r"testdata/009766_forSasView.h5")
self.assertIsNotNone(md.measData, "measData is not populated")
self.assertTrue("Q" in md.measData.keys())
# def test_mcdata1d_singleLine(self):
# md = McData1D.McData1D(filename=r"testdata/S2870 BSA THF 1 1 d.pdh")
# self.assertIsNotNone(md.measData, "measData is not populated")
# self.assertTrue("Q" in md.measData.keys())
# def test_mcdata1d_singleLineWithOptions(self):
# md = McData1D.McData1D(
# filename=r"testdata/S2870 BSA THF 1 1 d.pdh", dataRange=[0.1, 0.6], nbins=50
# )
# self.assertIsNotNone(md.measData, "measData is not populated")
# self.assertTrue("Q" in md.measData.keys(), "measData does not contain Q")
# self.assertTrue(
# np.min(md.measData["Q"]) > 0.1, "clipper has not applied minimum"
# )
# self.assertTrue(
# np.max(md.measData["Q"]) < 0.6, "clipper has not applied maximum"
# )
# self.assertTrue(
# len(md.measData["Q"]) < 51, "rebinner has not rebinned to <51 bins"
# )
# def test_mcdata1d_csv(self):
# md = McData1D.McData1D(
# filename=Path("testdata", "quickstartdemo1.csv"),
# nbins=100,
# csvargs={"sep": ";", "header": None, "names": ["Q", "I", "ISigma"]},
# )
# self.assertIsNotNone(md.measData, "measData is not populated")
# self.assertTrue("Q" in md.measData.keys(), "measData does not contain Q")
# self.assertTrue(
# len(md.measData["Q"]) < 101, "rebinner has not rebinned to <51 bins"
# )
# def test_mcdata1d_csv_norebin(self):
# md = McData1D.McData1D(
# filename=Path("testdata", "quickstartdemo1.csv"),
# nbins=0,
# csvargs={"sep": ";", "header": None, "names": ["Q", "I", "ISigma"]},
# )
# self.assertIsNotNone(md.measData, "measData is not populated")
# self.assertTrue("Q" in md.measData.keys(), "measData does not contain Q")
# self.assertTrue(
# len(md.measData["I"]) == len(md.rawData), "rebinner has not been bypassed")
# def test_restore_state(self):
# if Path("test_state.h5").is_file():
# Path("test_state.h5").unlink()
# mds = McData1D.McData1D(
# filename=Path("testdata", "quickstartdemo1.csv"),
# nbins=100,
# csvargs={"sep": ";", "header": None, "names": ["Q", "I", "ISigma"]},
# )
# mds.store(filename = "test_state.h5")
# del mds
# md = McData1D.McData1D(loadFromFile=Path("test_state.h5"))
# def test_restore_state_fromDataframe(self):
# # create state:
# if Path("test_state_df.h5").is_file():
# Path("test_state_df.h5").unlink()
# # test dataframe:
# Q = np.linspace(0.01, 0.99, 100, dtype=float)
# I = Q ** -4
# ISigma = I * 0.01
# testdf = pandas.DataFrame(data = {'Q':Q, 'I': I, 'ISigma': ISigma})
# od = McData1D.McData1D(df = testdf)
# od.store(filename = "test_state_df.h5")
# del od
# md = McData1D.McData1D(loadFromFile=Path("test_state_df.h5"))
# def test_from_nxsas(self):
# # tests whether McData can load from NXsas
# hpath = Path('testdata','20190725_11_expanded_stacked_processed_190807_161306.nxs')
# od = McData1D.McData1D(filename = hpath)
# def test_restore_state_from_nxsas(self):
# # tests whether I can restore state from a nexus file-derived McSAS state file
# hpath = Path('testdata','20190725_11_expanded_stacked_processed_190807_161306.nxs')
# od = McData1D.McData1D(filename = hpath)
# od.store(filename = "test_state_nxsas.h5")
# del od
# md = McData1D.McData1D(loadFromFile=Path("test_state_nxsas.h5"))
# def test_nxsas_io(self):
# # tests whether I can read and write in the same nexus file
# if Path('testdata', "test_nexus_io.nxs").is_file():
# Path('testdata', "test_nexus_io.nxs").unlink()
# hpath = Path('testdata', '20190725_11_expanded_stacked_processed_190807_161306.nxs')
# tpath = Path('testdata', "test_nexus_io.nxs")
# shutil.copy(hpath, tpath)
# od = McData1D.McData1D(filename = tpath)
# od.store(filename = tpath)
# del od
# md = McData1D.McData1D(loadFromFile=tpath)
# def test_read_datamerge(self):
# # tests whether I can read a file written by datamerge v2.5
# hpath = Path('testdata','datamerge.nxs')
# od = McData1D.McData1D(filename = hpath)
if __name__ == "__main__":
unittest.main()