typhon.physics

Various physics-related modules.

typhon.physics.density(p, T, R=287.0569075937786)[source]

Calculates gas density by ideal gas law.

\[\rho = \frac{p}{R \cdot T}\]
Parameters:
  • p (float or ndarray) – Pressure [Pa.]
  • T (float or ndarray) – Temperature [K]. If type of T and p is ndarray, size must match p.
  • R (float) – Gas constant [J K^-1 kg^-1]. Default is gas constant for dry air.
Returns:

Density [kg/m**3].

Return type:

float or ndarray

typhon.physics.e_eq_ice_mk(T)[source]

Calculate the equilibrium water vapor pressure over ice.

Equilibrium water vapor pressure over ice using Murphy and Koop 2005 parameterization formula.

\[\ln(e_i) = 9.550426 - \frac{5723.265}{T} + 3.53068 \cdot \ln(T) - 0.00728332 \cdot T\]
Parameters:T (float or ndarray) – Temperature in [K].
Returns:Equilibrium water vapor pressure over ice in [Pa].
Return type:float or ndarray

References

Murphy, D. M. and Koop, T. (2005): Review of the vapour pressures of ice and supercooled water for atmospheric applications, Quarterly Journal of the Royal Meteorological Society 131(608): 1539–1565. doi:10.1256/qj.04.94

typhon.physics.e_eq_water_mk(T)[source]

Calculate the equilibrium water vapor pressure over water.

Equilibrium water vapor pressure over water using Murphy and Koop 2005 parameterization formula.

\[\begin{split}\ln(e_w) &= 54.842763 - \frac{6763.22}{T} - 4.21 \cdot \ln(T) \\ &+ 0.000367 \cdot T + \tanh \left(0.0415 \cdot (T - 218.8)\right) \\ &\cdot \left(53.878 - \frac{1331.22}{T} - 9.44523 \cdot \ln(T) + 0.014025 \cdot T \right)\end{split}\]
Parameters:T (float or ndarray) – Temperature in [K].
Returns:Equilibrium water vapor pressure over water in [Pa].
Return type:float or ndarray

References

Murphy, D. M. and Koop, T. (2005): Review of the vapour pressures of ice and supercooled water for atmospheric applications, Quarterly Journal of the Royal Meteorological Society 131(608): 1539–1565. doi:10.1256/qj.04.94

typhon.physics.frequency2wavelength(frequency)[source]

Convert frequency to wavelength.

Parameters:frequency (float or ndarray) – Frequency [Hz].
Returns:Wavelength [m].
Return type:float or ndarray
typhon.physics.frequency2wavenumber(frequency)[source]

Convert frequency to wavenumber.

Parameters:frequency (float or ndarray) – Frequency [Hz].
Returns:Wavenumber [m^-1].
Return type:float or ndarray
typhon.physics.fresnel(n1, n2, theta1)[source]

Fresnel formulas for surface reflection.

The amplitude reflection coefficients for a flat surface can also be calculated (Rv and Rh). Note that these are the coefficients for the amplitude of the wave. The power reflection coefficients are obtained as

\[r = \lvert R \rvert^2\]

The expressions used are taken from Eq. 3.31 in “Physical principles of remote sensing”, by W.G. Rees, with the simplification that that relative magnetic permeability is 1 for both involved media. The theta2 angle is taken from snell.m.

The refractive index of medium 2 (n2) can be complex. The refractive index and the dielectric constant, epsilon, are releated as

\[n = \sqrt{\epsilon}\]

No expression for theta2 that allows n1 to be complex has been found.

If theta2 is found to be complex, it is returned as NaN. This can happen when n1 > n2, and corresponds to a total reflection and there is no transmitted part. Rv and Rh are here set to 1.

Parameters:
  • n1 (float or ndarray) – Refractive index for medium of incoming radiation.
  • n2 (float or ndarray) – Refractive index for reflecting medium.
  • theta1 (float or ndarray) – Angle between surface normal and incoming radiation [degree].
Returns:

Reflection coefficient for vertical polarisation, reflection coefficient for horisontal polarisation.

Return type:

float or ndarray, float or ndarray

typhon.physics.planck(f, T)[source]

Calculate black body radiation for given frequency and temperature.

Parameters:
  • f (float or ndarray) – Frquencies [Hz].
  • T (float or ndarray) – Temperature [K].
Returns:

Radiances.

Return type:

float or ndarray

typhon.physics.planck_wavelength(l, T)[source]

Calculate black body radiation for given wavelength and temperature.

Parameters:
  • l (float or ndarray) – Wavelength [m].
  • T (float or ndarray) – Temperature [K].
Returns:

Radiances.

Return type:

float or ndarray

typhon.physics.planck_wavenumber(n, T)[source]

Calculate black body radiation for given wavenumber and temperature.

Parameters:
  • n (float or ndarray) – Wavenumber.
  • T (float or ndarray) – Temperature [K].
Returns:

Radiances.

Return type:

float or ndarray

typhon.physics.radiance2planckTb(f, r)[source]

Convert spectral radiance to Planck brightness temperture.

Parameters:
  • f (float or ndarray) – Frequency [Hz].
  • r (float or ndarray) – Spectral radiance [W/m**-2/sr].
Returns:

Planck brightness temperature [K].

Return type:

float or ndarray

typhon.physics.radiance2rayleighjeansTb(f, r)[source]

Convert spectral radiance to Rayleight-Jeans brightness temperture.

Parameters:
  • f (float or ndarray) – Frequency [Hz].
  • r (float or ndarray) – Spectral radiance [W/m**-2/sr].
Returns:

Rayleigh-Jeans brightness temperature [K].

Return type:

float or ndarray

typhon.physics.rayleighjeans(f, T)[source]

Calculates the Rayleigh-Jeans approximation of the Planck function.

Calculates the approximation of the Planck function for given frequency and temperature.

Parameters:
  • f (float or ndarray) – Frequency [Hz].
  • T (float or ndarray) – Temperature [K].
Returns:

Radiance [W/(m2*Hz*sr)].

Return type:

float or ndarray

typhon.physics.rayleighjeans_wavelength(l, T)[source]

Calculates the Rayleigh-Jeans approximation of the Planck function.

Calculates the approximation of the Planck function for given wavelength and temperature.

Parameters:
  • l (float or ndarray) – Wavelength [m].
  • T (float or ndarray) – Temperature [K].
Returns:

Radiance [W/(m2*Hz*sr)].

Return type:

float or ndarray

typhon.physics.snell(n1, n2, theta1)[source]

Calculates the angle of the transmitted wave, according to Snell’s law.

Snell’s law for the case when both n1 and n2 have no imaginary part is found in all physics handbooks.

The expression for complex n2 is taken from “An introduction to atmospheric radiation” by K.N. Liou (Sec. 5.4.1.3).

No expression that allows n1 to be complex has been found.

If theta2 is found to be complex, it is returned as NaN. This can happen when n1 > n2, and corresponds to a total reflection and there is no transmitted part.

The refractive index and the dielectric constant, epsilon, are releated as

\[n = \sqrt{\epsilon}\]
Parameters:
  • n1 (float or ndarray) – Refractive index for medium of incoming radiation.
  • n2 (float or ndarray) – Refractive index for reflecting medium.
  • theta1 (float) – Angle between surface normal and incoming radiation [degree].
Returns:

Angle for transmitted part [degree].

Return type:

float or ndarray

typhon.physics.wavelength2frequency(wavelength)[source]

Convert wavelength to frequency.

Parameters:wavelength (float or ndarray) – Wavelength [m].
Returns:Frequency [Hz].
Return type:float or ndarray
typhon.physics.wavelength2wavenumber(wavelength)[source]

Convert wavelength to wavenumber.

Parameters:wavelength (float or ndarray) – Wavelength [m].
Returns:Wavenumber [m^-1].
Return type:float or ndarray
typhon.physics.wavenumber2frequency(wavenumber)[source]

Convert wavenumber to frequency.

Parameters:wavenumber (float or ndarray) – Wavenumber [m^-1].
Returns:Frequency [Hz].
Return type:float or ndarray
typhon.physics.wavenumber2wavelength(wavenumber)[source]

Convert wavenumber to wavelength.

Parameters:wavenumber (float or ndarray) – Wavenumber [m^-1].
Returns:Wavelength [m].
Return type:float or ndarray

typhon.physics.metrology

Functions related to metrology

All functions need sympy.

typhon.physics.metrology.express_uncertainty(expr, aliases={}, on_failure='raise')[source]

For a sympy expression, calculate uncertainty.

Uncertainty is given in the Guides to Uncertainties and Measurements (GUM), see http://www.bipm.org/en/publications/guides/gum.html equations 10 and 13.

This takes all free symbols. If you have IndexedBase symbols, you may want to pass them into aliases {free_symbol: indexed_base_symbol[index]} is this is not identified automatically.

Limitation: currently assumes all input quantities are uncorrelated!

Parameters:
  • expr (Expr) – Expression for which to calculate uncertainty
  • aliases (Mapping) – Mapping of replacements to apply prior.
  • on_failure (str) – Signals what to do when some variables cannot be differentiated against. This appears to be the case for indexed quantities (see https://github.com/sympy/sympy/issues/12191). Default is ‘raise’, but can set to ‘warn’ instead.
Returns:

Expression indicating uncertainty

typhon.physics.metrology.recursive_args(expr, stop_at=None, partial_at=None)[source]

Get arguments for expr, stopping at certain types

Get all arguments in expression down to the levels in expr. When expr is only {sympy.Symbol} this is identical to expr.free_symbols, but in some cases we want to retain IndexedBase, for example, when evaluating uncertainies.

This is mainly a helper for express_uncertainty where we don’t want to descend beyond Indexed quantities

typhon.physics.units

Various units-related things

This module has a soft dependency on the pint units library. Please import this module only conditionally or only if you can accept a pint dependency.

class typhon.physics.units.FwmuMixin[source]

Bases: object

Mixing for frequency/wavelength/wavenumber neutrality

Best to use pint ureg quantities at all times.

frequency
wavelength
wavenumber
class typhon.physics.units.SRF(f, W)[source]

Bases: typhon.physics.units.em.FwmuMixin

Respresents a spectral response function

TODO: representation of uncertainties

L_to_T = None
T_lookup_table = <Quantity([ 100. 100.05 100.1 ..., 369.9 369.95 370. ], 'kelvin')>
blackbody_radiance(T, spectral=True)[source]

Calculate integrated radiance for blackbody at temperature T

Parameters:
  • T – Temperature [K]. This can be either a python number, or a numpy ndarray, on a ureg quantity encompassing either.
  • spectral – Parameter to control whether to return spectral radiance or radiance. See self.integrate_radiances for details.

Returns quantity ndarray with blackbody radiance in desired unit. Note that this is an ndarray with dimension (1,) even if you passin a scalar.

centroid()[source]

Calculate centre frequency

channel_radiance2bt(L)[source]

Convert channel radiance to brightness temperature

Using the lookup table, convert channel radiance to brightness temperature. Will construct lookup table on first call.

Typhon also registers a pint context “radiance” which can be used to convert between radiance units and brightness temperature (even though this is a different quantity), for example, by using L.to(“K”, “radiance”, srf=srf)

Parameters:L – Radiance [W m^-2 sr^-1 Hz^-1] or compatible
estimate_band_coefficients()[source]

Estimate band coefficients for fast/explicit BT calculations

In some circumstances, a fully integrated SRF may be more expensive than needed. We can then choose an effective wavelength λ_c along with coefficients α, β such that instead of integrating, we estimate R = B(λ*, T*), with T* = α + β · T_B and λ* a wavelength which may be close to the centroid λ_c (but there is no guarantee). Such an approximation eliminates the explicit use of an integral which can make analysis easier.

Returns:Offset in approximation for T* β (float): Slope in approximation for T* λ_eff (float): Effective wavelength Δα (float): Uncertainty in α Δβ (float): Uncertainty in β Δλ_eff (float): Uncertainty in λ_eff
Return type:α (float)
classmethod fromArtsXML(sat, instr, ch)[source]

Read SRF from ArtsXML files.

Requires that in the TYPHONRC configuration file, the fields srf_backend_f and srf_backend_response in the section corresponding to instrument instr are defined to point to the respective files in ArtsXML format. Within those definitions, {sat:s} will be substituted with the satellite name. For example, in typhonrc, one might have:

[hirs] srf_backend_response = /path/to/{sat}_HIRS.backend_channel_response.xml srf_backend_f = /path/to/{sat}_HIRS.f_backend.xml

so that we can do:

>>> srf = SRF.fromArtsXML("NOAA15", "hirs", 12)
>>> R_300 = srf.blackbody_radiance(ureg.Quantity(atleast_1d(250), 'K'))
>>> print(R_300)
[  2.13002925e-13] watt / hertz / meter ** 2 / steradian
>>> print(R_300.to("cm * mW / m**2 / sr", "radiance"))
[ 6.38566704] centimeter * milliwatt / meter ** 2 / steradian
Parameters:
  • [str] (instr) – Satellite name, such as ‘NOAA15’
  • [str] – Instrument name, such as ‘hirs’.
  • [int] (ch) – Channel number (start counting at 1).
integrate_radiances(f, L, spectral=True)[source]

From a spectrum of radiances and a SRF, calculate channel (spectral) radiance

The spectral response function may not be specified on the same grid as the spectrum of radiances. Therefore, this function interpolates the spectral response function onto the grid of the radiances. This is less bad than the reverse, because a spectral response function tends to be more smooth than a spectrum.

Approximations:

  • Interpolation of spectral response function onto frequency grid on which radiances are specified.
Parameters:
  • f (ndarray) – Frequencies for spectral radiances [Hz]
  • L (ndarray) – Spectral radiances [W m^-2 sr^-1 Hz^-1]. Can be in radiance units of various kinds. Make sure this is consistent with the spectral response function. Innermost dimension must correspond to frequencies.
  • spectral (bool) – If true, return spectral radiance [W m^-2 sr^-1 Hz^-1]. If false, return radiance [W m^-2 sr^-1]. Defaults to True.
Returns:

Channel (spectral) radiance according to ‘spectral’

lookup_table = None
make_lookup_table()[source]

Construct lookup table radiance <-> BT

To convert a channel radiance to a brightness temperature, applying the (inverse) Planck function is not correct, because the Planck function applies to monochromatic radiances only. Instead, to convert from radiance (in W m^-2 sr^-1 Hz^-1) to brightness temperature, we use a lookup table. This lookup table is constructed by considering blackbodies at a range of temperatures, then calculating the channel radiance. This table can then be used to get a mapping from radiance to brightness temperature.

This method does not return anything, but fill self.lookup_table.

shift(amount)[source]

Get new SRF, shifted by <amount>

Return a new SRF, shifted by <amount> Hz. The shape of the SRF is retained.

Parameters:amount (Quantity) – Distance to shift SRF
typhon.physics.units.density(p, T, R=None)[source]

Wrapper around typhon.physics.thermodynamics.density().

Parameters:
  • p (Quantity) – Pressure.
  • T (Quantity) – Temperature. If magnitude of T and p is ndarray, sizes must match.
  • R (Quantity) – Gas constant.
Returns:

Density [kg/m**3].

Return type:

Quantity

typhon.physics.units.planck_f(f, T)[source]

Planck law expressed in frequency.

If more than 10⁵ resulting radiances, uses numexpr.

Parameters:
  • f – Frequency. Quantity in [Hz]
  • T – Temperature. Quantity in [K]
typhon.physics.units.specrad_frequency_to_planck_bt(L, f)[source]

Convert spectral radiance per frequency to brightness temperature

This function converts monochromatic spectral radiance per frequency to Planck brightness temperature. This is calculated by inverting the Planck function.

Note that this function is NOT correct to estimate polychromatic brightness temperatures such as channel brightness temperatures. For this, you need the spectral response function — see the SRF class.

Parameters:
  • L – Spectral radiance [W m^-2 sr^-1 Hz^-1]
  • f – Corresponding frequency [Hz]
Returns:

Planck brightness temperature [K].

typhon.physics.units.specrad_wavenumber2frequency(specrad_wavenum)[source]

Convert spectral radiance from per wavenumber to per frequency

Parameters:specrad_wavenum – Spectral radiance per wavenumber [W·sr^{-1}·m^{-2}·{m^{-1}}^{-1}]
Returns:Spectral radiance per frequency [W⋅sr−1⋅m−2⋅Hz−1]

typhon.physics.units.constants

Collection of physical constants and conversion factors.

The magnitudes of the defined constants are taken from typhon.constants.

This module adds units defined with pint’s UnitRegistry..