Quickstart#

This page takes you from installing lair to a first result in a few minutes.

Install#

lair is installed from GitHub, not from PyPI: Installation has the commands and says which route (conda or pip) your work needs.

Point lair at your data#

Most modules need no data folder. They work on the numbers you pass in.

The modules that read files you keep on disk (inventories, soundings, and noaa’s CarbonTracker and GMLData) take the folder as an argument, or read it from a LAIR_* environment variable. Data locations lists the variables, shows how to set one and says what happens when one is missing.

A first calculation#

The potential temperature of a sounding, with lair.meteorology.poisson(). The sounding here is made up: a temperature at three pressure levels.

In [1]: import xarray as xr

In [2]: from lair.meteorology import poisson

In [3]: levels = {"level": [850, 700, 500]}  # hPa, as labels

In [4]: p = xr.DataArray([85000.0, 70000.0, 50000.0], coords=levels, dims="level")  # Pa

In [5]: T = xr.DataArray([275.0, 265.0, 250.0], coords=levels, dims="level")  # K

In [6]: poisson(T, p)
Out[6]: 
<xarray.DataArray (level: 3)> Size: 24B
array([288.06612704, 293.41969721, 304.73389672])
Coordinates:
  * level    (level) int64 24B 850 700 500

The rule in lair.meteorology is plain SI in, plain SI out: pressure in pascals, temperature in kelvin, and the result in kelvin. So 850 hPa goes in as 85000. If your values carry units, pass them as quantities of lair.units (the pint unit registry; Convert a methane flux from moles to mass converts a flux from moles to mass with it). lair converts them to SI on the way in, and the result is still a plain number in kelvin:

In [7]: from lair import units

In [8]: poisson(units.Quantity(2, "degC"), 850 * units.hPa)
Out[8]: np.float64(288.22325401883245)

Plain numbers are the rule because the same function then works on a float, a numpy array, a pandas column or an xarray DataArray, and most of those carry no units.

Where next#

  • Examples: worked examples, one per job.

  • API Reference: every module, with what each function and class does. In Python, help(lair.meteorology) shows the same text.

  • Optional dependencies: which extra a module needs.