misc
index
/users/schrei_f/src/py4CAtS/lite/src3/misc.py

A 'random' collection of some useful(?) functions.

 
Functions
       
approx(this, other, eps=0.001)
Return True if the two numbers (usually floats) are equal within the tolerance eps (default 0.001).
effHgt2transitDepth(effHgt, radiusPlanet=6371.23, radiusStar=696342.0)
Return the additional transit depth from a given effective height.
 
effHgt:        effective height spectrum
radiusPlanet:  default Earth 6371.23km
radiusStar:    default Sun 696342km (https://de.wikipedia.org/wiki/Sonnenradius)
 
NOTE:  according to https://en.wikipedia.org/wiki/Solar_radius 695700km
float_in_list(value, floatList, eps=0.001)
Return True if value is contained in a list of float values within the tolerance eps (default 0.001).
monotone(data)
Check data for monotonicity and return
+1   increasing monotonically
-1   decreasing monotonically
 0   otherwise
regrid(yValues, newLen, method='L')
Regrid function values given on an equidistant/uniform grid to a new (usually denser) grid in the same interval.
 
yValues:  the function values to be interpolated with len(yValues)=oldLen
newLen:   the number of new function values after interpolation
method:   the interpolation method
          integers 2, 3, 4  ===> the self-made linear, quadratic or cubic Lagrange
          "linear", "quadratic", "cubic", etc. ===> scipy.interp1d
          otherwise ===> numpy.interp
 
RETURNS:  yData   ---   the function values interpolated with len(yData)=newLen
runningAverage(xy, n=2, splitXY=False)
Compute running average, i.e. sum up `n` consecutive array elements and divide by `n`.
 
ARGUMENTS:
----------
xy        a rank 1 or rank 2 array
n         the number of elements to combine (default 2)
splitXY   flag, default False
          if True and xy is a rank 2 array, separately return first column (xGrid) and further columns
 
RETURNS:
--------
a rank 1 or rank 2 array XY  (or a rank 1 array xGrid and rank 2 array yValues if splitXY)
the length of the returned array(s) is roughly xy.shape[0]/n
show_lambda(wavenumbers=[100, 200, 500, 800, 1000, 2000, 2500, 3333, 4000, 5000, 8000, 10000, 12500])
Write wavelengths [mue] corresponding to x-axis wavenumbers on the top-axis of plot.
trapez(x, Y, xLow=None, xHigh=None)
Integral_x[0]^x[-1] y(x) dx  with tabulated x,y values (2 arrays) using trapezoid quadrature.
 
ARGUMENTS:
----------
x         a rank 1 array of grid points
Y         a rank 1 or rank 2 array
          Y can be single or multi-dimensional, i.e. Y.shape=len(x) or Y.shape=[len(x),*]
xLow      lower integration limit; default None: start at x[0]
xHigh     upper integration limit; default None: start at x[-1]
          if xLow or xHigh are not grid points, Lagrange two-point interpolation is used for the first/last interval.
 
RETURNS:
--------
the integral approximated by 0.5*sum (y[i]+y[i-1]) * (x[i]-x[i-1])
 
NOTE:
-----
An alternative implementation is given by numpy's `trapz` function;
however, this does not allow to set the limits.
wien(**kwArgs)
Wien's displacement law:
for given temperature [K] return wavenumber (or wavelength) of maximum blackbody emission
or
for given wavenumber (or wavelength) return corresponding temperature.
 
KEYWORD ARGUMENTS:
x:      wavenumber or wavelength
T:      temperature [K]
xUnit:  cm-1 (default) or a wavelength unit
xTruncate(xGrid, yValues, xLimits)
Given an array of x grid points and a 'matrix' of y values (with len(xGrid) rows)
delete data outside the Interval defined by xLimits
and return the truncated grid and the corresponding 'matrix'.
zenithAngle_boa2toa(beta, zToA=120.0, radiusEarth=6371.23, degree=False)
Return the zenith angle at ToA (or nadir viewing observer) from given angle at BoA.
(beta=0 for vertical uplooking, alpha=pi=90dg for horizontal view)
zenithAngle_toa2boa(alpha, zToA=120.0, radiusEarth=6371.23, degree=False)
Return the viewing angle at BoA (or nadir viewing observer) from given zenith angle at ToA.
(alpha=0 for vertical uplooking, alpha=pi=180dg for downlooking observer)

 
Data
        pi = 3.141592653589793
wavelengthUnits = {'A': 1e-08, 'cm': 1.0, 'micrometer': 0.0001, 'mm': 0.1, 'mue': 0.0001, 'mum': 0.0001, 'nm': 1e-07, 'um': 0.0001}