@@ -191,7 +191,23 @@ def test_init_invalid_xtype():
191
191
"org_do_args, target_do_args, scale_inputs, expected" ,
192
192
[
193
193
# Test whether the original y-array is scaled as expected
194
- ( # C1: Same x-arrays
194
+ ( # C1: none of q, tth, d, provided, expect to scale on the maximal intensity from each object
195
+ {
196
+ "xarray" : np .array ([0.1 , 0.2 , 0.3 ]),
197
+ "yarray" : np .array ([1 , 2 , 3 ]),
198
+ "xtype" : "q" ,
199
+ "wavelength" : 2 * np .pi ,
200
+ },
201
+ {
202
+ "xarray" : np .array ([0.05 , 0.1 , 0.2 , 0.3 ]),
203
+ "yarray" : np .array ([5 , 10 , 20 , 30 ]),
204
+ "xtype" : "q" ,
205
+ "wavelength" : 2 * np .pi ,
206
+ },
207
+ {},
208
+ {"xtype" : "q" , "yarray" : np .array ([10 , 20 , 30 ])},
209
+ ),
210
+ ( # C2: Same x-arrays
195
211
# x-value has exact matches at tth=60 (y=60) and tth=60 (y=6),
196
212
# for original and target diffraction objects,
197
213
# expect original y-array to multiply by 6/60=1/10
@@ -207,15 +223,10 @@ def test_init_invalid_xtype():
207
223
"xtype" : "tth" ,
208
224
"wavelength" : 2 * np .pi ,
209
225
},
210
- {
211
- "q" : None ,
212
- "tth" : 60 ,
213
- "d" : None ,
214
- "offset" : 0 ,
215
- },
226
+ {"tth" : 60 },
216
227
{"xtype" : "tth" , "yarray" : np .array ([1 , 2 , 2.5 , 3 , 6 , 10 ])},
217
228
),
218
- ( # C2 : Different x-arrays with same length,
229
+ ( # C3 : Different x-arrays with same length,
219
230
# x-value has closest match at q=0.12 (y=10) and q=0.14 (y=1)
220
231
# for original and target diffraction objects,
221
232
# expect original y-array to multiply by 1/10
@@ -231,15 +242,10 @@ def test_init_invalid_xtype():
231
242
"xtype" : "q" ,
232
243
"wavelength" : 2 * np .pi ,
233
244
},
234
- {
235
- "q" : 0.1 ,
236
- "tth" : None ,
237
- "d" : None ,
238
- "offset" : 0 ,
239
- },
245
+ {"q" : 0.1 },
240
246
{"xtype" : "q" , "yarray" : np .array ([1 , 2 , 4 , 6 ])},
241
247
),
242
- ( # C3 : Different x-array lengths
248
+ ( # C4 : Different x-array lengths
243
249
# x-value has closest matches at tth=61 (y=50) and tth=62 (y=5),
244
250
# for original and target diffraction objects,
245
251
# expect original y-array to multiply by 5/50=1/10
@@ -255,43 +261,48 @@ def test_init_invalid_xtype():
255
261
"xtype" : "tth" ,
256
262
"wavelength" : 2 * np .pi ,
257
263
},
258
- {
259
- "q" : None ,
260
- "tth" : 60 ,
261
- "d" : None ,
262
- "offset" : 0 ,
263
- },
264
+ {"tth" : 60 },
264
265
{"xtype" : "tth" , "yarray" : np .array ([1 , 2 , 3 , 4 , 5 , 6 , 10 ])},
265
266
),
266
- ( # C4: Same x-array and y-array with 2.1 offset, expect y-array to shift up by 2.1
267
+ ( # C5.1: Reuse test case from C1, none of q, tth, d, provided, but include an offset,
268
+ # expect scaled y-array in C1 to shift up by 2
267
269
{
268
- "xarray" : np .array ([10 , 15 , 25 , 30 , 60 , 140 ]),
269
- "yarray" : np .array ([2 , 3 , 4 , 5 , 6 , 7 ]),
270
- "xtype" : "tth " ,
270
+ "xarray" : np .array ([0.1 , 0.2 , 0.3 ]),
271
+ "yarray" : np .array ([1 , 2 , 3 ]),
272
+ "xtype" : "q " ,
271
273
"wavelength" : 2 * np .pi ,
272
274
},
273
275
{
274
- "xarray" : np .array ([10 , 15 , 25 , 30 , 60 , 140 ]),
275
- "yarray" : np .array ([2 , 3 , 4 , 5 , 6 , 7 ]),
276
+ "xarray" : np .array ([0.05 , 0.1 , 0.2 , 0.3 ]),
277
+ "yarray" : np .array ([5 , 10 , 20 , 30 ]),
278
+ "xtype" : "q" ,
279
+ "wavelength" : 2 * np .pi ,
280
+ },
281
+ {"offset" : 2 },
282
+ {"xtype" : "q" , "yarray" : np .array ([12 , 22 , 32 ])},
283
+ ),
284
+ ( # C5.2: Reuse test case from C4, but include an offset, expect scaled y-array in C4 to shift up by 2
285
+ {
286
+ "xarray" : np .array ([10 , 25 , 30.1 , 40.2 , 61 , 120 , 140 ]),
287
+ "yarray" : np .array ([10 , 20 , 30 , 40 , 50 , 60 , 100 ]),
276
288
"xtype" : "tth" ,
277
289
"wavelength" : 2 * np .pi ,
278
290
},
279
291
{
280
- "q " : None ,
281
- "tth " : 60 ,
282
- "d " : None ,
283
- "offset " : 2.1 ,
292
+ "xarray " : np . array ([ 20 , 25.5 , 32 , 45 , 50 , 62 , 100 , 125 , 140 ]) ,
293
+ "yarray " : np . array ([ 1.1 , 2 , 3 , 3.5 , 4 , 5 , 10 , 12 , 13 ]) ,
294
+ "xtype " : "tth" ,
295
+ "wavelength " : 2 * np . pi ,
284
296
},
285
- {"xtype" : "tth" , "yarray" : np .array ([4.1 , 5.1 , 6.1 , 7.1 , 8.1 , 9.1 ])},
297
+ {"tth" : 60 , "offset" : 2 },
298
+ {"xtype" : "tth" , "yarray" : np .array ([3 , 4 , 5 , 6 , 7 , 8 , 12 ])},
286
299
),
287
300
],
288
301
)
289
302
def test_scale_to (org_do_args , target_do_args , scale_inputs , expected ):
290
303
original_do = DiffractionObject (** org_do_args )
291
304
target_do = DiffractionObject (** target_do_args )
292
- scaled_do = original_do .scale_to (
293
- target_do , q = scale_inputs ["q" ], tth = scale_inputs ["tth" ], d = scale_inputs ["d" ], offset = scale_inputs ["offset" ]
294
- )
305
+ scaled_do = original_do .scale_to (target_do , ** scale_inputs )
295
306
# Check the intensity data is the same as expected
296
307
assert np .allclose (scaled_do .on_xtype (expected ["xtype" ])[1 ], expected ["yarray" ])
297
308
@@ -300,27 +311,7 @@ def test_scale_to(org_do_args, target_do_args, scale_inputs, expected):
300
311
"org_do_args, target_do_args, scale_inputs" ,
301
312
[
302
313
# Test expected errors produced from scale_to() with invalid inputs
303
- ( # C1: none of q, tth, d, provided, expect ValueError
304
- {
305
- "xarray" : np .array ([0.1 , 0.2 , 0.3 ]),
306
- "yarray" : np .array ([1 , 2 , 3 ]),
307
- "xtype" : "q" ,
308
- "wavelength" : 2 * np .pi ,
309
- },
310
- {
311
- "xarray" : np .array ([0.05 , 0.1 , 0.2 , 0.3 ]),
312
- "yarray" : np .array ([5 , 10 , 20 , 30 ]),
313
- "xtype" : "q" ,
314
- "wavelength" : 2 * np .pi ,
315
- },
316
- {
317
- "q" : None ,
318
- "tth" : None ,
319
- "d" : None ,
320
- "offset" : 0 ,
321
- },
322
- ),
323
- ( # C2: tth and d both provided, expect ValueErrort
314
+ ( # C2: tth and d both provided, expect ValueError
324
315
{
325
316
"xarray" : np .array ([10 , 25 , 30.1 , 40.2 , 61 , 120 , 140 ]),
326
317
"yarray" : np .array ([10 , 20 , 30 , 40 , 50 , 60 , 100 ]),
@@ -334,10 +325,8 @@ def test_scale_to(org_do_args, target_do_args, scale_inputs, expected):
334
325
"wavelength" : 2 * np .pi ,
335
326
},
336
327
{
337
- "q" : None ,
338
328
"tth" : 60 ,
339
329
"d" : 10 ,
340
- "offset" : 0 ,
341
330
},
342
331
),
343
332
],
@@ -346,15 +335,11 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs):
346
335
original_do = DiffractionObject (** org_do_args )
347
336
target_do = DiffractionObject (** target_do_args )
348
337
with pytest .raises (
349
- ValueError , match = "You must specify exactly one of 'q', 'tth', or 'd'. Please rerun specifying only one."
338
+ ValueError ,
339
+ match = "You must specify none or exactly one of 'q', 'tth', or 'd'. "
340
+ "Please provide either none or one value." ,
350
341
):
351
- original_do .scale_to (
352
- target_do ,
353
- q = scale_inputs ["q" ],
354
- tth = scale_inputs ["tth" ],
355
- d = scale_inputs ["d" ],
356
- offset = scale_inputs ["offset" ],
357
- )
342
+ original_do .scale_to (target_do , ** scale_inputs )
358
343
359
344
360
345
@pytest .mark .parametrize (
0 commit comments