@@ -191,7 +191,23 @@ def test_init_invalid_xtype():
191191 "org_do_args, target_do_args, scale_inputs, expected" ,
192192 [
193193 # 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 x-arrays
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
195211 # x-value has exact matches at tth=60 (y=60) and tth=60 (y=6),
196212 # for original and target diffraction objects,
197213 # expect original y-array to multiply by 6/60=1/10
@@ -207,15 +223,10 @@ def test_init_invalid_xtype():
207223 "xtype" : "tth" ,
208224 "wavelength" : 2 * np .pi ,
209225 },
210- {
211- "q" : None ,
212- "tth" : 60 ,
213- "d" : None ,
214- "offset" : 0 ,
215- },
226+ {"tth" : 60 },
216227 {"xtype" : "tth" , "yarray" : np .array ([1 , 2 , 2.5 , 3 , 6 , 10 ])},
217228 ),
218- ( # C2 : Different x-arrays with same length,
229+ ( # C3 : Different x-arrays with same length,
219230 # x-value has closest match at q=0.12 (y=10) and q=0.14 (y=1)
220231 # for original and target diffraction objects,
221232 # expect original y-array to multiply by 1/10
@@ -231,15 +242,10 @@ def test_init_invalid_xtype():
231242 "xtype" : "q" ,
232243 "wavelength" : 2 * np .pi ,
233244 },
234- {
235- "q" : 0.1 ,
236- "tth" : None ,
237- "d" : None ,
238- "offset" : 0 ,
239- },
245+ {"q" : 0.1 },
240246 {"xtype" : "q" , "yarray" : np .array ([1 , 2 , 4 , 6 ])},
241247 ),
242- ( # C3 : Different x-array lengths
248+ ( # C4 : Different x-array lengths
243249 # x-value has closest matches at tth=61 (y=50) and tth=62 (y=5),
244250 # for original and target diffraction objects,
245251 # expect original y-array to multiply by 5/50=1/10
@@ -255,15 +261,10 @@ def test_init_invalid_xtype():
255261 "xtype" : "tth" ,
256262 "wavelength" : 2 * np .pi ,
257263 },
258- {
259- "q" : None ,
260- "tth" : 60 ,
261- "d" : None ,
262- "offset" : 0 ,
263- },
264+ {"tth" : 60 },
264265 {"xtype" : "tth" , "yarray" : np .array ([1 , 2 , 3 , 4 , 5 , 6 , 10 ])},
265266 ),
266- ( # C4 : Same x-array and y-array with 2.1 offset, expect y-array to shift up by 2.1
267+ ( # C5 : Same x-array and y-array with 2.1 offset, expect y-array to shift up by 2.1
267268 {
268269 "xarray" : np .array ([10 , 15 , 25 , 30 , 60 , 140 ]),
269270 "yarray" : np .array ([2 , 3 , 4 , 5 , 6 , 7 ]),
@@ -276,43 +277,15 @@ def test_init_invalid_xtype():
276277 "xtype" : "tth" ,
277278 "wavelength" : 2 * np .pi ,
278279 },
279- {
280- "q" : None ,
281- "tth" : 60 ,
282- "d" : None ,
283- "offset" : 2.1 ,
284- },
280+ {"tth" : 60 , "offset" : 2.1 },
285281 {"xtype" : "tth" , "yarray" : np .array ([4.1 , 5.1 , 6.1 , 7.1 , 8.1 , 9.1 ])},
286282 ),
287- ( # C5: none of q, tth, d, provided, expect to scale on the maximal x-arrays
288- {
289- "xarray" : np .array ([0.1 , 0.2 , 0.3 ]),
290- "yarray" : np .array ([1 , 2 , 3 ]),
291- "xtype" : "q" ,
292- "wavelength" : 2 * np .pi ,
293- },
294- {
295- "xarray" : np .array ([0.05 , 0.1 , 0.2 , 0.3 ]),
296- "yarray" : np .array ([5 , 10 , 20 , 30 ]),
297- "xtype" : "q" ,
298- "wavelength" : 2 * np .pi ,
299- },
300- {
301- "q" : None ,
302- "tth" : None ,
303- "d" : None ,
304- "offset" : 0 ,
305- },
306- {"xtype" : "q" , "yarray" : np .array ([10 , 20 , 30 ])},
307- ),
308283 ],
309284)
310285def test_scale_to (org_do_args , target_do_args , scale_inputs , expected ):
311286 original_do = DiffractionObject (** org_do_args )
312287 target_do = DiffractionObject (** target_do_args )
313- scaled_do = original_do .scale_to (
314- target_do , q = scale_inputs ["q" ], tth = scale_inputs ["tth" ], d = scale_inputs ["d" ], offset = scale_inputs ["offset" ]
315- )
288+ scaled_do = original_do .scale_to (target_do , ** scale_inputs )
316289 # Check the intensity data is the same as expected
317290 assert np .allclose (scaled_do .on_xtype (expected ["xtype" ])[1 ], expected ["yarray" ])
318291
@@ -335,10 +308,8 @@ def test_scale_to(org_do_args, target_do_args, scale_inputs, expected):
335308 "wavelength" : 2 * np .pi ,
336309 },
337310 {
338- "q" : None ,
339311 "tth" : 60 ,
340312 "d" : 10 ,
341- "offset" : 0 ,
342313 },
343314 ),
344315 ],
@@ -351,13 +322,7 @@ def test_scale_to_bad(org_do_args, target_do_args, scale_inputs):
351322 match = "You must specify none or exactly one of 'q', 'tth', or 'd'. "
352323 "Please provide either none or one value." ,
353324 ):
354- original_do .scale_to (
355- target_do ,
356- q = scale_inputs ["q" ],
357- tth = scale_inputs ["tth" ],
358- d = scale_inputs ["d" ],
359- offset = scale_inputs ["offset" ],
360- )
325+ original_do .scale_to (target_do , ** scale_inputs )
361326
362327
363328@pytest .mark .parametrize (
0 commit comments