Physical constants

A couple of short examples of using aeolus physical contants submodule, which can serve as a convenient way to store a number of constants used in an atmospheric model.

[1]:
from aeolus.const import init_const

General constants

First, generic (planet-independent constants) are available.

[2]:
gen = init_const()

Here, gen is a dataclass-like object containing a few constants. Each of the constants is stored with appropriate units as an iris.cube.Cube.

For example, in this example the container has the heat of vaporization of water (at 0 deg C).

[3]:
L = gen.water_heat_vaporization
L
[3]:
Water Heat Vaporization (m2 s-2) (scalar cube)
[4]:
type(L)
[4]:
iris.cube.Cube
[5]:
L.data, L.units
[5]:
(array(2501000.), Unit('m2 s-2'))

Having constants stored as iris cubes is convenient for unit-aware operations.

Earth constants

Along with aeolus, some basic constants of the Earth atmosphere are also provided. Note that all the “generic” constants are also added to this container.

[6]:
earth_const = init_const("earth")
earth_const
[6]:
EarthConstants(earth_day [s], stefan_boltzmann [W m-2 K-4], water_heat_vaporization [m2 s-2], water_molecular_weight [kg mol-1], molar_gas_constant [J K-1 mol-1], boltzmann [m^2 kg s^-2 K^-1], avogadro [mol-1], gravity [m s-2], radius [m], day [s], solar_constant [W m-2], semi_major_axis [au], eccentricity [1], obliquity [degree], dry_air_spec_heat_press [m2 s-2 K-1], dry_air_molecular_weight [kg mol-1], condensible_density [kg m-3], condensible_heat_vaporization [m2 s-2], condensible_molecular_weight [kg mol-1], reference_surface_pressure [Pa])
[7]:
c_p = earth_const.dry_air_spec_heat_press

It is possible to derive the gas constant for dry air using the universal gas constant.

[8]:
r_d = gen.molar_gas_constant / earth_const.dry_air_molecular_weight
r_d.rename("dry_air_gas_constant")
[9]:
r_d
[9]:
Dry Air Gas Constant (m2.s-2.K-1) (scalar cube)
[10]:
r_d.data
[10]:
array(287.05797807)

Extending constants container

All constants shown above are stored in JSON files, so it is possible to create a custom JSON file and read constants from it.

[11]:
from pathlib import Path

For example, we have an dummy.json file in the data/test_data/json sub-directory (downloaded from the exoclim/aeolus_data repository). The file looks like this:

[
    {
        "name": "my_constant",
        "units": "m s-1",
        "value": 123
    }
]

Then it can be loaded in the following way.

[12]:
ex_const = init_const(name="dummy", directory=(Path.cwd().parent / "tests" / "data" / "test_data" / "json"))
[13]:
ex_const
[13]:
DummyConstants(earth_day [s], stefan_boltzmann [W m-2 K-4], water_heat_vaporization [m2 s-2], water_molecular_weight [kg mol-1], molar_gas_constant [J K-1 mol-1], boltzmann [m^2 kg s^-2 K^-1], avogadro [mol-1], my_constant [m s-1])

In this case, the JSON file contains only one constant, my_constant, the rest are “general” constants.

[14]:
ex_const.my_constant
[14]:
My Constant (m s-1) (scalar cube)
[15]:
ex_const.my_constant.data
[15]:
array(123)