Skip to main content

A package for combining dithered images into a single image

Project description

Powered by Astropy Badge Drizzle's Coverage Status CI Status Documentation Status PyPI Status

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.

[Driz2012]

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drizzle-1.15.2.tar.gz (105.7 kB view details)

Uploaded Source

Built Distributions

drizzle-1.15.2-cp312-cp312-win_amd64.whl (78.2 kB view details)

Uploaded CPython 3.12 Windows x86-64

drizzle-1.15.2-cp312-cp312-win32.whl (69.7 kB view details)

Uploaded CPython 3.12 Windows x86

drizzle-1.15.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (296.7 kB view details)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

drizzle-1.15.2-cp312-cp312-macosx_11_0_arm64.whl (77.4 kB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

drizzle-1.15.2-cp312-cp312-macosx_10_9_x86_64.whl (83.9 kB view details)

Uploaded CPython 3.12 macOS 10.9+ x86-64

drizzle-1.15.2-cp311-cp311-win_amd64.whl (78.2 kB view details)

Uploaded CPython 3.11 Windows x86-64

drizzle-1.15.2-cp311-cp311-win32.whl (69.6 kB view details)

Uploaded CPython 3.11 Windows x86

drizzle-1.15.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (296.4 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

drizzle-1.15.2-cp311-cp311-macosx_11_0_arm64.whl (77.5 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

drizzle-1.15.2-cp311-cp311-macosx_10_9_x86_64.whl (83.8 kB view details)

Uploaded CPython 3.11 macOS 10.9+ x86-64

drizzle-1.15.2-cp310-cp310-win_amd64.whl (78.2 kB view details)

Uploaded CPython 3.10 Windows x86-64

drizzle-1.15.2-cp310-cp310-win32.whl (69.6 kB view details)

Uploaded CPython 3.10 Windows x86

drizzle-1.15.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (296.5 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

drizzle-1.15.2-cp310-cp310-macosx_11_0_arm64.whl (77.5 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

drizzle-1.15.2-cp310-cp310-macosx_10_9_x86_64.whl (83.8 kB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

File details

Details for the file drizzle-1.15.2.tar.gz.

File metadata

  • Download URL: drizzle-1.15.2.tar.gz
  • Upload date:
  • Size: 105.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for drizzle-1.15.2.tar.gz
Algorithm Hash digest
SHA256 de6049526218f4929e658338bf4b53ec6ba9bde0c6ec107951ad03449fa381c2
MD5 67dda7573958b9a58ed1cf47ec0ee1f0
BLAKE2b-256 237880a5945ee0f9f060e360b4a57c73c482ba20ab7c3e36046e4db5fae610c1

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: drizzle-1.15.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 78.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for drizzle-1.15.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c369960e4e86ccfbbce95915d45a4fe839ccc5d8e01a51443e367e60152bfe3c
MD5 8272f5810d1f3ae8cb6e8dea7b93370a
BLAKE2b-256 df2562a57531be7e1f32b739029c1bac731895e2e70e6a5bebaf063be8c71960

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp312-cp312-win32.whl.

File metadata

  • Download URL: drizzle-1.15.2-cp312-cp312-win32.whl
  • Upload date:
  • Size: 69.7 kB
  • Tags: CPython 3.12, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for drizzle-1.15.2-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 3e59b026365b0f6ca076e8801ded2e7aeb807dd32d928aef2cb513ffaeac855c
MD5 0cda4f4443d235683636b26535f2fa07
BLAKE2b-256 7e53045bf9b5679fda0b3524459192dde7455ae8de61b2a5dfd88a2d57c67322

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drizzle-1.15.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 80c66a157b922a025a03d7c725e23abc4bc763bc6b22db353c6f039734ae0cab
MD5 33002c2c5c7552288c41aee3ab9b1531
BLAKE2b-256 b0e2337786f46d5f1058a66a7933a98f4de89306c158cc45ce99a1196fdba27f

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drizzle-1.15.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a0b8f7a131344fd6712daa7a48add6d2995fdea3988ec195afa6241715fa4451
MD5 6ae620f1b0d428ae40d8b754e4c5005d
BLAKE2b-256 8dc18e44c78ba1bad694b418d220c52bd4cb449305dcda34d28b0b183ae852d0

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for drizzle-1.15.2-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5f85a2b1ce902b09db02fbd735f3e18faf446f34f9141a386efbd70c7d26bbf3
MD5 9e719ebf5702b9d21c38a5ea9ac5575b
BLAKE2b-256 2e17978a0050d3b0f30da38730ee663a2fb1c89aedf2dd3f8c04e7f6dc3fad2b

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: drizzle-1.15.2-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 78.2 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for drizzle-1.15.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 93ebe7e5e0d7241875bdef46d9511be20f6c9b0039466ff8caf6d93794fe66ed
MD5 a82ed4f3bed16997ee2b55c53afdc177
BLAKE2b-256 ba12fb207ed678d1d2ce26e06ee5926cdb021f2bb2116d39fecd5cd351cd5176

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp311-cp311-win32.whl.

File metadata

  • Download URL: drizzle-1.15.2-cp311-cp311-win32.whl
  • Upload date:
  • Size: 69.6 kB
  • Tags: CPython 3.11, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for drizzle-1.15.2-cp311-cp311-win32.whl
Algorithm Hash digest
SHA256 7063edb405d2784ac3ab1ff30d4e38c0386a0980176d3a44dd805d679605d3d5
MD5 baf2cee23916bb989253914fa83166b7
BLAKE2b-256 3e42cd3c7ca9c37394546c9d09584bd39f04fadca7683faa95e8b52a96002a68

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drizzle-1.15.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 395b4e6b5530d8e16a66893e4dfb58c27917c19c40451a5189ba9aa7f1b2ad29
MD5 3df178c3ec57927eb2831e9f1214be3b
BLAKE2b-256 a42db64412d9fc4a8da80f7213eec72cc136b506008e026a00747c4a1a2ba14d

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drizzle-1.15.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8fa0f48af3d4c646a1b6b184e6cbaa9af6f80fce3a827a434af0ecba46ca8079
MD5 74c6e345d6f5c544df5508e52da3bab4
BLAKE2b-256 e16e1292ba33fc7763728b82c7b6ab031ecefeabaa9dfdbc7a47eed2dab0254e

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for drizzle-1.15.2-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 2c1aa1478b8918795ae5bc0b9e2000556f67afd597d4332568bf56d02494c634
MD5 cf3116fd21813cfe1788d3f93de06a4e
BLAKE2b-256 629c6e70384328cac9c0fb16896bf66e38fbcce74037d27f15277b2d1f3e9cc5

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: drizzle-1.15.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 78.2 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for drizzle-1.15.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 bb8af4a69d47b5d3817f71ba23222e6f6eade41f6f5cdf4bde513780c7c6593b
MD5 4a5735aa4867d1803b00b525f62a4271
BLAKE2b-256 656510e541241b5f20314a055c683b925c5185a8f79309dd0d946180f5203ed1

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp310-cp310-win32.whl.

File metadata

  • Download URL: drizzle-1.15.2-cp310-cp310-win32.whl
  • Upload date:
  • Size: 69.6 kB
  • Tags: CPython 3.10, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for drizzle-1.15.2-cp310-cp310-win32.whl
Algorithm Hash digest
SHA256 b2c27af92eb400ace47c988b7bd32a60bf7d3f1b236137e22d5fac60b90137ef
MD5 f6abb240885d54e1d9908c96cf7cf1b8
BLAKE2b-256 4e76ae0806aab8423771c02325141f92b5b747f0ea39bfb2eef1bab5fb9bf495

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for drizzle-1.15.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 50996f5487c28f938a9048ba0ec4ab9b5f36c3c0d43aaf0b14dcf7fe3f15fe7b
MD5 ddc8627bacb2e45f4332e6a09d019029
BLAKE2b-256 1a36b71b5b0946d73cf202b1d2397100dcfbe54312a31f38b57084770f62706f

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for drizzle-1.15.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b4dfac28dbf7e98502e0df0e2414aee837cfb539766a8b1861942d04c0b15611
MD5 548ccb8c33bde915cdd053d13f802cd5
BLAKE2b-256 e8dd5e062a6b78baac08d506009af1f8c3a151dca2f18ceb4d17fa8cdcd7a461

See more details on using hashes here.

File details

Details for the file drizzle-1.15.2-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for drizzle-1.15.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7d003ad322e5651d1fa7f2dddbe2e9da6e48e94062f1bf7eaccdd726a3bce0e2
MD5 22ef4481a302cbab36a21c11599dbba3
BLAKE2b-256 453deba588644118bd280e791b1b382adb0b8698eb91aa27707509902b0e8ffc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page