11import numpy as np
2+ import pytest
23
34from sasdata .data import SasMeasurement
45from sasdata .dataset_types import angle_dim , one_dim , three_dim , two_dim
910from sasdata .quantities .units import per_angstrom , per_centimeter , radians
1011
1112
12- def test_1d (basic_metadata ):
13- q = [1 , 2 , 3 , 4 , 5 ]
14- i = [5 , 4 , 3 , 2 , 1 ]
15-
16- q_quantity = Quantity (np .array (q ), per_angstrom )
17- i_quantity = Quantity (np .array (i ), per_centimeter )
13+ @pytest .mark .parametrize (
14+ "q, i" ,
15+ [(np .array ([1 , 2 , 3 , 4 , 5 ]), np .array ([5 , 4 , 3 , 2 , 1 ])), (np .array ([2 , 4 , 1 , 5 , 3 ]), np .array ([1 , 2 , 3 , 4 , 5 ]))],
16+ )
17+ def test_1d (q , i , basic_metadata ):
18+ q_quantity = Quantity (q , per_angstrom )
19+ i_quantity = Quantity (i , per_centimeter )
1820
1921 data_contents = {"Q" : q_quantity , "I" : i_quantity }
2022
2123 data = SasMeasurement ("TestData" , data_contents , one_dim , basic_metadata , True )
2224
2325 assert data .abscissae .dimensionality == 1
24- assert all (data .abscissae .axes [0 ].value == np .array (q ))
25- assert all (data .ordinate .value == np .array (i ))
26-
27-
28- def test_2d (basic_metadata ):
29- # This could be autogenerated but I am hard coding to reduce the logic in
30- # the test.
31- qx = [[1 , 1 , 1 ], [2 , 2 , 2 ], [3 , 3 , 3 ]]
32- qy = [[1 , 2 , 3 ], [1 , 2 , 3 ], [1 , 2 , 3 ]]
33- i = [[1 , 0 , 0 ], [0 , 1 , 0 ], [0 , 0 , 1 ]]
34-
35- qx_quantity = Quantity (np .array (qx ), per_angstrom )
36- qy_quantity = Quantity (np .array (qy ), per_angstrom )
37- i_quantity = Quantity (np .array (i ), per_centimeter )
26+ assert all (data .abscissae .axes [0 ].value == q )
27+ assert all (data .ordinate == i_quantity )
28+
29+
30+ # This could be autogenerated but I am hard coding to reduce the logic in the test.
31+ @pytest .mark .parametrize (
32+ "qx, qy, i" ,
33+ [
34+ (
35+ np .array ([[1 , 1 , 1 ], [2 , 2 , 2 ], [3 , 3 , 3 ]]),
36+ np .array ([[1 , 2 , 3 ], [1 , 2 , 3 ], [1 , 2 , 3 ]]),
37+ np .array ([[1 , 0 , 0 ], [0 , 1 , 0 ], [0 , 0 , 1 ]]),
38+ ),
39+ (np .array ([1 , 2 ]), np .array ([1 , 2 , 3 , 4 , 5 ]), np .array ([[1 , 0 , 1 , 0 , 1 ], [0 , 1 , 0 , 1 , 0 ]])),
40+ ],
41+ )
42+ def test_2d (qx , qy , i , basic_metadata ):
43+ qx_quantity = Quantity (qx , per_angstrom )
44+ qy_quantity = Quantity (qy , per_angstrom )
45+ i_quantity = Quantity (i , per_centimeter )
3846
3947 data_contents = {"Qx" : qx_quantity , "Qy" : qy_quantity , "I" : i_quantity }
4048
4149 data = SasMeasurement ("TestData" , data_contents , two_dim , basic_metadata , True )
4250
4351 assert data .abscissae .dimensionality == 2
44- assert (data .ordinate .value == np .array (i )).all ()
45- assert (data .abscissae .axes [0 ].value == np .array (qx )).all ()
46- assert (data .abscissae .axes [1 ].value == np .array (qy )).all ()
47-
48-
49- def test_3d (basic_metadata ):
50- # test base 3D class
51- qx = [[[1 , 1 ], [2 , 2 ]], [[1 , 1 ], [2 , 2 ]]]
52- qy = [[[1 , 1 ], [1 , 1 ]], [[2 , 2 ], [2 , 2 ]]]
53- qz = [[[1 , 2 ], [1 , 2 ]], [[1 , 2 ], [1 , 2 ]]]
54- i = [[[1 , 0 ], [1 , 0 ]], [[0 , 1 ], [0 , 1 ]]]
55-
56- qx_quantity = Quantity (np .array (qx ), per_angstrom )
57- qy_quantity = Quantity (np .array (qy ), per_angstrom )
58- qz_quantity = Quantity (np .array (qz ), per_angstrom )
59- i_quantity = Quantity (np .array (i ), per_centimeter )
52+ assert (data .abscissae .axes [0 ].value == qx ).all ()
53+ assert (data .abscissae .axes [1 ].value == qy ).all ()
54+ assert (data .ordinate == i_quantity ).all ()
55+
56+
57+ @pytest .mark .parametrize (
58+ "qx, qy, qz, i" ,
59+ [
60+ (
61+ np .array ([[[1 , 1 ], [1 , 1 ]], [[2 , 2 ], [2 , 2 ]]]),
62+ np .array ([[[1 , 1 ], [2 , 2 ]], [[1 , 1 ], [2 , 2 ]]]),
63+ np .array ([[[1 , 2 ], [1 , 2 ]], [[1 , 2 ], [1 , 2 ]]]),
64+ np .array ([[[1 , 0 ], [1 , 0 ]], [[0 , 1 ], [0 , 1 ]]]),
65+ ),
66+ (
67+ np .array ([1 , 2 ]),
68+ np .array ([1 , 2 ]),
69+ np .array ([1 , 2 , 3 , 4 , 5 ]),
70+ np .array ([[[1 , 0 , 1 , 0 , 1 ], [1 , 0 , 1 , 0 , 1 ]], [[0 , 1 , 0 , 1 , 0 ], [0 , 1 , 0 , 1 , 0 ]]]),
71+ ),
72+ ],
73+ )
74+ def test_3d (qx , qy , qz , i , basic_metadata ):
75+ qx_quantity = Quantity (qx , per_angstrom )
76+ qy_quantity = Quantity (qy , per_angstrom )
77+ qz_quantity = Quantity (qz , per_angstrom )
78+ i_quantity = Quantity (i , per_centimeter )
6079
6180 data_contents = {"Qx" : qx_quantity , "Qy" : qy_quantity , "Qz" : qz_quantity , "I" : i_quantity }
6281
6382 data = SasMeasurement ("TestData" , data_contents , three_dim , basic_metadata , True )
6483
6584 assert data .abscissae .dimensionality == 3
66- assert (data .ordinate . value == np . array ( i ) ).all ()
67- assert (data .abscissae .axes [0 ].value == np . array ( qx ) ).all ()
68- assert (data .abscissae .axes [1 ].value == np . array ( qy ) ).all ()
69- assert (data .abscissae . axes [ 2 ]. value == np . array ( qz ) ).all ()
85+ assert (data .abscissae . axes [ 0 ]. value == qx ).all ()
86+ assert (data .abscissae .axes [1 ].value == qy ).all ()
87+ assert (data .abscissae .axes [2 ].value == qz ).all ()
88+ assert (data .ordinate == i_quantity ).all ()
7089
7190
7291def test_deduce_qz (basic_metadata ):
7392 root_two_pi = np .sqrt (2 ) * np .pi
74- qx = [
75- [root_two_pi , root_two_pi , root_two_pi ],
76- [root_two_pi , root_two_pi , root_two_pi ],
77- [root_two_pi , root_two_pi , root_two_pi ],
78- ]
79- qy = [
80- [root_two_pi , root_two_pi , root_two_pi ],
81- [root_two_pi , root_two_pi , root_two_pi ],
82- [root_two_pi , root_two_pi , root_two_pi ],
83- ]
84- i = [[1 , 0 , 0 ], [0 , 1 , 0 ], [0 , 0 , 1 ]]
85-
86- qx_quantity = Quantity (np .array (qx ), unitless ) / basic_metadata .instrument .source .wavelength
87- qy_quantity = Quantity (np .array (qy ), unitless ) / basic_metadata .instrument .source .wavelength
88- i_quantity = Quantity (np .array (i ), per_centimeter )
93+ qx = np .array (
94+ [
95+ [root_two_pi , root_two_pi , root_two_pi ],
96+ [root_two_pi , root_two_pi , root_two_pi ],
97+ [root_two_pi , root_two_pi , root_two_pi ],
98+ ]
99+ )
100+ qy = np .array (
101+ [
102+ [root_two_pi , root_two_pi , root_two_pi ],
103+ [root_two_pi , root_two_pi , root_two_pi ],
104+ [root_two_pi , root_two_pi , root_two_pi ],
105+ ]
106+ )
107+ i = np .array ([[1 , 0 , 0 ], [0 , 1 , 0 ], [0 , 0 , 1 ]])
108+
109+ qx_quantity = Quantity (qx , unitless ) / basic_metadata .instrument .source .wavelength
110+ qy_quantity = Quantity (qy , unitless ) / basic_metadata .instrument .source .wavelength
111+ i_quantity = Quantity (i , per_centimeter )
89112
90113 data_contents = {"Qx" : qx_quantity , "Qy" : qy_quantity , "I" : i_quantity }
91114
@@ -97,16 +120,16 @@ def test_deduce_qz(basic_metadata):
97120
98121
99122def test_angle (basic_metadata ):
100- phi = [0.4 * Pi , 0.8 * Pi , 1.2 * Pi , 1.6 * Pi , 2 * Pi ]
101- i = [5 , 4 , 3 , 2 , 1 ]
123+ phi = np . array ( [0.4 * Pi , 0.8 * Pi , 1.2 * Pi , 1.6 * Pi , 2 * Pi ])
124+ i = np . array ( [5 , 4 , 3 , 2 , 1 ])
102125
103- phi_quantity = Quantity (np . array ( phi ) , radians )
104- i_quantity = Quantity (np . array ( i ) , per_centimeter )
126+ phi_quantity = Quantity (phi , radians )
127+ i_quantity = Quantity (i , per_centimeter )
105128
106129 data_contents = {"Phi" : phi_quantity , "I" : i_quantity }
107130
108131 data = SasMeasurement ("TestData" , data_contents , angle_dim , basic_metadata , True )
109132
110133 assert data .abscissae .dimensionality == 1
111- assert all (data .abscissae .axes [0 ].value == np . array ( phi ) )
112- assert all (data .ordinate . value == np . array ( i ) )
134+ assert all (data .abscissae .axes [0 ].value == phi )
135+ assert all (data .ordinate == i_quantity )
0 commit comments