asi_core.camera

This module provides functionality for all-sky imagers.

Attributes

CAMERA_DATA_FILE

CAMERA_DATA_SCHEMA

Classes

AllSkyImager

RadiometricImager

GenericImager

A generic version of RadiometricImager which can be used for cameras with unknown properties.

Functions

load_camera_data([camera_data_file, camera_data_dir, ...])

Load data corresponding to available all-sky imagers.

load_camera_mask(mask_file[, struct_name, allow_failure])

Load a camera mask as numpy array from a mat file.

load_celestial_coordinate_masks(mask_file[, ...])

Load elevation and azimuth masks from a mat file.

get_camera_location(camera_name)

Get geolocation based on camera name from camera config.

Module Contents

asi_core.camera.CAMERA_DATA_FILE
asi_core.camera.CAMERA_DATA_SCHEMA
class asi_core.camera.AllSkyImager(camera_data, camera_id=None, image_path=None, tfms=None)
img_paths_buffer
tolerance_timestamp
rel_exp_tol = 0.1

Class for All-Sky Imagers.

id = None
name
latitude
longitude
altitude
img_timezone
start_recording
end_recording
external_orientation
min_ele_evaluated
ocam_model
height
width
resize
crop
crop_min_ele
undistort
undistort_limit_angle
apply_camera_mask
apply_elevation_mask
cropping_indexes
classmethod from_file(camera_data_file, image_path=None, tfms=None)

Create a list of AllSkyImager instances

Parameters:
  • camera_data_file – File with a single camera parameter set (specifying camera and time period)

  • image_path – path from which AllSkyImager instances will load images

  • tfms – A dictionary of image transformations.

Returns:

list of AllSkyImager instances

classmethod from_files(camera_data_dir, camera_name, image_path=None, tfms=None)

Create a list of AllSkyImager instances

Parameters:
  • camera_data_dir – Directory containing camera data yaml files (one file per camera and period)

  • camera_name – Name of the camera for which AllSkyImager instances will be created

  • image_path – path from which AllSkyImager instances will load images

  • tfms – A dictionary of image transformations.

Returns:

list of AllSkyImager instances

classmethod from_file_as_dict(camera_data_dir, camera_name, image_path=None)

Create a dictionary with camera_data parameter sets corresponding to multiple periods of a single camera id

Parameters:
  • camera_data_dir – Path to folder with camera_data yamls (one parameter set per camera and period)

  • camera_name – Name of the camera in the camera_data_dir for which the parameters sets will be extracted

  • image_path – path from which AllSkyImager instances will load images

Returns:

dictionary of AllSkyImager/ camera_data parameter sets, one set valid per period indicated by the key, each key consists of a tuple of two dates (mounted, unmounted)

classmethod from_config()

Creates a list of AllSkyImager instances, based on the camera name from config file and the camera_data collection.

Returns:

list of AllSkyImager instances

classmethod from_config_and_period(evaluated_timestamps=None)

Creates a single AllSkyImager instance, based on a config file and an evaluated period

An error is returned if the evaluated period contains a change of the camera setup.

Parameters:

evaluated_timestamps – timezone-aware datetime or pandas series of timezone-aware datetime

Returns:

AllSkyImager instance

static load_image(image_file)

Load image from file to numpy array.

Parameters:

image_file – Path to the image to be loaded

Returns:

Loaded image as numpy array

static save_image(image, image_file)

Save image from numpy array to file.

Parameters:
  • image – Image to be saved as numpy array

  • image_file – Path to save the image to

transform(images: [list, numpy.ndarray])

Apply image transformations to all-sky images as specified during initialization.

Can be used to preprocess images for deep learning models, e.g., to crop, resize or undistort an image.

Parameters:

images – list or array of raw all-sky images or single image.

Returns:

array of transformed image(s).

check_timestamp(timestamp)

Check if timestamp is within recording time range of camera.

Parameters:

timestamp – Timezone-aware datetime

Returns:

Boolean test result

get_cropping_indexes()

Generate cropping indexes based on the selected cropping method.

Returns:

Tuple of cropping indexes along x and y axes.

get_azimuth_elevation(ocam_model, min_ele_mask, external_orientation)

Get azimuth and elevation angle of every pixel in current image.

The map depends on actual camera model, camera mask and projection function. Calls Scaramuzzas cam2world function to get the 3-D coordinates of 2-D pixel points. The cartesian coordinates will be transformed to spherical ones.

Parameters:
  • ocam_model – Instance of OcamModel

  • min_ele_mask – [degree] Elevation angle over horizontal below which image is not evaluated (masked)

  • external_orientation – 3-entry array of angles indicating external_orientation, see cam2world_eor

Returns:

Matrices indicating azimuth and elevation angle for each image pixel

get_img_and_meta(timestamp=None, exp_time=160, img_path=None)

Load an image and determine the image path if needed

Parameters:
  • timestamp – timezone-aware datetime, timestamp of the image

  • exp_time – [microseconds] Integer, exposure time of the image

  • img_path – String, path to image: If None it will be determined.

Returns:

Dict containing the image array (‘img’) and meta data (‘meta’)

static get_meta(img_bytes)

Read metadata from an image byte array or a file.

Note: This method currently only handles Mobotix cameras. It should be generalized as needed.

Parameters:

img_bytes – Binary encoded image

Returns:

Dict, metadata read from image

get_img(timestamp, exp_time=0)

Return an image which complies with the requested timestamp and exposure time.

Parameters:
  • timestamp – Timezone-aware datetime, requested timestamp

  • exp_time – [microseconds] requested exposure time

Returns:

numpy array, loaded image

get_img_path(timestamp, exp_time=160, tolerance_timestamp=None)

Return the path to an image which complies with the requested timestamp and exposure time.

Parameters:
  • timestamp – Timezone-aware datetime, requested timestamp

  • exp_time – [microseconds] requested exposure time

  • tolerance_timestamp – Timedelta, acceptable temporal deviation between actual and requested timestamp of the image

Returns:

String, path to a suited image if available, empty string if unavailable

update_buffer(timestamp)

Update a collection of available image files from the same day as a requested timestamp.

TODO: waive key ‘prev_date’

Parameters:

timestamp – datetime, requested timestamp

Returns:

Dict, collection of all available images from the same day as the requested timestamps with keys ‘prev_date’ – date to which collection corresponds, ‘imgs’ – dataframe describing all images of the day with the columns ‘timestamp’, exposure time (‘exp_time’), image path (‘path’)

class asi_core.camera.RadiometricImager(camera_data, camera_id=None, image_path=None, tfms=None)

Bases: AllSkyImager

color_temperature
weighting_luminosity
satVal
base_sensitivity
rel_overest_with_DNI
satur_cor
beta_planck
invert_gamma_corr(img)

This function so far only implements the trivial case when the gamma correction is inactive!

Parameters:

img – Gamma-corrected image

Returns:

Image

class asi_core.camera.GenericImager(camera_data, camera_id=None, image_path=None)

Bases: RadiometricImager

A generic version of RadiometricImager which can be used for cameras with unknown properties.

get_meta(_)

Return generic image meta data.

Returns:

Dict of image meta data

asi_core.camera.load_camera_data(camera_data_file=None, camera_data_dir=None, camera_name=None, timestamp=None)

Load data corresponding to available all-sky imagers.

Parameters:
  • camera_data_file – yaml file path containing camera data.

  • camera_data_dir – directory where camera data yaml files are located.

  • camera_name – specifies a camera by name to filter data from (multiple ids possible for single name).

  • timestamp – If not None, timestamp based on which the camera_id will be determined

Returns:

camera data as dictionary.

asi_core.camera.load_camera_mask(mask_file, struct_name='Mask', allow_failure=True)

Load a camera mask as numpy array from a mat file.

Parameters:
  • mask_file – file path of camera mask.

  • struct_name – name of matlab struct containing camera mask array.

Returns:

camera mask as 2D numpy array.

asi_core.camera.load_celestial_coordinate_masks(mask_file, struct_name='AngleMatrix', field_el='ELE', field_az='AZ')

Load elevation and azimuth masks from a mat file.

Parameters:
  • mask_file – file path of mat file.

  • struct_name – name of matlab struct.

  • field_el – variable name of elevation angles array.

  • field_az – variable name of azimuth angles array.

Returns:

tuple of elevation angle mask and azimuth angle mask.

asi_core.camera.get_camera_location(camera_name)

Get geolocation based on camera name from camera config.