11# Licensed under a 3-clause BSD style license - see LICENSE.rst
22
3- import array_api_compat
43import pytest
54from astropy import units as u
65from astropy .utils .exceptions import AstropyDeprecationWarning
98from numpy .random import default_rng
109from numpy .testing import assert_allclose
1110
11+ # Set up the array library to be used in tests
12+ from ccdproc .conftest import testing_array_library as xp
1213from ccdproc .core import (
1314 background_deviation_box ,
1415 background_deviation_filter ,
2627def add_cosmicrays (data , scale , threshold , ncrays = NCRAYS ):
2728 size = data .shape [0 ]
2829 rng = default_rng (99 )
29- xp = array_api_compat .array_namespace (data .data )
3030 crrays = xp .asarray (rng .integers (0 , size , size = (ncrays , 2 )))
3131 # use (threshold + 15) below to make sure cosmic ray is well above the
3232 # threshold no matter what the random number generator returns
@@ -58,7 +58,6 @@ def test_cosmicray_lacosmic():
5858
5959def test_cosmicray_lacosmic_ccddata ():
6060 ccd_data = ccd_data_func (data_scale = DATA_SCALE )
61- xp = array_api_compat .array_namespace (ccd_data .data )
6261 threshold = 5
6362 add_cosmicrays (ccd_data , DATA_SCALE , threshold , ncrays = NCRAYS )
6463 noise = DATA_SCALE * xp .ones_like (ccd_data .data )
@@ -75,7 +74,6 @@ def test_cosmicray_lacosmic_ccddata():
7574
7675def test_cosmicray_lacosmic_check_data ():
7776 ccd_data = ccd_data_func (data_scale = DATA_SCALE )
78- xp = array_api_compat .array_namespace (ccd_data .data )
7977 with pytest .raises (TypeError ):
8078 noise = DATA_SCALE * xp .ones_like (ccd_data .data )
8179 cosmicray_lacosmic (10 , noise )
@@ -90,7 +88,6 @@ def test_cosmicray_gain_correct(array_input, gain_correct_data):
9088 # data and returns that gain corrected data. That is not the
9189 # intent...
9290 ccd_data = ccd_data_func (data_scale = DATA_SCALE )
93- xp = array_api_compat .array_namespace (ccd_data .data )
9491 threshold = 5
9592 add_cosmicrays (ccd_data , DATA_SCALE , threshold , ncrays = NCRAYS )
9693 noise = DATA_SCALE * xp .ones_like (ccd_data .data )
@@ -123,7 +120,6 @@ def test_cosmicray_gain_correct(array_input, gain_correct_data):
123120
124121def test_cosmicray_lacosmic_accepts_quantity_gain ():
125122 ccd_data = ccd_data_func (data_scale = DATA_SCALE )
126- xp = array_api_compat .array_namespace (ccd_data .data )
127123 threshold = 5
128124 add_cosmicrays (ccd_data , DATA_SCALE , threshold , ncrays = NCRAYS )
129125 noise = DATA_SCALE * xp .ones_like (ccd_data .data )
@@ -138,7 +134,6 @@ def test_cosmicray_lacosmic_accepts_quantity_gain():
138134
139135def test_cosmicray_lacosmic_accepts_quantity_readnoise ():
140136 ccd_data = ccd_data_func (data_scale = DATA_SCALE )
141- xp = array_api_compat .array_namespace (ccd_data .data )
142137 threshold = 5
143138 add_cosmicrays (ccd_data , DATA_SCALE , threshold , ncrays = NCRAYS )
144139 noise = DATA_SCALE * xp .ones_like (ccd_data .data )
@@ -156,7 +151,6 @@ def test_cosmicray_lacosmic_detects_inconsistent_units():
156151 # of adu, a readnoise in electrons and a gain in adu / electron.
157152 # That is not internally inconsistent.
158153 ccd_data = ccd_data_func (data_scale = DATA_SCALE )
159- xp = array_api_compat .array_namespace (ccd_data .data )
160154 ccd_data .unit = "adu"
161155 threshold = 5
162156 add_cosmicrays (ccd_data , DATA_SCALE , threshold , ncrays = NCRAYS )
@@ -176,7 +170,6 @@ def test_cosmicray_lacosmic_detects_inconsistent_units():
176170def test_cosmicray_lacosmic_warns_on_ccd_in_electrons ():
177171 # Check that an input ccd in electrons raises a warning.
178172 ccd_data = ccd_data_func (data_scale = DATA_SCALE )
179- xp = array_api_compat .array_namespace (ccd_data .data )
180173 # The unit below is important for the test; this unit on
181174 # input is supposed to raise an error.
182175 ccd_data .unit = u .electron
@@ -206,7 +199,6 @@ def test_cosmicray_lacosmic_invar_inbkg(new_args):
206199 # that calling with the new keyword arguments to astroscrappy
207200 # 1.1.0 raises no error.
208201 ccd_data = ccd_data_func (data_scale = DATA_SCALE )
209- xp = array_api_compat .array_namespace (ccd_data .data )
210202 threshold = 5
211203 add_cosmicrays (ccd_data , DATA_SCALE , threshold , ncrays = NCRAYS )
212204 noise = DATA_SCALE * xp .ones_like (ccd_data .data )
@@ -304,28 +296,28 @@ def test_cosmicray_median_background_deviation():
304296
305297def test_background_deviation_box ():
306298 scale = 5.3
307- cd = default_rng (seed = 123 ).normal (loc = 0 , size = (100 , 100 ), scale = scale )
299+ cd = xp . asarray ( default_rng (seed = 123 ).normal (loc = 0 , size = (100 , 100 ), scale = scale ) )
308300 bd = background_deviation_box (cd , 25 )
309301 assert abs (bd .mean () - scale ) < 0.10
310302
311303
312304def test_background_deviation_box_fail ():
313305 scale = 5.3
314- cd = default_rng (seed = 123 ).normal (loc = 0 , size = (100 , 100 ), scale = scale )
306+ cd = xp . asarray ( default_rng (seed = 123 ).normal (loc = 0 , size = (100 , 100 ), scale = scale ) )
315307 with pytest .raises (ValueError ):
316308 background_deviation_box (cd , 0.5 )
317309
318310
319311def test_background_deviation_filter ():
320312 scale = 5.3
321- cd = default_rng (seed = 123 ).normal (loc = 0 , size = (100 , 100 ), scale = scale )
313+ cd = xp . asarray ( default_rng (seed = 123 ).normal (loc = 0 , size = (100 , 100 ), scale = scale ) )
322314 bd = background_deviation_filter (cd , 25 )
323315 assert abs (bd .mean () - scale ) < 0.10
324316
325317
326318def test_background_deviation_filter_fail ():
327319 scale = 5.3
328- cd = default_rng (seed = 123 ).normal (loc = 0 , size = (100 , 100 ), scale = scale )
320+ cd = xp . asarray ( default_rng (seed = 123 ).normal (loc = 0 , size = (100 , 100 ), scale = scale ) )
329321 with pytest .raises (ValueError ):
330322 background_deviation_filter (cd , 0.5 )
331323
@@ -356,7 +348,6 @@ def test_cosmicray_lacosmic_pssl_does_not_fail():
356348 # to make sure that passing in pssl does not lead to an error
357349 # since the new interface does not include pssl.
358350 ccd_data = ccd_data_func (data_scale = DATA_SCALE )
359- xp = array_api_compat .array_namespace (ccd_data .data )
360351 threshold = 5
361352 add_cosmicrays (ccd_data , DATA_SCALE , threshold , ncrays = NCRAYS )
362353 noise = DATA_SCALE * xp .ones_like (ccd_data .data )
0 commit comments