solrad.terrain package#
Submodules#
solrad.terrain.horizon module#
This module contains all functions, methods and classes related to the computation of a site’s horizon and related quantities.
- solrad.terrain.horizon.clear_horizon_func(azimuth)#
Generates an array of elevation values filled with zeros based on the provided azimuth data.
- Parameters:
azimuth (float or array_like (npoints,)) – Single value or array of azimuth angle values.
- Returns:
elevation – Single value or array of elevation values, initialized with zeros.
- Return type:
float or numpy.array (npoints,)
- solrad.terrain.horizon.compute_fraction_of_unblocked_sky_patch_by_horizon(horizon_func, el0, el1, az0, az1, npts=250)#
Compute the fraction of a sky patch that is not blocked by the horizon.
- Parameters:
horizon_func (callable) – A function that takes an array of azimuth angles and returns the corresponding elevation angles of the horizon.
el0 (int or float) – Lower limit of elevation angle (in degrees) of the sky patch.
el1 (int or float) – Upper limit of elevation angle (in degrees) of the sky patch.
az0 (int or float) – Lower limit of azimuth angle (in degrees) of the sky patch.
az1 (int or float) – Upper limit of azimuth angle (in degrees) of the sky patch.
npts (int, optional) – The number of points used for discretization along azimuth and elevation, default is 250.
- Returns:
unblocked_fraction – The fraction of area of the sky patch not blocked by the horizon.
- Return type:
float
- Raises:
1) Exception – az0 must be strictly greater than az1.
2) Exception – el0 must be strictly greater than el1.
Notes
This function calculates the fraction of the sky patch that is unblocked by the horizon, given a function horizon_func that provides the elevation angles of the horizon for a given array of azimuth angles. The computation is performed by discretizing the azimuth and elevation angles, and then integrating over the unblocked region.
- solrad.terrain.horizon.horizon_arrays_from_pvgis(latitude, longitude, timeout=30)#
Get a site’s horizon profile, computed by PVGIS, using its API Non-Interactive Service.
- Parameters:
latitude (float) – Site’s latitude in sexagesimal degrees. Must be a number between -90 and 90.
longitude (float) – Site’s longitude in sexagesimal degrees. Must be a number between -180 and 180.
timeout (float) – Number of seconds after which the requests library will stop waiting for a response of the server. That is, if the requests library does not receive a response in the specified number of seconds, it will raise a Timeout error.
- Returns:
azimuth (numpy.array of floats) – Array of azimuth angle values in degrees.
elevation (numpy.array of floats) – Array of elevation angle values in degrees.
Note
1) Horizon height is the angle between the local horizontal plane and the horizon. In other words, the Horizon height is equal to the horizon’s elevation angle.
Examples
>>> from solrad.terrain.horizon import horizon_arrays_from_pvgis >>> azimuth, elevation = horizon_arrays_from_pvgis(latitude = 6.25184, >>> longitude = -75.56359)
- solrad.terrain.horizon.horizon_func_from_arrays(azimuth, elevation, interp_method='linear')#
Create horizon elevation function by interpolating provided data points.
- Parameters:
azimuth ((npoints, ) array_like) – Array of azimuth angle values in degrees, from 0 to 360. Must be monotonic-increasing.
elevation ((npoints, ) array_like) – Array of horizon elevation angle values in degrees. Elevation values must lie between 0 and 90.
interp_method ({'linear', 'quadratic', 'cubic'}, optional) – Order of the spline interpolator to use. Default is ‘linear’.
- Returns:
terrain_func – Interpolation function for azimuth, elevation values.
- Return type:
callable
Examples
>>> import numpy as np >>> from solrad.terrain.horizon import horizon_func_from_arrays >>> >>> azimuth = np.linspace(0, 360, 100) >>> elevation = np.sin(azimuth*np.pi/180)**2 >>> func = horizon_func_from_arrays(azimuth, elevation, interp_method="linear") >>> func([88, 89, 90])
- solrad.terrain.horizon.plot_horizon(y, azimuth, config=None)#
Plots the horizon profile based on the provided azimuth and elevation data.
- Parameters:
y (array_like (npoints,) or callable) – Elevation data in degrees or a callable function that takes azimuth values and returns elevation values.
azimuth (array_like) – Array of azimuth angle values in degrees.
config (None or dict, optional) –
Configuration settings of the plot. When equal to None (which is the default) the default plot settings are used. When not equal to None, it must be a dict containing some or all of the following key-value pairs:
- “projection””polar” or “cartesian”
If equal to “polar”, the Horizon profile is plotted using a polar plot. If equal to “cartesian”, it is plotted using a cartesian plot. “Default is “polar”.
- ”show_polar_elevation”bool
If true, it shows the elevation angle makers for the polar plot. If False, it does not. Default is False.
- ”title”str
Title of the plot. Default is ‘Horizon Profile’.
- ”facecolor”str
Background color of the Horizon Height part of the plot. Must be equal to str(x), where x is a float between 0 and 1. 0 means that the background color is black. 1 means that it is white. Any value in between represents a shade of gray. Default is “0.5”.
- ”figsize”tuple of float
Figure size of the plot.
- Return type:
None
Notes
The function utilizes the ‘_check_for_elevation_array_compliance’ and ‘_check_for_azimuth_array_compliance’ functions to ensure the compliance of elevation and azimuth data before plotting.
Examples
>>> from terrain.horizon import , plot_horizon >>> >>> # Plots the horizon profile based on the provided data. >>> azimuth_data = np.linspace(0, 360, 100) >>> elevation_data = 10*np.sin(np.deg2rad(azimuth_data))**2 >>> plot_horizon(elevation_data, azimuth_data) >>> # Plots the horizon profile based on the provided data. >>> >>> # Plots the horizon profile using a custom function and customized configuration. >>> azimuth_data = np.linspace(0, 360, 100) >>> def custom_function(azimuth): >>> return 30*np.sin(np.deg2rad(azimuth)) + 45 >>> plot_horizon(custom_function, azimuth_data, config={"projection": "cartesian"})