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
HDUListobjectAn image HDU object such as a
PrimaryHDU,ImageHDU, orCompImageHDUinstanceA tuple where the first element is an
ndarrayand the second element is either aWCSor aHeaderobjectAn
NDDataobject from which the.dataand.wcsattributes will be used as the input data.
- output_projection
BaseLowLevelWCSorBaseHighLevelWCSorHeader The output projection, which can be either a
BaseLowLevelWCS,BaseHighLevelWCS, or aHeaderinstance.- shape_outtuple, optional
If
output_projectionis 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:The name of a FITS file
An
HDUListobjectAn image HDU object such as a
PrimaryHDU,ImageHDU, orCompImageHDUinstanceAn
ndarrayarray
- hdu_inint or str, optional
If one or more items in
input_datais a FITS file or anHDUListinstance, specifies the HDU to use.- hdu_weightsint or str, optional
If one or more items in
input_weightsis a FITS file or anHDUListinstance, 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 withreturn_type='numpy'it cannot be computed on the fly, so all the reprojected arrays are kept until the end (as formatch_background;intermediate_memmapcan be used to keep them on disk).- match_backgroundbool
Whether to match the backgrounds of the images. Only supported with
return_type='numpy'.- background_reference
Noneorint 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_outor derived from the output projection. Can only be specified withreturn_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_outor derived from the output projection. Can only be specified withreturn_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_interpdocumentation 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 toreproject_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, usenumpy.memmapto 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 withmatch_background=True. Only supported withreturn_type='numpy'.- return_type{None, ‘numpy’, ‘dask’, ‘zarr’}, optional
If
'dask', reproject each image lazily (usingreturn_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 thereturn_type='numpy'path exactly (footprint-weighted for ‘mean’ and ‘sum’, footprint-aware selection for ‘first’, ‘last’, ‘min’ and ‘max’), andinput_weightsare supported. Acombine_functionof ‘median’ is available as an unweighted median.match_background,output_array,output_footprintandintermediate_memmapare 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 atzarr_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 theparallelkeyword, with the same semantics as for the individual reprojection functions ('current-scheduler'to use the active scheduler, an integer for that many threads,Truefor the default number of threads andFalseto compute synchronously).- **kwargs
Keyword arguments to be passed to the reprojection function.
- Returns:
- array
ndarrayorArray The co-added array. This is an uncomputed dask array when
return_type='dask', and a dask array reading from the computed zarr store whenreturn_type='zarr'.- footprint
ndarrayorArray 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'.
- array