Skip to content

Commit a6fd81a

Browse files
authored
Fix dependencies. Simplify tests. Reduce data file size. Add a new unit test. (#166)
Remove unused data files. Simplify tests. Add new tests
1 parent ca5da2a commit a6fd81a

19 files changed

+234
-50006
lines changed

drizzle/tests/data/input1.fits

Lines changed: 0 additions & 24734 deletions
This file was deleted.

drizzle/tests/data/input3.fits

Lines changed: 0 additions & 24734 deletions
This file was deleted.

drizzle/tests/data/j8bt06nyq_sip_flt.fits

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-15.1 MB
Binary file not shown.
0 Bytes
Binary file not shown.

drizzle/tests/helpers.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import os
2+
3+
import numpy as np
4+
5+
from astropy import wcs
6+
from astropy.io import fits
7+
8+
__all__ = ["wcs_from_file"]
9+
10+
TEST_DIR = os.path.abspath(os.path.dirname(__file__))
11+
DATA_DIR = os.path.join(TEST_DIR, 'data')
12+
13+
14+
def wcs_from_file(filename, ext=None, return_data=False, crpix_shift=None):
15+
"""
16+
Read the WCS from a ".fits" file.
17+
"""
18+
full_file_name = os.path.join(DATA_DIR, filename)
19+
path = os.path.join(DATA_DIR, full_file_name)
20+
with fits.open(path) as hdu:
21+
if ext is None:
22+
for k, u in enumerate(hdu):
23+
if "CTYPE1" in u.header:
24+
ext = k
25+
break
26+
27+
hdr = hdu[ext].header
28+
naxis1 = hdr.get("WCSNAX1", hdr.get("NAXIS1"))
29+
naxis2 = hdr.get("WCSNAX2", hdr.get("NAXIS2"))
30+
if naxis1 is not None and naxis2 is not None:
31+
shape = (naxis2, naxis1)
32+
if hdu[ext].data is None:
33+
hdu[ext].data = np.zeros(shape, dtype=np.float32)
34+
else:
35+
shape = None
36+
37+
if crpix_shift is not None and "CRPIX1" in hdr:
38+
hdr["CRPIX1"] += crpix_shift[0]
39+
hdr["CRPIX2"] += crpix_shift[1]
40+
41+
result = wcs.WCS(hdr, hdu)
42+
result.array_shape = shape
43+
44+
if return_data:
45+
result = (result, )
46+
if not isinstance(return_data, (list, tuple)):
47+
return_data = [ext]
48+
for ext in return_data:
49+
data = (hdu[ext].data, )
50+
result = result + data
51+
52+
return result

0 commit comments

Comments
 (0)