skyimage

The skyimage module contains algorithms that are used by skymatch to manage all of the information for footprints (image outlines) on the sky as well as perform useful operations on these outlines such as computing intersections and statistics in the overlap regions.

class romancal.skymatch.skyimage.DataAccessor[source]

Base class for all data accessors. Provides a common interface to access data.

abstract get_data()[source]
abstract get_data_shape()[source]
abstract set_data(data)[source]

Sets data.

Parameters:

data (numpy.ndarray) – Data array to be set.

class romancal.skymatch.skyimage.NDArrayInMemoryAccessor(data)[source]

Acessor for in-memory numpy.ndarray data.

get_data()[source]
get_data_shape()[source]
set_data(data)[source]

Sets data.

Parameters:

data (numpy.ndarray) – Data array to be set.

class romancal.skymatch.skyimage.NDArrayMappedAccessor(data, tmpfile=None, prefix='tmp_skymatch_', suffix='.npy', tmpdir='')[source]

Data accessor for arrays stored in temporary files.

get_data()[source]
get_data_shape()[source]
set_data(data)[source]

Sets data.

Parameters:

data (numpy.ndarray) – Data array to be set.

class romancal.skymatch.skyimage.SkyGroup(images, id=None, sky=0.0)[source]

Holds multiple SkyImage objects whose sky background values must be adjusted together.

SkyGroup provides methods for obtaining bounding polygon of the group of SkyImage objects and to compute sky value of the group.

append(value)[source]

Appends a SkyImage to the group.

calc_sky(overlap=None, delta=True)[source]

Compute sky background value.

Parameters:
  • overlap (SkyImage, SkyGroup, SphericalPolygon, list of tuples, None, optional) – Another SkyImage, SkyGroup, spherical_geometry.polygons.SphericalPolygon, or a list of tuples of (RA, DEC) of vertices of a spherical polygon. This parameter is used to indicate that sky statistics should computed only in the region of intersection of this image with the polygon indicated by overlap. When overlap is None, sky statistics will be computed over the entire image.

  • delta (bool, optional) – Should this function return absolute sky value or the difference between the computed value and the value of the sky stored in the sky property.

Returns:

  • skyval (float, None) – Computed sky value (absolute or relative to the sky attribute). If there are no valid data to perform this computations (e.g., because this image does not overlap with the image indicated by overlap), skyval will be set to None.

  • npix (int) – Number of pixels used to compute sky statistics.

  • polyarea (float) – Area (in srad) of the polygon that bounds data used to compute sky statistics.

property id

Set or get SkyImage’s id.

While id can be of any type, it is preferable that id be of a type with nice string representation.

insert(idx, value)[source]

Inserts a SkyImage into the group.

intersection(skyimage)[source]

Compute intersection of this SkyImage object and another SkyImage, SkyGroup, or SphericalPolygon object.

Parameters:

skyimage (SkyImage, SkyGroup, SphericalPolygon) – Another object that should be intersected with this SkyImage.

Returns:

intersect_poly – A SphericalPolygon that is the intersection of this SkyImage and skyimage.

Return type:

SphericalPolygon

property polygon

Get image’s bounding polygon.

property radec

Get RA and DEC of the vertices of the bounding polygon as a ndarray of shape (N, 2) where N is the number of vertices + 1.

property sky

Sky background value. See calc_sky for more details.

class romancal.skymatch.skyimage.SkyImage(image, wcs_fwd, wcs_inv, pix_area=1.0, convf=1.0, mask=None, id=None, skystat=None, stepsize=None, meta=None, reduce_memory_usage=True)[source]

Container that holds information about properties of a single image such as:

  • image data;

  • WCS of the chip image;

  • bounding spherical polygon;

  • id;

  • pixel area;

  • sky background value;

  • sky statistics parameters;

  • mask associated image data indicating “good” (1) data.

Initializes the SkyImage object.

Parameters:
  • image (numpy.ndarray, NDArrayDataAccessor) – A 2D array of image data or a NDArrayDataAccessor.

  • wcs_fwd (function) – “forward” pixel-to-world transformation function.

  • wcs_inv (function) – “inverse” world-to-pixel transformation function.

  • pix_area (float, optional) – Average pixel’s sky area.

  • convf (float, optional) –

    Conversion factor that when multiplied to image data converts the data to “uniform” (across multiple images) surface brightness units.

    Note

    The functionality to support this conversion is not yet implemented and at this moment convf is ignored.

  • mask (numpy.ndarray, NDArrayDataAccessor) – A 2D array or NDArrayDataAccessor of a 2D array that indicates which pixels in the input image should be used for sky computations (1) and which pixels should not be used for sky computations (0).

  • id (anything) – The value of this parameter is simply stored within the SkyImage object. While it can be of any type, it is preferable that id be of a type with nice string representation.

  • skystat (callable, None, optional) –

    A callable object that takes a either a 2D image (2D numpy.ndarray) or a list of pixel values (an Nx1 array) and returns a tuple of two values: some statistics (e.g., mean, median, etc.) and number of pixels/values from the input image used in computing that statistics.

    When skystat is not set, SkyImage will use SkyStats object to perform sky statistics on image data.

  • stepsize (int, None, optional) – Spacing between vertices of the image’s bounding polygon. Default value of None creates bounding polygons with four vertices corresponding to the corners of the image.

  • meta (dict, None, optional) – A dictionary of various items to be stored within the SkyImage object.

  • reduce_memory_usage (bool, optional) – Indicates whether to attempt to minimize memory usage by attaching input image and/or mask numpy.ndarray arrays to file-mapped accessor. This has no effect when input parameters image and/or mask are already of NDArrayDataAccessor objects.

calc_bounding_polygon(stepsize=None)[source]

Compute image’s bounding polygon.

Parameters:

stepsize (int, None, optional) – Indicates the maximum separation between two adjacent vertices of the bounding polygon along each side of the image. Corners of the image are included automatically. If stepsize is None, bounding polygon will contain only vertices of the image.

calc_sky(overlap=None, delta=True)[source]

Compute sky background value.

Parameters:
  • overlap (SkyImage, SkyGroup, SphericalPolygon, list of tuples, None, optional) – Another SkyImage, SkyGroup, spherical_geometry.polygons.SphericalPolygon, or a list of tuples of (RA, DEC) of vertices of a spherical polygon. This parameter is used to indicate that sky statistics should computed only in the region of intersection of this image with the polygon indicated by overlap. When overlap is None, sky statistics will be computed over the entire image.

  • delta (bool, optional) – Should this function return absolute sky value or the difference between the computed value and the value of the sky stored in the sky property.

Returns:

  • skyval (float, None) – Computed sky value (absolute or relative to the sky attribute). If there are no valid data to perform this computations (e.g., because this image does not overlap with the image indicated by overlap), skyval will be set to None.

  • npix (int) – Number of pixels used to compute sky statistics.

  • polyarea (float) – Area (in srad) of the polygon that bounds data used to compute sky statistics.

copy()[source]

Return a shallow copy of the SkyImage object.

property id

Set or get SkyImage’s id.

While id can be of any type, it is preferable that id be of a type with nice string representation.

property image

Set or get SkyImage’s image data array.

property image_shape

Get SkyImage’s image data shape.

intersection(skyimage)[source]

Compute intersection of this SkyImage object and another SkyImage, SkyGroup, or SphericalPolygon object.

Parameters:

skyimage (SkyImage, SkyGroup, SphericalPolygon) – Another object that should be intersected with this SkyImage.

Returns:

polygon – A SphericalPolygon that is the intersection of this SkyImage and skyimage.

Return type:

SphericalPolygon

property is_sky_valid

Indicates whether sky value was successfully computed. Must be set externally.

property mask

Set or get SkyImage’s mask data array or None.

property pix_area

Set or get mean pixel area.

property poly_area

Get bounding polygon area in srad units.

property polygon

Get image’s bounding polygon.

property radec

Get RA and DEC of the vertices of the bounding polygon as a ndarray of shape (N, 2) where N is the number of vertices + 1.

set_builtin_skystat(skystat='median', lower=None, upper=None, nclip=5, lsigma=4.0, usigma=4.0, binwidth=0.1)[source]

Replace already set skystat with a “built-in” version of a statistics callable object used to measure sky background.

See SkyStats for the parameter description.

property sky

Sky background value. See calc_sky for more details.

property skystat

Stores/retrieves a callable object that takes a either a 2D image (2D numpy.ndarray) or a list of pixel values (an Nx1 array) and returns a tuple of two values: some statistics (e.g., mean, median, etc.) and number of pixels/values from the input image used in computing that statistics.

When skystat is not set, SkyImage will use SkyStats object to perform sky statistics on image data.