asi_core.asi_analysis

This module provides functions to analyse all-sky images.

Functions

_to_radians(ele, az)

Converts elevation and azimuth angles from degrees to radians.

polar_to_cart(r, ele, az)

Converts polar coordinates to Cartesian coordinates.

get_sun_pos_in_asi(sun_ele, sun_az, ele_mat, az_mat)

Determines the pixel position of the sun in an all-sky image.

compute_sun_dist_map(sun_ele, sun_az, ele_mat, az_mat)

Computes the distance map from each pixel to the sun in an all-sky image.

compute_cloud_coverage_and_distance_to_sun(seg_mask, ...)

Computes cloud coverage and the minimum distance between clouds and the sun.

sph2cart(az, el, r)

Transform spherical to cartesian coordinates

cart2sph(x, y, z)

Transform cartesian to spherical coordinates. See reverse function sph2cart, for further convention.

create_perspective_undistortion_LUT(o, sf)

Create a look-up table for perspective undistortion.

create_panoramic_undistortion_LUT(r_min, r_max, o)

Create a look-up table for panoramic undistortion.

get_sun_dist(az, ele, timestamp, location)

Calculate the sun distance angle based on azimuth and elevation angles.

is_circle_contour(contour[, aspect_ratio_tolerance, ...])

Determines if a contour is circular based on its aspect ratio and circularity.

get_saturated_mask(img[, saturation_limit, ...])

Module Contents

asi_core.asi_analysis._to_radians(ele, az)

Converts elevation and azimuth angles from degrees to radians.

asi_core.asi_analysis.polar_to_cart(r, ele, az)

Converts polar coordinates to Cartesian coordinates.

asi_core.asi_analysis.get_sun_pos_in_asi(sun_ele, sun_az, ele_mat, az_mat)

Determines the pixel position of the sun in an all-sky image.

Parameters:
  • sun_ele – Sun elevation angle in degrees.

  • sun_az – Sun azimuth angle in degrees.

  • ele_mat – Elevation matrix of the all-sky image.

  • az_mat – Azimuth matrix of the all-sky image.

Returns:

(row, col) coordinates of the sun in the image.

asi_core.asi_analysis.compute_sun_dist_map(sun_ele, sun_az, ele_mat, az_mat, apply_filter=False, size=5)

Computes the distance map from each pixel to the sun in an all-sky image.

Parameters:
  • sun_ele – Sun elevation angle in degrees.

  • sun_az – Sun azimuth angle in degrees.

  • ele_mat – Elevation matrix of the all-sky image.

  • az_mat – Azimuth matrix of the all-sky image.

  • apply_filter – Whether to apply median filtering (default: False).

  • size – Kernel size for median filtering (default: 5).

Returns:

Distance map (in degrees) to the sun.

asi_core.asi_analysis.compute_cloud_coverage_and_distance_to_sun(seg_mask, cam_mask, sun_dist_map, cloud_value=1)

Computes cloud coverage and the minimum distance between clouds and the sun.

Parameters:
  • seg_mask – Segmentation mask of the sky (clouds vs. background).

  • cam_mask – Camera mask indicating valid pixels.

  • sun_dist_map – Distance map from each pixel to the sun.

  • cloud_value – Value representing clouds in the segmentation mask (default: 1).

Returns:

Tuple (cloud_coverage, min_dist_cloud, coord_cloud): - cloud_coverage: Fraction of the sky covered by clouds. - min_dist_cloud: Minimum distance between a cloud pixel and the sun. - coord_cloud: Coordinates of the closest cloud pixel to the sun.

asi_core.asi_analysis.sph2cart(az, el, r)

Transform spherical to cartesian coordinates

Parameters:
  • az – [radian] array of the azimuth angle, over positive x-axis, rotating around z-axis

  • el – [radian] array of the elevation angle

  • r – array of the radius

Returns:

arrays of the cartesian coordinates x, y, z (same unit as radius)

asi_core.asi_analysis.cart2sph(x, y, z)

Transform cartesian to spherical coordinates. See reverse function sph2cart, for further convention.

Parameters:
  • x – cartesian coordinate x

  • y – cartesian coordinate y, same unit as x

  • z – cartesian coordinate z, same unit as x

Returns:

arrays of the azimuth angle, elevation angle, radius (same unit as x)

asi_core.asi_analysis.create_perspective_undistortion_LUT(o, sf)

Create a look-up table for perspective undistortion.

Parameters:
  • o – OcamModel instance

  • sf – Scaling factor.

Returns:

Two look-up tables (mapx and mapy) for perspective undistortion.

asi_core.asi_analysis.create_panoramic_undistortion_LUT(r_min, r_max, o)

Create a look-up table for panoramic undistortion.

Parameters:
  • r_min – Minimum radial distance.

  • r_max – Maximum radial distance.

  • o – Dictionary containing camera parameters (height, width, xc, yc).

Returns:

Two look-up tables (map_x and map_y) for panoramic undistortion.

asi_core.asi_analysis.get_sun_dist(az, ele, timestamp, location)

Calculate the sun distance angle based on azimuth and elevation angles.

Parameters:
  • az – Azimuth angles (in degrees) of the sun.

  • ele – Elevation angles (in degrees) of the sun.

  • timestamp – Specific timestamp for which the solar position is calculated.

  • location – Dictionary containing the latitude, longitude, and altitude of the location.

Returns:

Three values: sun distance angle, sun azimuth angle, and sun elevation angle.

asi_core.asi_analysis.is_circle_contour(contour, aspect_ratio_tolerance=0.1, circularity_threshold=0.8)

Determines if a contour is circular based on its aspect ratio and circularity.

Parameters:
  • contour – (numpy.ndarray) The contour to analyze.

  • aspect_ratio_tolerance – (float, optional) The maximum difference between the aspect ratio of the contour’s bounding rectangle and 1. Default is 0.1.

  • circularity_threshold – (float, optional) The minimum circularity of the contour. Default is 0.7.

Returns:

bool, True if the contour is circular, False otherwise.

asi_core.asi_analysis.get_saturated_mask(img, saturation_limit=240, gray_scale=True, channel_dim=-1)