Image

class sofia_redux.scan.source_models.maps.image.Image(data=None, blanking_value=None, dtype=<class 'float'>, shape=None, unit=None)[source]

Bases: FitsData

Creates an Image instance.

This class is an extension of the FitsData class and is used to provide additional handling for FITS image HDUs.

Parameters:
datanumpy.ndarray, optional

Data to initialize the flagged array with. If supplied, sets the shape of the array. Note that the data type will be set to that defined by the dtype parameter.

blanking_valueint or float, optional

The blanking value defines invalid values in the data array. This is the equivalent of defining a NaN value.

dtypetype, optional

The data type of the data array.

shapetuple (int), optional

The shape of the data array. This will only be relevant if data is not defined.

unitstr or units.Unit or units.Quantity, optional

The data unit.

Methods Summary

auto_crop()

Auto crop the image data.

copy([with_contents])

Return a copy of the image.

crop(ranges)

Crop the image to the required dimensions.

destroy()

Destroy the image data.

edit_header(header)

Edit a FITS header using information in the current map.

get_asymmetry(grid, center_index, angle, ...)

Return the Asymmetry.

get_asymmetry_2d(grid, center_index, angle, ...)

Return the 2-D asymmetry.

get_data_asymmetry(data, valid, grid, ...)

Return the asymmetry for the given data.

get_id()

Return the image ID.

get_image([dtype, blanking_value])

Return an image copy, optionally changing type and blanking value.

get_valid_data([default])

Return a copy of the image data, optionally replacing invalid points.

new_image()

Return a new image.

parse_header(header)

Parse a FITS header and apply to the image.

read_hdu(image_hdu)

Read and apply an HDU.

read_hdul(hdul, hdu_index)

Read a specific HDU image from an HDU list, and return an image.

renew()

Renew the image by clearing all data.

set_data(data[, change_type])

Set the image data array.

set_id(image_id)

Set the image ID.

transpose()

Transpose the data array.

Methods Documentation

auto_crop()[source]

Auto crop the image data.

The data is cropped to the extent of valid data point indices.

Returns:
None
copy(with_contents=True)[source]

Return a copy of the image.

Parameters:
with_contentsbool, optional

If True, paste the contents of this image onto the new one.

Returns:
Image
crop(ranges)[source]

Crop the image to the required dimensions.

Parameters:
rangesnumpy.ndarray (int,)

The ranges to set crop the data to. Should be of shape (n_dimensions, 2) where ranges[0, 0] would give the minimum crop limit for the first dimension and ranges[0, 1] would give the maximum crop limit for the first dimension. In this case, the ‘first’ dimension is in numpy format. i.e., (y, x) for a 2-D array. Also note that the upper crop limit is inclusive so a range of (0, 3) includes indices [0, 1, 2, 3].

Returns:
None
destroy()[source]

Destroy the image data.

Returns:
None
edit_header(header)[source]

Edit a FITS header using information in the current map.

Parameters:
headerastropy.io.fits.header.Header
Returns:
None
get_asymmetry(grid, center_index, angle, radial_range)[source]

Return the Asymmetry.

The asymmetry and rms are calculated via:

asymmetry = sum(d * c) / sum(|d|)
rms = sum(|c|) / sum(|d|)

where:

c = cos(arctan2(dy, dx) - angle)
dx = x - x_0
dy = y - y_0

The sum occurs over all points within the provided radial_range about the center_index. The coordinates (x, y) are the projected coordinates of the image map indices onto the grid, and (x_0, y_0) is the center_index projected onto the same grid. The data values d are the image data values.

Parameters:
gridGrid2D

The grid used to convert image pixel locations to the coordinate system in which to calculate the asymmetry.

center_indexCoordinate2D

The center index on the image (x_pix, y_pix) from which to calculate the asymmetry.

angleunits.Quantity

The rotation of the image with respect to the asymmetry,

radial_rangeRange

The range (in grid units) about center_index on which to base the asymmetry calculation.

Returns:
asymmetry, asymmetry_rmsfloat, float

The asymmetry and asymmetry RMS.

get_asymmetry_2d(grid, center_index, angle, radial_range)[source]

Return the 2-D asymmetry.

Calculates the asymmetry in both the x and y directions. The y asymmetry values are calculated by applying an addition rotation of 90 degrees to supplied angle during the asymmetry derivation.

Parameters:
gridGrid2D

The grid used to convert image pixel locations to the coordinate system in which to calculate the asymmetry.

center_indexCoordinate2D

The center index on the image (x_pix, y_pix) from which to calculate the asymmetry.

angleunits.Quantity

The rotation of the image with respect to the asymmetry,

radial_rangeRange

The range (in grid units) about center_index on which to base the asymmetry calculation.

Returns:
asymmetryAsymmetry2D
static get_data_asymmetry(data, valid, grid, center_index, angle, radial_range)[source]

Return the asymmetry for the given data.

Parameters:
datanumpy.ndarray (float)

The 2-D data for which to calculate the asymmetry of shape (ny, nx)

validnumpy.ndarray (bool)

A mask for the data of shape (ny, nx) where False excludes any given element from inclusion in the calculation.

gridGrid2D

The grid used to convert image pixel locations to the coordinate system in which to calculate the asymmetry.

center_indexCoordinate2D

The center index on the image (x_pix, y_pix) from which to calculate the asymmetry.

angleunits.Quantity

The rotation of the image with respect to the asymmetry,

radial_rangeRange

The range (in grid units) about center_index on which to base the asymmetry calculation.

Returns:
asymmetry, asymmetry_rmsfloat, float

The asymmetry and asymmetry RMS.

get_id()[source]

Return the image ID.

Returns:
image_idstr
get_image(dtype=None, blanking_value=None)[source]

Return an image copy, optionally changing type and blanking value.

Parameters:
dtypetype, optional

The image data type.

blanking_valueint or float, optional

The new image blanking value.

Returns:
imageImage
get_valid_data(default=None)[source]

Return a copy of the image data, optionally replacing invalid points.

Parameters:
defaultint or float, optional

The value to replace blanked values with.

Returns:
numpy.ndarray or None
new_image()[source]

Return a new image.

Returns:
imageImage
parse_header(header)[source]

Parse a FITS header and apply to the image.

Parameters:
headerastropy.io.fits.header.Header

The FITS header to parse.

Returns:
None
read_hdu(image_hdu)[source]

Read and apply an HDU.

Parameters:
image_hduastropy.io.fits.hdu.image.ImageHDU

The image HDU to read and apply.

Returns:
None
classmethod read_hdul(hdul, hdu_index)[source]

Read a specific HDU image from an HDU list, and return an image.

Parameters:
hdulastropy.io.fits.hdu.hdulist.HDUList

The HDU list to read.

hdu_indexint

The index of the HDU in the provided hdul to read.

Returns:
imageImage
renew()[source]

Renew the image by clearing all data.

Returns:
None
set_data(data, change_type=False)[source]

Set the image data array.

Parameters:
datanumpy.ndarray or FlaggedArray

A 2-dimensional image array.

change_typebool, optional

If True, change the data type to that of the data.

Returns:
None
set_id(image_id)[source]

Set the image ID.

Parameters:
image_idstr
Returns:
None
transpose()[source]

Transpose the data array.

Returns:
None