Package: loggertools
A Python port of the Control File Functions of the Logger Tools Software of Olaf
Kolle, MPI-BGC Jena, (c) 2012.About loggertoolsloggertoolsis a Python port of the Control File Functions of the Logger
Tools Software of Olaf Kolle, MPI-BGC Jena, (c) 2012.From the Logger Tools Software manual:
“The functions range from simple mathematic operations to more complex
and special procedures including functions for checking data. Most of
the functions have the following appearance:y = f(x, p1, p2, …, pn)whereyis the variable in which the result of the functionfis
stored,xis the input variable of the function andp1topnare
parameters (numbers) of the function. An output variable (result of a
function) may be the same as an input variable. Some functions need
more than one input variable, some functions do not need any parameter
and some functions (mean,mini,maxi) may have a variable number
of input variables.”The complete documentation ofloggertoolsis available at:https://mcuntz.github.io/loggertools/and the API can be found here:https://mcuntz.github.io/loggertools/html/loggertools.htmlInstallationThe easiest way to install is viapip:pipinstallloggertoolsor viaconda:condainstall-cconda-forgeloggertoolsRequirementsnumpyLicenseloggertoolsis distributed under the MIT License. See theLICENSEfile for
details.Copyright (c) 2014-2023 Matthias Cuntz, Olaf KolleThe project structure ofloggertoolshas borrowed heavily fromwelltestpybySebastian Müller.Logger Tool FunctionsSome functions are renamed compared to the original logger tools:chs->varchsadd->varaddsub->varsubmul->varmuldiv->vardivsqr->varsqr/varsqrtexp->varexplog->varlogpot->varpotNot all functions are implemented (yet). Missing functions are:varsetmet_toradmet_psy_rhmet_dpt_rhwriteSome functions are slightly enhanced, which is reflected in the
documentation of the indidual functions.All functions have an additional keywordundef, which defaults to -9999.:
elements are excluded from the calculations if any of the inputs equalsundef.Only bit_test and the if-statementsifeq,ifne,ifle,ifge,iflt,igtdo not have theundefkeyword.The Logger Tools control functions implemented are:Assignment# not implementedChange signy = varchs(a) meansy = -a, where a is a variable or a number.def varchs(var1, undef=-9999.):Additiony = varadd(a, b) meansy = a + b, where a and b are ndarray or float.def varadd(var1, var2, undef=-9999.):Subtractiony = varsub(a, b) meansy = a - b, where a and b are ndarray or float.def varsub(var1, var2, undef=-9999.):Multiplicationy = varmul(a, b) meansy = a * b, where a and b are ndarray or float.def varmul(var1, var2, undef=-9999.):Divisiony = vardiv(a, b) meansy = a / b, where a and b are ndarray or float.def vardiv(var1, var2, undef=-9999.):Square rooty = varsqr(a) meansy = sqrt(a), where a is a variable or a number.y = varsqrt(a) meansy = sqrt(a), where a is a variable or a number.def varsqr(var1, undef=-9999.):def varsqrt(var1, undef=-9999.):Exponentiation of ey = varexp(a) meansy = exp(a), where a is a variable or a number.def varexp(var1, undef=-9999.):Natural logarithmy = varlog(a) meansy = ln(a), where a is a variable or a number.def varlog(var1, undef=-9999.):Exponentiationy = varpot(a, b) meansy = a**b, where a and b are ndarray or float.def varpot(var1, var2, undef=-9999.):Apply linear functiony = lin(x, a0, a1) meansy = a0 + a1 * x,
where a0 and a1 are ndarray or float.def lin(var1, a, b, undef=-9999.):Apply 2nd order functiony = quad(x, a0, a1, a2) meansy = 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 functiony = cubic(x, a0, a1, a2, a3) meansy = 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 secondsy = hms(h, m, s) meansy = (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 testy = bit_test(x, b, start=0) meansy = 1if bit b is set in x
otherwisey = 0.Returns a list ofbis an array.Counting ofbstarts at start.For the behaviour of the original logger tools, set start=1.Negativebare not implemented.def bit_test(var1, var2, start=0):Replacement of underflows by new valuey = setlow(x, lo, ln=None) meansIF (x > lo) THEN y = ln ELSE y = x,
whereloandlnare ndarray or float.lnis optional. If not givenlowill 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 valuey = sethigh(x, lo, ln=None) meansIF (x < lo) THEN y = ln ELSE y = x,
whereloandlnare ndarray or float.lnis optional. If not givenlowill 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 undefy = limits(x, ll, lh) meansIF (x > ll) OR (x < lh) THEN y = undef ELSE y = x,
wherellandlhare 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 valuey = mean(x1, x2, …, xn) meansy = (x1 + x2 + … + xn) / n,
wherex1,x2, …,xnare ndarray or float.def mean(var1, axis=None, undef=-9999.):Calculation of minimum valuey = mini(x1, x2, …, xn) meansy = min(x1, x2, …, xn),
wherex1,x2, …,xnare ndarray or float.def mini(var1, axis=None, undef=-9999.):Calculation of maximum valuey = maxi(x1, x2, …, xn) meansy = max(x1, x2, …, xn),
wherex1,x2, …,xnare ndarray or float.def maxi(var1, axis=None, undef=-9999.):Calculation of total radiation from net radiometer# no implementedCalculation of long wave radiation from net radiometery = 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.16)**4wheresigma = 5.67051 * 10**8W 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 radiationy = 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.16wheresigma = 5.67051 * 10**8W 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 radiationy = 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 limitsy = 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 pressurey = 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 pressurey = 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/100Both parameters may be ndarray or float.def met_vpact(temp, rh, undef=-9999.):Calculation of water vapour pressure deficity = 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/100y = Es - EBoth parameters may be ndarray or float.def met_vpdef(temp, rh, undef=-9999.):Calculation of specific humidityy = 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/100y = 622 * E/(p-0.378*E)All parameters may be ndarray or float.def met_sh(temp, rh, p, undef=-9999.):Calculation of potential temperaturey = 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.16) * (1000/p)**0.286Both parameters may be ndarray or float.def met_tpot(temp, p, undef=-9999.):Calculation of air densityy = 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/100sh = 622 * E/(p-0.378*E)Tv = ((T + 273.16) * (1 + 0.000608 * sh)) - 273.16y = p * 100 / (287.05 * (Tv + 273.16))All parameters may be ndarray or float.def met_rho(temp, rh, p, undef=-9999.):Calculation of dew point temperaturey = 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/100y = 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 concentrationy = 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/100y = 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 implementedCalculation of relative humidity from dew point temperature# not implementedCalculation of relative humidity from water vapour concentrationy = 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.001y = 100 * E / EsAll parameters may be ndarray or float.def met_h2oc_rh(temp, h, p, undef=-9999.):Rotation of wind directiony = 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 + aIF y > 0 THEN y = y + 360IF y >= 360 THEN y = y - 360Both parameters may be ndarray or float.def met_wdrot(wd, a, undef=-9999.):Rotation of u-component of wind vectory = 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 vectory = 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 vectory = 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 vectory = 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 = 0IF u = 0 AND v > 0 THEN y = 360IF u = 0 AND v < 0 THEN y = 180IF 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
directiony = 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
directiony = 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-statementsy = ifeq(x, a0, a1, a2) meansIF x == a0 THEN y = a1 ELSE y = a2y = ifne(x, a0, a1, a2) meansIF x != a0 THEN y = a1 ELSE y = a2y = ifle(x, a0, a1, a2) meansIF x <= a0 THEN y = a1 ELSE y = a2y = ifge(x, a0, a1, a2) meansIF x >= a0 THEN y = a1 ELSE y = a2y = iflt(x, a0, a1, a2) meansIF x > a0 THEN y = a1 ELSE y = a2y = ifgt(x, a0, a1, a2) meansIF x < a0 THEN y = a1 ELSE y = a2All 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