1- import pytest
21import numpy as np
3-
4- from astropy .wcs import WCS
2+ import pytest
53from astropy .io import fits
4+ from astropy .utils .data import get_pkg_data_filename
5+ from astropy .wcs import WCS
66
77from reproject import reproject_interp
88from reproject .hips import reproject_to_hips
99from reproject .hips ._dask_array import hips_as_dask_and_wcs
10- from astropy . utils . data import get_pkg_data_filename
10+
1111
1212class TestHIPSDaskArray :
1313
1414 def setup_method (self ):
15-
16- hdu = fits . open ( get_pkg_data_filename ( 'allsky/allsky_rosat.fits' ))[ 0 ]
17- self . original_header = hdu . header
15+ # We use an all-sky WCS image as input since this will test all parts
16+ # of the HiPS projection (some issues happen around boundaries for instance)
17+ hdu = fits . open ( get_pkg_data_filename ( "allsky/allsky_rosat.fits" ))[ 0 ]
1818 self .original_wcs = WCS (hdu .header )
1919 self .original_array = hdu .data .size + np .arange (hdu .data .size ).reshape (hdu .data .shape )
2020
21- @pytest .mark .parametrize (' frame' , (' galactic' , ' equatorial' ))
22- @pytest .mark .parametrize (' level' , (0 , 1 ))
21+ @pytest .mark .parametrize (" frame" , (" galactic" , " equatorial" ))
22+ @pytest .mark .parametrize (" level" , (0 , 1 ))
2323 def test_roundtrip (self , tmp_path , frame , level ):
2424
25- self . output_directory = tmp_path / ' roundtrip'
25+ output_directory = tmp_path / " roundtrip"
2626
27+ # Note that we always use level=1 to generate, but use a variable level
28+ # to construct the dask array - this is deliberate and ensure that the
29+ # dask array has a proper separation of maximum and current level.
2730 reproject_to_hips (
2831 (self .original_array , self .original_wcs ),
2932 coord_system_out = frame ,
30- level = level ,
33+ level = 1 ,
3134 reproject_function = reproject_interp ,
32- output_directory = self .output_directory ,
35+ output_directory = output_directory ,
36+ tile_size = 256 ,
3337 )
3438
35- dask_array , wcs = hips_as_dask_and_wcs (self .output_directory , level = level )
39+ # Represent the HiPS as a dask array
40+ dask_array , wcs = hips_as_dask_and_wcs (output_directory , level = level )
3641
37- final_array , footprint = reproject_interp ((dask_array , wcs ), self .original_wcs , shape_out = self .original_array .shape )
42+ # Reproject back to the original WCS
43+ final_array , footprint = reproject_interp (
44+ (dask_array , wcs ),
45+ self .original_wcs ,
46+ shape_out = self .original_array .shape ,
47+ )
3848
3949 # FIXME: Due to boundary effects and the fact there are NaN values in
4050 # the whole-map dask array, there are a few NaN pixels in the image in
@@ -47,10 +57,33 @@ def test_roundtrip(self, tmp_path, frame, level):
4757 # values.
4858
4959 valid = ~ np .isnan (final_array )
50-
5160 assert np .sum (valid ) > 90400
52-
5361 np .testing .assert_allclose (final_array [valid ], self .original_array [valid ], rtol = 0.01 )
5462
63+ def test_level_validation (self , tmp_path ):
64+
65+ output_directory = tmp_path / "levels"
66+
67+ reproject_to_hips (
68+ (self .original_array , self .original_wcs ),
69+ coord_system_out = "equatorial" ,
70+ level = 1 ,
71+ reproject_function = reproject_interp ,
72+ output_directory = output_directory ,
73+ tile_size = 32 ,
74+ )
75+
76+ dask_array , wcs = hips_as_dask_and_wcs (output_directory , level = 0 )
77+ assert dask_array .shape == (160 , 160 )
78+
79+ dask_array , wcs = hips_as_dask_and_wcs (output_directory , level = 1 )
80+ assert dask_array .shape == (320 , 320 )
81+
82+ dask_array , wcs = hips_as_dask_and_wcs (output_directory )
83+ assert dask_array .shape == (320 , 320 )
84+
85+ with pytest .raises (Exception , match = r"does not contain level 2 data" ):
86+ hips_as_dask_and_wcs (output_directory , level = 2 )
5587
56- # VALIDATE LEVEL
88+ with pytest .raises (Exception , match = r"should be positive" ):
89+ hips_as_dask_and_wcs (output_directory , level = - 1 )
0 commit comments