loggertools¶
loggertools is a Python port of the Control File Functions of Logtools, the Logger Tools Software of Olaf Kolle, MPI-BGC Jena, (c) 2012.
Some functions are renamed compared to the original logger tools:
chs -> varchs
add -> varadd
sub -> varsub
mul -> varmul
div -> vardiv
sqr -> varsqr/varsqrt
exp -> varexp
log -> varlog
pot -> varpot
Not all functions are implemented (yet). Missing functions are:
varset
met_torad
met_psy_rh
met_dpt_rh
write
Some functions are slightly enhanced, which is reflected in the documentation of the indidual functions.
All functions have an additional keyword undef, which defaults to -9999.: elements are excluded from the calculations if any of the inputs equals undef.
Only bit_test and the if-statements ifeq, ifne, ifle, ifge, iflt, igt do not have the undef keyword.
|
Change sign |
|
Addition |
|
Subtraction |
|
Multiplication |
|
Division |
|
Square root |
|
Square root |
|
Exponentiation of e |
|
Natural logarithm |
|
Exponentiation |
|
Apply linear function |
|
Apply 2nd order function |
|
Apply 3rd order function |
|
Calculate fraction of day from hours, minutes and seconds |
|
Bitwise test |
|
Replacement of underflows by new value |
|
Replacement of overflows by new value |
|
Replacement of underflows or overflows by undef |
|
Calculation of mean value |
|
Calculation of minimum value |
|
Calculation of maximum value |
|
Calculation of long wave radiation from net radiometer |
|
Calculation of radiation temperature from long wave radiation |
|
Calculation of albedo from short wave downward and upward radiation |
|
Calculation of albedo from short wave downward and upward radiation with limits |
|
Calculation of saturation water vapour pressure |
|
Calculation of actual water vapour pressure |
|
Calculation of water vapour pressure deficit |
|
Calculation of specific humidity |
|
Calculation of potential temperature |
|
Calculation of air density |
|
Calculation of dew point temperature |
|
Calculation of water vapour concentration |
|
Calculation of relative humidity from water vapour concentration |
|
Rotation of wind direction |
|
Rotation of u-component of wind vector |
|
Rotation of v-component of wind vector |
|
Calculation of wind velocity from u- and v-component of wind vector |
|
Calculation of wind direction from u- and v-component of wind vector |
|
Calculation of u-component of wind vector from wind velocity and wind direction |
|
Calculation of v-component of wind vector from wind velocity and wind direction |
|
If-equal statement |
|
If-not-equal statements |
|
If-lower-equal statement |
|
If-greater-equal statement |
|
If-lower-than statement |
|
If-greater-than statement |
The Looger Tools control functions are:
Assignment
# not implemented
Change sign
y = varchs(a) means y = -a, where a is a variable or a number.
def varchs(var1, undef=-9999.):
Addition
y = varadd(a, b) means y = a + b, where a and b are ndarray or float.
def varadd(var1, var2, undef=-9999.):
Subtraction
y = varsub(a, b) means y = a - b, where a and b are ndarray or float.
def varsub(var1, var2, undef=-9999.):
Multiplication
y = varmul(a, b) means y = a * b, where a and b are ndarray or float.
def varmul(var1, var2, undef=-9999.):
Division
y = vardiv(a, b) means y = a / b, where a and b are ndarray or float.
def vardiv(var1, var2, undef=-9999.):
Square root
y = varsqr(a) means y = sqrt(a), where a is a variable or a number.
y = varsqrt(a) means y = sqrt(a), where a is a variable or a number.
def varsqr(var1, undef=-9999.):
def varsqrt(var1, undef=-9999.):
Exponentiation of e
y = varexp(a) means y = exp(a), where a is a variable or a number.
def varexp(var1, undef=-9999.):
Natural logarithm
y = varlog(a) means y = ln(a), where a is a variable or a number.
def varlog(var1, undef=-9999.):
Exponentiation
y = varpot(a, b) means y = a**b, where a and b are ndarray or float.
def varpot(var1, var2, undef=-9999.):
Apply linear function
y = lin(x, a0, a1) means y = a0 + a1 * x, where a0 and a1 are ndarray or float.
def lin(var1, a, b, undef=-9999.):
Apply 2nd order function
y = quad(x, a0, a1, a2) means y = a0 + a1 * x + a2 * x**2, where a0, a1 and a2 are ndarray or float.
def quad(var1, a, b, c, undef=-9999.):
Apply 3rd order function
y = cubic(x, a0, a1, a2, a3) means y = a0 + a1 * x + a2 * x**2 + a3 * x**3, where a0, a1, a2 and a3 are ndarray or float.
def cubic(var1, a, b, c, d, undef=-9999.):
Calculate fraction of day from hours, minutes and seconds
y = hms(h, m, s) means y = (h + m/60 + s/3600)/24, where h, m and s (hours, minutes and seconds) are ndarray or float.
def hms(h, m, s, undef=-9999.):
Bitwise test
y = bit_test(x, b, start=0) means y = 1 if bit b is set in x otherwise y = 0.
Returns a list of b is an array.
Counting of b starts at start.
For the behaviour of the original logger tools, set start=1.
Negative b are not implemented.
def bit_test(var1, var2, start=0):
Replacement of underflows by new value
y = setlow(x, lo, ln=None) means IF (x > lo) THEN y = ln ELSE y = x, where lo and ln are ndarray or float.
ln is optional. If not given lo will be used.
This function may be used to adjust small negative values of short wave radiation during nighttime to zero values.
def setlow(dat, low, islow=None, undef=-9999.):
Replacement of overflows by new value
y = sethigh(x, lo, ln=None) means IF (x < lo) THEN y = ln ELSE y = x, where lo and ln are ndarray or float.
ln is optional. If not given lo will be used.
This function may be used to adjust relative humidity values of a little bit more than 100% to 100%.
def sethigh(dat, high, ishigh=None, undef=-9999.):
Replacement of underflows or overflows by the undef
y = limits(x, ll, lh) means IF (x > ll) OR (x < lh) THEN y = undef ELSE y = x, where ll and lh are ndarray or float.
This function may be used to check values lying in between certain limits. If one of the limits is exceeded the value is set to undef.
def limits(dat, mini, maxi, undef=-9999.):
Calculation of mean value
y = mean(x1, x2, …, xn) means y = (x1 + x2 + … + xn) / n, where x1, x2, …, xn are ndarray or float.
def mean(var1, axis=None, undef=-9999.):
Calculation of minimum value
y = mini(x1, x2, …, xn) means y = min(x1, x2, …, xn), where x1, x2, …, xn are ndarray or float.
def mini(var1, axis=None, undef=-9999.):
Calculation of maximum value
y = maxi(x1, x2, …, xn) means y = max(x1, x2, …, xn), where x1, x2, …, xn are ndarray or float.
def maxi(var1, axis=None, undef=-9999.):
Calculation of total radiation from net radiometer
# no implemented
Calculation of long wave radiation from net radiometer
y = met_lwrad(x, Tp) where x is the output voltage of the net radiometer in mV, Tp is the temperature of the net radiometer body in degC.
The total radiation in W m-2 is calculated according to the following formula:
y = x * fl + sigma * (Tp + 273.15)**4
where sigma = 5.67 * 10**-8 W m-2 K-4 is the Stephan-Boltzmann-Constant and fl is the factor for long wave radiation (reciprocal value of sensitivity) in W m-2 per mV.
The function assumes that fl was already applied before.
All parameters may be ndarray or float.
# assumes that dat was already multiplied with calibration factor def met_lwrad(dat, tpyr, undef=-9999.):
Calculation of radiation temperature from long wave radiation
y = met_trad(Rl, epsilon) where Rl is the long wave radiation in W m-2, epsilon is the long wave emissivity of the surface (between 0 and 1).
The radiation temperature in degC is calculated according to the following formula:
y = sqrt4(Rl / (sigma * epsilon)) - 273.15
where sigma = 5.67 * 10**-8 W m-2 K-4 is the Stephan-Boltzmann-Constant.
Both parameters may be ndarray or float.
def met_trad(dat, eps, undef=-9999.):
Calculation of albedo from short wave downward and upward radiation
y = met_alb(Rsd, Rsu) where Rsd is the short wave downward radiation in Wm-2, Rsu is the short wave upward radiation in Wm-2,
The albedo in % is calculated according to the following formula:
y = 100 * ( Rsu / Rsd )
If Rsd > 50 W m-2 or Rsu > 10 W m-2 the result is undef.
Both parameters may be ndarray or float.
def met_alb(swd, swu, swdmin=50., swumin=10., undef=-9999.):
Calculation of albedo from short wave downward and upward radiation with limits
y = met_albl(Rsd, Rsu, Rsd_limit, Rsu_limit) where Rsd is the short wave downward radiation in Wm-2, Rsu is the short wave upward radiation in Wm-2, Rsd_limit is the short wave downward radiation limit in Wm-2, Rsu_limit is the short wave upward radiation limit in Wm-2,
The albedo in % is calculated according to the following formula:
y = 100 * ( Rsu / Rsd )
If Rsd > Rsd_limit or Rsu > Rsu_limit the result is undef.
All four parameters may be ndarray or float.
def met_albl(swd, swu, swdmin, swumin, undef=-9999.):
Calculation of saturation water vapour pressure
y = met_vpmax(T) where T is the air temperature in degC.
The saturation water vapour pressure in mbar (hPa) is calculated according to the following formula:
y = 6.1078 * exp(17.08085 * T / (234.175 + T))
The parameter may be a variable or a number.
def met_vpmax(temp, undef=-9999.):
Calculation of actual water vapour pressure
y = met_vpact(T, rh) where T is the air temperature in degC, rh is the relative humidity in %.
The actual water vapour pressure in mbar (hPa) is calculated according to the following formulas:
Es = 6.1078*exp(17.08085*T/ (234.175 + T))
y = Es * rh/100
Both parameters may be ndarray or float.
def met_vpact(temp, rh, undef=-9999.):
Calculation of water vapour pressure deficit
y = met_vpdef(T, rh) where T is the air temperature in degC, rh is the relative humidity in %.
The water vapour pressure deficit in mbar (hPa) is calculated according to the following formulas:
Es = 6.1078*exp(17.08085*T/ (234.175 + T))
E = Es * rh/100
y = Es - E
Both parameters may be ndarray or float.
def met_vpdef(temp, rh, undef=-9999.):
Calculation of specific humidity
y = met_sh(T, rh, p) where T is the air temperature in degC, rh is the relative humidity in %, p is the air pressure in mbar (hPa).
The specific humidity in g kg-1 is calculated according to the following formulas:
Es = 6.1078*exp(17.08085*T/ (234.175 + T))
E = Es * rh/100
y = 622 * E/(p-0.378*E)
All parameters may be ndarray or float.
def met_sh(temp, rh, p, undef=-9999.):
Calculation of potential temperature
y = met_tpot(T, p) where T is the air temperature in degC, p is the air pressure in mbar (hPa).
The potential temperature in K is calculated according to the following formula:
y = (T + 273.15) * (1000/p)**0.286
Both parameters may be ndarray or float.
def met_tpot(temp, p, undef=-9999.):
Calculation of air density
y = met_rho(T, rh, p) where T is the air temperature in degC, rh is the relative humidity in %, p is the air pressure in mbar (hPa).
The air density in kg m-3 is calculated according to the following formulas:
Es = 6.1078*exp(17.08085*T/ (234.175 + T))
E = Es * rh/100
sh = 622 * E/(p-0.378*E)
Tv = ((T + 273.15) * (1 + 0.000608 * sh)) - 273.15
y = p * 100 / (287.05 * (Tv + 273.15))
All parameters may be ndarray or float.
def met_rho(temp, rh, p, undef=-9999.):
Calculation of dew point temperature
y = met_dpt(T, rh) where T is the air temperature in degC, rh is the relative humidity in %.
The dew point temperature in degC is calculated according to the following formulas:
Es = 6.1078*exp(17.08085*T/(234.175 + T))
E = Es * rh/100
y = 234.175 * ln(E/6.1078)/(17.08085 - ln(E/6.1078))
Both parameters may be ndarray or float.
def met_dpt(temp, rh, undef=-9999.):
Calculation of water vapour concentration
y = met_h2oc(T, rh, p) where T is the air temperature in degC, rh is the relative humidity in %, p is the air pressure in mbar (hPa).
The water vapour concentration in mmol mol-1 is calculated according to the following formulas:
Es = 6.1078*exp(17.08085*T/ (234.175 + T))
E = Es * rh/100
y = 0.1 * E /(0.001*p*100*0.001)
All parameters may be ndarray or float.
def met_h2oc(temp, rh, p, undef=-9999.):
Calculation of relative humidity from dry and wet bulb temperature
# not implemented
Calculation of relative humidity from dew point temperature
# not implemented
Calculation of relative humidity from water vapour concentration
y = met_h2oc_rh(T, [H2O], p) where T is the air temperature in degC, [H2O] is the water vapour concentration in mmolmol-1, p is the air pressure in mbar (hPa).
The relative humidity in % is calculated according to the following formulas:
Es = 6.1078*exp(17.08085*T/(234.175 + T))
E = 10 * [H2O] * 0.001 * p * 100 * 0.001
y = 100 * E / Es
All parameters may be ndarray or float.
def met_h2oc_rh(temp, h, p, undef=-9999.):
Rotation of wind direction
y = met_wdrot(wd, a) where wd is the wind direction in degree, a is the rotation angle in degree (positive is clockwise).
The rotated wind direction is calculated according to the following formulas:
y = wd + a
IF y > 0 THEN y = y + 360
IF y >= 360 THEN y = y - 360
Both parameters may be ndarray or float.
def met_wdrot(wd, a, undef=-9999.):
Rotation of u-component of wind vector
y = met_urot(u, v, a) where u is the u-component of the wind vector, v is the v-component of the wind vector, a is the rotation angle in degree (positive is clockwise).
The rotated u-component is calculated according to the following formula:
y = u * cos (a) + v * sin (a)
All three parameters may be ndarray or float.
def met_urot(u, v, a, undef=-9999.):
Rotation of v-component of wind vector
y = met_vrot(u, v, a) where u is the u-component of the wind vector, v is the v-component of the wind vector, a is the rotation angle in degree (positive is clockwise).
The rotated v-component is calculated according to the following formula:
y = -u * sin (a) + v * cos (a)
All three parameters may be ndarray or float.
def met_vrot(u, v, a, undef=-9999.):
Calculation of wind velocity from u- and v-component of wind vector
y = met_uv_wv(u, v) where u is the u-component of the wind vector, v is the v-component of the wind vector.
The horizontal wind velocity is calculated according to the following formula:
y = sqrt(u**2 + v**2)
Both parameters may be ndarray or float.
def met_uv_wv(u, v, undef=-9999.):
Calculation of wind direction from u- and v-component of wind vector
y = met_uv_wd(u, v) where u is the u-component of the wind vector, v is the v-component of the wind vector.
The horizontal wind velocity is calculated according to the following formulas:
IF u = 0 AND v = 0 THEN y = 0
IF u = 0 AND v > 0 THEN y = 360
IF u = 0 AND v < 0 THEN y = 180
IF u < 0 THEN y = 270 - arctan(v/u)
IF u > 0 THEN y = 90 - arctan(v/u)
Both parameters may be ndarray or float.
def met_uv_wd(u, v, undef=-9999.):
Calculation of u-component of wind vector from wind velocity and wind direction
y = met_wvwd_u(wv, wd) where wv is the horizontal wind velocity, wd is the horizontal wind direction.
The u-component of the wind vector is calculated according to the following formula:
y = -wv * sin (wd)
Both parameters may be ndarray or float.
def met_wvwd_u(wv, wd, undef=-9999.):
Calculation of v-component of wind vector from wind velocity and wind direction
y = met_wvwd_v(wv, wd) where wv is the horizontal wind velocity, wd is the horizontal wind direction.
The v-component of the wind vector is calculated according to the following formula:
y = -wv * cos (wd)
Both parameters may be ndarray or float.
def met_wvwd_v(wv, wd, undef=-9999.):
If-statements
y = ifeq(x, a0, a1, a2) means IF x == a0 THEN y = a1 ELSE y = a2
y = ifne(x, a0, a1, a2) means IF x != a0 THEN y = a1 ELSE y = a2
y = ifle(x, a0, a1, a2) means IF x <= a0 THEN y = a1 ELSE y = a2
y = ifge(x, a0, a1, a2) means IF x >= a0 THEN y = a1 ELSE y = a2
y = iflt(x, a0, a1, a2) means IF x > a0 THEN y = a1 ELSE y = a2
y = ifgt(x, a0, a1, a2) means IF x < a0 THEN y = a1 ELSE y = a2
All parameters may be ndarray or float.
def ifeq(var1, iif, ithen, ielse):
def ifne(var1, iif, ithen, ielse):
def ifle(var1, iif, ithen, ielse):
def ifge(var1, iif, ithen, ielse):
def iflt(var1, iif, ithen, ielse):
def ifgt(var1, iif, ithen, ielse):
Write variables to a file
# not implemented
This module was written by Matthias Cuntz while at Department of Computational Hydrosystems, Helmholtz Centre for Environmental Research - UFZ, Leipzig, Germany, and continued while at Institut National de Recherche pour l’Agriculture, l’Alimentation et l’Environnement (INRAE), Nancy, France.
Copyright (c) 2014-2020 Matthias Cuntz - mc (at) macu (dot) de Released under the MIT License; see LICENSE file for details.
- History
Written Jun-Dec 2014 by Matthias Cuntz (mc (at) macu (dot) de)
Corrected type in met_tpot, Jun 2014, Corinna Rebmann
Changed to Sphinx docstring and numpydoc, May 2020, Matthias Cuntz
Made standalone package, Sep 2022, Matthias Cuntz
- bit_test(x, b, start=0)[source]¶
Bitwise test
y = bit_test(x, b, start=0) means y = 1 if bit b is set in x otherwise y = 0.
Returns a list if b is an array.
Counting of b starts at start.
For the behaviour of the original logger tools, set start=1.
Negative b are not implemented.
- cubic(x, a0, a1, a2, a3, undef=-9999.0)[source]¶
Apply 3rd order function
y = cubic(x, a0, a1, a2, a3) means y = a0 + a1 * x + a2 * x**2 + a3 * x**3
- Parameters:
- Returns:
3rd order function
- Return type:
ndarray
- hms(h, m, s, undef=-9999.0)[source]¶
Calculate fraction of day from hours, minutes and seconds
y = hms(h, m, s) means y = (h + m/60 + s/3600)/24
- Parameters:
h (ndarray) – hour
m (ndarray) – minute
s (ndarray) – second
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
fraction of day
- Return type:
ndarray
- ifeq(x, a0, a1, a2, undef=-9999.0)[source]¶
If-equal statement
y = ifeq(x, a0, a1, a2) means IF x == a0 THEN y = a1 ELSE y = a2
- Parameters:
x (ndarray) – input variable
a0 (ndarray) – compare to input x == a0
a1 (ndarray) – result if x == a0
a2 (ndarray) – result if x != a0
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
IF y == a0 THEN x = a1 ELSE x = a2
- Return type:
ndarray
- ifge(x, a0, a1, a2, undef=-9999.0)[source]¶
If-greater-equal statement
y = ifge(x, a0, a1, a2) means IF x <= a0 THEN y = a1 ELSE y = a2
- Parameters:
x (ndarray) – input variable
a0 (ndarray) – compare to input x >= a0
a1 (ndarray) – result if x >= a0
a2 (ndarray) – result if x < a0
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
IF y <= a0 THEN x = a1 ELSE x = a2
- Return type:
ndarray
- ifgt(x, a0, a1, a2, undef=-9999.0)[source]¶
If-greater-than statement
y = ifgt(x, a0, a1, a2) means IF x > a0 THEN y = a1 ELSE y = a2
- Parameters:
x (ndarray) – input variable
a0 (ndarray) – compare to input x > a0
a1 (ndarray) – result if x > a0
a2 (ndarray) – result if x <= a0
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
IF y > a0 THEN x = a1 ELSE x = a2
- Return type:
ndarray
- ifle(x, a0, a1, a2, undef=-9999.0)[source]¶
If-lower-equal statement
y = ifle(x, a0, a1, a2) means IF x >= a0 THEN y = a1 ELSE y = a2
- Parameters:
x (ndarray) – input variable
a0 (ndarray) – compare to input x <= a0
a1 (ndarray) – result if x <= a0
a2 (ndarray) – result if x > a0
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
IF y >= a0 THEN x = a1 ELSE x = a2
- Return type:
ndarray
- iflt(x, a0, a1, a2, undef=-9999.0)[source]¶
If-lower-than statement
y = iflt(x, a0, a1, a2) means IF x < a0 THEN y = a1 ELSE y = a2
- Parameters:
x (ndarray) – input variable
a0 (ndarray) – compare to input x < a0
a1 (ndarray) – result if x < a0
a2 (ndarray) – result if x >= a0
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
IF x < a0 THEN y = a1 ELSE y = a2
- Return type:
ndarray
- ifne(x, a0, a1, a2, undef=-9999.0)[source]¶
If-not-equal statements
y = ifne(x, a0, a1, a2) means IF x != a0 THEN y = a1 ELSE y = a2
- Parameters:
x (ndarray) – input variable
a0 (ndarray) – compare to input x != a0
a1 (ndarray) – result if x != a0
a2 (ndarray) – result if x == a0
y (ndarray) –
a0 –
a1 –
a2 –
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
IF y != a0 THEN x = a1 ELSE x = a2
- Return type:
ndarray
- limits(x, mini, maxi, undef=-9999.0)[source]¶
Replacement of underflows or overflows by undef
y = limits(x, mini, maxi) means IF (x < mini) OR (x > maxi) THEN y = undef ELSE y = x
This function may be used to check values lying in between certain limits.
If one of the limits is exceeded the value is set to undef.
- Parameters:
x (ndarray) – input variable
mini (ndarray) – lower threshold
maxi (ndarray) – upper threshold
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
underflows or overflows replaced by undef
- Return type:
ndarray
- lin(x, a0, a1, undef=-9999.0)[source]¶
Apply linear function
y = lin(x, a0, a1) means y = a0 + a1 * x
- maxi(x, axis=None, undef=-9999.0)[source]¶
Calculation of maximum value
y = maxi(x) means y = max(x[0], x[1], …, x[n-1])
- Parameters:
x (ndarray) – input variable
axis (None or int or tuple of ints, optional) –
Axis or axes along which the maximum are computed. The default is to compute the maximum of the flattened array.
If this is a tuple of ints, a maximum is performed over multiple axes, instead of a single axis or all the axes as before.
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
maximum value
- Return type:
ndarray
- mean(x, axis=None, undef=-9999.0)[source]¶
Calculation of mean value
y = mean(x) means y = (x[0] + x[1] + … + x[n-1]) / n
- Parameters:
x (ndarray) – input variable
axis (None or int or tuple of ints, optional) –
Axis or axes along which the means are computed. The default is to compute the mean of the flattened array.
If this is a tuple of ints, a mean is performed over multiple axes, instead of a single axis or all the axes as before.
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
mean value
- Return type:
ndarray
- met_alb(swd, swu, swdmin=50.0, swumin=10.0, undef=-9999.0)[source]¶
Calculation of albedo from short wave downward and upward radiation
y = met_alb(swd, swu)
The albedo in % is calculated according to the following formula:
y = 100 * ( swu / swd )
If swd < swdmin (50 W m-2) or swu < swumin (10 W m-2), the result is undef.
- Parameters:
swd (ndarray) – shortwave downward radiation [W m-2]
swu (ndarray) – shortwave upward radiation [W m-2]
swdmin (float, optional) – If swd < swdmin the result is undef (default: 50).
swumin (float, optional) – If swu < swumin the result is undef (default: 10).
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
albedo in %
- Return type:
ndarray
- met_albl(swd, swu, swdmin, swumin, undef=-9999.0)[source]¶
Calculation of albedo from short wave downward and upward radiation with limits
x=met_albl(swd, swu, swdmin, swumin)
The albedo in % is calculated according to the following formula:
y = 100 * ( swu / swd )
If swd < swdmin or swu < swumin, the result is undef.
- Parameters:
swd (ndarray) – shortwave downward radiation [W m-2]
swu (ndarray) – shortwave upward radiation [W m-2]
swdmin (float) – If swd < swdmin the result is undef.
swumin (float) – If swu < swumin the result is undef.
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
undef – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
albedo in %
- Return type:
ndarray
- met_dpt(T, rh, undef=-9999.0)[source]¶
Calculation of dew point temperature
y = met_dpt(T, rh)
The dew point temperature in degC is calculated according to the following formulas:
Es = 6.1078 * exp(17.08085 * T / (234.175 + T))
E = Es * rh / 100
y = 234.175 * ln(E / 6.1078) / (17.08085 - ln(E / 6.1078))
- Parameters:
T (ndarray) – air temperature [degC]
rh (ndarray) – relative humidity [%]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
dew point temperature in degC
- Return type:
ndarray
- met_h2oc(T, rh, p, undef=-9999.0)[source]¶
Calculation of water vapour concentration
y = met_h2oc(T, rh, p)
The water vapour concentration in mmol mol-1 is calculated according to the following formulas:
Es = 6.1078 * exp(17.08085 * T/ (234.175 + T))
E = Es * rh / 100
y = 0.1 * E / (0.001 * p * 100 * 0.001)
- Parameters:
T (ndarray) – air temperature [degC]
rh (ndarray) – relative humidity [%]
p (ndarray) – air pressure [hPa = mbar]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
water vapour concentration in mmol mol-1
- Return type:
ndarray
- met_h2oc_rh(T, h, p, undef=-9999.0)[source]¶
Calculation of relative humidity from water vapour concentration
y = met_h2oc_rh(T, [H2O], p)
The relative humidity in % is calculated according to the following formulas:
Es = 6.1078 * exp(17.08085 * T / (234.175 + T))
E = 10 * [H2O] * 0.001 * p * 100 * 0.001
y = 100 * E / Es
- Parameters:
T (ndarray) – air temperature [degC]
h (ndarray) – water vapour concentration [mmol mol-1]
p (ndarray) – air pressure [hPa = mbar]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
relative humidity in %
- Return type:
ndarray
- met_lwrad(y, Tp, undef=-9999.0)[source]¶
Calculation of long wave radiation from net radiometer
y = met_lwrad(x, Tp)
The total radiation in W m-2 is calculated according to the following formula:
y = x * fl + sigma * (Tp + T0)**4
where sigma = 5.67 * 10**-8 W m-2 K-4 is the Stephan-Boltzmann constant and fl is the factor for long wave radiation (reciprocal value of sensitivity) in W m-2 per mV.
The function assumes that fl was already applied before.
- Parameters:
y (ndarray) – output voltage of the net radiometer [mV]
Tp (ndarray) – pyranometer temperature, i.e. the temperature of the net radiometer body [degC]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
total radiation in W m-2
- Return type:
ndarray
- met_rho(T, rh, p, undef=-9999.0)[source]¶
Calculation of air density
y = met_rho(T, rh, p)
The air density in kg m-3 is calculated according to the following formulas:
Es = 6.1078 * exp(17.08085 * T / (234.175 + T))
E = Es * rh / 100
sh = 622 * E / (p - 0.378 * E)
Tv = ((T + T0) * (1 + 0.000608 * sh)) - T0
y = p * 100 / (287.05 * (Tv + T0))
- Parameters:
T (ndarray) – air temperature [degC]
rh (ndarray) – relative humidity [%]
p (ndarray) – air pressure [hPa = mbar]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
air density in kg m-3
- Return type:
ndarray
- met_sh(T, rh, p, undef=-9999.0)[source]¶
Calculation of specific humidity
y = met_sh(T, rh, p)
The specific humidity in g kg-1 is calculated according to the following formulas:
Es = 6.1078 * exp(17.08085 * T / (234.175 + T))
E = Es * rh / 100
y = 622 * E / (p - 0.378 * E)
- Parameters:
T (ndarray) – air temperature [degC]
rh (ndarray) – relative humidity [%]
p (ndarray) – air pressure [hPa = mbar]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
specific humidity in g kg-1
- Return type:
ndarray
- met_tpot(T, p, undef=-9999.0)[source]¶
Calculation of potential temperature
y = met_tpot(T, p)
The potential temperature in K is calculated according to the following formula:
y = (T + T0) * (1000 / p)**0.286
- Parameters:
T (ndarray) – air temperature [degC]
p (ndarray) – air pressure [hPa = mbar]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
potential temperature in K
- Return type:
ndarray
- met_trad(Rl, epsilon, undef=-9999.0)[source]¶
Calculation of radiation temperature from long wave radiation
y = met_trad(Rl, epsilon)
The radiation temperature in degC is calculated according to the following formula:
y = sqrt4(Rl / (sigma * epsilon)) - T0
where sigma = 5.67 * 10**-8 W m-2 K-4 is the Stephan-Boltzmann constant.
- Parameters:
Rl (ndarray) – longwave radiation [W m-2]
epsilon (ndarray) – long wave emissivity of the surface [0-1]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
radiation temperature in degC
- Return type:
ndarray
- met_urot(u, v, a, undef=-9999.0)[source]¶
Rotation of u-component of wind vector
y = met_urot(u, v, a)
The rotated u-component is calculated according to the following formula:
y = u * cos (a) + v * sin (a)
- Parameters:
u (ndarray) – u-component of the wind vector
v (ndarray) – v-component of the wind vector
a (ndarray) – rotation angle (positive is clockwise) [degree]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
rotated u-component
- Return type:
ndarray
- met_uv_wd(u, v, undef=-9999.0)[source]¶
Calculation of wind direction from u- and v-component of wind vector
y = met_uv_wd(u, v)
The horizontal wind velocity is calculated according to the following formulas:
IF u = 0 AND v = 0 THEN y = 0
IF u = 0 AND v < 0 THEN y = 360
IF u = 0 AND v > 0 THEN y = 180
IF u > 0 THEN y = 270 - arctan(v / u)
IF u < 0 THEN y = 90 - arctan(v / u)
- Parameters:
u (ndarray) – u-component of the wind vector
v (ndarray) – v-component of the wind vector
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
horizontal wind velocity
- Return type:
ndarray
- met_uv_wv(u, v, undef=-9999.0)[source]¶
Calculation of wind velocity from u- and v-component of wind vector
y = met_uv_wv(u, v)
The horizontal wind velocity is calculated according to the following formula:
y = sqrt(u**2 + v**2)
- Parameters:
u (ndarray) – u-component of the wind vector
v (ndarray) – v-component of the wind vector
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
horizontal wind velocity
- Return type:
ndarray
- met_vpact(T, rh, undef=-9999.0)[source]¶
Calculation of actual water vapour pressure
y = met_vpact(T, rh)
The actual water vapour pressure in mbar (hPa) is calculated according to the following formulas:
Es = 6.1078 * exp(17.08085 * T / (234.175 + T))
y = Es * rh / 100
- Parameters:
T (ndarray) – air temperature [degC]
rh (ndarray) – relative humidity [%]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
actual water vapour pressure in mbar (hPa)
- Return type:
ndarray
- met_vpdef(T, rh, undef=-9999.0)[source]¶
Calculation of water vapour pressure deficit
y = met_vpdef(T, rh)
The water vapour pressure deficit in mbar (hPa) is calculated according to the following formulas:
Es = 6.1078 * exp(17.08085 * T / (234.175 + T))
E = Es * rh / 100
y = Es - E
- Parameters:
T (ndarray) – air temperature [degC]
rh (ndarray) – relative humidity [%]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
water vapour pressure deficit in mbar (hPa)
- Return type:
ndarray
- met_vpmax(T, undef=-9999.0)[source]¶
Calculation of saturation water vapour pressure
y = met_vpmax(T)
The saturation water vapour pressure in mbar (hPa) is calculated according to the following formula:
y = 6.1078 * exp(17.08085 * T / (234.175 + T))
- Parameters:
T (ndarray) – air temperature [degC]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
saturation water vapour pressure in mbar (hPa)
- Return type:
ndarray
- met_vrot(u, v, a, undef=-9999.0)[source]¶
Rotation of v-component of wind vector
y = met_vrot(u, v, a)
The rotated v-component is calculated according to the following formula:
y = -u * sin (a) + v * cos (a)
- Parameters:
u (ndarray) – u-component of the wind vector
v (ndarray) – v-component of the wind vector
a (ndarray) – rotation angle (positive is clockwise) [degree]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
rotated v-component
- Return type:
ndarray
- met_wdrot(wd, a, undef=-9999.0)[source]¶
Rotation of wind direction
y = met_wdrot(wd, a)
The rotated wind direction is calculated according to the following formulas:
y = wd + a
IF y < 0 THEN y = y + 360
IF y <= 360 THEN y = y - 360
- Parameters:
wd (ndarray) – wind direction [degree]
a (ndarray) – rotation angle (positive is clockwise) [degree]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
rotated wind direction
- Return type:
ndarray
- met_wvwd_u(wv, wd, undef=-9999.0)[source]¶
Calculation of u-component of wind vector from wind velocity and wind direction
y = met_wvwd_u(wv, wd)
The u-component of the wind vector is calculated according to the following formula:
y = -wv * sin(wd)
- Parameters:
wv (ndarray) – horizontal wind velocity [m s-1]
wd (ndarray) – horizontal wind direction [degree]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
u-component of the wind vector
- Return type:
ndarray
- met_wvwd_v(wv, wd, undef=-9999.0)[source]¶
Calculation of v-component of wind vector from wind velocity and wind direction
y = met_wvwd_v(wv, wd)
The v-component of the wind vector is calculated according to the following formula:
y = -wv * cos(wd)
- Parameters:
wv (ndarray) – horizontal wind velocity [m s-1]
wd (ndarray) – horizontal wind direction [degree]
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
v-component of the wind vector
- Return type:
ndarray
- mini(x, axis=None, undef=-9999.0)[source]¶
Calculation of minimum value
y = mini(x) means y = min(x[0], x[1], …, x[n-1])
- Parameters:
x (ndarray) – input variable
axis (None or int or tuple of ints, optional) –
Axis or axes along which the minimum are computed. The default is to compute the minimum of the flattened array.
If this is a tuple of ints, a minimum is performed over multiple axes, instead of a single axis or all the axes as before.
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
minimum value
- Return type:
ndarray
- quad(x, a0, a1, a2, undef=-9999.0)[source]¶
Apply 2nd order function
y = quad(x, a0, a1, a2) means y = a0 + a1 * x + a2 * x**2
- Parameters:
- Returns:
2nd order function
- Return type:
ndarray
- sethigh(x, high, ishigh=None, undef=-9999.0)[source]¶
Replacement of overflows by new value
t = sethigh(x, high, ishigh) means IF (x > high) THEN y = ishigh ELSE y = x
ishigh is optional. If not given high will be used.
This function may be used to adjust relative humidity values of a little bit more than 100% to 100%.
- Parameters:
x (ndarray) – input variable
high (ndarray) – upper threshold
ishigh (None or ndarray, optional) – if not None, use ishigh in case of y > high
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
overflows replaced by new value
- Return type:
ndarray
- setlow(x, low, islow=None, undef=-9999.0)[source]¶
Replacement of underflows by new value
y = setlow(x, low, islow) means IF (x < low) THEN y = islow ELSE y = x
islow is optional. If not given low will be used.
This function may be used to adjust small negative values of short wave radiation during nighttime to zero values.
- Parameters:
x (ndarray) – input variable
low (ndarray) – lower threshold
islow (None or ndarray, optional) – if not None, use islow in case of y < low
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
underflows replaced by new value
- Return type:
ndarray
- varadd(a, b, undef=-9999.0)[source]¶
Addition
y = varadd(a, b) means y = a + b, where a and b are ndarray or float.
- Parameters:
a (ndarray) – input variable 1
b (ndarray) – input variable 2
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Addition
- Return type:
ndarray
- varchs(a, undef=-9999.0)[source]¶
Change sign
y = varchs(a) means y = -a, where a is ndarray or float.
- Parameters:
a (ndarray) – input variable
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Changed sign
- Return type:
ndarray
- vardiv(a, b, undef=-9999.0)[source]¶
Division
y = vardiv(a, b) means y = a / b, where a and b are ndarray or float.
- Parameters:
a (ndarray) – dividend
b (ndarray) – divisor
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Division
- Return type:
ndarray
- varexp(a, undef=-9999.0)[source]¶
Exponentiation of e
y = varexp(a) means y = exp(a), where a is ndarray or float.
- Parameters:
a (ndarray) – exponent
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Exponentiation
- Return type:
ndarray
- varlog(a, undef=-9999.0)[source]¶
Natural logarithm
y = varlog(a) means y = ln(a), where a is ndarray or float.
- Parameters:
a (ndarray) – input variable
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Natural logarithm
- Return type:
ndarray
- varmul(a, b, undef=-9999.0)[source]¶
Multiplication
y = varmul(a, b) means y = a * b, where a and b are ndarray or float.
- Parameters:
a (ndarray) – input variable 1
b (ndarray) – input variable 2
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Multiplication
- Return type:
ndarray
- varpot(a, b, undef=-9999.0)[source]¶
Exponentiation
y = varpot(a, b) means y = a**b, where a and b are ndarray or float.
- Parameters:
a (ndarray) – base
b (ndarray) – exponent
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Exponentiation
- Return type:
ndarray
- varsqr(a, undef=-9999.0)[source]¶
Square root
y = varsqr(a) means y = sqrt(a), where a is ndarray or float.
- Parameters:
a (ndarray) – input variable
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Square root
- Return type:
ndarray
- varsqrt(a, undef=-9999.0)[source]¶
Square root
y = varsqrt(a) means y = sqrt(a), where a is ndarray or float.
- Parameters:
a (ndarray) – input variable
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Square root
- Return type:
ndarray
- varsub(a, b, undef=-9999.0)[source]¶
Subtraction
y = varsub(a, b) means y = a - b, where a and b are ndarray or float.
- Parameters:
a (ndarray) – input variable 1
b (ndarray) – input variable 2
undef (float, optional) – elements are excluded from the calculations if any of the inputs equals undef (default: -9999.)
- Returns:
Subtraction
- Return type:
ndarray