image module

A module containing various methods for loading, saving and modifying images.

This module is designed to facilitate image processing. A class is provided that defines a custom AllSkyImage object that contains all necessary details about an image when it is loaded. This AllSkyImage object is used in all image processing methods throughout the other modules. Methods are provided to load and save an image in this format. Additional methods are provided to draw analysis objects on top of the images.

class image.AllSkyImage(name, date, camera, data)[source]

Bases: object

An all-sky image taken at a certain point in time.

name

The name of the image.

Type:str
date

The date on which the image was taken.

Type:str
camera

The camera used to take the image. Either KPNO for the all-sky camera at Kitt-Peak or MMTO for the all-sky camera at the MMT Observatory.

Type:str
data

The image data.

Type:numpy.ndarray
formatdate

The date and time the image was taken in yyyy-mm-dd hh:mm:ss format.

Type:str
time

The time at which the image was taken.

Type:astropy.time.Time
image.draw_celestial_horizon(img)[source]

Draw a path representing where the declination angle is zero.

Parameters:img (image.AllSkyImage) – The image.
Returns:img – A greyscale image with a pink path representing the celestial horizon.
Return type:image.AllSkyImage
image.draw_contours(img)[source]

Draw three angular contours on an image.

Contours will be drawn in lime green.

Parameters:img (image.AllSkyImage) – The image.
Returns:img – The image with contours drawn on top.
Return type:image.AllSkyImage

Notes

This method draws contours directly onto an image using matplotlib patches. These contours represent altitude angles of 0, 30, and 60 degrees up from the horizon. The returned image will be in the same color mode as the input image, i.e. if the input image is in RGB color, then the returned image will be also. If the input image is greyscale, then the returned image will be also.

image.draw_patch(img, patch)[source]

Draw a given patch on an image.

Patches will be drawn in lime green.

Parameters:
Returns:

img – The image with patches drawn on top.

Return type:

image.AllSkyImage

Notes

This method draws patches directly onto an image. The returned image will be in the same color mode as the input image, i.e. if the input image is in RGB color, then the returned image will be also. If the input image is greyscale, then the returned image will be also.

image.draw_square(x, y, img)[source]

Draw squares centered at the given coordinates.

Drawn squares will be cyan in color and will have a side length of 10 pixels.

Parameters:
  • x (array_like) – The x coordinates of the centers of each square.
  • y (array_like) – The x coordinates of the centers of each square.
  • img (image.AllSkyImage) – The image.
  • rgb (bool, optional) – If the returned image should be in RGB color or greyscale. Defaults to False, representing greyscale.
Returns:

img – The image with squares drawn on top.

Return type:

image.AllSkyImage

Notes

The returned image will be in the same color mode as the input image, i.e. if the input image is in RGB color, then the returned image will be also. If the input image is greyscale, then the returned image will be also.

image.get_exposure(img)[source]

Get the exposure time of an image.

Parameters:img (image.AllSkyImage) – The image.
Returns:The exposure time in seconds of the provided image. Possible values are 0.3, 0.02 or 6.
Return type:float or int

Notes

get_exposure works by looking at two specific pixels in an image taken on the KPNO camera. The first pixel is at (174, 19) in (x, y) coordinates, where (0, 0) is the top left corner of the image. This pixel appears as gray in images taken at 0.3s or 0.02s exposure times, but as black in images taken in 6s exposure times. In order to differentiate between 0.3s and 0.02s a second pixel at (119, 17) is used, which appears as gray in images taken at 0.02s exposure time but as black in images taken in 0.3s exposure time.

image.load_image(name, date, camera, mode='L')[source]

Load an image.

Parameters:
  • name (str) – The name of the image.
  • date (str) – The date on which the image was taken.
  • camera ({"KPNO", "MMTO", "SW"}) – The camera used to take the image. “KPNO” represents the all-sky camera at Kitt-Peak. “MMTO” represents the all-sky camera at the MMT Observatory. “SW” represents the spacewatch all-sky camera.
  • mode ({"L", "RGB", "RGBA"}, optional) – The color mode to load the image in. Defaults to “L” for greyscale. Use “RGB” for color and “RGBA” for color with an alpha layer.
Returns:

img – The image.

Return type:

image.AllSkyImage

image.save_image(img, location, cmap='gray')[source]

Save an image.

Save an image passed in img with the name img.name into the location in location. cmap provides an option to save the image in greyscale.

Parameters:
  • img (image.AllSkyImage) – The image.
  • location (str) – The relative path to save the image to. If the path does not exist, it is created.
  • cmap (str, optional) – A colormap to use when saving the image. Supports any matplotlib supported colormap. Defaults to “gray” to save in grayscale.

Notes

See https://matplotlib.org/tutorials/colors/colormaps.html for more detail on matplotlib colormaps.