ASDFCutout

class astrocut.ASDFCutout(input_files: List[Union[str, Path, S3Path]], coordinates: Union[SkyCoord, str], cutout_size: Union[int, ndarray, Quantity, List[int], Tuple[int]] = 25, fill_value: Union[int, float] = nan, key: Optional[str] = None, secret: Optional[str] = None, token: Optional[str] = None, verbose: bool = False)[source]

Bases: ImageCutout

Class for creating cutouts from ASDF files.

Parameters
input_fileslist

List of input image files.

coordinatesstr | SkyCoord

Coordinates of the center of the cutout.

cutout_sizeint | array | list | tuple | Quantity

Size of the cutout array.

fill_valueint | float

Value to fill the cutout with if the cutout is outside the image.

keystr

Optional, default None. Access key ID for S3 file system.

secretstr

Optional, default None. Secret access key for S3 file system.

tokenstr

Optional, default None. Security token for S3 file system.

verbosebool

If True, log messages are printed to the console.

Attributes
cutoutslist

The cutouts as a list of astropy.nddata.Cutout2D objects.

cutouts_by_filedict

The cutouts as astropy.nddata.Cutout2D objects stored by input filename.

fits_cutoutslist

Return the cutouts as a list astropy.io.fits.HDUList objects.

asdf_cutoutslist

Return the cutouts as a list of asdf.AsdfFile objects.

image_cutoutslist

Return the cutouts as a list of PIL.Image objects.

Methods

cutout()

Generate cutouts from a list of input images.

write_as_fits(output_dir)

Write the cutouts to disk or memory in FITS format.

write_as_asdf(output_dir)

Write the cutouts to disk or memory in ASDF format.

Attributes Summary

asdf_cutouts

Return the cutouts as a list of asdf.AsdfFile objects.

fits_cutouts

Return the cutouts as a list astropy.io.fits.HDUList objects.

image_cutouts

Return the cutouts as a list of PIL.Image objects.

Methods Summary

cutout()

Generate cutouts from a list of input images.

get_image_cutouts([stretch, minmax_percent, ...])

Get the cutouts as Image objects given certain normalization parameters.

normalize_img(img_arr[, stretch, ...])

Apply given stretch and scaling to an image array.

write_as_asdf([output_dir])

Write the cutouts to disk or memory in ASDF format.

write_as_fits([output_dir])

Write the cutouts to disk or memory in FITS format.

write_as_img([stretch, minmax_percent, ...])

Write the cutout to memory or to a file in an image format.

Attributes Documentation

asdf_cutouts

Return the cutouts as a list of asdf.AsdfFile objects.

fits_cutouts

Return the cutouts as a list astropy.io.fits.HDUList objects.

image_cutouts

Return the cutouts as a list of PIL.Image objects.

If the image objects have not been generated yet, they will be generated with default normalization parameters.

Methods Documentation

cutout() Union[str, List[str], List[HDUList]][source]

Generate cutouts from a list of input images.

Returns
cutout_pathPath | list

Cutouts as memory objects or path(s) to the written cutout files.

Raises
InvalidQueryError

If no cutouts contain data.

get_image_cutouts(stretch: Optional[str] = 'asinh', minmax_percent: Optional[List[int]] = None, minmax_value: Optional[List[int]] = None, invert: Optional[bool] = False, colorize: Optional[bool] = False) List[Image]

Get the cutouts as Image objects given certain normalization parameters. This method also sets the image_cutouts attribute.

Parameters
stretchstr

Optional, default ‘asinh’. The stretch to apply to the image array. Valid values are: asinh, sinh, sqrt, log, linear

minmax_percentarray

Optional. Interval based on a keeping a specified fraction of pixels (can be asymmetric) when scaling the image. The format is [lower percentile, upper percentile], where pixel values below the lower percentile and above the upper percentile are clipped. Only one of minmax_percent and minmax_value should be specified.

minmax_valuearray

Optional. Interval based on user-specified pixel values when scaling the image. The format is [min value, max value], where pixel values below the min value and above the max value are clipped. Only one of minmax_percent and minmax_value should be specified.

invertbool

Optional, default False. If True the image is inverted (light pixels become dark and vice versa).

colorizebool

Optional, default False. If True, the first three cutouts will be combined into a single RGB image.

Returns
image_cutoutslist

List of Image objects representing the cutouts.

static normalize_img(img_arr: ndarray, stretch: str = 'asinh', minmax_percent: Optional[List[int]] = None, minmax_value: Optional[List[int]] = None, invert: bool = False) ndarray

Apply given stretch and scaling to an image array.

Parameters
img_arrarray

The input image array.

stretchstr

Optional, default ‘asinh’. The stretch to apply to the image array. Valid values are: asinh, sinh, sqrt, log, linear

minmax_percentarray

Optional. Interval based on a keeping a specified fraction of pixels (can be asymmetric) when scaling the image. The format is [lower percentile, upper percentile], where pixel values below the lower percentile and above the upper percentile are clipped. Only one of minmax_percent and minmax_value shoul be specified.

minmax_valuearray

Optional. Interval based on user-specified pixel values when scaling the image. The format is [min value, max value], where pixel values below the min value and above the max value are clipped. Only one of minmax_percent and minmax_value should be specified.

invertbool

Optional, default False. If True the image is inverted (light pixels become dark and vice versa).

Returns
responsearray

The normalized image array, in the form in an integer arrays with values in the range 0-255.

Raises
InvalidInputError

If the stretch is not supported.

write_as_asdf(output_dir: Union[str, Path] = '.') List[str][source]

Write the cutouts to disk or memory in ASDF format.

Parameters
output_dirstr | Path

The output directory to write the cutouts to. Defaults to the current directory.

Returns
list

A list of paths to the cutout ASDF files.

write_as_fits(output_dir: Union[str, Path] = '.') List[str][source]

Write the cutouts to disk or memory in FITS format.

Parameters
output_dirstr | Path

The output directory to write the cutouts to. Defaults to the current directory.

Returns
list

A list of paths to the cutout FITS files.

write_as_img(stretch: Optional[str] = 'asinh', minmax_percent: Optional[List[int]] = None, minmax_value: Optional[List[int]] = None, invert: Optional[bool] = False, colorize: Optional[bool] = False, output_format: str = '.jpg', output_dir: Union[str, Path] = '.', cutout_prefix: str = 'cutout') Union[str, List[str]]

Write the cutout to memory or to a file in an image format. If colorize is set, the first 3 cutouts will be combined into a single RGB image. Otherwise, each cutout will be written to a separate file.

Parameters
stretchstr

Optional, default ‘asinh’. The stretch to apply to the image array. Valid values are: asinh, sinh, sqrt, log, linear

minmax_percentarray

Optional. Interval based on a keeping a specified fraction of pixels (can be asymmetric) when scaling the image. The format is [lower percentile, upper percentile], where pixel values below the lower percentile and above the upper percentile are clipped. Only one of minmax_percent and minmax_value shoul be specified.

minmax_valuearray

Optional. Interval based on user-specified pixel values when scaling the image. The format is [min value, max value], where pixel values below the min value and above the max value are clipped. Only one of minmax_percent and minmax_value should be specified.

invertbool

Optional, default False. If True the image is inverted (light pixels become dark and vice versa).

colorizebool

Optional, default False. If True, the first three cutouts will be combined into a single RGB image.

output_formatstr

Optional, default ‘.jpg’. The output format for the cutout image(s).

output_dirstr | Path

Optional, default ‘.’. The directory to write the cutout image(s) to.

cutout_prefixstr

Optional, default ‘cutout’. The prefix to add to the cutout image file name.

Returns
cutout_pathList[Path]

Path(s) to the written cutout files.

Raises
InvalidInputError

If less than three inputs were provided for a colorized cutout.