varwg.meteo package

Submodules

varwg.meteo.avrwind module

written by Raphael Lutz 2010

varwg.meteo.avrwind.angle2component(angle, norm, wind=True)[source]

Converts wind data with the format (direction, speed) into the velocity components (u,v).

If wind == True, 0 degree is wind blowing from north, 90 degree is wind from east, etc. If False (if data is not wind data but ship movement or anything else), 0 degree is pointing to north, 90 to east etc.

Parameters:
anglefloat or np.array of floats

direction [0,360] where the wind is coming from

normfloat or np.array of floats

wind speed

windboole, optional

input data is wind data, default is True

Returns:
ufloat or np.array of floats

component u pointing from west to east

vfloat or np.array of floats

component v pointing from south to north

See also

component2angle

vice versa

Examples

>>> angle2component(90, 1)
(-1.0, -6.123233995736766e-17)
>>> angle2component([90,180],[1,1], wind=False)
(array([  1.00000000e+00,   1.22464680e-16]),
 array([  6.12323400e-17,  -1.00000000e+00]))
varwg.meteo.avrwind.avrwind(u, v, date_time, new_timeres, method='vector', verbose=True, sec=16, wind_=True)[source]

function to convert measured data from one time resolution to another you can decide which method you will use, sector=sector-wise or vector=vector-adding polygon trace

Parameters:
ufloat or np.array of floats

component u pointing from west to east

vfloat or np.array of floats

component v pointing from south to north

date_timetimeinfo as list/array of string ‘01.01.2010 12:30:40’

or datetime-object, or single timedelta in seconds(e.g: 60)

new_timeresint

[seconds] new time resolution of output data

method{‘vector’,’sector’}
verbose{True, False}, optional

give information about problems during calculation

secint, optional

number of sectors used for sector interpolation. Default is 16

wind_boole, optional

input data is wind data, default is True (for details: see documentation to angle2component)

Returns:
avr_ufloat

averaged u velocity

avr_vfloat

averaged v velocity

avr_wind_directionfloat

direction of averaged wind (‘vector’) or most common wind direction (‘sector’)

average_speed_maxsectorfloat

speed of averaged wind (‘vector’) or average speed in most commen wind direction (‘sector’)

return_timelist or array if str or datetime objects, depending in input

See also

avrwind_vec

wind averaging using vector method

avrwind_sec

wind averaging using sector method

Examples

>>> date_str = ['01.01.2010 12:00:00', '01.01.2010 12:01:00']
>>> avrwind([1,2], [3,4], date_str, 60*2, 'vector')
[[1.5],
 [3.5],
 [203.19859051364818],
 [3.8078865529319543],
 array(['01.01.2010 12:01:00'],
      dtype='|S19')]
>>> avrwind([1,2], [3,4], date_str, 60*2, 'vector', wind_=False)
[[1.5],
 [3.5],
 [23.198590513648185],
 [3.8078865529319543],
 array(['01.01.2010 12:01:00'],
      dtype='|S19')]
>>> avrwind([1,2], [3,4], 60, 120, 'sector', sec=16)
[[1.4607818031736237],
 [3.526639240889589],
 [202.5],
 [3.8172068075839798],
 [datetime.datetime(1900, 1, 1, 0, 1)]]
varwg.meteo.avrwind.avrwind_sec(u, v, sec=16, verbose=True, timeinfo=None, return_secdata=False, wind=True)[source]

function to calculate the average windspeed and directions via sectors

looks for sector with most wind, gives the sector as dir and the average of wind speed in this sector as speed

Parameters:
ufloat or np.array of floats

component u pointing from west to east

vfloat or np.array of floats

component v pointing from south to north

secint, optional

number of sectors used for interpolation. Default is 16

verbose{True, False}, optional

give information about problems during calculation

timeinfoNone or string, optional

time string, fmt=”%d.%m.%Y %H:%M:%S”, only for problem information

return_secdata{False, True}, optional

print information about sectors to screen

windboole, optional

input data is wind data, default is True (for details: see documentation to angle2component)

Returns:
avr_ufloat

averaged u velocity

avr_vfloat

averaged v velocity

avr_wind_directionfloat

most common wind direction

average_speed_maxsectorfloat

average speed in most commen wind direction

norm_uv_directfloat

speed: averaged input wind speeds

See also

avrwind_vec

wind averaging using vector method

avrwind

convienience function

Examples

>>> avrwind_sec([1,10,10],[-1,5,5])
(10.329287188579819, 4.2785308431564255, 247.5, 11.180339887498949, 0.6666666666666666, 7.924964445790331)
>>> avrwind_sec([1,10,10],[-1,5,5], wind=False)
(10.329287188579821, 4.2785308431564202, 67.5, 11.180339887498949, 0.6666666666666666, 7.924964445790331)
varwg.meteo.avrwind.avrwind_vec(u, v, sec=16, verbose=True, timeinfo=None, return_secdata=False, wind=True)[source]

calculates the average windspeed and direction using vector averaging

Parameters:
ufloat or np.array of floats

component u pointing from west to east

vfloat or np.array of floats

component v pointing from south to north

sec, verbose, timeinfo, return_secdatakwargs

kwargs for avrwind_sec, not used here. Only for easier making the function call of the two functions the same

windboole, optional

input data is wind data, default is True (for details: see documentation to angle2component)

Returns:
avr_ufloat

averaged u velocity

avr_vfloat

averaged v velocity

angle_avrfloat

direction of averaged wind

norm_avrfloat

speed of averaged wind

norm_uv_directfloat

speed: averaged input wind speeds

See also

avrwind_sec

wind averaging using sector method

avrwind

convienience function

Examples

>>> avrwind_vec([1,23],[-1,5])
(12.0, 2.0, 260.53767779197437, 12.165525060596439, 12.475709077126368)
varwg.meteo.avrwind.component2angle(u, v, wind=True)[source]

converts a tuple of (u,v) to (angle,norm) in deg 0=north 90=east

Parameters:
ufloat or np.array of floats

component u pointing from west to east

vfloat or np.array of floats

component v pointing from south to north

windboole, optional

input data is wind data, default is True

Returns:
anglefloat or np.array of floats

direction [0,360] where the wind is coming from

normfloat or np.array of floats

wind speed

See also

angle2component

vice versa

Examples

>>> component2angle(1,0)
(270.0, 1.0)
>>> component2angle([1,-1,0,0],[0,0,1,-1], wind=False)
(array([  90.,  270.,    0.,  180.]), array([ 1.,  1.,  1.,  1.]))
varwg.meteo.avrwind.phi_main(u, v)[source]
varwg.meteo.avrwind.plothist(x, legend)[source]
varwg.meteo.avrwind.turn_uv(u, v, phi)[source]

varwg.meteo.meteox2y module

Meteorological Conversions (meteo.meteox2y)

The meteox2y module provides functions to calculate derived meteorological variables from measured meteorological values.

sat_vap_p

saturation vapour pressure from air temperature

rel2vap_p

vapour pressure from relative humidity and air temperature

vap_p2rel

relative humidity from vapour pressure and air temperature

dewpoint

dewpoint from air temperature and humidity

dew2rel

relative humidity from dewpoint and air temperature

norm_pressure

normalize pressure to sealevel

iziomon

incident long wave radiation following Iziomon et al (2003)[R6331e1085f99-1]_

lw2clouds

Cloud cover from incident long wave radiation (Iziomon et al (2003)[Rd8835ed535f1-1]_)

lw_tennessee

incident long wave radiation

haude

calculates the evapotranspiration following Haude (1955) [1] as described in the Hydrologie-I-Skript

turc

calculates the potential evapotranspiration following Turc [1] as described in the Hydrologie-I-Skript (p.

turc_rad

calculates the potential evapotranspiration following Turc

hargreaves

calculates the potential evapotranspiration rate [mm/d] following Hargreaves & Samani 1985 according to THE ASCE STANDARDIZED REFERENCE EVAPOTRANSPIRATION EQUATION

penman_monteith

Calculates the reference crop evaporation following the Penman-Monteith method and the FAO-56 determinations published in ASCE Standardized Reference Evapotranspiration Equation

pot_s_rad

theoretical maximal potential solar radiation outside of atmosphere

sunshine

sunshine or not?

blackbody_rad

Stefan-Boltzmann law

altitude

Converts continous meassured vertical pressure and temperature data to altitude.

spec_hum

Calculates the specific humidity

psychro2e

Vapour pressure from dry and wet temperature from Assmann psychrometer using Sprung's [1] formula (as seen on wikipedia)

slope_sat_p

slope of the saturation vapor pressure function, depends only on air temperature

varwg.meteo.meteox2y.SPI_ar(obs_ar, weeks=1, reference=None)[source]
varwg.meteo.meteox2y.SPI_ds(obs_ds, weeks=1, reference=None)[source]
varwg.meteo.meteox2y.STI_ar(obs_ar, weeks=1, reference=None)[source]
varwg.meteo.meteox2y.STI_ds(obs_ds, weeks=1, reference=None)[source]
varwg.meteo.meteox2y.abs_hum2rel(abs_hum, at)[source]

Relative humidity from absolute humidity and air temperature.

Parameters:
abs_humfloat or numpy.array of floats

absolute humidity [g / m^3]

atfloat or numpy.array of floats

air temperature [deg C]

Returns:
rhfloat or numpy.array of floats

relative humidity with values between 0 and 1

Examples

>>> abs_hum2rel(13.831072059995932, 20)
0.8
varwg.meteo.meteox2y.altitude(temp1, temp0, pres1, pres0, alt0)[source]

Converts continous meassured vertical pressure and temperature data to altitude. # 1 means i and 0 means i-1

Parameters:
temp1float or array_like

Temperature value at timestep i.

temp0float or array_like

Temperature value at timestep i-1.

pres1float or array_like

Pressure value at timestep i.

pres0float or array_like

Pressure value at timestep i-1.

alt0float or array_like

Altitude value at timestep i-1.

Returns:
altitudefloat or array_like

Altitude at timestep i

Notes

This is the implemented equation:

g : Gravity acceleration 9.81 m/s^2 T_0 : Temperature 273.16 K

altitude = ((\frac{\ln(pres0)}{pres1})*287*((\frac{(\frac{(temp1+temp0)}{2})+T_0)}/{g}))+alt0

References

* -> Ask Felix!!! *

Examples

>>> alt = np.nan*np.ones(40)
>>> alt[0] = 600
>>> for i,element in enumerate(alt):
...    if str(element) == 'nan':
...        element = altitude(temp[i], temp[i-1], pres[i], pres[i-1], alt[i-1])
varwg.meteo.meteox2y.apparent_temperature(Ta, rh, ws, Q)[source]

Australian Bureau of Meteorology formulation of Steadman (1984).

varwg.meteo.meteox2y.blackbody_rad(rad=None, temp=None, eps=1.0)[source]

Stefan-Boltzmann law

There are two ways to use this funtion:

1) If input is radiation, then the function calculates the absolute temperature of the body emitting the radiation

2) If input is temperature, then the function calculates the radiation emitted by the body of this temperature

Parameters:
radfloat or numpy.array of floats or None

radiation [W/m**2]

tempfloat or numpy.array of floats or None

temperature [deg C]

epsfloat or numpy.array of floats, optional

emissivity of a grey body, values between 0 and 1, default=1

Returns:
either:
tempfloat or numpy.array of floats or None

temperature [deg C]

or:
radfloat or numpy.array of floats or None

radiation [W/m**2]

Examples

>>> "%.9f" % blackbody_rad(rad=350)
'7.138805085'
>>> "%.9f" % blackbody_rad(temp=0)
'315.683203500'
varwg.meteo.meteox2y.brunner_compound(sti, spi, sequential=False, progress=False)[source]

Rank-based hot-dry index.

Notes

Brunner 2021 uses E-GPD for precipitation and a STI index for temperature. This implementation just uses empirical ranks.

References

Brunner, Manuela I., Eric Gilleland, and Andrew W. Wood. “Space–Time Dependence of Compound Hot–Dry Events in the United States: Assessment Using a Multi-Site Multi-Variable Weather Generator.” Earth System Dynamics 12, no. 2 (May 19, 2021): 621–34. https://doi.org/10.5194/esd-12-621-2021.

varwg.meteo.meteox2y.dew2rel(dew, at)[source]

relative humidity from dewpoint and air temperature

Parameters:
atfloat or numpy.array of floats

air temperature [deg C]

dewfloat or numpy.array of floats

dewpoint [deg C]

Returns:
rhfloat or numpy.array of floats

relative humidity with values between 0 and 1 [-]

Examples

>>> dew2rel(15.,16.0)
0.9378863357566809
>>> at = np.array((0.0, 2.5, 5.0, 7.5, 10.0))
>>> dew = np.array((0.0, 3., 5.0, 7.7, 10.0))
>>> dew2rel(at,dew)
array([1.        ,  0.96506519,  1.        ,  0.98642692,  1.        ])
varwg.meteo.meteox2y.dewpoint(at, rh=None, e=None)[source]

dewpoint from air temperature and humidity

As input is required: air temperature (at) and EITHER relative humidity (rh) OR vapour pressure (e).

Parameters:
atfloat or numpy.array of floats

air temperature [deg C]

rhfloat or numpy.array of floats or None

relative humidity with values between 0 and 1 [-]

efloat or numpy.array of floats or None

vapour pressure [hPa]

Returns:
dewfloat or numpy.array of floats

dewpoint [deg C]

Raises:
Warning

If relative humidity is > 1.1 (e. g. if vapour pressure is taken as relative humidity)

Examples

>>> dewpoint(20.,rh=0.5)
9.269628637124908
>>> dewpoint(20.,e=10.0)
6.968196840688138
>>> at = np.array((0.0, 2.5, 5.0, 7.5, 10.0))
>>> rh = np.array((0.9, 0.8, 0.7, 0.6, 0.5))
>>> dewpoint(at, rh=rh)
array([-1.43893707, -0.59071344, -0.0041022 ,  0.25144096,  0.07140267])
>>> at = np.array((0.0, 2.5, 5.0, 7.5, 10.0))
>>> e = np.array((5.5, 5.8, 6.1, 6.2, 6.3))
>>> dewpoint(at, e=e)
array([-1.43646874, -0.71330622, -0.02250498,  0.20109231,  0.42152362])
varwg.meteo.meteox2y.esi(at, rh, sw)[source]

Environmental stress index (wet bulb globe temperature substitute)

Parameters:
atfloat or numpy.array of floats

air temperature [deg C]

rhfloat or numpy.array of floats

relative humidity [%]

swfloat or numpy.array of floats

solar radiation [W / m²]

Returns:
ESIenvironmental stress index

References

[1]

Moran et al., “An Environmental Stress Index (ESI) as a Substitute for the Wet Bulb Globe Temperature (WBGT).”

varwg.meteo.meteox2y.get_tz_offset(dates, longitude, latitude)[source]
varwg.meteo.meteox2y.hargreaves(tmax, tmin, date, in_format='%Y-%m-%dT%H:%M:%S')[source]

calculates the potential evapotranspiration rate [mm/d] following Hargreaves & Samani 1985 according to THE ASCE STANDARDIZED REFERENCE EVAPOTRANSPIRATION EQUATION

Parameters:
tmaxnp.array of floats

maximum of the daily air temperature [deg C]

tminnp.array of floats

minimum of the daily air temperature [deg C]

datenp.array of strings

date strings in format in_format

in_formatformat string

default: ‘%Y-%m-%dT%H:%M:%S’

Returns:
etpnumpy.array of floats

potential evapotranspiration [mm/d]

Notes

  • equation needs the extraterrestrial radiation Ra, which depends on:

    • inverse relative distance factor for the earth-sun dr []

    • solar declination delta [rad]

    • sunset hour angle [rad] with latitude Lauchaecker lat=48.738 deg => pi/180 * 48.738 deg = 0.8506 rad

  • conversion of date in day of year (j)

  • ETPmax = 7.0 mm/d due to energetic limit (Germany)

varwg.meteo.meteox2y.haude(svp, vp, mon)[source]

calculates the evapotranspiration following Haude (1955) [1] as described in the Hydrologie-I-Skript

Parameters:
svpfloat or numpy.array of floats

saturation vapour pressure [hPa], measured at 2pm

vpfloat or numpy.array of floats

vapour pressure [hPa], measured at 2pm

monint or numpy.array of ints

month: 1=january, 12=december

Returns:
etpfloat or numpy.array of floats

evapotranspiration [mm] daily values

See also

turc

potential evapotranspiration following Turc

Notes

The Haude formula is only valid in temperate humid climate

References

[1] (1,2)

Haude, W. (1955): Zur Bestimmung der Verdunstung auf moeglichst einfache Weise. - Mitt. Dt. Wetterd. 2 (11), Bad Kissingen (Dt. Wetterd.)

Examples

>>> haude(12.28,8.83,5)
1.0005
>>> haude(12.28,8.83,12)
0.759
>>> svp = np.array([11.87809345,  12.28364703,  12.70132647])
>>> vp = np.array([8.55222728,  8.84422586,  9.14495506])
>>> haude(svp,vp,12)
array([0.73169056,  0.75667266,  0.78240171])
>>> mon = np.array([2,3,4])
>>> haude(svp,vp,mon)
array([0.73169056,  0.75667266,  1.03134771])
varwg.meteo.meteox2y.humidex(at, rh)[source]
varwg.meteo.meteox2y.iziomon(temp, clouds, rh=None, dew=None, e=None, site='low')[source]

incident long wave radiation following Iziomon et al (2003)[R6331e1085f99-1]_

As input is required: air temperature (temp), cloud cover (clouds) and EITHER relative humidity (rh) OR dewpoint (dew) OR vapour pressure (e).

Parameters:
tempfloat or numpy.array of floats

air temperature [deg C]

cloudsfloat or numpy.array of floats

cloud cover with values between 0 and 1 [-]

rhfloat or numpy.array of floats or None

relative humidity with values between 0 and 1 [-]

dewfloat or numpy.array of floats or None

dewpoint [deg C]

efloat or numpy.array of floats or None

vapour pressure [hPa]

site{‘low’, ‘high’}

parameterisation for lowland or highland site

Returns:
lwfloat or numpy.array of floats

incident longwave radiation [W/m**2]

See also

lw2clouds

reverse (get cloud cover out of long wave, temperature and humidity)

Notes

Empirical formula, found for experiments in Bremgarten (47deg54’35’’N; 7deg37’18’’E) in the Upper Rhine plain in Germany (lowland site) and Feldberg, 1489 m asl, 47deg52’31’’N, 8deg00’11’’E, Black Forest, Germany (highland site)

References

[1]

Iziomon, M.G., Mayer H, Matzarakis A. (2003): Downward atmospheric longwave irradiance under clear and cloudy skies: Measurement and parameterization, Journal of Atmospheric and Solar-Terrestrial Physics 65 (2003) 1107 - 1116

Examples

>>> iziomon(15.,0.5,rh=0.89)
327.52426791875763
>>> temp = np.array((0.0, 2.5, 5.0, 7.5, 10.0))
>>> clouds = np.array((0.0, 0.1, 0.8, 0.5, 1.0))
>>> e = np.array((5.5, 5.8, 6.1, 6.2, 6.3))
>>> iziomon(temp,clouds,e=e)
array([225.34414848,  235.0777488 ,  279.01405432,  267.25348612,
        321.15448959])
varwg.meteo.meteox2y.lw2clouds(lw, temp, rh=None, dew=None, e=None, site='low')[source]

Cloud cover from incident long wave radiation (Iziomon et al (2003)[Rd8835ed535f1-1]_)

As input is required: incident long wave radiation (lw), air temperature (temp) and EITHER relative humidity (rh) OR dewpoint (dew) OR vapour pressure (e)

Parameters:
lwfloat or numpy.array of floats

incident longwave radiation [W/m**2]

tempfloat or numpy.array of floats

air temperature [deg C]

rhfloat or numpy.array of floats or None

relative humidity with values between 0 and 1 [-]

dewfloat or numpy.array of floats or None

dewpoint [deg C]

efloat or numpy.array of floats or None

vapour pressure [hPa]

site{‘low’, ‘high’}

parameterisation for lowland or highland site

Returns:
cloudsfloat or numpy.array of floats

cloud cover with values between 0 and 1 [-]

See also

iziomon

incident long wave radiation from air temperature, cloud cover and humidity

Notes

Resulting cloud cover is always between 0 and 1. Gives 0 for unrealistic low and 1 for unrealistic high values of lw.

References

[1]

Iziomon, M.G., Mayer H, Matzarakis A. (2003): Downward atmospheric longwave irradiance under clear and cloudy skies: Measurement and parameterization, Journal of Atmospheric and Solar-Terrestrial Physics 65 (2003) 1107 - 1116

Examples

>>> lw2clouds(328., 15., rh=0.9)
0.49959967427213553
>>> lw = np.array((225.5, 235.1, 279, 267, 321.2))
>>> temp = np.array((0.0, 2.5, 5.0, 7.5, 10.0))
>>> e = np.array((5.5, 5.8, 6.1, 6.2, 6.5))
>>> lw2clouds(lw,temp,e=e)
array([0.0555659 ,  0.1020956 ,  0.79983929,  0.49550839,  0.99289638])
varwg.meteo.meteox2y.lw_tennessee(temp, clouds)[source]

incident long wave radiation

Parameters:
tempfloat or numpy.array of floats

air temperature [deg C]

cloudsfloat or numpy.array of floats

cloud cover with values between 0 and 1 [-]

Returns:
lwfloat or numpy.array of floats

incident longwave radiation [W/m**2]

See also

iziomon

other empirical formula, from southwestern germany

References

[1]

Tennessee Valley Authority 1972. Heat and mass transfer between a water surface and the atmosphere Water Resources Research Laboratory Report 14, Report No. 0-6803. (I didn’t find it. But it’s mentioned in:)

[2]

ELCOM Science manual

varwg.meteo.meteox2y.max_sunshine_minutes(dates, longitude, latitude, tz_offset=None)[source]
varwg.meteo.meteox2y.norm_pressure(p, at, h=454.0)[source]

normalize pressure to sealevel

formula from wikipedia.de for linear temperature gradient 0.0065K/m

Parameters:
pfloat or numpy.array of floats

pressure [hPa]

atfloat or numpy.array of floats

air temperature [deg C]

hfloat, optional

height above sea level of measuring station [m] default value = 454.0 (height of station Stuttgart-Lauchaecker)

Returns:
p_nnfloat or numpy.array of floats

sea level pressure [hPa]

Examples

>>> "%.9f" % norm_pressure(930,10.0)
'982.074383073'
>>> "%.9f" % norm_pressure(930,10.0,h=765)
'1019.090035371'
>>> at = np.array((0.0, 2.5, 5.0, 7.5, 10.0))
>>> p = np.array((925, 930, 935, 932, 931))
>>> norm_pressure(p,at,h=765)
array([1016.98077228,  1021.60706988,  1026.24032953,  1022.10690872,
        1020.18583111])
varwg.meteo.meteox2y.penman_monteith(at, u, Rn, rh)[source]

Calculates the reference crop evaporation following the Penman-Monteith method and the FAO-56 determinations published in ASCE Standardized Reference Evapotranspiration Equation

Parameters:
atnp.array of floats

mean daily air temperature at 2m-height [deg C]

unp.array of floats

mean daily wind speed at 2m-height [m/s]

Rnnp.array of floats

measured net radiation at the crop surface [MJ m^-2 d^-1]

rhnp.array of floats

relative humidity [%]

Returns:
etonp.array of floats
FAO Penman-Monteith standardized reference crop evapotranspiration for

short (~=0.12m) surfaces [mm d^-1]

Notes

  • Units for the 0.408 coefficient are m^2 mm MJ^-1

  • The FAO-56 Penman-Monteith equation is a grass reference equation that was derived from the Penman-Monteith form of the combination equation (Monteith 1965, 1981) by fixing h = 0.12 m for clipped grass and by assuming measurement heights of z = 2 m (at, rh, u) and using a latent heat of vaporization of 2.45 MJ kg-1. The result is an equation that defines the reference evapotranspiration from a hypothetical grass surface having a fixed height of 0.12 m, bulk surface resistance of 70 s m-1, and albedo of 0.23.

  • in relationship to the net radiation, the soil heat flux is very small and is fixed with G = 0.1*Rn

varwg.meteo.meteox2y.pot_s_rad(date, lat=48.738, longt=9.099, in_format='%Y-%m-%dT%H:%M', tz_mer=15.0, wog=-1)[source]

theoretical maximal potential solar radiation outside of atmosphere

Parameters:
datenumpy.array of time strings (format: in_format) or datetime objects

or floats (doys)

latfloat, optional

latitude of station in decimal degrees, default: Stuttgart Lauchaecker

longtfloat, optional

longitude of station in decimal degrees, default: Stuttgart Lauchaecker

in_formattime format string, optional

format of date if date is string, default ‘%Y-%m-%dT%H:%M’

tz_merint, optional

central meridian of time zone, default: 15 (CET)

wog{-1, 1}, optional

west of greenwich, 1 if west, -1 if east, default = -1

Returns:
smaxnumpy.array of floats

maximal potential solar radiation in W/m^2

Notes

from campbell technical note 18 [1], except declination of sun (d): formula of Spencer (1971) [2]

WARNING: Campbell Scientific recommends the use of a high quality sun screen lotion when exposing your skin to solar radiation for large values of sunshine hours!

References

[1]

Campbell Scientific (2005) technical note 18: CALCULATING SUNSHINE HOURS FROM PYRANOMETER / SOLARIMETER DATA

[2]

Spencer JW (1971) Fourier series representation of the position of the Sun. Search 2: 172.

Examples

>>> date_str = np.array(["2011-09-28T11:27"])
>>> pot_s_rad(date_str)
array([855.35624182])
>>> from varwg import times
>>> dt = times.str2datetime(date_str, "%Y-%m-%dT%H:%M")
>>> pot_s_rad(dt)
array([855.35624182])
>>> pot_s_rad(times.datetime2doy(dt))
array([855.35624182])
varwg.meteo.meteox2y.pot_s_rad_daily(date, lat=48.738, longt=9.099, in_format='%Y-%m-%d', tz_mer=15.0, wog=-1)[source]

daily average values of –> pot_s_rad

varwg.meteo.meteox2y.psychro2e(t_dry, t_wet, p=None)[source]

Vapour pressure from dry and wet temperature from Assmann psychrometer using Sprung’s [1] formula (as seen on wikipedia)

Parameters:
t_dryfloat or np.array of floats

dry temperature [deg C]

t_wetfloat or np.array of floats

wet temperature [deg C]

pfloat or np.array of floats or None, optional

air pressure [hPa], if None: use the simplified version of the formula, default is None

Returns:
efloat or np.array of floats

vapour pressure [hPa]

Notes

If p is None, a simplification is used which can be used below 500m above sea level

References

[1] (1,2)

Sprung, A.: Ueber die Bestimmung der Luftfeuchtigkeit mit Hilfe des Assmannschen Aspirationspsychrometers, Z. Angew. Meteorol., Das Wetter, 5 (1888), S. 105?108

Examples

>>> psychro2e(np.array([17.5,18.9]),np.array([12.3,12.1]))
array([10.82619823,   9.56701424])
>>> p = np.array([800,800])
>>> psychro2e(np.array([17.5,18.9]),np.array([12.3,12.1]),p=p)
array([11.57630294,  10.54309631])
varwg.meteo.meteox2y.rel2abs_hum(rh, at)[source]

Absolute humidity from relative humidity and air temperature.

Parameters:
rhfloat or numpy.array of floats

relative humidity with values between 0 and 1

atfloat or numpy.array of floats

air temperature [deg C]

Returns:
abs_humfloat or numpy.array of floats

absolute humidity [g / m^3]

Examples

>>> rel2abs_hum(0.8, 20)
13.831072059995932
varwg.meteo.meteox2y.rel2vap_p(rh, at)[source]

vapour pressure from relative humidity and air temperature

Parameters:
rhfloat or numpy.array of floats

relative humidity with values between 0 and 1 [-]

atfloat or numpy.array of floats

air temperature [deg C]

Returns:
efloat or numpy.array of floats

vapour pressure [hPa]

Examples

>>> rel2vap_p(0.5,20.0)
11.695234581996313
>>> rh = np.array((0.9, 0.8, 0.7, 0.6, 0.5))
>>> at = np.array((0.0, 2.5, 5.0, 7.5, 10.0))
>>> rel2vap_p(rh,at)
array([5.499     ,  5.85226692,  6.10817613,  6.22271646,  6.14182351])
varwg.meteo.meteox2y.sat_vap_p(at)[source]

saturation vapour pressure from air temperature

Parameters:
atfloat or numpy.array of floats

air temperature [deg C]

Returns:
c_efloat or numpy.array of floats

saturation vapour pressure [hPa]

References

Hydrologie-Skript I, p. 17

Examples

>>> sat_vap_p(25.0)
31.688149728170984
>>> at = np.array((0.0, 2.5, 5.0, 7.5, 10.0))
>>> sat_vap_p(at[:3])
array([6.11      ,  7.31533365,  8.72596589])
>>> sat_vap_p(at[3:])
array([10.3711941 ,  12.28364703])
varwg.meteo.meteox2y.slope_sat_p(at)[source]

slope of the saturation vapor pressure function, depends only on air temperature

Parameters:
atfloat or numpy.array of floats

(mean daily) air temperature [deg C]

Returns:
slopefloat or numpy.array of floats

slope of the saturation vapor pressure function [kPa/deg C]

Notes

A polynomial is used to evaluate the slope and is only valid for -5 < ‘at’ > 45 [deg C].

References

[1]

Campbell Scientific (1995) application note 4-D: On-Line Estimation of Grass Reference Evapotranspiration with the Campbell Scientific Automated Weather Station

varwg.meteo.meteox2y.sonnenscheindauer(date, sw, del_t=60)[source]

bestimmt Sonnenscheindauer anhand der kurzwelligen Solarstrahlung

Parameters:
datestring

datetime.datetime(2040, 1, 1, 0, 0, 0)

swstring
del_tint, optional

timestep in minutes: 1-min-data is averaged to this timestep. Default is 60

Returns:
sunshine_hour
varwg.meteo.meteox2y.spec_hum(e, p)[source]

Calculates the specific humidity

Parameters:
pressurefloat

air pressure in hPa

efloat

vapour pressure in hPa

Returns:
spec_humfloat

Notes

The formula is: s = ((0.623*e)/(p-0.377*e))*1000 where M_w/M_tL=0.622 and 0.378 = 1-0.622

varwg.meteo.meteox2y.sunshine(sw, date, lat=48.738, longt=9.099, in_format='%Y-%m-%dT%H:%M', tz_mer=15.0, wog=-1)[source]

sunshine or not?

calculates maximum potential solar radiation depending on latitude, longitude, and time and compares it to actual solar radiation. Sunshine if actual solar radiation > 0.4*maximum potential solar radiation accurate enough for normal non-scientific use of sunshine hour data

Parameters:
swnumpy.array of floats

solar (short wave) radiation in W/m^2

datenumpy.array of time strings

date and time in format in_format

latfloat, optional

latitude of station in decimal degrees, default: Stuttgart Lauchaecker

longtfloat, optional

longitude of station in decimal degrees, default: Stuttgart Lauchaecker

in_formattime format string, optional

format of date, default ‘%Y-%m-%dT%H:%M’

tz_merint, optional

central meridian of time zone, default: 15 (CET)

wog{-1, 1}, optional

west of greenwich, 1 if west, -1 if east, default = -1

Returns:
shiningnumpy.array containing 0 and 1

1: sun is shining in corresponding time step, 0: sun is not shining in corresponding time step

Examples

>>> sunshine(np.array([450]),np.array(["2011-09-28T11:27"]))
array([1])
>>> sunshine(np.array([200]),np.array(["2011-09-28T11:27"]))
array([0])
varwg.meteo.meteox2y.sunshine_hours(dates, longitude, latitude, tz_offset=None)[source]

Calculates hours from sunrise to sunset.

Notes

see: https://en.wikipedia.org/wiki/Sunrise_equation https://michelanders.blogspot.com/2010/12/calulating-sunrise-and-sunset-in-python.html

Examples

>>> from datetime import date
>>> sunshine_hours([date(2018, 6, 1)], 8.848, 48.943)  # mühlacker
array([15.89961046])
varwg.meteo.meteox2y.sunshine_pot(doys, lat=48.738, longt=9.099, tz_mer=15.0, wog=-1)[source]

Maximum daily sunshine hours based on evaluating pot_s_rad per minute.

varwg.meteo.meteox2y.sunshine_riseset(dates, longitude, latitude, tz_offset=None)[source]

Calculates sunrise and sunset hours.

varwg.meteo.meteox2y.temp2lw(temp)[source]

Incident long-wave radiation from air temperature (Gal pc).

Parameters:
tempfloat or numpy.array of floats

air temperature [deg C]

Returns:
lwfloat or numpy.array of floats

incident longwave radiation [W/m**2]

varwg.meteo.meteox2y.turc(at, ts, mon)[source]

calculates the potential evapotranspiration following Turc [1] as described in the Hydrologie-I-Skript (p. 55)

Parameters:
atfloat or numpy.array of floats

daily average air temperature [degC]

tsfloat or numpy.array of floats

number of sunshine hours per day

monint or numpy.array of ints

month: 1=january, 12=december

Returns:
etpfloat or numpy.array of floats

potential evapotranspiration [mm] daily values

See also

haude

evapotranspiration following Haude

Notes

The Turc formula is only valid for at > 0 deg C

References

[1] (1,2)

TURC??

Examples

>>> "%.9f" % turc(10,0,5)
'1.104000000'
>>> "%.9f" % turc(10,0,12)
'0.408000000'
varwg.meteo.meteox2y.turc_rad(at, rh, G)[source]

calculates the potential evapotranspiration following Turc

with the global radiation instead of the empiric factors according to Hydrologie und Wasserwirtschaft by Maniak

Parameters:
atnumpy.array of floats

mean daily air temperature [deg C]

rhnumpy.array of floats

relative humidity [%]

Gnumpy.array of floats

global radiation [W/m^2]

Returns:
etpnumpy.array of floats

potential evapotranspiration [mm/d]

Notes

  • For etp < 0.1 mm/d the evapotranspiration rate is set to 0.1 mm/d. [DVWK 1996]

  • According to the energetic limit of 7 mm/d in Germany, ETPmax is set to 7 mm/d.

varwg.meteo.meteox2y.vap_p2rel(e, at)[source]

relative humidity from vapour pressure and air temperature

Parameters:
efloat or numpy.array of floats

vapour pressure [hPa]

atfloat or numpy.array of floats

air temperature [deg C]

Returns:
rhfloat or numpy.array of floats

relative humidity with values between 0 and 1 [-]

Examples

>>> vap_p2rel(6.22,20.0)
0.26592027532201407
>>> e = np.array((5.5, 5.8, 6.1, 6.2, 6.3))
>>> at = np.array((0.0, 2.5, 5.0, 7.5, 10.0))
>>> vap_p2rel(e,at)
array([0.90016367, 0.79285516, 0.69906301, 0.59780966, 0.512877  ])
varwg.meteo.meteox2y.wet_bulb_stull(at, rh)[source]

varwg.meteo.windrose module

Provides functions to plot windroses when given wind directions.

varwg.meteo.windrose.equal_num_bins(values, n_bins, round=True)[source]

Returns bins so that values is cut into n_bins bins that each contain the same number of values’ values.

varwg.meteo.windrose.mind_the_gap(hist, overlap_i)[source]
varwg.meteo.windrose.rel_ranks(values)[source]

Returns ranks of values in the range [0,1].

varwg.meteo.windrose.scatter(wind_dirs, speed)[source]
varwg.meteo.windrose.seasonal_windroses(datetimes, wind_dirs, n_sectors=32, time_format_str='%m', fig=None, speed=None, title=None, normalize=True, separate=False, *args, **kwds)[source]

Plots a figure with subplots of windroses. Each subplot is a windrose containing only directions from the measurement times signified by “time_format_str”. The default (“%m”) plots one windrose for each distinct month.

varwg.meteo.windrose.windrose(wind_dirs, n_sectors=32, speed=None, speed_bins=6, fig=None, subfig=False, ticks=True, normalize=True, *args, **kwds)[source]

Plots a windrose (histogram with polar axes) of the given wind_dirs. If speed_bins is an int, equally filled speed_bins will be created.

Module contents