A package for combining dithered images into a single image
Project description
The drizzle library is a Python package for combining dithered images into a single image. This library is derived from code used in DrizzlePac. Like DrizzlePac, most of the code is implemented in the C language. The biggest change from DrizzlePac is that this code passes an array that maps the input to output image into the C code, while the DrizzlePac code computes the mapping by using a Python callback. Switching to using an array allowed the code to be greatly simplified.
The DrizzlePac code is currently used in the Space Telescope processing pipelines. This library is forward looking in that it can be used with the new GWCS code.
Requirements
Python 3.10 or later
Numpy
Astropy
The Drizzle Algorithm
This section has been extracted from Chapter 2 of The DrizzlePac Handbook [Driz2012]
There are a family of linear reconstruction techniques that, at two opposite extremes, are represented by the interlacing and shift-and-add techniques, with the Drizzle algorithm representing a continuum between these two extremes.
If the dithers are particularly well-placed, one can simply interlace the pixels from the images onto a finer grid. In the interlacing method, pixels from the independent input images are placed in alternate pixels on the output image according to the alignment of the pixel centers in the original images. However, due to occasional small positioning errors by the telescope, and non-uniform shifts in pixel space across the detector caused by geometric distortion of the optics, true interlacing of images is generally not feasible.
Another standard simple linear technique for combining shifted images, descriptively named “shift-and-add”, has been used for many years to combine dithered infrared data onto finer grids. Each input pixel is block-replicated onto a finer subsampled grid, shifted into place, and added to the output image. Shift-and-add has the advantage of being able to easily handle arbitrary dither positions. However, it convolves the image yet again with the original pixel, thus adding to the blurring of the image and to the correlation of noise in the image. Furthermore, it is difficult to use shift-and-add in the presence of missing data (e.g., from cosmic rays) and geometric distortion.
In response to the limitations of the two techniques described above, an improved method known formally as variable-pixel linear reconstruction, and more commonly referred to as Drizzle, was developed by Andy Fruchter and Richard Hook, initially for the purposes of combining dithered images of the Hubble Deep Field North (HDF-N). This algorithm can be thought of as a continuous set of linear functions that vary smoothly between the optimum linear combination technique (interlacing) and shift-and-add. This often allows an improvement in resolution and a reduction in correlated noise, compared with images produced by only using shift-and-add.
The degree to which the algorithm departs from interlacing and moves towards shift-and-add depends upon how well the PSF is subsampled by the shifts in the input images. In practice, the behavior of the Drizzle algorithm is controlled through the use of a parameter called pixfrac, which can be set to values ranging from 0 to 1, that represents the amount by which input pixels are shrunk before being mapped onto the output image plane.
A key to understanding the use of pixfrac is to realize that a CCD image can be thought of as the true image convolved first by the optics, then by the pixel response function (ideally a square the size of a pixel), and then sampled by a delta-function at the center of each pixel. A CCD image is thus a set of point samples of a continuous two-dimensional function. Hence the natural value of pixfrac is 0, which corresponds to pure interlacing. Setting pixfrac to values greater than 0 causes additional broadening of the output PSF by convolving the original PSF with pixels of non-zero size. Thus, setting pixfrac to its maximum value of 1 is equivalent to shift-and-add, the other extreme of linear combination, in which the output image PSF has been smeared by a convolution with the full size of the original input pixels.
The Drizzle algorithm is conceptually straightforward. Pixels in the original input images are mapped into pixels in the subsampled output image, taking into account shifts and rotations between images and the optical distortion of the camera. However, in order to avoid convolving the image with the large pixel “footprint” of the camera, Drizzle allows the user to shrink the pixel before it is averaged into the output image through the pixfrac parameter.
The flux value of each input pixel is divided up into the output pixels with weights proportional to the area of overlap between the “drop” and each output pixel. If the drop size is too small, not all output pixels have data added to them from each of the input images. One should therefore choose a drop size that is small enough to avoid convolving the image with too large an input pixel footprint, yet sufficiently large to ensure that there is not too much variation in the number of input pixels contributing to each output pixel.
When images are combined using Drizzle, a weight map can be specified for each input image. The weight image contains information about bad pixels in the image (in that bad pixels result in lower weight values). When the final output science image is generated, an output weight map which combines information from all the input weight images, is also saved.
Drizzle has a number of advantages over standard linear reconstruction methods. Since the pixel area can be scaled by the Jacobian of the geometric distortion, it is preserved for surface and absolute photometry. Therefore, the flux in the drizzled image, that was corrected for geometric distortion, can be measured with an aperture size that’s not dependent of its position on the image. Since the Drizzle code anticipates that a given output pixel might not receive any information from an input pixel, missing data does not cause a substantial problem as long as the observer has taken enough dither samples to fill in the missing information.
The blot methods perform the inverse operation of drizzle. That is, blotting performs the inverse mapping to transform the dithered median image back into the coordinate system of the original input image. Blotting is primarily used for identifying cosmic rays in the original image. Like the original drizzle task, blot requires the user to provide the world coordinate system (WCS) transformations as inputs.
Gonzaga, S., Hack, W., Fruchter, A., Mack, J., eds. 2012, The DrizzlePac Handbook. (Baltimore, STScI)
The Drizzle Library
The Drizzle library is object-oriented and you use it by first creating an object of the Drizzle class. To create a new Drizzle output image, supply an Astropy WCS object representing the coordinate system of the output image. The other parameters are the linear pixel dimension described in the previous section, the drizzle kernel used, how each input image is scaled (by exposure time or time squared), and the pixel value set in the output image where the input images do not overlap.
After creating a Drizzle object, you add one or more images by calling the add_fits_file method. The arguments are the name of the FITS file containing the input image and optionally the name of a FITS file containing the pixel weighting. Both file names can be followed by an extension name or number in square brackets. Optionally you can pass the name of the header keywords containing the exposure time and units. Two units are understood: counts and cps (counts per second).
The following function is a demonstration of how you can create a new output image:
def drizzle_demo_one(reference, outfile, infiles): """ First demonstration of drizzle Parameters ========== reference A file containing the wcs of the output image outfile The name of the output image infiles The names of the input images to be combined """ # Get the WCS for the output image hdulist = fits.open(reference) reference_wcs = wcs.WCS(hdulist[1].header) # Initialize the output with the WCS driz = drizzle.drizzle.Drizzle(outwcs=reference_wcs) # Combine the input images into on drizzle image for infile in infiles: driz.add_fits_file(infile) # Write the drizzled image out driz.write(outfile)
Optionally you can supply the input and weight images as Numpy arrays by using the add_image method. If you use this method, you must supply the extra information that would otherwise be read from the FITS image: The WCS of the input image, the exposure time, and image units.
Here is an example of how you would call add_image:
def drizzle_demo_two(reference, outfile, infiles): """ Demonstration of drizzle with add image. Parameters ========== reference A file containing the wcs of the output image. outfile The name of the output image. infiles The names of the input images to be combined. """ # Get the WCS for the output image reflist = fits.open(reference) reference_wcs = wcs.WCS(reflist[1].header) # Initialize the output with the WCS driz = drizzle.drizzle.Drizzle(outwcs=reference_wcs) # Combine the input images into on drizzle image for infile in infiles: # Open the file and read the image and wcs # This is a contrived example, we would not do this # unless the data came from another source # than a FITS file imlist = fits.open(reference) image = imlist[1].data image_wcs = wcs.WCS(imlist[1].header) driz.add_image(image, image_wcs) # Write the drizzled image out driz.write(outfile)
After combining all the input images, you write the output image into a FITS file with the write method. You must pass the name of the output image and optionally the units. You can also supply a set of header cards to be added to the primary header of the output FITS file.
You can also add more images to an existing Drizzle output file by creating a new Drizzle object and passing the existing output file name as the new object is created. In that case the output WCS and all other parameters are read from the file.
Here is a demonstration of adding additional input images to a drizzled image:
def drizzle_demo_three(outfile, infiles): """ Demonstration of drizzle and adding to an existing output. Parameters ========== outfile Name of output image that new files will be appended to. infiles The names of the input images to be added. """ # Re-open the output file driz = drizzle.drizzle.Drizzle(infile=outfile) # Add the input images to the existing output image for infile in infiles: driz.add_fits_file(infile) # Write the modified drizzled image out driz.write(outfile)
You can use the methods blot_fits_file and blot_image to transform the drizzled output image into another WCS. Most usually this is the coordinates of one of the input images and is used to identify cosmic rays or other defects. The two methods blot_fits_file and blot_image allow you to retrieve the WCS from the FITS file header or input it directly. The optional parameter interp allows you to selct the method used to resample the pixels on the new grid, and sincscl is used to scale the sinc function if one of the sinc interpolation methods is used. This function demonstrates how both methods are called:
def drizzle_demo_four(outfile, blotfile): """ Demonstration of blot methods. Parameters ========== outfile Name of output image that will be converted. blotfile Name of image containing wcs to be transformed to. """ # Open drizzle using the output file # Transform it to another coordinate system driz = drizzle.drizzle.Drizzle(infile=outfile) driz.blot_fits_file(blotfile) driz.write(outfile) # Read the WCS and transform using it instead # This is a contrived example blotlist = fits.open(blotfile) blot_wcs = wcs.WCS(blotlist[1].header) driz = drizzle.drizzle.Drizzle(infile=outfile) driz.blot_image(blot_wcs) driz.write(outfile)
The lower level function dodrizzle is present for backwards compatibility with the existing STScI DrizzlePac code and should not be used unless you are also concerned with this compatibility.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file drizzle-1.15.3.tar.gz
.
File metadata
- Download URL: drizzle-1.15.3.tar.gz
- Upload date:
- Size: 105.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c96684ff686481e97bad16f8f2df0b82f62b6e0a135204ee1931e44e7712175f |
|
MD5 | 09dc65d3f317611c3b893a2b4530296c |
|
BLAKE2b-256 | 7fdeecc6e322ad05bd4ca24f5be6208ec2d8332c685ee122bf8773d0fc449b98 |
File details
Details for the file drizzle-1.15.3-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 78.3 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a7221d179509fb92ad6ca3142f15764627e444411f44ce168f24444661d4f82 |
|
MD5 | db8cca3f5d8bc5a0f303c527a8812d3a |
|
BLAKE2b-256 | 51eb664067fbe1cdcf950b81c8676782735fd9b60f29132cc19afcded628d9a3 |
File details
Details for the file drizzle-1.15.3-cp312-cp312-win32.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp312-cp312-win32.whl
- Upload date:
- Size: 69.8 kB
- Tags: CPython 3.12, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 020ef46fda81de9022fd745a86cc557c065115defb1cd1df86fb181f2070f9b4 |
|
MD5 | 5ba78b1118c0b5aad7fd81d703cd74ed |
|
BLAKE2b-256 | f8a3983c82b8bdde7d2eb8dedcd7a6fb0cfb6e1e37def7821e1110d9a3791db5 |
File details
Details for the file drizzle-1.15.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 296.9 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b58def6266bbd6966f8646b7feaee62644aafda7fe9e8054c0e949bf2339138d |
|
MD5 | d8e2458cd36018e12c49476532a623a2 |
|
BLAKE2b-256 | 0159eb1f48324c709d0521f2451f84739723a29adabe386ce056698f44afce98 |
File details
Details for the file drizzle-1.15.3-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 77.5 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5901d236f3c7d0632f72a941fad28789c58579933610bb897dbdc841ab3ac1bb |
|
MD5 | 3eab7f40abbc00a421e9d978bc772745 |
|
BLAKE2b-256 | 62703a45961d912fef38158e21166aefa3ee8e3560ae8ae0b9bb28dcd3e829c3 |
File details
Details for the file drizzle-1.15.3-cp312-cp312-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 84.0 kB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4af5e5a197e010ba14f016d5e45645f630581c55d550ed1ddec73d3bde32af68 |
|
MD5 | 03a45d1e5702c4c3622f81192010e5c5 |
|
BLAKE2b-256 | c954e5f0d3e0b6e3e0f95bca7ebe66bf963cf1146f66a9db08c2e417dacd5746 |
File details
Details for the file drizzle-1.15.3-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 78.3 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6faa9c6c6a7d0e17b4b4f31bbf77781f82f6bfd8fcb4cd08259199aecce009d2 |
|
MD5 | b28f7a9e9515df6b4204f69a446d12f9 |
|
BLAKE2b-256 | d0ad70573d9ea1a206d67d1f77d7c9320b7f8517c51b7bfbb4c4ebc1cbd39070 |
File details
Details for the file drizzle-1.15.3-cp311-cp311-win32.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp311-cp311-win32.whl
- Upload date:
- Size: 69.7 kB
- Tags: CPython 3.11, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21992822773eb51a1852001100db00153bdb64db759fca18d7976a88be5ffcfd |
|
MD5 | e2636b3dda7c69a24c151f0b8b91225e |
|
BLAKE2b-256 | 471e4b1facc0dafc3328de209f2c595bd2bcc1678fdcff75067d46d98904d490 |
File details
Details for the file drizzle-1.15.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 296.6 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec411f282531801b67e8f98e7544f8aa9f84a0ba0623210e38667d4c3784470d |
|
MD5 | 71d42ba9a4efe4af4bd8804e6f0a70d2 |
|
BLAKE2b-256 | 1edfbb4c370a887badd21712927b38c280a86a0c2387c46b7f4586279b6f9d76 |
File details
Details for the file drizzle-1.15.3-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 77.6 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 371175cb3ce57e10a159dfc3d543071d98be257c683ca0869deb097f7cd25939 |
|
MD5 | d413c49b190890b052f7be4114880fe0 |
|
BLAKE2b-256 | c42da1365033c9930d8f4ccd2bf45d05cdcb2fcf2834db912a7f336b67ac395b |
File details
Details for the file drizzle-1.15.3-cp311-cp311-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 83.9 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6327a072aaabae9a89403abd33db066d33ca31f77e7048abb35e8ec2bdacbc70 |
|
MD5 | cd8b3aff738dd53b37bc7616e4de0c0d |
|
BLAKE2b-256 | 0b2331314dfa5989dd658963a731102d4545d45532277572940732938e07f77c |
File details
Details for the file drizzle-1.15.3-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 78.3 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8b9377acec22ae77c5255f13ae37319409ace1c1e2d2abf2aca6f604d70c23b |
|
MD5 | 445901582a33487d70723fb353af55bc |
|
BLAKE2b-256 | f1097a09f9b898962bfc80b658bc366d207065c5ed0d4d01807b969ffe1ab278 |
File details
Details for the file drizzle-1.15.3-cp310-cp310-win32.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp310-cp310-win32.whl
- Upload date:
- Size: 69.7 kB
- Tags: CPython 3.10, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f59a27e23941de5ed77cb4c1b77cfc683256040b22b5bf2cc11953b32cb7c013 |
|
MD5 | 8059ab7a331f203cad5f346ff784ab13 |
|
BLAKE2b-256 | 33cb3ab66270891c11ee9d3a114b94bfb6240f6f8fb186d00742d6a6ac7cdef5 |
File details
Details for the file drizzle-1.15.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 296.7 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1d6db7b1592ae4b0c38778c70701b6ca545674c162acbf127f4555641a7991e |
|
MD5 | 2c068fbbf6edc616f5d506b2d3d83b4b |
|
BLAKE2b-256 | 1a57a509562d034903f93c1c603dd6c5ccf793be41a2734b4eb5b2478cb51c7e |
File details
Details for the file drizzle-1.15.3-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 77.6 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53d977001f733cde14dd0d8ffa6d83844d345128445fba11200b56646b0cad4b |
|
MD5 | 5f1f6dab50fbf1d6a82785661575c055 |
|
BLAKE2b-256 | 8ab574fe580f5c5472d09736689a4a7ba4ec3aade27ee0151a481bcf223771b2 |
File details
Details for the file drizzle-1.15.3-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: drizzle-1.15.3-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 83.9 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f282b407c6b6c20458b7415572bd070ac878f3f2e7f1546895ce9c95ae763d7 |
|
MD5 | 0f31cd1ae638d95827df228a8eb49f9a |
|
BLAKE2b-256 | 4ea253d1f8e588b8470d83de1eb0ef4d046cd40725fccb0dc05b192168a8aca4 |