reproject_and_coadd#

reproject.mosaicking.reproject_and_coadd(input_data, output_projection, shape_out=None, input_weights=None, hdu_in=None, hdu_weights=None, reproject_function=None, combine_function='mean', match_background=False, background_reference=None, output_array=None, output_footprint=None, block_sizes=None, non_reprojected_dims=None, progress_bar=None, blank_pixel_value=0, intermediate_memmap=False, return_type=None, zarr_path=None, zarr_batch_size=None, **kwargs)[source]#

Given a set of input data, reproject and co-add these to a single final image.

Parameters:
input_dataiterable

One or more input datasets to reproject and co-add. This should be an iterable containing one entry for each dataset, where a single dataset is one of:

  • The name of a FITS file

  • An HDUList object

  • An image HDU object such as a PrimaryHDU, ImageHDU, or CompImageHDU instance

  • A tuple where the first element is an ndarray and the second element is either a WCS or a Header object

  • An NDData object from which the .data and .wcs attributes will be used as the input data.

output_projectionBaseLowLevelWCS or BaseHighLevelWCS or Header

The output projection, which can be either a BaseLowLevelWCS, BaseHighLevelWCS, or a Header instance.

shape_outtuple, optional

If output_projection is a WCS instance, the shape of the output data should be specified separately.

input_weightsiterable

If specified, this should be an iterable with the same length as input_data, where each item is one of:

hdu_inint or str, optional

If one or more items in input_data is a FITS file or an HDUList instance, specifies the HDU to use.

hdu_weightsint or str, optional

If one or more items in input_weights is a FITS file or an HDUList instance, specifies the HDU to use.

reproject_functioncallable

The function to use for the reprojection.

combine_function{ ‘mean’, ‘sum’, ‘first’, ‘last’, ‘min’, ‘max’, ‘median’ }

The type of function to use for combining the values into the final image. For ‘first’ and ‘last’, respectively, the reprojected images are simply overlaid on top of each other. With respect to the order of the input images in input_data, either the first or the last image to cover a region of overlap determines the output data for that region. The median is unweighted, and with return_type='numpy' it cannot be computed on the fly, so all the reprojected arrays are kept until the end (as for match_background; intermediate_memmap can be used to keep them on disk).

match_backgroundbool

Whether to match the backgrounds of the images. Only supported with return_type='numpy'.

background_referenceNone or int

If None, the background matching will make it so that the average of the corrections for all images is zero. If an integer, this specifies the index of the image to use as a reference.

output_arrayarray or None

The final output array. Specify this if you already have an appropriately-shaped array to store the data in. Must match shape specified with shape_out or derived from the output projection. Can only be specified with return_type='numpy'.

output_footprintarray or None

The final output footprint array. Specify this if you already have an appropriately-shaped array to store the data in. Must match shape specified with shape_out or derived from the output projection. Can only be specified with return_type='numpy'.

block_sizeslist of tuples or None

The block size to use for each dataset. Could also be a single tuple if you want the same block size for all data sets. With return_type='dask', a single common block size is also used as the chunking of the returned dask arrays.

non_reprojected_dimstuple, optional

Leading dimensions of the data that should not be reprojected but for which a one-to-one mapping between input and output pixels is assumed (see the reproject_interp documentation for details). This makes it possible to co-add cubes where the input and output WCS have the same number of dimensions as the data, broadcasting the co-addition over these dimensions. It is passed through to reproject_function.

progress_barcallable, optional

If specified, use this as a progress_bar to track loop iterations over data sets.

blank_pixel_valuefloat, optional

Value to use for areas of the resulting mosaic that do not have input data.

intermediate_memmap{‘False’, ‘True’, ‘zarr’}, optional

If True, use numpy.memmap to store intermediate reprojected arrays on disk. If 'zarr', store the intermediate arrays as zarr arrays on disk instead, which is typically more efficient (each image is then reprojected in blocks and the zarr store is removed once the image has been combined), but cannot be used together with match_background=True. Only supported with return_type='numpy'.

return_type{None, ‘numpy’, ‘dask’, ‘zarr’}, optional

If 'dask', reproject each image lazily (using return_type='dask' on the reprojection function) and assemble each chunk of the output from the images that overlap it, returning the resulting uncomputed dask arrays so the whole co-addition is computed lazily in one go. The combination matches the return_type='numpy' path exactly (footprint-weighted for ‘mean’ and ‘sum’, footprint-aware selection for ‘first’, ‘last’, ‘min’ and ‘max’), and input_weights are supported. A combine_function of ‘median’ is available as an unweighted median. match_background, output_array, output_footprint and intermediate_memmap are not supported, since the result is an uncomputed graph rather than arrays filled in place. If 'zarr', build the same graphs as 'dask' but compute them here, batch by batch along the first dimension, into a zarr store at zarr_path, returning dask arrays that read from the store. This bounds the memory used by the computation to one batch regardless of the size of the mosaic, at the cost of recomputing reprojected chunks of images that span a batch boundary, and the restrictions of 'dask' apply. The default (None) is equivalent to 'numpy'.

zarr_pathstr, optional

The path at which to create the zarr store when return_type='zarr'. The path must not already exist. The store is created as a group with 'array' and 'footprint' arrays.

zarr_batch_sizeint, optional

The number of output chunks to compute per batch when return_type='zarr', iterating over the output chunks in C order. The default picks a batch size such that one batch of the output is around 2 GB. The batches are computed with the scheduler implied by the parallel keyword, with the same semantics as for the individual reprojection functions ('current-scheduler' to use the active scheduler, an integer for that many threads, True for the default number of threads and False to compute synchronously).

**kwargs

Keyword arguments to be passed to the reprojection function.

Returns:
arrayndarray or Array

The co-added array. This is an uncomputed dask array when return_type='dask', and a dask array reading from the computed zarr store when return_type='zarr'.

footprintndarray or Array

Footprint of the co-added array. Values of 0 indicate no coverage or valid values in the input image, while values of 1 indicate valid values. This is an uncomputed dask array when return_type='dask'.