@@ -183,137 +183,153 @@ def test_init_invalid_xtype():
183
183
params_scale_to = [
184
184
# UC1: same x-array and y-array, check offset
185
185
(
186
- [
187
- np .array ([10 , 15 , 25 , 30 , 60 , 140 ]),
188
- np .array ([2 , 3 , 4 , 5 , 6 , 7 ]),
189
- "tth" ,
190
- 2 * np .pi ,
191
- np .array ([10 , 15 , 25 , 30 , 60 , 140 ]),
192
- np .array ([2 , 3 , 4 , 5 , 6 , 7 ]),
193
- "tth" ,
194
- 2 * np .pi ,
195
- None ,
196
- 60 ,
197
- None ,
198
- 2.1 ,
199
- ] ,
200
- [ " tth" , np .array ([4.1 , 5.1 , 6.1 , 7.1 , 8.1 , 9.1 ])] ,
186
+ {
187
+ "xarray" : np .array ([10 , 15 , 25 , 30 , 60 , 140 ]),
188
+ "yarray" : np .array ([2 , 3 , 4 , 5 , 6 , 7 ]),
189
+ "xtype" : " tth" ,
190
+ "wavelength" : 2 * np .pi ,
191
+ "target_xarray" : np .array ([10 , 15 , 25 , 30 , 60 , 140 ]),
192
+ "target_yarray" : np .array ([2 , 3 , 4 , 5 , 6 , 7 ]),
193
+ "target_xtype" : " tth" ,
194
+ "target_wavelength" : 2 * np .pi ,
195
+ "q" : None ,
196
+ "tth" : 60 ,
197
+ "d" : None ,
198
+ "offset" : 2.1 ,
199
+ } ,
200
+ { "xtype" : " tth" , "yarray" : np .array ([4.1 , 5.1 , 6.1 , 7.1 , 8.1 , 9.1 ])} ,
201
201
),
202
202
# UC2: same length x-arrays with exact x-value match
203
203
(
204
- [
205
- np .array ([10 , 15 , 25 , 30 , 60 , 140 ]),
206
- np .array ([10 , 20 , 25 , 30 , 60 , 100 ]),
207
- "tth" ,
208
- 2 * np .pi ,
209
- np .array ([10 , 20 , 25 , 30 , 60 , 140 ]),
210
- np .array ([2 , 3 , 4 , 5 , 6 , 7 ]),
211
- "tth" ,
212
- 2 * np .pi ,
213
- None ,
214
- 60 ,
215
- None ,
216
- 0 ,
217
- ] ,
218
- [ " tth" , np .array ([1 , 2 , 2.5 , 3 , 6 , 10 ])] ,
204
+ {
205
+ "xarray" : np .array ([10 , 15 , 25 , 30 , 60 , 140 ]),
206
+ "yarray" : np .array ([10 , 20 , 25 , 30 , 60 , 100 ]),
207
+ "xtype" : " tth" ,
208
+ "wavelength" : 2 * np .pi ,
209
+ "target_xarray" : np .array ([10 , 20 , 25 , 30 , 60 , 140 ]),
210
+ "target_yarray" : np .array ([2 , 3 , 4 , 5 , 6 , 7 ]),
211
+ "target_xtype" : " tth" ,
212
+ "target_wavelength" : 2 * np .pi ,
213
+ "q" : None ,
214
+ "tth" : 60 ,
215
+ "d" : None ,
216
+ "offset" : 0 ,
217
+ } ,
218
+ { "xtype" : " tth" , "yarray" : np .array ([1 , 2 , 2.5 , 3 , 6 , 10 ])} ,
219
219
),
220
220
# UC3: same length x-arrays with approximate x-value match
221
221
(
222
- [
223
- np .array ([0.12 , 0.24 , 0.31 , 0.4 ]),
224
- np .array ([10 , 20 , 40 , 60 ]),
225
- "q" ,
226
- 2 * np .pi ,
227
- np .array ([0.14 , 0.24 , 0.31 , 0.4 ]),
228
- np .array ([1 , 3 , 4 , 5 ]),
229
- "q" ,
230
- 2 * np .pi ,
231
- 0.1 ,
232
- None ,
233
- None ,
234
- 0 ,
235
- ] ,
236
- [ " q" , np .array ([1 , 2 , 4 , 6 ])] ,
222
+ {
223
+ "xarray" : np .array ([0.12 , 0.24 , 0.31 , 0.4 ]),
224
+ "yarray" : np .array ([10 , 20 , 40 , 60 ]),
225
+ "xtype" : " q" ,
226
+ "wavelength" : 2 * np .pi ,
227
+ "target_xarray" : np .array ([0.14 , 0.24 , 0.31 , 0.4 ]),
228
+ "target_yarray" : np .array ([1 , 3 , 4 , 5 ]),
229
+ "target_xtype" : " q" ,
230
+ "target_wavelength" : 2 * np .pi ,
231
+ "q" : 0.1 ,
232
+ "tth" : None ,
233
+ "d" : None ,
234
+ "offset" : 0 ,
235
+ } ,
236
+ { "xtype" : " q" , "yarray" : np .array ([1 , 2 , 4 , 6 ])} ,
237
237
),
238
238
# UC4: different x-array lengths with approximate x-value match
239
239
(
240
- [
241
- np .array ([10 , 25 , 30.1 , 40.2 , 61 , 120 , 140 ]),
242
- np .array ([10 , 20 , 30 , 40 , 50 , 60 , 100 ]),
243
- "tth" ,
244
- 2 * np .pi ,
245
- np .array ([20 , 25.5 , 32 , 45 , 50 , 62 , 100 , 125 , 140 ]),
246
- np .array ([1.1 , 2 , 3 , 3.5 , 4 , 5 , 10 , 12 , 13 ]),
247
- "tth" ,
248
- 2 * np .pi ,
249
- None ,
250
- 60 ,
251
- None ,
252
- 0 ,
253
- ] ,
254
- # scaling factor is calculated at index = 5 for self and index = 6 for target
255
- [ " tth" , np .array ([1 , 2 , 3 , 4 , 5 , 6 , 10 ])] ,
240
+ {
241
+ "xarray" : np .array ([10 , 25 , 30.1 , 40.2 , 61 , 120 , 140 ]),
242
+ "yarray" : np .array ([10 , 20 , 30 , 40 , 50 , 60 , 100 ]),
243
+ "xtype" : " tth" ,
244
+ "wavelength" : 2 * np .pi ,
245
+ "target_xarray" : np .array ([20 , 25.5 , 32 , 45 , 50 , 62 , 100 , 125 , 140 ]),
246
+ "target_yarray" : np .array ([1.1 , 2 , 3 , 3.5 , 4 , 5 , 10 , 12 , 13 ]),
247
+ "target_xtype" : " tth" ,
248
+ "target_wavelength" : 2 * np .pi ,
249
+ "q" : None ,
250
+ "tth" : 60 ,
251
+ "d" : None ,
252
+ "offset" : 0 ,
253
+ } ,
254
+ # scaling factor is calculated at index = 4 (tth=61) for self and index = 5 for target (tth=62)
255
+ { "xtype" : " tth" , "yarray" : np .array ([1 , 2 , 3 , 4 , 5 , 6 , 10 ])} ,
256
256
),
257
257
]
258
258
259
259
260
260
@pytest .mark .parametrize ("inputs, expected" , params_scale_to )
261
261
def test_scale_to (inputs , expected ):
262
- orig_diff_object = DiffractionObject (xarray = inputs [0 ], yarray = inputs [1 ], xtype = inputs [2 ], wavelength = inputs [3 ])
262
+ orig_diff_object = DiffractionObject (
263
+ xarray = inputs ["xarray" ], yarray = inputs ["yarray" ], xtype = inputs ["xtype" ], wavelength = inputs ["wavelength" ]
264
+ )
263
265
target_diff_object = DiffractionObject (
264
- xarray = inputs [4 ], yarray = inputs [5 ], xtype = inputs [6 ], wavelength = inputs [7 ]
266
+ xarray = inputs ["target_xarray" ],
267
+ yarray = inputs ["target_yarray" ],
268
+ xtype = inputs ["target_xtype" ],
269
+ wavelength = inputs ["target_wavelength" ],
265
270
)
266
271
scaled_diff_object = orig_diff_object .scale_to (
267
- target_diff_object , q = inputs [8 ], tth = inputs [9 ], d = inputs [10 ], offset = inputs [11 ]
272
+ target_diff_object , q = inputs ["q" ], tth = inputs ["tth" ], d = inputs ["d" ], offset = inputs ["offset" ]
268
273
)
269
- # Check the intensity data is same as expected
270
- assert np .allclose (scaled_diff_object .on_xtype (expected [0 ])[1 ], expected [1 ])
274
+ # Check the intensity data is the same as expected
275
+ assert np .allclose (scaled_diff_object .on_xtype (expected ["xtype" ])[1 ], expected ["yarray" ])
271
276
272
277
273
278
params_scale_to_bad = [
274
279
# UC1: user did not specify anything
275
280
(
276
- np .array ([0.1 , 0.2 , 0.3 ]),
277
- np .array ([1 , 2 , 3 ]),
278
- "q" ,
279
- 2 * np .pi ,
280
- np .array ([0.05 , 0.1 , 0.2 , 0.3 ]),
281
- np .array ([5 , 10 , 20 , 30 ]),
282
- "q" ,
283
- 2 * np .pi ,
284
- None ,
285
- None ,
286
- None ,
287
- 0 ,
281
+ {
282
+ "xarray" : np .array ([0.1 , 0.2 , 0.3 ]),
283
+ "yarray" : np .array ([1 , 2 , 3 ]),
284
+ "xtype" : "q" ,
285
+ "wavelength" : 2 * np .pi ,
286
+ "target_xarray" : np .array ([0.05 , 0.1 , 0.2 , 0.3 ]),
287
+ "target_yarray" : np .array ([5 , 10 , 20 , 30 ]),
288
+ "target_xtype" : "q" ,
289
+ "target_wavelength" : 2 * np .pi ,
290
+ "q" : None ,
291
+ "tth" : None ,
292
+ "d" : None ,
293
+ "offset" : 0 ,
294
+ }
288
295
),
289
296
# UC2: user specified more than one of q, tth, and d
290
297
(
291
- np .array ([10 , 25 , 30.1 , 40.2 , 61 , 120 , 140 ]),
292
- np .array ([10 , 20 , 30 , 40 , 50 , 60 , 100 ]),
293
- "tth" ,
294
- 2 * np .pi ,
295
- np .array ([20 , 25.5 , 32 , 45 , 50 , 62 , 100 , 125 , 140 ]),
296
- np .array ([1.1 , 2 , 3 , 3.5 , 4 , 5 , 10 , 12 , 13 ]),
297
- "tth" ,
298
- 2 * np .pi ,
299
- None ,
300
- 60 ,
301
- 10 ,
302
- 0 ,
298
+ {
299
+ "xarray" : np .array ([10 , 25 , 30.1 , 40.2 , 61 , 120 , 140 ]),
300
+ "yarray" : np .array ([10 , 20 , 30 , 40 , 50 , 60 , 100 ]),
301
+ "xtype" : "tth" ,
302
+ "wavelength" : 2 * np .pi ,
303
+ "target_xarray" : np .array ([20 , 25.5 , 32 , 45 , 50 , 62 , 100 , 125 , 140 ]),
304
+ "target_yarray" : np .array ([1.1 , 2 , 3 , 3.5 , 4 , 5 , 10 , 12 , 13 ]),
305
+ "target_xtype" : "tth" ,
306
+ "target_wavelength" : 2 * np .pi ,
307
+ "q" : None ,
308
+ "tth" : 60 ,
309
+ "d" : 10 ,
310
+ "offset" : 0 ,
311
+ }
303
312
),
304
313
]
305
314
306
315
307
316
@pytest .mark .parametrize ("inputs" , params_scale_to_bad )
308
317
def test_scale_to_bad (inputs ):
309
- orig_diff_object = DiffractionObject (xarray = inputs [0 ], yarray = inputs [1 ], xtype = inputs [2 ], wavelength = inputs [3 ])
318
+ orig_diff_object = DiffractionObject (
319
+ xarray = inputs ["xarray" ], yarray = inputs ["yarray" ], xtype = inputs ["xtype" ], wavelength = inputs ["wavelength" ]
320
+ )
310
321
target_diff_object = DiffractionObject (
311
- xarray = inputs [4 ], yarray = inputs [5 ], xtype = inputs [6 ], wavelength = inputs [7 ]
322
+ xarray = inputs ["target_xarray" ],
323
+ yarray = inputs ["target_yarray" ],
324
+ xtype = inputs ["target_xtype" ],
325
+ wavelength = inputs ["target_wavelength" ],
312
326
)
313
327
with pytest .raises (
314
328
ValueError , match = "You must specify exactly one of 'q', 'tth', or 'd'. Please rerun specifying only one."
315
329
):
316
- orig_diff_object .scale_to (target_diff_object , q = inputs [8 ], tth = inputs [9 ], d = inputs [10 ], offset = inputs [11 ])
330
+ orig_diff_object .scale_to (
331
+ target_diff_object , q = inputs ["q" ], tth = inputs ["tth" ], d = inputs ["d" ], offset = inputs ["offset" ]
332
+ )
317
333
318
334
319
335
params_index = [
0 commit comments