io_util module¶
A module providing facilities for loading, saving, and downloading
Methods are provided for downloading and saving images taken at two different all-sky cameras. These cameras are located at Kitt Peak, designated KPNO, and at the Multiple Mirror Telescope Observatory, designated MMTO. One class is provided to read the raw HTML provided by each camera”s website.
-
class
io_util.DateHTMLParser[source]¶ Bases:
html.parser.HTMLParserParser for data passed from image websites.
-
io_util.download_all_date(date, camera='kpno')[source]¶ Download all images for a given date and all-sky camera.
Parameters: - date (str) – Date to download images for, in yyyymmdd format.
- camera (str, optional) – Camera to download images from. Defaults to kpno (the all-sky camera at Kitt-Peak) but may be specified instead as mmto (the all-sky camera at the MMT Observatory) or sw (the all-sky camera at the Spacewatch collaboration).
See also
download_image()- Images are downloaded using download_image.
Notes
Over the course of the run time of this method various status updates will be printed. The method will exit early with a print out of what happened.
Images will be saved to Images/Original/camera/date/.
The Kitt-Peak National Observatory images are located at http://kpasca-archives.tuc.noao.edu/.
The MMT Observatory images are located at http://skycam.mmto.arizona.edu/skycam/.
The Spacewatch images are located at http://varuna.kpno.noao.edu/allsky-all/images/cropped/.
-
io_util.download_image(date, image, camera='kpno', directory=None)[source]¶ Download a single image.
This method is of a similar form to download_all_date, where date provides the date and camera provides the camera. image is the name of the image to be downloaded.
Parameters: - date (str) – Date to download images for, in the form yyyymmdd.
- image (str) – Image name to download.
- camera (str, optional) – Camera to download images from. Defaults to kpno (the all-sky camera at Kitt-Peak) but may be specified instead as mmto (the all-sky camera at the MMT Observatory) or sw (the all-sky camera at the Spacewatch collaboration).
- directory (str, optional) – The directory to save the downloaded image to. Defaults to Images/Original/camera.upper()/date.
Notes
Over the course of the run time of this method various status updates will be printed. The method will exit early and fail to download the image with a failure print out.
The Kitt-Peak National Observatory images are located at http://kpasca-archives.tuc.noao.edu/.
The MMT Observatory images are located at http://skycam.mmto.arizona.edu/skycam/.
The Spacewatch images are located at http://varuna.kpno.noao.edu/allsky-all/images/cropped/.
-
io_util.download_url(link)[source]¶ Read the data at a url.
Parameters: link (str) – The link to access and download data from. Returns: A requests.Response object containing data on success, or None on failure. Return type: requests.Response or None
-
io_util.gray_and_color_image(file)[source]¶ Load an image in both grayscale and color.
Load an image and return an image where each pixel is represented by a four item list, of the form [L, R, G, B] where L is the luma grayscale value.
Parameters: file (str) – The location of the image to be read. Returns: The ndarray representing the grayscale and color combination image. Return type: numpy.ndarray See also
PIL.Image.Image.convert()- For more details on the ITU-R 601-2 luma grayscale transform used by this method.
Notes
The Pillow documentation includes the following definition of the ITU-R 601-2 luma grayscale transform:
L = R * 299/1000 + G * 587/1000 + B * 114/1000
-
io_util.image_diff(img1, img2)[source]¶ Find the mathematical difference between two grayscale images.
Parameters: - img1 (numpy.ndarray) – The first image.
- img2 (numpy.ndarray) – The second image.
Returns: The difference image.
Return type: Notes
The order of the parameters does not matter. In essence, image_diff(img1, img2) == image_diff(img2, img1).
Greyscale values in the returned image represent the difference between the images. Black means the pixels were identical in both images, whereas white represents the maximum difference between the two, where in one image the pixel is white and in one it is black.
-
io_util.load_all_date(date, camera='KPNO')[source]¶ Load all images for a given date.
Parameters: - date (str) – The date in yyyymmdd format.
- camera ({"KPNO", "SW"}) – The camera used to take the image. “KPNO” represents the all-sky camera at Kitt-Peak. “SW” represents the spacewatch all-sky camera.
Returns: An
ndarraythat contains all images for that date.ndarrayis of the shape (512, 512, 4, N) where N is the number of images for that day.Return type: See also
gray_and_color_image()- Method used to load images.