drizzle 1.15.0__cp39-cp39-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of drizzle might be problematic. Click here for more details.
- drizzle/__init__.py +11 -0
- drizzle/calc_pixmap.py +52 -0
- drizzle/cdrizzle.cp39-win32.pyd +0 -0
- drizzle/doblot.py +80 -0
- drizzle/dodrizzle.py +189 -0
- drizzle/drizzle.py +569 -0
- drizzle/tests/__init__.py +0 -0
- drizzle/tests/test_cdrizzle.py +24 -0
- drizzle/tests/test_drizzle.py +644 -0
- drizzle/tests/test_file_io.py +173 -0
- drizzle/tests/test_overlap_calc.py +262 -0
- drizzle/tests/test_pixmap.py +76 -0
- drizzle/util.py +256 -0
- drizzle-1.15.0.dist-info/LICENSE.rst +31 -0
- drizzle-1.15.0.dist-info/METADATA +364 -0
- drizzle-1.15.0.dist-info/RECORD +18 -0
- drizzle-1.15.0.dist-info/WHEEL +5 -0
- drizzle-1.15.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
import numpy as np
|
|
5
|
+
from astropy import wcs
|
|
6
|
+
from astropy.io import fits
|
|
7
|
+
|
|
8
|
+
from drizzle import drizzle
|
|
9
|
+
from drizzle import util
|
|
10
|
+
|
|
11
|
+
TEST_DIR = os.path.abspath(os.path.dirname(__file__))
|
|
12
|
+
DATA_DIR = os.path.join(TEST_DIR, 'data')
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def read_header(filename):
|
|
16
|
+
"""
|
|
17
|
+
Read the primary header from a fits file
|
|
18
|
+
"""
|
|
19
|
+
fileroot, extn = util.parse_filename(os.path.join(DATA_DIR, filename))
|
|
20
|
+
with fits.open(fileroot) as hdulist:
|
|
21
|
+
header = hdulist[0].header
|
|
22
|
+
return header
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def read_image(filename):
|
|
26
|
+
"""
|
|
27
|
+
Read the image from a fits file
|
|
28
|
+
"""
|
|
29
|
+
fileroot, extn = util.parse_filename(os.path.join(DATA_DIR, filename))
|
|
30
|
+
with fits.open(fileroot, memmap=False) as hdulist:
|
|
31
|
+
data = hdulist[1].data.copy()
|
|
32
|
+
return data
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def read_wcs(filename):
|
|
36
|
+
"""
|
|
37
|
+
Read the wcs of a fits file
|
|
38
|
+
"""
|
|
39
|
+
fileroot, extn = util.parse_filename(os.path.join(DATA_DIR, filename))
|
|
40
|
+
with fits.open(fileroot) as hdulist:
|
|
41
|
+
the_wcs = wcs.WCS(hdulist[1].header)
|
|
42
|
+
return the_wcs
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@pytest.fixture
|
|
46
|
+
def run_drizzle_reference_square_points(tmpdir):
|
|
47
|
+
"""Create an empty drizzle image"""
|
|
48
|
+
output_file = str(tmpdir.join('output_null_run.fits'))
|
|
49
|
+
output_template = os.path.join(DATA_DIR, 'reference_square_point.fits')
|
|
50
|
+
|
|
51
|
+
output_wcs = read_wcs(output_template)
|
|
52
|
+
driz = drizzle.Drizzle(outwcs=output_wcs, wt_scl="expsq", pixfrac=0.5,
|
|
53
|
+
kernel="turbo", fillval="NaN")
|
|
54
|
+
driz.write(output_file)
|
|
55
|
+
|
|
56
|
+
return output_file
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def test_null_run(run_drizzle_reference_square_points):
|
|
60
|
+
output_file = run_drizzle_reference_square_points
|
|
61
|
+
with fits.open(output_file) as hdulist:
|
|
62
|
+
|
|
63
|
+
assert hdulist.index_of("SCI") == 1
|
|
64
|
+
assert hdulist.index_of("WHT") == 2
|
|
65
|
+
assert hdulist.index_of("CTX") == 3
|
|
66
|
+
|
|
67
|
+
pheader = hdulist["PRIMARY"].header
|
|
68
|
+
|
|
69
|
+
assert pheader['DRIZOUDA'] == 'SCI'
|
|
70
|
+
assert pheader['DRIZOUWE'] == 'WHT'
|
|
71
|
+
assert pheader['DRIZOUCO'] == 'CTX'
|
|
72
|
+
assert pheader['DRIZWTSC'] == 'expsq'
|
|
73
|
+
assert pheader['DRIZKERN'] == 'turbo'
|
|
74
|
+
assert pheader['DRIZPIXF'] == 0.5
|
|
75
|
+
assert pheader['DRIZFVAL'] == 'NaN'
|
|
76
|
+
assert pheader['DRIZOUUN'] == 'cps'
|
|
77
|
+
assert pheader['EXPTIME'] == 0.0
|
|
78
|
+
assert pheader['DRIZEXPT'] == 1.0
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_file_init(run_drizzle_reference_square_points):
|
|
82
|
+
"""
|
|
83
|
+
Initialize drizzle object from a file
|
|
84
|
+
"""
|
|
85
|
+
input_file = run_drizzle_reference_square_points
|
|
86
|
+
|
|
87
|
+
driz = drizzle.Drizzle(infile=input_file)
|
|
88
|
+
|
|
89
|
+
assert driz.outexptime == 1.0
|
|
90
|
+
assert driz.wt_scl == 'expsq'
|
|
91
|
+
assert driz.kernel == 'turbo'
|
|
92
|
+
assert driz.pixfrac == 0.5
|
|
93
|
+
assert driz.fillval == 'NaN'
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@pytest.fixture
|
|
97
|
+
def add_header(tmpdir):
|
|
98
|
+
"""Add extra keywords read from the header"""
|
|
99
|
+
output_file = str(tmpdir.join('output_add_header.fits'))
|
|
100
|
+
|
|
101
|
+
input_file = os.path.join(DATA_DIR, 'j8bt06nyq_flt.fits')
|
|
102
|
+
output_template = os.path.join(DATA_DIR, 'reference_square_point.fits')
|
|
103
|
+
|
|
104
|
+
driz = drizzle.Drizzle(infile=output_template)
|
|
105
|
+
image = read_image(input_file)
|
|
106
|
+
inwcs = read_wcs(input_file)
|
|
107
|
+
driz.add_image(image, inwcs)
|
|
108
|
+
|
|
109
|
+
header = fits.header.Header()
|
|
110
|
+
header['ONEVAL'] = (1.0, 'test value')
|
|
111
|
+
header['TWOVAL'] = (2.0, 'test value')
|
|
112
|
+
|
|
113
|
+
driz.write(output_file, outheader=header)
|
|
114
|
+
|
|
115
|
+
return output_file
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_add_header(add_header):
|
|
119
|
+
output_file = add_header
|
|
120
|
+
header = read_header(output_file)
|
|
121
|
+
assert header['ONEVAL'] == 1.0
|
|
122
|
+
assert header['TWOVAL'] == 2.0
|
|
123
|
+
assert header['DRIZKERN'] == 'square'
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def test_add_file(add_header, tmpdir):
|
|
127
|
+
"""
|
|
128
|
+
Add an image read from a file
|
|
129
|
+
"""
|
|
130
|
+
test_file = add_header
|
|
131
|
+
output_file = str(tmpdir.join('output_add_file.fits'))
|
|
132
|
+
|
|
133
|
+
input_file = os.path.join(DATA_DIR, 'j8bt06nyq_flt.fits[1]')
|
|
134
|
+
output_template = os.path.join(DATA_DIR, 'reference_square_point.fits')
|
|
135
|
+
|
|
136
|
+
driz = drizzle.Drizzle(infile=output_template)
|
|
137
|
+
driz.add_fits_file(input_file)
|
|
138
|
+
driz.write(output_file)
|
|
139
|
+
|
|
140
|
+
output_image = read_image(output_file)
|
|
141
|
+
test_image = read_image(test_file)
|
|
142
|
+
diff_image = np.absolute(output_image - test_image)
|
|
143
|
+
|
|
144
|
+
assert np.amax(diff_image) == 0.0
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def test_blot_file(tmpdir):
|
|
148
|
+
"""
|
|
149
|
+
Blot an image read from a file
|
|
150
|
+
"""
|
|
151
|
+
output_file = str(tmpdir.join('output_blot_file.fits'))
|
|
152
|
+
test_file = str(tmpdir.join('output_blot_image.fits'))
|
|
153
|
+
|
|
154
|
+
input_file = os.path.join(DATA_DIR, 'j8bt06nyq_flt.fits[1]')
|
|
155
|
+
output_template = os.path.join(DATA_DIR, 'reference_blot_image.fits')
|
|
156
|
+
|
|
157
|
+
blotwcs = read_wcs(input_file)
|
|
158
|
+
|
|
159
|
+
driz = drizzle.Drizzle(infile=output_template)
|
|
160
|
+
driz.add_fits_file(input_file)
|
|
161
|
+
driz.blot_image(blotwcs)
|
|
162
|
+
driz.write(test_file)
|
|
163
|
+
|
|
164
|
+
driz = drizzle.Drizzle(infile=output_template)
|
|
165
|
+
driz.add_fits_file(input_file)
|
|
166
|
+
driz.blot_fits_file(input_file)
|
|
167
|
+
driz.write(output_file)
|
|
168
|
+
|
|
169
|
+
output_image = read_image(output_file)
|
|
170
|
+
test_image = read_image(test_file)
|
|
171
|
+
diff_image = np.absolute(output_image - test_image)
|
|
172
|
+
|
|
173
|
+
assert np.amax(diff_image) == 0.0
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from math import sqrt
|
|
3
|
+
from itertools import product
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from drizzle.cdrizzle import clip_polygon, invert_pixmap
|
|
8
|
+
|
|
9
|
+
SQ2 = 1.0 / sqrt(2.0)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _is_poly_eq(p1, p2, rtol=0, atol=1e-12):
|
|
13
|
+
if len(p1) != len(p2):
|
|
14
|
+
return False
|
|
15
|
+
|
|
16
|
+
p1 = p1[:]
|
|
17
|
+
for _ in p1:
|
|
18
|
+
p1.append(p1.pop(0))
|
|
19
|
+
if np.allclose(p1, p2, rtol=rtol, atol=atol):
|
|
20
|
+
return True
|
|
21
|
+
return False
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _coord_mapping(xin, yin):
|
|
25
|
+
crpix = (289, 348) # center of distortions
|
|
26
|
+
shift = (1000, 1000)
|
|
27
|
+
rmat = 2.0 * np.array([[0.78103169, 0.66712321], [-0.63246699, 0.74091539]])
|
|
28
|
+
x = xin - crpix[0]
|
|
29
|
+
y = yin - crpix[1]
|
|
30
|
+
|
|
31
|
+
# add non-linear distortions
|
|
32
|
+
x += 2.4e-6 * x**2 - 1.0e-7 * x * y + 3.1e-6 * y**2
|
|
33
|
+
y += 1.2e-6 * x**2 - 2.0e-7 * x * y + 1.1e-6 * y**2
|
|
34
|
+
|
|
35
|
+
x, y = np.dot(rmat, [x, y])
|
|
36
|
+
x += shift[0]
|
|
37
|
+
y += shift[1]
|
|
38
|
+
|
|
39
|
+
return x, y
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _roll_vertices(polygon, n=1):
|
|
43
|
+
n = n % len(polygon)
|
|
44
|
+
return polygon[n:] + polygon[:n]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_invert_pixmap():
|
|
48
|
+
yin, xin = np.indices((1000, 1200), dtype=float)
|
|
49
|
+
xin = xin.flatten()
|
|
50
|
+
yin = yin.flatten()
|
|
51
|
+
|
|
52
|
+
xout, yout = _coord_mapping(xin, yin)
|
|
53
|
+
xout = xout.reshape((1000, 1200))
|
|
54
|
+
yout = yout.reshape((1000, 1200))
|
|
55
|
+
pixmap = np.dstack([xout, yout])
|
|
56
|
+
|
|
57
|
+
test_coords = [
|
|
58
|
+
(300, 600),
|
|
59
|
+
(0, 0),
|
|
60
|
+
(1199, 999),
|
|
61
|
+
(0, 999),
|
|
62
|
+
(1199, 0),
|
|
63
|
+
(200, 0),
|
|
64
|
+
(0, 438),
|
|
65
|
+
(1199, 432),
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
for xr, yr in test_coords:
|
|
69
|
+
xout_t, yout_t = _coord_mapping(xr, yr)
|
|
70
|
+
xyin = invert_pixmap(pixmap, [xout_t, yout_t], [[-0.5, 1199.5], [-0.5, 999.5]])
|
|
71
|
+
assert np.allclose(xyin, [xr, yr], atol=0.05)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def test_invert_small_pixmap():
|
|
75
|
+
yin, xin = np.indices((2, 2), dtype=float)
|
|
76
|
+
pixmap = np.dstack([xin, yin])
|
|
77
|
+
|
|
78
|
+
test_coords = list(product(*(2 * [[-0.5, 1.5]])))
|
|
79
|
+
|
|
80
|
+
for xr, yr in test_coords:
|
|
81
|
+
xyin = invert_pixmap(pixmap, [xr, yr], [[-0.5, 1.5], [-0.5, 1.5]])
|
|
82
|
+
assert np.allclose(xyin, [xr, yr], atol=0.05)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_poly_intersection_with_self():
|
|
86
|
+
p = [(0, 0), (1, 0), (1, 1), (0, 1)]
|
|
87
|
+
|
|
88
|
+
for k in range(4):
|
|
89
|
+
q = _roll_vertices(p, k)
|
|
90
|
+
|
|
91
|
+
pq = clip_polygon(q, p)
|
|
92
|
+
assert _is_poly_eq(pq, q)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@pytest.mark.parametrize(
|
|
96
|
+
'shift', [(0.25, 0.1), (-0.25, -0.1), (-0.25, 0.1), (0.25, -0.1)],
|
|
97
|
+
)
|
|
98
|
+
def test_poly_intersection_shifted(shift):
|
|
99
|
+
p = [(0, 0), (1, 0), (1, 1), (0, 1)]
|
|
100
|
+
sx, sy = shift
|
|
101
|
+
pq_ref = sorted(
|
|
102
|
+
[
|
|
103
|
+
(max(0, sx), max(0, sy)),
|
|
104
|
+
(min(1, sx + 1), max(0, sy)),
|
|
105
|
+
(min(1, sx + 1), min(1, sy + 1)),
|
|
106
|
+
(max(0, sx), min(1, sy + 1)),
|
|
107
|
+
],
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
for k in range(4):
|
|
111
|
+
q = [(x + sx, y + sy) for x, y in p]
|
|
112
|
+
q = _roll_vertices(q, k)
|
|
113
|
+
pq = clip_polygon(q, p)
|
|
114
|
+
assert np.allclose(sorted(pq), pq_ref)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@pytest.mark.parametrize(
|
|
118
|
+
'shift', [(0, 70), (70, 0), (0, -70), (-70, 0)],
|
|
119
|
+
)
|
|
120
|
+
def test_poly_intersection_shifted_large(shift):
|
|
121
|
+
p = [(-0.5, -0.5), (99.5, -0.5), (99.5, 99.5), (-0.5, 99.5)]
|
|
122
|
+
sx, sy = shift
|
|
123
|
+
pq_ref = sorted(
|
|
124
|
+
[
|
|
125
|
+
(max(-0.5, -0.5 + sx), max(-0.5, -0.5 + sy)),
|
|
126
|
+
(min(99.5, 99.5 + sx), max(-0.5, -0.5 + sy)),
|
|
127
|
+
(min(99.5, 99.5 + sx), min(99.5, 99.5 + sy)),
|
|
128
|
+
(max(-0.5, -0.5 + sx), min(99.5, 99.5 + sy)),
|
|
129
|
+
],
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
for k in range(4):
|
|
133
|
+
q = [(x + sx, y + sy) for x, y in p]
|
|
134
|
+
q = _roll_vertices(q, k)
|
|
135
|
+
pq = clip_polygon(p, q)
|
|
136
|
+
assert len(pq) == 4
|
|
137
|
+
assert np.allclose(sorted(pq), pq_ref)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def test_poly_intersection_rotated45():
|
|
141
|
+
p = [(0, 0), (1, 0), (1, 1), (0, 1)]
|
|
142
|
+
q = [(0, 0), (SQ2, -SQ2), (2.0 * SQ2, 0), (SQ2, SQ2)]
|
|
143
|
+
pq_ref = [(0, 0), (SQ2, SQ2), (1, 0), (1, SQ2 / (1.0 + SQ2))]
|
|
144
|
+
|
|
145
|
+
for k in range(4):
|
|
146
|
+
q = _roll_vertices(q, k)
|
|
147
|
+
pq = clip_polygon(p, q)
|
|
148
|
+
assert np.allclose(sorted(pq), pq_ref)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@pytest.mark.parametrize(
|
|
152
|
+
'axis', [0, 1],
|
|
153
|
+
)
|
|
154
|
+
def test_poly_intersection_flipped_axis(axis):
|
|
155
|
+
p = [(0, 0), (1, 0), (1, 1), (0, 1)]
|
|
156
|
+
# (flipped wrt X-axis or Y-axis). Also change direction:
|
|
157
|
+
if axis == 0:
|
|
158
|
+
q = [(i, -j) for i, j in p][::-1]
|
|
159
|
+
else:
|
|
160
|
+
q = [(-i, j) for i, j in p][::-1]
|
|
161
|
+
|
|
162
|
+
for k in range(4):
|
|
163
|
+
q = _roll_vertices(q, k)
|
|
164
|
+
pq = clip_polygon(p, q)
|
|
165
|
+
assert len(pq) == 0
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def test_poly_intersection_reflect_origin():
|
|
169
|
+
p = [(0, 0), (1, 0), (1, 1), (0, 1)]
|
|
170
|
+
# reflect wrt origin:
|
|
171
|
+
q = [(-i, -j) for i, j in p]
|
|
172
|
+
|
|
173
|
+
for k in range(4):
|
|
174
|
+
q = _roll_vertices(q, k)
|
|
175
|
+
pq = clip_polygon(p, q)
|
|
176
|
+
assert not pq
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
@pytest.mark.parametrize(
|
|
180
|
+
'q,small',
|
|
181
|
+
[
|
|
182
|
+
([(0.1, 0.1), (0.9, 0.1), (0.9, 0.9), (0.1, 0.9)], True),
|
|
183
|
+
([(0.0, 0.0), (1.0, 0.0), (1.0, 0.4), (0.0, 0.4)], True),
|
|
184
|
+
([(-0.1, -0.1), (1.1, -0.1), (1.1, 1.1), (-0.1, 1.1)], False),
|
|
185
|
+
],
|
|
186
|
+
)
|
|
187
|
+
def test_poly_includes_the_other(q, small):
|
|
188
|
+
wnd = [(0, 0), (1, 0), (1, 1), (0, 1)]
|
|
189
|
+
|
|
190
|
+
for k in range(4):
|
|
191
|
+
q = _roll_vertices(q, k)
|
|
192
|
+
qp = clip_polygon(q, wnd)
|
|
193
|
+
|
|
194
|
+
assert _is_poly_eq(qp, q if small else wnd)
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
@pytest.mark.parametrize(
|
|
198
|
+
'q',
|
|
199
|
+
[
|
|
200
|
+
[(0, 0), (1, 0), (0.5, 0.6)],
|
|
201
|
+
[(0.1, 0), (0.9, 0), (0.5, 0.6)],
|
|
202
|
+
],
|
|
203
|
+
)
|
|
204
|
+
def test_poly_triangle_common_side(q):
|
|
205
|
+
p = [(0, 0), (1, 0), (1, 1), (0, 1)]
|
|
206
|
+
sq = sorted(q)
|
|
207
|
+
|
|
208
|
+
for k in range(3):
|
|
209
|
+
q = _roll_vertices(q, k)
|
|
210
|
+
pq = clip_polygon(p, q)
|
|
211
|
+
assert np.allclose(sq, sorted(pq))
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def test_poly_triangle_common_side_lg():
|
|
215
|
+
p = [(0, 0), (1, 0), (1, 1), (0, 1)]
|
|
216
|
+
q = [(-0.1, 0), (1.1, 0), (0.5, 0.6)]
|
|
217
|
+
ref_pq = [(0, 0), (0, 0.1), (0.5, 0.6), (1, 0), (1, 0.1)]
|
|
218
|
+
|
|
219
|
+
for k in range(3):
|
|
220
|
+
q = _roll_vertices(q, k)
|
|
221
|
+
pq = clip_polygon(p, q)
|
|
222
|
+
assert np.allclose(ref_pq, sorted(pq))
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
def test_poly_intersection_with_self_extra_vertices():
|
|
226
|
+
p = [(0, 0), (1, 0), (1, 1), (0, 1)]
|
|
227
|
+
p_ref = [(0, 0), (0, 1), (1, 0), (1, 1)]
|
|
228
|
+
# Q is same as P with extra vertices places along P's edges
|
|
229
|
+
q = [(0, 0), (0.5, 0), (1, 0), (1, 0.4), (1, 1), (0.7, 1), (0, 1), (0, 0.2)]
|
|
230
|
+
|
|
231
|
+
for k in range(4):
|
|
232
|
+
q = _roll_vertices(q, k)
|
|
233
|
+
|
|
234
|
+
pq = clip_polygon(p, q)
|
|
235
|
+
assert sorted(pq) == p_ref
|
|
236
|
+
|
|
237
|
+
pq = clip_polygon(q, p)
|
|
238
|
+
assert sorted(pq) == p_ref
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def test_intersection_case01():
|
|
242
|
+
# a real case of failure of the code from PR #104
|
|
243
|
+
p = [
|
|
244
|
+
(4517.377385, 8863.424319),
|
|
245
|
+
(5986.279535, 12966.888023),
|
|
246
|
+
(1917.908619, 14391.538506),
|
|
247
|
+
(453.893145, 10397.019260),
|
|
248
|
+
]
|
|
249
|
+
|
|
250
|
+
wnd = [(-0.5, -0.5), (5224.5, -0.5), (5224.5, 15999.5), (-0.5, 15999.5)]
|
|
251
|
+
|
|
252
|
+
cp_ref = [
|
|
253
|
+
(4517.377385, 8863.424319),
|
|
254
|
+
(5224.5, 10838.812526396974),
|
|
255
|
+
(5224.5, 13233.64580022457),
|
|
256
|
+
(1917.908619, 14391.538506),
|
|
257
|
+
(453.893145, 10397.01926),
|
|
258
|
+
]
|
|
259
|
+
|
|
260
|
+
cp = clip_polygon(p, wnd)
|
|
261
|
+
|
|
262
|
+
assert _is_poly_eq(cp, cp_ref)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from numpy.testing import assert_equal, assert_almost_equal
|
|
5
|
+
from astropy import wcs
|
|
6
|
+
from astropy.io import fits
|
|
7
|
+
|
|
8
|
+
from drizzle import calc_pixmap
|
|
9
|
+
|
|
10
|
+
TEST_DIR = os.path.abspath(os.path.dirname(__file__))
|
|
11
|
+
DATA_DIR = os.path.join(TEST_DIR, 'data')
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_map_rectangular():
|
|
15
|
+
"""
|
|
16
|
+
Make sure the initial index array has correct values
|
|
17
|
+
"""
|
|
18
|
+
naxis1 = 1000
|
|
19
|
+
naxis2 = 10
|
|
20
|
+
|
|
21
|
+
pixmap = np.indices((naxis1, naxis2), dtype='float32')
|
|
22
|
+
pixmap = pixmap.transpose()
|
|
23
|
+
|
|
24
|
+
assert_equal(pixmap[5,500], (500,5))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def test_map_to_self():
|
|
28
|
+
"""
|
|
29
|
+
Map a pixel array to itself. Should return the same array.
|
|
30
|
+
"""
|
|
31
|
+
input_file = os.path.join(DATA_DIR, 'input1.fits')
|
|
32
|
+
input_hdu = fits.open(input_file)
|
|
33
|
+
|
|
34
|
+
input_wcs = wcs.WCS(input_hdu[1].header)
|
|
35
|
+
naxis1, naxis2 = input_wcs.pixel_shape
|
|
36
|
+
input_hdu.close()
|
|
37
|
+
|
|
38
|
+
ok_pixmap = np.indices((naxis1, naxis2), dtype='float32')
|
|
39
|
+
ok_pixmap = ok_pixmap.transpose()
|
|
40
|
+
|
|
41
|
+
pixmap = calc_pixmap.calc_pixmap(input_wcs, input_wcs)
|
|
42
|
+
|
|
43
|
+
# Got x-y transpose right
|
|
44
|
+
assert_equal(pixmap.shape, ok_pixmap.shape)
|
|
45
|
+
# Mapping an array to itself
|
|
46
|
+
assert_almost_equal(pixmap, ok_pixmap, decimal=5)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_translated_map():
|
|
50
|
+
"""
|
|
51
|
+
Map a pixel array to at translated array.
|
|
52
|
+
"""
|
|
53
|
+
first_file = os.path.join(DATA_DIR, 'input1.fits')
|
|
54
|
+
first_hdu = fits.open(first_file)
|
|
55
|
+
first_header = first_hdu[1].header
|
|
56
|
+
|
|
57
|
+
first_wcs = wcs.WCS(first_header)
|
|
58
|
+
naxis1, naxis2 = first_wcs.pixel_shape
|
|
59
|
+
first_hdu.close()
|
|
60
|
+
|
|
61
|
+
second_file = os.path.join(DATA_DIR, 'input3.fits')
|
|
62
|
+
second_hdu = fits.open(second_file)
|
|
63
|
+
second_header = second_hdu[1].header
|
|
64
|
+
|
|
65
|
+
second_wcs = wcs.WCS(second_header)
|
|
66
|
+
second_hdu.close()
|
|
67
|
+
|
|
68
|
+
ok_pixmap = np.indices((naxis1, naxis2), dtype='float32') - 2.0
|
|
69
|
+
ok_pixmap = ok_pixmap.transpose()
|
|
70
|
+
|
|
71
|
+
pixmap = calc_pixmap.calc_pixmap(first_wcs, second_wcs)
|
|
72
|
+
|
|
73
|
+
# Got x-y transpose right
|
|
74
|
+
assert_equal(pixmap.shape, ok_pixmap.shape)
|
|
75
|
+
# Mapping an array to a translated array
|
|
76
|
+
assert_almost_equal(pixmap, ok_pixmap, decimal=5)
|