Image¶
- class sofia_redux.scan.source_models.maps.image.Image(data=None, blanking_value=None, dtype=<class 'float'>, shape=None, unit=None)[source]¶
Bases:
FitsDataCreates an Image instance.
This class is an extension of the
FitsDataclass 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
dtypeparameter.- 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
datais not defined.- unitstr or units.Unit or units.Quantity, optional
The data unit.
Methods Summary
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.
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 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
- 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_rangeabout thecenter_index. The coordinates (x, y) are the projected coordinates of the image map indices onto the grid, and (x_0, y_0) is thecenter_indexprojected 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
gridunits) aboutcenter_indexon 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
gridunits) aboutcenter_indexon 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
Falseexcludes 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
gridunits) aboutcenter_indexon which to base the asymmetry calculation.
- Returns:
- asymmetry, asymmetry_rmsfloat, float
The asymmetry and asymmetry RMS.
- 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
- 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
hdulto read.
- Returns:
- imageImage