improver.utilities.solar module

Utilities to find the relative position of the sun.

class improver.utilities.solar.DayNightMask[source]

Bases: improver.BasePlugin

Plugin Class to generate a daynight mask for the provided cube

__init__()[source]

Initial the DayNightMask Object

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 213
_abc_registry = <_weakrefset.WeakSet object>
_create_daynight_mask(cube)[source]

Create blank daynight mask cube

Parameters

cube (iris.cube.Cube) – cube with the times and coordinates required for mask

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.

Return type

iris.cube.Cube

_daynight_lat_lon_cube(mask_cube, day_of_year, utc_hour)[source]

Calculate the daynight mask for the provided Lat Lon cube

Parameters
  • mask_cube (iris.cube.Cube) – daynight mask cube - data initially set to self.night

  • day_of_year (int) – day of the year 0 to 365, 0 = 1st January

  • utc_hour (float) – Hour in UTC

Returns

daynight mask cube - daytime set to self.day

Return type

iris.cube.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)
Parameters

cube (iris.cube.Cube) – input cube

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.

Return type

iris.cube.Cube

improver.utilities.solar.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

Parameters

day_of_year (int) – Day of the year 0 to 365, 0 = 1st January

Returns

Declination in degrees.North-South

Return type

float

improver.utilities.solar.calc_solar_elevation(latitudes, longitudes, day_of_year, utc_hour, return_sine=False)[source]

Calculate the Solar elevation.

Parameters
  • latitudes (float or numpy.ndarray) – A single Latitude or array of Latitudes latitudes needs to be between -90.0 and 90.0

  • longitudes (float or numpy.ndarray) – A single Longitude or array of Longitudes longitudes needs to be between 180.0 and -180.0

  • day_of_year (int) – Day of the year 0 to 365, 0 = 1st January

  • utc_hour (float) – Hour of the day in UTC in hours

  • return_sine (bool) – If True return sine of solar elevation. Default False.

Returns

Solar elevation in degrees for each location.

Return type

float or numpy.ndarray

improver.utilities.solar.calc_solar_hour_angle(longitudes, day_of_year, utc_hour)[source]

Calculate the Solar Hour angle 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
  • longitudes (float or numpy.ndarray) – A single Longitude or array of Longitudes longitudes needs to be between 180.0 and -180.0 degrees

  • day_of_year (int) – Day of the year 0 to 365, 0 = 1st January

  • utc_hour (float) – Hour of the day in UTC

Returns

solar_hour_angle (float or numpy.ndarray)

Hour angles in degrees East-West

improver.utilities.solar.daynight_terminator(longitudes, day_of_year, utc_hour)[source]

Calculate the Latitude values of the daynight terminator for the given longitudes.

Parameters
  • longitudes (numpy.ndarray) – Array of longitudes. longitudes needs to be between 180.0 and -180.0 degrees

  • day_of_year (int) – Day of the year 0 to 365, 0 = 1st January

  • utc_hour (float) – Hour of the day in UTC

Returns

latitudes of the daynight terminator

Return type

numpy.ndarray