drizzle 1.15.0__cp310-cp310-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 ADDED
@@ -0,0 +1,11 @@
1
+ """
2
+ A package for combining dithered images into a single image
3
+ """
4
+ from importlib.metadata import PackageNotFoundError, version
5
+
6
+
7
+ try:
8
+ __version__ = version(__name__)
9
+ except PackageNotFoundError:
10
+ # package is not installed
11
+ __version__ = 'unknown'
drizzle/calc_pixmap.py ADDED
@@ -0,0 +1,52 @@
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
Binary file
drizzle/doblot.py ADDED
@@ -0,0 +1,80 @@
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
drizzle/dodrizzle.py ADDED
@@ -0,0 +1,189 @@
1
+ """
2
+ STScI Python compatable drizzle module
3
+ """
4
+ import numpy as np
5
+
6
+ from . import util
7
+ from . import calc_pixmap
8
+ from . import cdrizzle
9
+
10
+
11
+ def dodrizzle(insci, input_wcs, inwht,
12
+ output_wcs, outsci, outwht, outcon,
13
+ expin, in_units, wt_scl,
14
+ wcslin_pscale=1.0, uniqid=1,
15
+ xmin=0, xmax=0, ymin=0, ymax=0,
16
+ pixfrac=1.0, kernel='square', fillval="INDEF"):
17
+ """
18
+ Low level routine for performing 'drizzle' operation.on one image.
19
+
20
+ The interface is compatible with STScI code. All images are Python
21
+ ndarrays, instead of filenames. File handling (input and output) is
22
+ performed by the calling routine.
23
+
24
+ Parameters
25
+ ----------
26
+
27
+ insci : 2d array
28
+ A 2d numpy array containing the input image to be drizzled.
29
+ it is an error to not supply an image.
30
+
31
+ input_wcs : 2d array
32
+ The world coordinate system of the input image.
33
+
34
+ inwht : 2d array
35
+ A 2d numpy array containing the pixel by pixel weighting.
36
+ Must have the same dimensions as insci. If none is supplied,
37
+ the weghting is set to one.
38
+
39
+ output_wcs : wcs
40
+ The world coordinate system of the output image.
41
+
42
+ outsci : 2d array
43
+ A 2d numpy array containing the output image produced by
44
+ drizzling. On the first call it should be set to zero.
45
+ Subsequent calls it will hold the intermediate results
46
+
47
+ outwht : 2d array
48
+ A 2d numpy array containing the output counts. On the first
49
+ call it should be set to zero. On subsequent calls it will
50
+ hold the intermediate results.
51
+
52
+ outcon : 2d or 3d array, optional
53
+ A 2d or 3d numpy array holding a bitmap of which image was an input
54
+ for each output pixel. Should be integer zero on first call.
55
+ Subsequent calls hold intermediate results.
56
+
57
+ expin : float
58
+ The exposure time of the input image, a positive number. The
59
+ exposure time is used to scale the image if the units are counts.
60
+
61
+ in_units : str
62
+ The units of the input image. The units can either be "counts"
63
+ or "cps" (counts per second.)
64
+
65
+ wt_scl : float
66
+ A scaling factor applied to the pixel by pixel weighting.
67
+
68
+ wcslin_pscale : float, optional
69
+ The pixel scale of the input image. Conceptually, this is the
70
+ linear dimension of a side of a pixel in the input image, but it
71
+ is not limited to this and can be set to change how the drizzling
72
+ algorithm operates.
73
+
74
+ uniqid : int, optional
75
+ The id number of the input image. Should be one the first time
76
+ this function is called and incremented by one on each subsequent
77
+ call.
78
+
79
+ xmin : float, optional
80
+ This and the following three parameters set a bounding rectangle
81
+ on the input image. Only pixels on the input image inside this
82
+ rectangle will have their flux added to the output image. Xmin
83
+ sets the minimum value of the x dimension. The x dimension is the
84
+ dimension that varies quickest on the image. If the value is zero,
85
+ no minimum will be set in the x dimension. All four parameters are
86
+ zero based, counting starts at zero.
87
+
88
+ xmax : float, optional
89
+ Sets the maximum value of the x dimension on the bounding box
90
+ of the input image. If the value is zero, no maximum will
91
+ be set in the x dimension, the full x dimension of the output
92
+ image is the bounding box.
93
+
94
+ ymin : float, optional
95
+ Sets the minimum value in the y dimension on the bounding box. The
96
+ y dimension varies less rapidly than the x and represents the line
97
+ index on the input image. If the value is zero, no minimum will be
98
+ set in the y dimension.
99
+
100
+ ymax : float, optional
101
+ Sets the maximum value in the y dimension. If the value is zero, no
102
+ maximum will be set in the y dimension, the full x dimension
103
+ of the output image is the bounding box.
104
+
105
+ pixfrac : float, optional
106
+ The fraction of a pixel that the pixel flux is confined to. The
107
+ default value of 1 has the pixel flux evenly spread across the image.
108
+ A value of 0.5 confines it to half a pixel in the linear dimension,
109
+ so the flux is confined to a quarter of the pixel area when the square
110
+ kernel is used.
111
+
112
+ kernel: str, optional
113
+ The name of the kernel used to combine the input. The choice of
114
+ kernel controls the distribution of flux over the kernel. The kernel
115
+ names are: "square", "turbo", "point", "gaussian", "lanczos2",
116
+ and "lanczos3".
117
+
118
+ .. warning::
119
+ The "gaussian" and "lanczos2/3" kernels **DO NOT** conserve flux.
120
+
121
+ fillval: str, optional
122
+ The value a pixel is set to in the output if the input image does
123
+ not overlap it. The default value of INDEF does not set a value.
124
+
125
+ Returns
126
+ -------
127
+ A tuple with three values: a version string, the number of pixels
128
+ on the input image that do not overlap the output image, and the
129
+ number of complete lines on the input image that do not overlap the
130
+ output input image.
131
+
132
+ """
133
+
134
+ # Ensure that the fillval parameter gets properly interpreted
135
+ # for use with tdriz
136
+ if util.is_blank(fillval):
137
+ fillval = 'INDEF'
138
+ else:
139
+ fillval = str(fillval)
140
+
141
+ if in_units == 'cps':
142
+ expscale = 1.0
143
+ else:
144
+ expscale = expin
145
+
146
+ # Add input weight image if it was not passed in
147
+
148
+ if (insci.dtype > np.float32):
149
+ insci = insci.astype(np.float32)
150
+
151
+ if inwht is None:
152
+ inwht = np.ones_like(insci)
153
+
154
+ # Compute what plane of the context image this input would
155
+ # correspond to:
156
+ planeid = int((uniqid - 1) / 32)
157
+
158
+ # Check if the context image has this many planes
159
+ if outcon.ndim == 3:
160
+ nplanes = outcon.shape[0]
161
+ elif outcon.ndim == 2:
162
+ nplanes = 1
163
+ else:
164
+ nplanes = 0
165
+
166
+ if nplanes <= planeid:
167
+ raise IndexError("Not enough planes in drizzle context image")
168
+
169
+ # Alias context image to the requested plane if 3d
170
+ if outcon.ndim == 3:
171
+ outcon = outcon[planeid]
172
+
173
+ pix_ratio = output_wcs.pscale / wcslin_pscale
174
+
175
+ # Compute the mapping between the input and output pixel coordinates
176
+ pixmap = calc_pixmap.calc_pixmap(input_wcs, output_wcs)
177
+
178
+ #
179
+ # Call 'drizzle' to perform image combination
180
+ # This call to 'cdriz.tdriz' uses the new C syntax
181
+ #
182
+ _vers, nmiss, nskip = cdrizzle.tdriz(
183
+ insci, inwht, pixmap, outsci, outwht, outcon,
184
+ uniqid=uniqid, xmin=xmin, xmax=xmax,
185
+ ymin=ymin, ymax=ymax, scale=pix_ratio, pixfrac=pixfrac,
186
+ kernel=kernel, in_units=in_units, expscale=expscale,
187
+ wtscale=wt_scl, fillstr=fillval)
188
+
189
+ return _vers, nmiss, nskip