asi_core.camera =============== .. py:module:: asi_core.camera .. autoapi-nested-parse:: This module provides functionality for all-sky imagers. Attributes ---------- .. autoapisummary:: asi_core.camera.CAMERA_DATA_FILE asi_core.camera.CAMERA_DATA_SCHEMA Classes ------- .. autoapisummary:: asi_core.camera.AllSkyImager asi_core.camera.RadiometricImager asi_core.camera.GenericImager Functions --------- .. autoapisummary:: asi_core.camera.load_camera_data asi_core.camera.load_camera_mask asi_core.camera.load_celestial_coordinate_masks asi_core.camera.get_camera_location Module Contents --------------- .. py:data:: CAMERA_DATA_FILE .. py:data:: CAMERA_DATA_SCHEMA .. py:class:: AllSkyImager(camera_data, camera_id=None, image_path=None, tfms=None) .. py:attribute:: img_paths_buffer .. py:attribute:: tolerance_timestamp .. py:attribute:: rel_exp_tol :value: 0.1 Class for All-Sky Imagers. .. py:attribute:: id :value: None .. py:attribute:: name .. py:attribute:: latitude .. py:attribute:: longitude .. py:attribute:: altitude .. py:attribute:: img_timezone .. py:attribute:: start_recording .. py:attribute:: end_recording .. py:attribute:: external_orientation .. py:attribute:: min_ele_evaluated .. py:attribute:: ocam_model .. py:attribute:: height .. py:attribute:: width .. py:attribute:: resize .. py:attribute:: crop .. py:attribute:: crop_min_ele .. py:attribute:: undistort .. py:attribute:: undistort_limit_angle .. py:attribute:: apply_camera_mask .. py:attribute:: apply_elevation_mask .. py:attribute:: cropping_indexes .. py:method:: from_file(camera_data_file, image_path=None, tfms=None) :classmethod: Create a list of AllSkyImager instances :param camera_data_file: File with a single camera parameter set (specifying camera and time period) :param image_path: path from which AllSkyImager instances will load images :param tfms: A dictionary of image transformations. :return: list of AllSkyImager instances .. py:method:: from_files(camera_data_dir, camera_name, image_path=None, tfms=None) :classmethod: Create a list of AllSkyImager instances :param camera_data_dir: Directory containing camera data yaml files (one file per camera and period) :param camera_name: Name of the camera for which AllSkyImager instances will be created :param image_path: path from which AllSkyImager instances will load images :param tfms: A dictionary of image transformations. :return: list of AllSkyImager instances .. py:method:: from_file_as_dict(camera_data_dir, camera_name, image_path=None) :classmethod: Create a dictionary with camera_data parameter sets corresponding to multiple periods of a single camera id :param camera_data_dir: Path to folder with camera_data yamls (one parameter set per camera and period) :param camera_name: Name of the camera in the camera_data_dir for which the parameters sets will be extracted :param image_path: path from which AllSkyImager instances will load images :return: 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) .. py:method:: from_config() :classmethod: Creates a list of AllSkyImager instances, based on the camera name from config file and the camera_data collection. :return: list of AllSkyImager instances .. py:method:: from_config_and_period(evaluated_timestamps=None) :classmethod: 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. :param evaluated_timestamps: timezone-aware datetime or pandas series of timezone-aware datetime :return: AllSkyImager instance .. py:method:: load_image(image_file) :staticmethod: Load image from file to numpy array. :param image_file: Path to the image to be loaded :return: Loaded image as numpy array .. py:method:: save_image(image, image_file) :staticmethod: Save image from numpy array to file. :param image: Image to be saved as numpy array :param image_file: Path to save the image to .. py:method:: 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. :param images: list or array of raw all-sky images or single image. :return: array of transformed image(s). .. py:method:: check_timestamp(timestamp) Check if timestamp is within recording time range of camera. :param timestamp: Timezone-aware datetime :return: Boolean test result .. py:method:: get_cropping_indexes() Generate cropping indexes based on the selected cropping method. :return: Tuple of cropping indexes along x and y axes. .. py:method:: 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. :param ocam_model: Instance of OcamModel :param min_ele_mask: [degree] Elevation angle over horizontal below which image is not evaluated (masked) :param external_orientation: 3-entry array of angles indicating external_orientation, see cam2world_eor :return: Matrices indicating azimuth and elevation angle for each image pixel .. py:method:: get_img_and_meta(timestamp=None, exp_time=160, img_path=None) Load an image and determine the image path if needed :param timestamp: timezone-aware datetime, timestamp of the image :param exp_time: [microseconds] Integer, exposure time of the image :param img_path: String, path to image: If None it will be determined. :return: Dict containing the image array ('img') and meta data ('meta') .. py:method:: get_meta(img_bytes) :staticmethod: Read metadata from an image byte array or a file. Note: This method currently only handles Mobotix cameras. It should be generalized as needed. :param img_bytes: Binary encoded image :return: Dict, metadata read from image .. py:method:: get_img(timestamp, exp_time=0) Return an image which complies with the requested timestamp and exposure time. :param timestamp: Timezone-aware datetime, requested timestamp :param exp_time: [microseconds] requested exposure time :return: numpy array, loaded image .. py:method:: 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. :param timestamp: Timezone-aware datetime, requested timestamp :param exp_time: [microseconds] requested exposure time :param tolerance_timestamp: Timedelta, acceptable temporal deviation between actual and requested timestamp of the image :return: String, path to a suited image if available, empty string if unavailable .. py:method:: update_buffer(timestamp) Update a collection of available image files from the same day as a requested timestamp. TODO: waive key 'prev_date' :param timestamp: datetime, requested timestamp :return: 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') .. py:class:: RadiometricImager(camera_data, camera_id=None, image_path=None, tfms=None) Bases: :py:obj:`AllSkyImager` .. py:attribute:: color_temperature .. py:attribute:: weighting_luminosity .. py:attribute:: satVal .. py:attribute:: base_sensitivity .. py:attribute:: rel_overest_with_DNI .. py:attribute:: satur_cor .. py:attribute:: beta_planck .. py:method:: invert_gamma_corr(img) This function so far only implements the trivial case when the gamma correction is inactive! :param img: Gamma-corrected image :return: Image .. py:class:: GenericImager(camera_data, camera_id=None, image_path=None) Bases: :py:obj:`RadiometricImager` A generic version of RadiometricImager which can be used for cameras with unknown properties. .. py:method:: get_meta(_) Return generic image meta data. :return: Dict of image meta data .. py:function:: load_camera_data(camera_data_file=None, camera_data_dir=None, camera_name=None, timestamp=None) Load data corresponding to available all-sky imagers. :param camera_data_file: yaml file path containing camera data. :param camera_data_dir: directory where camera data yaml files are located. :param camera_name: specifies a camera by name to filter data from (multiple ids possible for single name). :param timestamp: If not None, timestamp based on which the camera_id will be determined :return: camera data as dictionary. .. py:function:: load_camera_mask(mask_file, struct_name='Mask', allow_failure=True) Load a camera mask as numpy array from a mat file. :param mask_file: file path of camera mask. :param struct_name: name of matlab struct containing camera mask array. :return: camera mask as 2D numpy array. .. py:function:: load_celestial_coordinate_masks(mask_file, struct_name='AngleMatrix', field_el='ELE', field_az='AZ') Load elevation and azimuth masks from a mat file. :param mask_file: file path of mat file. :param struct_name: name of matlab struct. :param field_el: variable name of elevation angles array. :param field_az: variable name of azimuth angles array. :return: tuple of elevation angle mask and azimuth angle mask. .. py:function:: get_camera_location(camera_name) Get geolocation based on camera name from camera config.