meteo module

Meteorological module.

Daily and hourly (instantaneous) meteorology properties.

Author - Christopher Teh Boon Sung


SolarRadComponents namedtuple

SolarRadComponents(total, direct, diffuse)

namedtuple: Solar radiation components

total

float: total solar radiation (direct + diffuse)

direct

float: direct solar radiation

diffuse

float: diffuse solar radiation

SolarPos namedtuple

SolarPos(inc, hgt, azi)

namedtuple: Solar position

inc

float: solar inclination (angle from vertical)

hgt

float: solar elevation or height (angle from horizontal)

azi

float: solar azimuth (angle from North in a clockwise direction)

Meteo class

Meteorology class.

Daily and hourly (instantaneous) meteorology properties.

Daily meteorological properties can either be read from a provided weather file, or have them simulated. If the latter, users can provide a specific seed number for deterministic runs, which means model output always returns the exact same results, provided model input do not change, or users can enter a zero or negative seed value, which means the model output would vary even though the model input remained the same.

Important

If the weather data are loaded from a file, ensure the weather file contains information on the minimum and maximum air temperature, wind speed, and rainfall.

Based on daily values, hourly (instantaneous) meteorological properties are then simulated, as needed.

Note

Time is indicated by local solar hour (not local time). This class only allows the day of year (doy) to move forward a day at a time, where each time the day moves forward, the model is updated (see generator next_day()).

ATTRIBUTES

  • seed (int): Random seed number
  • lat (float): Site latitude (deg.) methgt (float)- Weather station height (m)
  • doy (int): Day of year (Jan 1 = 1, Feb 1 = 32, ..., Dec 31 = 365)
  • solarhour (float): Local solar hour (not local time!) (hours)
  • dewtemp (float): Dew temperature (deg. C)
  • lag (float): No. of hours after sunrise when air temperature and wind speed are minimum (hours)
  • is_generated (bool): True to generate daily weather or False to read in daily weather
  • weatherfilename (str): Name of weather file
  • annwthr (AnnualWeather): Annual daily weather data for current year
  • nyears (int): Year number (number of years elapsed)
  • decl (float): Solar declination (radians)
  • sunrise (float): Local solar hour of sunrise (hour)
  • sunset (float): Local solar hour of sunset (hour)
  • daylen (float): Length of day (hour)
  • solarconst (float): Solar constant (W/m2)
  • dayetrad (float): Daily extra-terrestrial (ET) solar irradiance (MJ/m2)
  • dayrad (SolarRadComponents): Daily solar rad components (MJ/m2)
  • daytmin (float): Min. daily air temperature (deg. C)
  • daytmax (float): Max. daily air temperature (deg. C)
  • daytmean (float): Mean daily air temperature (deg. C)
  • daywind (float): Daily wind speed (m/s)
  • dayrain (float): Rainfall amount (mm/day)
  • solarpos (SolarPos): Solar position (inclination and azimuth) (radians)
  • etrad (float): Extra-terrestrial (ET) solar irradiance (W/m2)
  • rad (SolarRadComponents): Solar radiation components (W/m2)
  • airtemp (float): Air temperature (deg. C)
  • slopesvp (float): Slope of the saturated air vapor pressure curve (mbar/K)
  • svp (float): Saturated air vapor pressure (mbar)
  • vp (float): Air vapor pressure (mbar)
  • vpd (float): Vapor pressure deficit (mbar)
  • rh (float): Air relative humidity (%)
  • netrad (float): Net radiation (W/m2)
  • windspd (float): Wind speed (m/s)

METHODS

  • doy365: Forces the day of year to stay within 1 and 365 inclusive
  • rnd: Random number, needs to be seeded by the user or computer
  • svp_fn: Saturated air vapor pressure for a given air temperature (mbar)
  • solar_declination: Solar declination (radians)
  • sunrise_set_hour: Local solar hour of sunrise and sunset (hours)
  • daylength: No. of hours between sunrise and sunset (hours)
  • solar_constant: Solar irradiance outside Earth (W/m2)
  • day_et_radiation: Daily total extraterrestrial solar irradiance (MJ/m2/day)
  • day_radiation: Daily direct, diffuse, and total solar irradiance (MJ/m2/day)
  • solar_position: Inclination, height, and azimuth of the Sun (radians)
  • et_radiation: Instantaneous extraterrestrial solar irradiance (W/m2)
  • radiation: Instantaneous direct, diffuse, and total solar irradiance (W/m2)
  • air_temperature: Instantaneous air temperature (deg. C)
  • svp: Saturated air vapor pressure (mbar)
  • slope_svp: Slope of the saturated air vapor pressure (mbar/deg. C)
  • vapor_pressure: Air vapor pressure (mbar)
  • vapor_pressure_deficit: Vapor pressure deficit (mbar)
  • relative_humidity: Relative humidity (%)
  • net_radiation: Net radiation (W/m2)
  • wind_speed: Wind speed (m/s)
  • integrate: N-point numerical Gaussian integration
  • update_weather: Update daily weather when day of year and/or local solr hour have changed
  • next_day: Generator to increment DOY and then update the model properties

  • doy_has_changed: To be implemented in descendant classes that day of year has changed

  • update: To be implemented in descendant classes for updating model properties based on current model settings or values

Constructor __init__

Meteo(self, fname_in)

Create and initialize the Weather object.

Arguments

  • fname_in (str): path and filename of the model initialization file

rnd

Meteo.rnd()

Note

rnd is a static method.

Generate a uniform random number between the interval [0 - 1).

Returns

int: random value [0-1)

doy365

Meteo.doy365(doy)

Note

doy365 is a static method.

Return a given day of year so that it stays within 1 and 365 inclusive.

Returns

int: day of year [1-365]

svp_fn

Meteo.svp_fn(temp)

Note

svp_fn is a static method.

Saturated vapor pressure (mbar) at a given air temperature (deg. C).

Arguments

  • temp (float): air temperature (deg. C)

Returns

float: saturated vapor pressure

solar_declination

Meteo.solar_declination(self)

Solar declination (radians).

Returns

float: solar declination

sunrise_set_hour

Meteo.sunrise_set_hour(self)

Hour of sunrise and sunset (hours).

Returns

tuple: local solar hour of sunrise and sunset (float)

daylength

Meteo.daylength(self)

Length of day, between sunrise and sunset (hours).

Returns

float: day length

solar_constant

Meteo.solar_constant(self)

Solar constant (W/m2), corrected for eccentricity.

Returns

float: solar constant

day_et_radiation

Meteo.day_et_radiation(self)

Extra-terrestrial (outside Earth) solar irradiance (MJ/m2/day).

Returns

float: ET solar irradiance

day_radiation

Daily total solar irradiance and its direct and diffuse components (MJ/m2/day).

Returns

SolarRadComponents: namedtuple containing the daily solar radiation components (float)

solar_position

Solar position: inclination, height (solar elevation), and azimuth (radians).

Returns

SolarPos: namedtuple containing position of the sun (float)

et_radiation

Meteo.et_radiation(self)

Instantaneous extra-terrestrial solar irradiance (W/m2).

Returns

float: ET solar radiation

radiation

Instantaneous total solar irradiance and its direct and diffuse components (W/m2).

Returns

SolarRadComponents: namedtuple containing solar radiation components (float)

air_temperature

Meteo.air_temperature(self)

Instantaneous air temperature (deg. C).

Returns

float: air temperature

saturated_vapor_presure

Meteo.saturated_vapor_presure(self)

Saturated air vapor pressure (mbar).

Returns

float: saturated air vapor pressure

slope_svp

Meteo.slope_svp(self)

Slope of the saturated air vapor pressure (SVP) against air temperature (mbar/deg. C).

Returns

float: slope of the curve between SVP and air temperature

vapor_pressure

Meteo.vapor_pressure(self)

Instantaneous air vapor pressure (mbar).

Returns

float: air vapor pressure

vapor_pressure_deficit

Meteo.vapor_pressure_deficit(self)

Air vapor pressure deficit (mbar).

The difference between saturated air vapor pressure and current air vapor pressure.

Returns

float: air vapor pressure deficit

relative_humidity

Meteo.relative_humidity(self)

Air relative humidity (RH) (%).

Returns

float: RH

net_radiation

Meteo.net_radiation(self)

Instantaneous net solar irradiance (W/m2).

Returns

float: net solar radiation

wind_speed

Meteo.wind_speed(self)

Instantaneous wind speed (m/s) based on a sine curve.

Returns

float: wind speed

integrate

Meteo.integrate(self, n, lower, upper, func, *args)

N-point numerical Gaussian integration.

Arguments

  • n (int): no. of points for integration (min. 1, max, 9; typically, 3 or 5)
  • lower (float): lower limit of integration
  • upper (float): upper limit of integration
  • func: function to be integrated
  • args: variable length of function arguments to passed into func()

Returns

tuple: results of integration

update_weather

Meteo.update_weather(self, nextdoy=None, nexthour=None, reuse=False)

Update the daily (and/or hourly) meteorological properties.

Arguments

  • nextdoy (int): the new day of year
  • nexthour (int/float): the new local solar hour
  • reuse (bool): False by default so that annual weather will be updated (i.e., regenerated) if the year end has been passed. Set to True so that the same annual weather is used regardless if the year end has been passed (i.e., always use the same annual weather data).

Returns

None:

next_day

Meteo.next_day(self, duration)

Generator to increment DOY and then update the model properties.

This class only allows the day of year (DOY) to move forward a day at a time, where each time the day moves forward, the model properties are updated.

Arguments

  • duration (int): number of daily cycles/steps to increment the DOY and model update

Yields

int: current day run number

doy_has_changed

Meteo.doy_has_changed(self)

To be implemented in descendant classes that the DOY has gone forward by a day.

Note

To be implemented by descendant classes on how the model will be updated when the DOY has changed.

Raises

  • NotImplementedError: raised if this method is used at this base class level

update

Meteo.update(self, external_info)

To be implemented in descendant classes for updating model properties.

Implementation

To be implemented by descendant classes on how the model will be updated.

Arguments

  • external_info (dict): information determined from external sources

Raises

  • NotImplementedError: thrown if this method is used at this base class level