improver.utilities.solar module
Utilities to find the relative position of the sun.
- class DayNightMask[source]
Bases:
BasePlugin
Plugin Class to generate a daynight mask for the provided cube
- _abc_impl = <_abc_data object>
- _create_daynight_mask(cube)[source]
Create blank daynight mask cube
- Parameters:
cube (
Cube
) – cube with the times and coordinates required for mask- Return type:
- Returns:
Blank daynight mask cube. The resulting cube will be the same shape as the time, y, and x coordinate, other coordinates will be ignored although they might appear as attributes on the cube as it is extracted from the first slice.
- _daynight_lat_lon_cube(mask_cube, day_of_year, utc_hour)[source]
Calculate the daynight mask for the provided Lat Lon cube
- process(cube)[source]
Calculate the daynight mask for the provided cube. Note that only the hours and minutes of the dtval variable are used. To ensure consistent behaviour with changes of second or subsecond precision, the second component is added to the time object. This means that when the hours and minutes are used, we have correctly rounded to the nearest minute, e.g.:
dt(2017, 1, 1, 11, 59, 59) -- +59 --> dt(2017, 1, 1, 12, 0, 58) dt(2017, 1, 1, 12, 0, 1) -- +1 --> dt(2017, 1, 1, 12, 0, 2) dt(2017, 1, 1, 12, 0, 30) -- +30 --> dt(2017, 1, 1, 12, 1, 0)
If the cube’s time coordinate has time bounds the mid-point of these bounds rather than the time point is used in the calculation. This ensures that should a majority of the period described fall into daylight hours, the data is not classified as falling at night. This is an issue as the time point is always located at the end of the time bounds. Without this approach weather symbols representing e.g. 20-21Z will be marked as night symbols should the sun set at 20:59, which is not suitable.
- Parameters:
cube (
Cube
) – input cube- Return type:
- Returns:
daynight mask cube, daytime set to self.day nighttime set to self.night. The resulting cube will be the same shape as the time, y, and x coordinate, other coordinates will be ignored although they might appear as attributes on the cube as it is extracted from the first slice.
- calc_solar_declination(day_of_year)[source]
Calculate the Declination for the day of the year.
Calculation equivalent to the calculation defined in NOAA Earth System Research Lab Low Accuracy Equations https://www.esrl.noaa.gov/gmd/grad/solcalc/sollinks.html
- calc_solar_elevation(latitudes, longitudes, day_of_year, utc_hour, return_sine=False)[source]
Calculate the Solar elevation.
- Parameters:
latitudes (
Union
[float
,ndarray
]) – A single Latitude or array of Latitudes latitudes needs to be between -90.0 and 90.0longitudes (
Union
[float
,ndarray
]) – A single Longitude or array of Longitudes longitudes needs to be between 180.0 and -180.0day_of_year (
int
) – Day of the year 0 to 365, 0 = 1st Januaryutc_hour (
float
) – Hour of the day in UTC in hoursreturn_sine (
bool
) – If True return sine of solar elevation. Default False.
- Return type:
- Returns:
Solar elevation in degrees for each location.
- calc_solar_hour_angle(longitudes, day_of_year, utc_hour)[source]
Calculate the Solar Hour angle from the Local Solar Time.
- Parameters:
- Return type:
- Returns:
Hour angles in degrees East-West.
- calc_solar_time(longitudes, day_of_year, utc_hour, normalise=False)[source]
Calculate the Local Solar Time for each element of an array of longitudes.
Calculation equivalent to the calculation defined in NOAA Earth System Research Lab Low Accuracy Equations https://www.esrl.noaa.gov/gmd/grad/solcalc/sollinks.html
- Parameters:
- Return type:
- Returns:
Local solar time in hours.
- daynight_terminator(longitudes, day_of_year, utc_hour)[source]
Calculate the Latitude values of the daynight terminator for the given longitudes.
- get_hour_of_day(time)[source]
Get the hour of day from datetime, with the minute values included as a fraction of the hour, and seconds rounded to the nearest minute.
Where rounding seconds moves the datetime into the following day, the hour_of_day returned is 24.0 rather than 0.0 to ensure the hour_of_day is consistent with the day_of_year value associated with datetime.