drizzle 1.15.3__cp311-cp311-win_amd64.whl → 2.0.1__cp311-cp311-win_amd64.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 +2 -1
- drizzle/cdrizzle.cp311-win_amd64.pyd +0 -0
- drizzle/resample.py +702 -0
- drizzle/tests/helpers.py +190 -0
- drizzle/tests/test_cdrizzle.py +14 -9
- drizzle/tests/test_overlap_calc.py +2 -2
- drizzle/tests/test_resample.py +1100 -0
- drizzle/tests/test_utils.py +238 -0
- drizzle/util.py +17 -239
- drizzle/utils.py +285 -0
- {drizzle-1.15.3.dist-info → drizzle-2.0.1.dist-info}/METADATA +24 -185
- drizzle-2.0.1.dist-info/RECORD +16 -0
- {drizzle-1.15.3.dist-info → drizzle-2.0.1.dist-info}/WHEEL +1 -1
- drizzle/calc_pixmap.py +0 -52
- drizzle/doblot.py +0 -80
- drizzle/dodrizzle.py +0 -189
- drizzle/drizzle.py +0 -569
- drizzle/tests/test_drizzle.py +0 -834
- drizzle/tests/test_file_io.py +0 -173
- drizzle/tests/test_pixmap.py +0 -76
- drizzle-1.15.3.dist-info/RECORD +0 -18
- {drizzle-1.15.3.dist-info → drizzle-2.0.1.dist-info}/LICENSE.rst +0 -0
- {drizzle-1.15.3.dist-info → drizzle-2.0.1.dist-info}/top_level.txt +0 -0
drizzle/utils.py
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import math
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
__all__ = ["calc_pixmap", "decode_context", "estimate_pixel_scale_ratio"]
|
|
6
|
+
|
|
7
|
+
_DEG2RAD = math.pi / 180.0
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def calc_pixmap(wcs_from, wcs_to, shape=None, disable_bbox="to"):
|
|
11
|
+
"""
|
|
12
|
+
Calculate a discretized on a grid mapping between the pixels of two images
|
|
13
|
+
using provided WCS of the original ("from") image and the destination ("to")
|
|
14
|
+
image.
|
|
15
|
+
|
|
16
|
+
.. note::
|
|
17
|
+
This function assumes that output frames of ``wcs_from`` and ``wcs_to``
|
|
18
|
+
WCS have the same units.
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
wcs_from : wcs
|
|
23
|
+
A WCS object representing the coordinate system you are
|
|
24
|
+
converting from. This object's ``array_shape`` (or ``pixel_shape``)
|
|
25
|
+
property will be used to define the shape of the pixel map array.
|
|
26
|
+
If ``shape`` parameter is provided, it will take precedence
|
|
27
|
+
over this object's ``array_shape`` value.
|
|
28
|
+
|
|
29
|
+
wcs_to : wcs
|
|
30
|
+
A WCS object representing the coordinate system you are
|
|
31
|
+
converting to.
|
|
32
|
+
|
|
33
|
+
shape : tuple, None, optional
|
|
34
|
+
A tuple of integers indicating the shape of the output array in the
|
|
35
|
+
``numpy.ndarray`` order. When provided, it takes precedence over the
|
|
36
|
+
``wcs_from.array_shape`` property.
|
|
37
|
+
|
|
38
|
+
disable_bbox : {"to", "from", "both", "none"}, optional
|
|
39
|
+
Indicates whether to use or not to use the bounding box of either
|
|
40
|
+
(both) ``wcs_from`` or (and) ``wcs_to`` when computing pixel map. When
|
|
41
|
+
``disable_bbox`` is "none", pixel coordinates outside of the bounding
|
|
42
|
+
box are set to `NaN` only if ``wcs_from`` or (and) ``wcs_to`` sets
|
|
43
|
+
world coordinates to NaN when input pixel coordinates are outside of
|
|
44
|
+
the bounding box.
|
|
45
|
+
|
|
46
|
+
Returns
|
|
47
|
+
-------
|
|
48
|
+
pixmap : numpy.ndarray
|
|
49
|
+
A three dimensional array representing the transformation between
|
|
50
|
+
the two. The last dimension is of length two and contains the x and
|
|
51
|
+
y coordinates of a pixel center, repectively. The other two coordinates
|
|
52
|
+
correspond to the two coordinates of the image the first WCS is from.
|
|
53
|
+
|
|
54
|
+
Raises
|
|
55
|
+
------
|
|
56
|
+
ValueError
|
|
57
|
+
A `ValueError` is raised when output pixel map shape cannot be
|
|
58
|
+
determined from provided inputs.
|
|
59
|
+
|
|
60
|
+
Notes
|
|
61
|
+
-----
|
|
62
|
+
When ``shape`` is not provided and ``wcs_from.array_shape`` is not set
|
|
63
|
+
(i.e., it is `None`), `calc_pixmap` will attempt to determine pixel map
|
|
64
|
+
shape from the ``bounding_box`` property of the input ``wcs_from`` object.
|
|
65
|
+
If ``bounding_box`` is not available, a `ValueError` will be raised.
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
if (bbox_from := getattr(wcs_from, "bounding_box", None)) is not None:
|
|
69
|
+
try:
|
|
70
|
+
# to avoid dependency on astropy just to check whether
|
|
71
|
+
# the bounding box is an instance of
|
|
72
|
+
# modeling.bounding_box.ModelBoundingBox, we try to
|
|
73
|
+
# directly use and bounding_box(order='F') and if it fails,
|
|
74
|
+
# fall back to converting the bounding box to a tuple
|
|
75
|
+
# (of intervals):
|
|
76
|
+
bbox_from = bbox_from.bounding_box(order='F')
|
|
77
|
+
except AttributeError:
|
|
78
|
+
bbox_from = tuple(bbox_from)
|
|
79
|
+
|
|
80
|
+
if (bbox_to := getattr(wcs_to, "bounding_box", None)) is not None:
|
|
81
|
+
try:
|
|
82
|
+
# to avoid dependency on astropy just to check whether
|
|
83
|
+
# the bounding box is an instance of
|
|
84
|
+
# modeling.bounding_box.ModelBoundingBox, we try to
|
|
85
|
+
# directly use and bounding_box(order='F') and if it fails,
|
|
86
|
+
# fall back to converting the bounding box to a tuple
|
|
87
|
+
# (of intervals):
|
|
88
|
+
bbox_to = bbox_to.bounding_box(order='F')
|
|
89
|
+
except AttributeError:
|
|
90
|
+
bbox_to = tuple(bbox_to)
|
|
91
|
+
|
|
92
|
+
if shape is None:
|
|
93
|
+
shape = wcs_from.array_shape
|
|
94
|
+
if shape is None and bbox_from is not None:
|
|
95
|
+
if (nd := np.ndim(bbox_from)) == 1:
|
|
96
|
+
bbox_from = (bbox_from, )
|
|
97
|
+
if nd > 1:
|
|
98
|
+
shape = tuple(
|
|
99
|
+
int(math.ceil(lim[1] + 0.5)) for lim in bbox_from[::-1]
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
if shape is None:
|
|
103
|
+
raise ValueError(
|
|
104
|
+
'The "from" WCS must have pixel_shape property set.'
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
y, x = np.indices(shape, dtype=np.float64)
|
|
108
|
+
|
|
109
|
+
# temporarily disable the bounding box for the "from" WCS:
|
|
110
|
+
if disable_bbox in ["from", "both"] and bbox_from is not None:
|
|
111
|
+
wcs_from.bounding_box = None
|
|
112
|
+
if disable_bbox in ["to", "both"] and bbox_to is not None:
|
|
113
|
+
wcs_to.bounding_box = None
|
|
114
|
+
try:
|
|
115
|
+
x, y = wcs_to.world_to_pixel_values(
|
|
116
|
+
*wcs_from.pixel_to_world_values(x, y)
|
|
117
|
+
)
|
|
118
|
+
finally:
|
|
119
|
+
if bbox_from is not None:
|
|
120
|
+
wcs_from.bounding_box = bbox_from
|
|
121
|
+
if bbox_to is not None:
|
|
122
|
+
wcs_to.bounding_box = bbox_to
|
|
123
|
+
|
|
124
|
+
pixmap = np.dstack([x, y])
|
|
125
|
+
return pixmap
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def estimate_pixel_scale_ratio(wcs_from, wcs_to, refpix_from=None, refpix_to=None):
|
|
129
|
+
"""
|
|
130
|
+
Compute the ratio of the pixel scale of the "to" WCS at the ``refpix_to``
|
|
131
|
+
position to the pixel scale of the "from" WCS at the ``refpix_from``
|
|
132
|
+
position. Pixel scale ratio,
|
|
133
|
+
when requested, is computed near the centers of the bounding box
|
|
134
|
+
(a property of the WCS object) or near ``refpix_*`` coordinates
|
|
135
|
+
if supplied.
|
|
136
|
+
|
|
137
|
+
Pixel scale is estimated as the square root of pixel's area, i.e.,
|
|
138
|
+
pixels are assumed to have a square shape at the reference
|
|
139
|
+
pixel position. If input reference pixel position for a WCS is `None`,
|
|
140
|
+
it will be taken as the center of the bounding box
|
|
141
|
+
if ``wcs_*`` has a bounding box defined, or as the center of the box
|
|
142
|
+
defined by the ``pixel_shape`` attribute of the input WCS if
|
|
143
|
+
``pixel_shape`` is defined (not `None`), or at pixel coordinates
|
|
144
|
+
``(0, 0)``.
|
|
145
|
+
|
|
146
|
+
Parameters
|
|
147
|
+
----------
|
|
148
|
+
wcs_from : wcs
|
|
149
|
+
A WCS object representing the coordinate system you are
|
|
150
|
+
converting from. This object *must* have ``pixel_shape`` property
|
|
151
|
+
defined.
|
|
152
|
+
|
|
153
|
+
wcs_to : wcs
|
|
154
|
+
A WCS object representing the coordinate system you are
|
|
155
|
+
converting to.
|
|
156
|
+
|
|
157
|
+
refpix_from : numpy.ndarray, tuple, list
|
|
158
|
+
Image coordinates of the reference pixel near which pixel scale should
|
|
159
|
+
be computed in the "from" image. In FITS WCS this could be, for example,
|
|
160
|
+
the value of CRPIX of the ``wcs_from`` WCS.
|
|
161
|
+
|
|
162
|
+
refpix_to : numpy.ndarray, tuple, list
|
|
163
|
+
Image coordinates of the reference pixel near which pixel scale should
|
|
164
|
+
be computed in the "to" image. In FITS WCS this could be, for example,
|
|
165
|
+
the value of CRPIX of the ``wcs_to`` WCS.
|
|
166
|
+
|
|
167
|
+
Returns
|
|
168
|
+
-------
|
|
169
|
+
pixel_scale_ratio : float
|
|
170
|
+
Estimate the ratio of "to" to "from" WCS pixel scales. This value is
|
|
171
|
+
returned only when ``estimate_pixel_scale_ratio`` is `True`.
|
|
172
|
+
|
|
173
|
+
"""
|
|
174
|
+
pscale_ratio = (_estimate_pixel_scale(wcs_to, refpix_to) /
|
|
175
|
+
_estimate_pixel_scale(wcs_from, refpix_from))
|
|
176
|
+
return pscale_ratio
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _estimate_pixel_scale(wcs, refpix):
|
|
180
|
+
# estimate pixel scale (in rad) using approximate algorithm
|
|
181
|
+
# from https://trs.jpl.nasa.gov/handle/2014/40409
|
|
182
|
+
if refpix is None:
|
|
183
|
+
if hasattr(wcs, 'bounding_box') and wcs.bounding_box is not None:
|
|
184
|
+
refpix = np.mean(wcs.bounding_box, axis=-1)
|
|
185
|
+
else:
|
|
186
|
+
if wcs.pixel_shape:
|
|
187
|
+
refpix = np.array([(i - 1) // 2 for i in wcs.pixel_shape])
|
|
188
|
+
else:
|
|
189
|
+
refpix = np.zeros(wcs.pixel_n_dim)
|
|
190
|
+
|
|
191
|
+
else:
|
|
192
|
+
refpix = np.asarray(refpix)
|
|
193
|
+
|
|
194
|
+
l1, phi1 = wcs.pixel_to_world_values(*(refpix - 0.5))
|
|
195
|
+
l2, phi2 = wcs.pixel_to_world_values(*(refpix + [-0.5, 0.5]))
|
|
196
|
+
l3, phi3 = wcs.pixel_to_world_values(*(refpix + 0.5))
|
|
197
|
+
l4, phi4 = wcs.pixel_to_world_values(*(refpix + [0.5, -0.5]))
|
|
198
|
+
area = _DEG2RAD * abs(
|
|
199
|
+
0.5 * (
|
|
200
|
+
(l4 - l2) * (math.sin(_DEG2RAD * phi1) - math.sin(_DEG2RAD * phi3)) +
|
|
201
|
+
(l1 - l3) * (math.sin(_DEG2RAD * phi2) - math.sin(_DEG2RAD * phi4))
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
return math.sqrt(area)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def decode_context(context, x, y):
|
|
208
|
+
"""Get 0-based indices of input images that contributed to (resampled)
|
|
209
|
+
output pixel with coordinates ``x`` and ``y``.
|
|
210
|
+
|
|
211
|
+
Parameters
|
|
212
|
+
----------
|
|
213
|
+
context: numpy.ndarray
|
|
214
|
+
A 3D `~numpy.ndarray` of integral data type.
|
|
215
|
+
|
|
216
|
+
x: int, list of integers, numpy.ndarray of integers
|
|
217
|
+
X-coordinate of pixels to decode (3rd index into the ``context`` array)
|
|
218
|
+
|
|
219
|
+
y: int, list of integers, numpy.ndarray of integers
|
|
220
|
+
Y-coordinate of pixels to decode (2nd index into the ``context`` array)
|
|
221
|
+
|
|
222
|
+
Returns
|
|
223
|
+
-------
|
|
224
|
+
A list of `numpy.ndarray` objects each containing indices of input images
|
|
225
|
+
that have contributed to an output pixel with coordinates ``x`` and ``y``.
|
|
226
|
+
The length of returned list is equal to the number of input coordinate
|
|
227
|
+
arrays ``x`` and ``y``.
|
|
228
|
+
|
|
229
|
+
Examples
|
|
230
|
+
--------
|
|
231
|
+
An example context array for an output image of array shape ``(5, 6)``
|
|
232
|
+
obtained by resampling 80 input images.
|
|
233
|
+
|
|
234
|
+
>>> import numpy as np
|
|
235
|
+
>>> from drizzle.utils import decode_context
|
|
236
|
+
>>> ctx = np.array(
|
|
237
|
+
... [[[0, 0, 0, 0, 0, 0],
|
|
238
|
+
... [0, 0, 0, 36196864, 0, 0],
|
|
239
|
+
... [0, 0, 0, 0, 0, 0],
|
|
240
|
+
... [0, 0, 0, 0, 0, 0],
|
|
241
|
+
... [0, 0, 537920000, 0, 0, 0]],
|
|
242
|
+
... [[0, 0, 0, 0, 0, 0,],
|
|
243
|
+
... [0, 0, 0, 67125536, 0, 0],
|
|
244
|
+
... [0, 0, 0, 0, 0, 0],
|
|
245
|
+
... [0, 0, 0, 0, 0, 0],
|
|
246
|
+
... [0, 0, 163856, 0, 0, 0]],
|
|
247
|
+
... [[0, 0, 0, 0, 0, 0],
|
|
248
|
+
... [0, 0, 0, 8203, 0, 0],
|
|
249
|
+
... [0, 0, 0, 0, 0, 0],
|
|
250
|
+
... [0, 0, 0, 0, 0, 0],
|
|
251
|
+
... [0, 0, 32865, 0, 0, 0]]],
|
|
252
|
+
... dtype=np.int32
|
|
253
|
+
... )
|
|
254
|
+
>>> decode_context(ctx, [3, 2], [1, 4])
|
|
255
|
+
[array([ 9, 12, 14, 19, 21, 25, 37, 40, 46, 58, 64, 65, 67, 77]),
|
|
256
|
+
array([ 9, 20, 29, 36, 47, 49, 64, 69, 70, 79])]
|
|
257
|
+
|
|
258
|
+
"""
|
|
259
|
+
if context.ndim != 3:
|
|
260
|
+
raise ValueError("'context' must be a 3D array.")
|
|
261
|
+
|
|
262
|
+
x = np.atleast_1d(x)
|
|
263
|
+
y = np.atleast_1d(y)
|
|
264
|
+
|
|
265
|
+
if x.size != y.size:
|
|
266
|
+
raise ValueError("Coordinate arrays must have equal length.")
|
|
267
|
+
|
|
268
|
+
if x.ndim != 1:
|
|
269
|
+
raise ValueError("Coordinates must be scalars or 1D arrays.")
|
|
270
|
+
|
|
271
|
+
if not (np.issubdtype(x.dtype, np.integer) and
|
|
272
|
+
np.issubdtype(y.dtype, np.integer)):
|
|
273
|
+
raise ValueError('Pixel coordinates must be integer values')
|
|
274
|
+
|
|
275
|
+
nbits = 8 * context.dtype.itemsize
|
|
276
|
+
one = np.array(1, context.dtype)
|
|
277
|
+
flags = np.array([one << i for i in range(nbits)])
|
|
278
|
+
|
|
279
|
+
idx = []
|
|
280
|
+
for xi, yi in zip(x, y):
|
|
281
|
+
idx.append(
|
|
282
|
+
np.flatnonzero(np.bitwise_and.outer(context[:, yi, xi], flags))
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
return idx
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: drizzle
|
|
3
|
-
Version:
|
|
3
|
+
Version: 2.0.1
|
|
4
4
|
Summary: A package for combining dithered images into a single image
|
|
5
5
|
Author-email: STScI <help@stsci.edu>
|
|
6
6
|
License: Copyright (C) 2011,2014 Association of Universities for Research in
|
|
@@ -39,25 +39,29 @@ Project-URL: Homepage, https://github.com/spacetelescope/drizzle
|
|
|
39
39
|
Project-URL: Bug Tracker, https://github.com/spacetelescope/drizzle/issues
|
|
40
40
|
Project-URL: Documentation, http://spacetelescope.github.io/drizzle/
|
|
41
41
|
Project-URL: Source Code, https://github.com/spacetelescope/drizzle
|
|
42
|
-
Requires-Python:
|
|
42
|
+
Requires-Python: >=3.10
|
|
43
43
|
Description-Content-Type: text/x-rst
|
|
44
44
|
License-File: LICENSE.rst
|
|
45
45
|
Requires-Dist: numpy
|
|
46
|
-
Requires-Dist: astropy
|
|
47
|
-
Provides-Extra: docs
|
|
48
|
-
Requires-Dist: sphinx ; extra == 'docs'
|
|
49
|
-
Requires-Dist: sphinx-automodapi ; extra == 'docs'
|
|
50
|
-
Requires-Dist: sphinx-rtd-theme ; extra == 'docs'
|
|
51
|
-
Requires-Dist: matplotlib ; extra == 'docs'
|
|
52
|
-
Requires-Dist: tomli ; (python_version < "3.11") and extra == 'docs'
|
|
53
46
|
Provides-Extra: test
|
|
54
|
-
Requires-Dist:
|
|
47
|
+
Requires-Dist: astropy; extra == "test"
|
|
48
|
+
Requires-Dist: gwcs; extra == "test"
|
|
49
|
+
Requires-Dist: pytest; extra == "test"
|
|
50
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
51
|
+
Requires-Dist: pytest-doctestplus; extra == "test"
|
|
52
|
+
Provides-Extra: docs
|
|
53
|
+
Requires-Dist: tomli; python_version < "3.11" and extra == "docs"
|
|
54
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
55
|
+
Requires-Dist: sphinx-automodapi; extra == "docs"
|
|
56
|
+
Requires-Dist: sphinx-rtd-theme; extra == "docs"
|
|
57
|
+
Requires-Dist: matplotlib; extra == "docs"
|
|
58
|
+
Requires-Dist: pytest-doctestplus; extra == "docs"
|
|
55
59
|
|
|
56
60
|
drizzle Documentation
|
|
57
61
|
=====================
|
|
58
62
|
|
|
59
|
-
.. image::
|
|
60
|
-
:target:
|
|
63
|
+
.. image:: https://img.shields.io/badge/powered%20by-AstroPy-orange.svg?style=flat
|
|
64
|
+
:target: https://www.astropy.org
|
|
61
65
|
:alt: Powered by Astropy Badge
|
|
62
66
|
|
|
63
67
|
.. image:: https://codecov.io/github/spacetelescope/drizzle/branch/main/graphs/badge.svg
|
|
@@ -76,6 +80,10 @@ drizzle Documentation
|
|
|
76
80
|
:target: https://pypi.org/project/drizzle
|
|
77
81
|
:alt: PyPI Status
|
|
78
82
|
|
|
83
|
+
.. image:: https://zenodo.org/badge/28100377.svg
|
|
84
|
+
:target: https://doi.org/10.5281/zenodo.10672889
|
|
85
|
+
:alt: Zenodo DOI
|
|
86
|
+
|
|
79
87
|
The ``drizzle`` library is a Python package for combining dithered images into a
|
|
80
88
|
single image. This library is derived from code used in DrizzlePac. Like
|
|
81
89
|
DrizzlePac, most of the code is implemented in the C language. The biggest
|
|
@@ -188,177 +196,8 @@ missing information.
|
|
|
188
196
|
The blot methods perform the inverse operation of drizzle. That is, blotting
|
|
189
197
|
performs the inverse mapping to transform the dithered median image back into
|
|
190
198
|
the coordinate system of the original input image. Blotting is primarily used
|
|
191
|
-
for identifying cosmic rays in the original image.
|
|
192
|
-
|
|
193
|
-
|
|
199
|
+
for identifying cosmic rays in the original image. Blot requires the user
|
|
200
|
+
to provide the world coordinate system (WCS)-based transformations in the
|
|
201
|
+
form of a pixel map array as input.
|
|
194
202
|
|
|
195
203
|
.. [Driz2012] Gonzaga, S., Hack, W., Fruchter, A., Mack, J., eds. 2012, The DrizzlePac Handbook. (Baltimore, STScI)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
The Drizzle Library
|
|
199
|
-
-------------------
|
|
200
|
-
|
|
201
|
-
The Drizzle library is object-oriented and you use it by first creating an object of
|
|
202
|
-
the ``Drizzle`` class. To create a new Drizzle output image, supply an Astropy
|
|
203
|
-
WCS object representing the coordinate system of the output image.
|
|
204
|
-
The other parameters are the linear pixel dimension described in the previous
|
|
205
|
-
section, the drizzle kernel used, how each input image is scaled (by exposure
|
|
206
|
-
time or time squared), and the pixel value set in the output image where the
|
|
207
|
-
input images do not overlap.
|
|
208
|
-
|
|
209
|
-
After creating a Drizzle object, you add one or more images by calling the
|
|
210
|
-
``add_fits_file`` method. The arguments are the name of the FITS file containing
|
|
211
|
-
the input image and optionally the name of a FITS file containing the pixel
|
|
212
|
-
weighting. Both file names can be followed by an extension name or number in
|
|
213
|
-
square brackets. Optionally you can pass the name of the header keywords
|
|
214
|
-
containing the exposure time and units. Two units are understood: counts and
|
|
215
|
-
cps (counts per second).
|
|
216
|
-
|
|
217
|
-
The following function is a demonstration of how you can create a new output
|
|
218
|
-
image::
|
|
219
|
-
|
|
220
|
-
def drizzle_demo_one(reference, outfile, infiles):
|
|
221
|
-
"""
|
|
222
|
-
First demonstration of drizzle
|
|
223
|
-
|
|
224
|
-
Parameters
|
|
225
|
-
==========
|
|
226
|
-
reference
|
|
227
|
-
A file containing the wcs of the output image
|
|
228
|
-
|
|
229
|
-
outfile
|
|
230
|
-
The name of the output image
|
|
231
|
-
|
|
232
|
-
infiles
|
|
233
|
-
The names of the input images to be combined
|
|
234
|
-
"""
|
|
235
|
-
# Get the WCS for the output image
|
|
236
|
-
hdulist = fits.open(reference)
|
|
237
|
-
reference_wcs = wcs.WCS(hdulist[1].header)
|
|
238
|
-
|
|
239
|
-
# Initialize the output with the WCS
|
|
240
|
-
driz = drizzle.drizzle.Drizzle(outwcs=reference_wcs)
|
|
241
|
-
|
|
242
|
-
# Combine the input images into on drizzle image
|
|
243
|
-
for infile in infiles:
|
|
244
|
-
driz.add_fits_file(infile)
|
|
245
|
-
|
|
246
|
-
# Write the drizzled image out
|
|
247
|
-
driz.write(outfile)
|
|
248
|
-
|
|
249
|
-
Optionally you can supply the input and weight images as Numpy arrays by using
|
|
250
|
-
the ``add_image`` method. If you use this method, you must supply the extra
|
|
251
|
-
information that would otherwise be read from the FITS image: The WCS
|
|
252
|
-
of the input image, the exposure time, and image units.
|
|
253
|
-
|
|
254
|
-
Here is an example of how you would call ``add_image``::
|
|
255
|
-
|
|
256
|
-
def drizzle_demo_two(reference, outfile, infiles):
|
|
257
|
-
"""
|
|
258
|
-
Demonstration of drizzle with add image.
|
|
259
|
-
|
|
260
|
-
Parameters
|
|
261
|
-
==========
|
|
262
|
-
reference
|
|
263
|
-
A file containing the wcs of the output image.
|
|
264
|
-
|
|
265
|
-
outfile
|
|
266
|
-
The name of the output image.
|
|
267
|
-
|
|
268
|
-
infiles
|
|
269
|
-
The names of the input images to be combined.
|
|
270
|
-
"""
|
|
271
|
-
# Get the WCS for the output image
|
|
272
|
-
reflist = fits.open(reference)
|
|
273
|
-
reference_wcs = wcs.WCS(reflist[1].header)
|
|
274
|
-
|
|
275
|
-
# Initialize the output with the WCS
|
|
276
|
-
driz = drizzle.drizzle.Drizzle(outwcs=reference_wcs)
|
|
277
|
-
|
|
278
|
-
# Combine the input images into on drizzle image
|
|
279
|
-
for infile in infiles:
|
|
280
|
-
# Open the file and read the image and wcs
|
|
281
|
-
# This is a contrived example, we would not do this
|
|
282
|
-
# unless the data came from another source
|
|
283
|
-
# than a FITS file
|
|
284
|
-
imlist = fits.open(reference)
|
|
285
|
-
image = imlist[1].data
|
|
286
|
-
image_wcs = wcs.WCS(imlist[1].header)
|
|
287
|
-
driz.add_image(image, image_wcs)
|
|
288
|
-
|
|
289
|
-
# Write the drizzled image out
|
|
290
|
-
driz.write(outfile)
|
|
291
|
-
|
|
292
|
-
After combining all the input images, you write the output image into a FITS
|
|
293
|
-
file with the ``write`` method. You must pass the name of the output image and
|
|
294
|
-
optionally the units. You can also supply a set of header cards to be added
|
|
295
|
-
to the primary header of the output FITS file.
|
|
296
|
-
|
|
297
|
-
You can also add more images to an existing Drizzle output file by creating
|
|
298
|
-
a new Drizzle object and passing the existing output file name as the new
|
|
299
|
-
object is created. In that case the output WCS and all
|
|
300
|
-
other parameters are read from the file.
|
|
301
|
-
|
|
302
|
-
Here is a demonstration of adding additional input images to a drizzled image::
|
|
303
|
-
|
|
304
|
-
def drizzle_demo_three(outfile, infiles):
|
|
305
|
-
"""
|
|
306
|
-
Demonstration of drizzle and adding to an existing output.
|
|
307
|
-
|
|
308
|
-
Parameters
|
|
309
|
-
==========
|
|
310
|
-
outfile
|
|
311
|
-
Name of output image that new files will be appended to.
|
|
312
|
-
|
|
313
|
-
infiles
|
|
314
|
-
The names of the input images to be added.
|
|
315
|
-
"""
|
|
316
|
-
# Re-open the output file
|
|
317
|
-
driz = drizzle.drizzle.Drizzle(infile=outfile)
|
|
318
|
-
|
|
319
|
-
# Add the input images to the existing output image
|
|
320
|
-
for infile in infiles:
|
|
321
|
-
driz.add_fits_file(infile)
|
|
322
|
-
|
|
323
|
-
# Write the modified drizzled image out
|
|
324
|
-
driz.write(outfile)
|
|
325
|
-
|
|
326
|
-
You can use the methods ``blot_fits_file`` and ``blot_image`` to transform the drizzled
|
|
327
|
-
output image into another WCS. Most usually this is the
|
|
328
|
-
coordinates of one of the input images and is used to identify cosmic rays or
|
|
329
|
-
other defects. The two methods ``blot_fits_file`` and ``blot_image`` allow you to
|
|
330
|
-
retrieve the WCS from the FITS file header or input it directly.
|
|
331
|
-
The optional parameter ``interp`` allows you to selct the method used to resample
|
|
332
|
-
the pixels on the new grid, and ``sincscl`` is used to scale the sinc function if one
|
|
333
|
-
of the sinc interpolation methods is used. This function demonstrates how both
|
|
334
|
-
methods are called::
|
|
335
|
-
|
|
336
|
-
def drizzle_demo_four(outfile, blotfile):
|
|
337
|
-
"""
|
|
338
|
-
Demonstration of blot methods.
|
|
339
|
-
|
|
340
|
-
Parameters
|
|
341
|
-
==========
|
|
342
|
-
outfile
|
|
343
|
-
Name of output image that will be converted.
|
|
344
|
-
|
|
345
|
-
blotfile
|
|
346
|
-
Name of image containing wcs to be transformed to.
|
|
347
|
-
"""
|
|
348
|
-
# Open drizzle using the output file
|
|
349
|
-
# Transform it to another coordinate system
|
|
350
|
-
driz = drizzle.drizzle.Drizzle(infile=outfile)
|
|
351
|
-
driz.blot_fits_file(blotfile)
|
|
352
|
-
driz.write(outfile)
|
|
353
|
-
|
|
354
|
-
# Read the WCS and transform using it instead
|
|
355
|
-
# This is a contrived example
|
|
356
|
-
blotlist = fits.open(blotfile)
|
|
357
|
-
blot_wcs = wcs.WCS(blotlist[1].header)
|
|
358
|
-
driz = drizzle.drizzle.Drizzle(infile=outfile)
|
|
359
|
-
driz.blot_image(blot_wcs)
|
|
360
|
-
driz.write(outfile)
|
|
361
|
-
|
|
362
|
-
The lower level function ``dodrizzle`` is present for backwards compatibility with
|
|
363
|
-
the existing STScI DrizzlePac code and should not be used unless you are also
|
|
364
|
-
concerned with this compatibility.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
drizzle/__init__.py,sha256=hMpqmjPhrUWTRU0eXNOcrpiqQFGp4lf9opY8FXqLLEQ,325
|
|
2
|
+
drizzle/cdrizzle.cp311-win_amd64.pyd,sha256=_PEpXUcvcJFL1kep8KmmAm8Zapc8tJ82lflmol1ALj0,100864
|
|
3
|
+
drizzle/resample.py,sha256=LXc3TxaXvOd05zrszMa94JZbMSu7T3kDn4zoL3N7yeI,28982
|
|
4
|
+
drizzle/util.py,sha256=os9wHm1JkKiG5jtnNCZAXG3vnnXxLHBpi8OTWsiPI7k,845
|
|
5
|
+
drizzle/utils.py,sha256=hz6TVSb5dWIVw3P28EeeSc6PjVJNy4JAG5tB1v1yIrE,10846
|
|
6
|
+
drizzle/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
drizzle/tests/helpers.py,sha256=BF_IbAwBZFgrTglw33Mgw56xfKYqNJXVTtjCwUB_U98,5887
|
|
8
|
+
drizzle/tests/test_cdrizzle.py,sha256=utepqMiY8xtgQ8gBRBHwnlMhbBB1pq1xE4spf-wO7Kw,726
|
|
9
|
+
drizzle/tests/test_overlap_calc.py,sha256=ucwDL9fd8NVAxTdz-sWum_uobhm-TGkCr2yl69BKiC4,7062
|
|
10
|
+
drizzle/tests/test_resample.py,sha256=13UfYaGtTT2utQfF7j_8pQXzC51RFZ8EpRLFYSdz1MM,31600
|
|
11
|
+
drizzle/tests/test_utils.py,sha256=s4-z4ZMTcoIUyxHW0pMRpQB2GiA1lbfuNLQzkOgflp8,7691
|
|
12
|
+
drizzle-2.0.1.dist-info/LICENSE.rst,sha256=sUXj5W73D9TcOw5ZXaDdcthYdY2b2dTJPsxBuZTOYWQ,1505
|
|
13
|
+
drizzle-2.0.1.dist-info/METADATA,sha256=2G_rWumBwJpBy9MC7qc_c7CHA3qj_4RLxIHehazIIdM,10894
|
|
14
|
+
drizzle-2.0.1.dist-info/WHEEL,sha256=yNnHoQL2GZYIUXm9YvoaBpFjGlUoK9qq9oqYeudrWlE,101
|
|
15
|
+
drizzle-2.0.1.dist-info/top_level.txt,sha256=MA5uqwTj1sJBi-hCeQj9v3-sZ9nVUTe6bd_zGWTKy5A,8
|
|
16
|
+
drizzle-2.0.1.dist-info/RECORD,,
|
drizzle/calc_pixmap.py
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
def calc_pixmap(first_wcs, second_wcs):
|
|
5
|
-
"""
|
|
6
|
-
Calculate a mapping between the pixels of two images.
|
|
7
|
-
|
|
8
|
-
Parameters
|
|
9
|
-
----------
|
|
10
|
-
|
|
11
|
-
first_wcs : wcs
|
|
12
|
-
A WCS object representing the coordinate system you are
|
|
13
|
-
converting from
|
|
14
|
-
|
|
15
|
-
seond_wcs : wcs
|
|
16
|
-
A WCS object representing the coordinate system you are
|
|
17
|
-
converting to
|
|
18
|
-
|
|
19
|
-
Returns
|
|
20
|
-
-------
|
|
21
|
-
|
|
22
|
-
A three dimensional array representing the transformation between
|
|
23
|
-
the two. The last dimension is of length two and contains the x and
|
|
24
|
-
y coordinates of a pixel center, repectively. The other two coordinates
|
|
25
|
-
correspond to the two coordinates of the image the first WCS is from.
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
first_naxis1, first_naxis2 = first_wcs.pixel_shape
|
|
29
|
-
|
|
30
|
-
# We add one to the pixel co-ordinates before the transformation and subtract
|
|
31
|
-
# it afterwards because wcs co-ordinates are one based, while pixel co-ordinates
|
|
32
|
-
# are zero based, The result is the final values in pixmap give a tranformation
|
|
33
|
-
# between the pixel co-ordinates in the first image to pixel co-ordinates in the
|
|
34
|
-
# co-ordinate system of the second.
|
|
35
|
-
|
|
36
|
-
one = np.ones(2, dtype='float64')
|
|
37
|
-
idxmap = np.indices((first_naxis1, first_naxis2), dtype='float64')
|
|
38
|
-
idxmap = idxmap.transpose() + one
|
|
39
|
-
|
|
40
|
-
idxmap = idxmap.reshape(first_naxis2 * first_naxis1, 2)
|
|
41
|
-
|
|
42
|
-
worldmap = first_wcs.all_pix2world(idxmap, 1)
|
|
43
|
-
|
|
44
|
-
if second_wcs.sip is None:
|
|
45
|
-
pixmap = second_wcs.wcs_world2pix(worldmap, 1)
|
|
46
|
-
else:
|
|
47
|
-
pixmap = second_wcs.all_world2pix(worldmap, 1)
|
|
48
|
-
|
|
49
|
-
pixmap = pixmap.reshape(first_naxis2, first_naxis1, 2)
|
|
50
|
-
pixmap = pixmap - one
|
|
51
|
-
|
|
52
|
-
return pixmap
|
drizzle/doblot.py
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
STScI Python compatable blot module
|
|
3
|
-
"""
|
|
4
|
-
import numpy as np
|
|
5
|
-
|
|
6
|
-
from drizzle import calc_pixmap
|
|
7
|
-
from drizzle import cdrizzle
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def doblot(source, source_wcs, blot_wcs, exptime, coeffs=True,
|
|
11
|
-
interp='poly5', sinscl=1.0, stepsize=10, wcsmap=None):
|
|
12
|
-
"""
|
|
13
|
-
Low level routine for performing the 'blot' operation.
|
|
14
|
-
|
|
15
|
-
Create a single blotted image from a single source image. The
|
|
16
|
-
interface is compatible with STScI code. All distortion information
|
|
17
|
-
is assumed to be included in the WCS specification of the 'output'
|
|
18
|
-
blotted image given in 'blot_wcs'.
|
|
19
|
-
|
|
20
|
-
Parameters
|
|
21
|
-
----------
|
|
22
|
-
|
|
23
|
-
source : 2d array
|
|
24
|
-
Input numpy array of the source image in units of 'cps'.
|
|
25
|
-
|
|
26
|
-
source_wcs : wcs
|
|
27
|
-
The source image WCS.
|
|
28
|
-
|
|
29
|
-
blot_wcs : wcs
|
|
30
|
-
The blotted image WCS. The WCS that the source image will be
|
|
31
|
-
resampled to.
|
|
32
|
-
|
|
33
|
-
exptime : float
|
|
34
|
-
The exposure time of the input image.
|
|
35
|
-
|
|
36
|
-
interp : str, optional
|
|
37
|
-
The type of interpolation used in the blotting. The
|
|
38
|
-
possible values are "nearest" (nearest neighbor interpolation),
|
|
39
|
-
"linear" (bilinear interpolation), "poly3" (cubic polynomial
|
|
40
|
-
interpolation), "poly5" (quintic polynomial interpolation),
|
|
41
|
-
"sinc" (sinc interpolation), "lan3" (3rd order Lanczos
|
|
42
|
-
interpolation), and "lan5" (5th order Lanczos interpolation).
|
|
43
|
-
|
|
44
|
-
sincscl : float, optional
|
|
45
|
-
The scaling factor for sinc interpolation.
|
|
46
|
-
|
|
47
|
-
Returns
|
|
48
|
-
-------
|
|
49
|
-
|
|
50
|
-
A 2d numpy array with the blotted image
|
|
51
|
-
|
|
52
|
-
Other Parameters
|
|
53
|
-
----------------
|
|
54
|
-
|
|
55
|
-
coeffs : bool, optional
|
|
56
|
-
Not used. Only kept for backwards compatibility.
|
|
57
|
-
|
|
58
|
-
stepsize : float, optional
|
|
59
|
-
Was used when input to output mapping was computed
|
|
60
|
-
internally. Is no longer used and only here for backwards compatibility.
|
|
61
|
-
|
|
62
|
-
wcsmap : function, optional
|
|
63
|
-
Was used when input to output mapping was computed
|
|
64
|
-
internally. Is no longer used and only here for backwards compatibility.
|
|
65
|
-
"""
|
|
66
|
-
_outsci = np.zeros(blot_wcs.pixel_shape[::-1], dtype=np.float32)
|
|
67
|
-
|
|
68
|
-
# compute the undistorted 'natural' plate scale
|
|
69
|
-
blot_wcs.sip = None
|
|
70
|
-
blot_wcs.cpdis1 = None
|
|
71
|
-
blot_wcs.cpdis2 = None
|
|
72
|
-
blot_wcs.det2im = None
|
|
73
|
-
|
|
74
|
-
pixmap = calc_pixmap.calc_pixmap(blot_wcs, source_wcs)
|
|
75
|
-
pix_ratio = source_wcs.pscale / blot_wcs.pscale
|
|
76
|
-
|
|
77
|
-
cdrizzle.tblot(source, pixmap, _outsci, scale=pix_ratio, kscale=1.0,
|
|
78
|
-
interp=interp, exptime=exptime, misval=0.0, sinscl=sinscl)
|
|
79
|
-
|
|
80
|
-
return _outsci
|