Chaining calculations#
A derived quantity is an input like any other.
Sometimes you’ll have a pipeline that is two or three calculations deep. Because every calculation returns the same form you passed in, the result of one is a valid argument to the next: in Polars you add it as a column and refer to it by name, in Pandas you assign it and pass it straight back.
For example, estimate evapotranspiration from an eddy-covariance energy balance: first latent heat flux from net radiation, soil heat flux and sensible heat flux, then evapotranspiration from that.
df = df.with_columns(
le=evapotranspiration.latent_heat_flux("rn", "g", "h"),
).with_columns(
et=evapotranspiration.evapotranspiration_from_latent_heat_flux("le", "ta"),
)
shape: (2, 6)
┌───────┬─────┬──────┬──────┬──────┬──────────┐
│ rn ┆ g ┆ h ┆ ta ┆ le ┆ et │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 │
╞═══════╪═════╪══════╪══════╪══════╪══════════╡
│ 80.0 ┆ 5.0 ┆ 30.0 ┆ 15.0 ┆ 45.0 ┆ 0.065704 │
│ 120.0 ┆ 8.0 ┆ 40.0 ┆ 18.0 ┆ 72.0 ┆ 0.10543 │
└───────┴─────┴──────┴──────┴──────┴──────────┘
df["le"] = evapotranspiration.latent_heat_flux(
df["rn"], df["g"], df["h"]
)
df["et"] = evapotranspiration.evapotranspiration_from_latent_heat_flux(
df["le"], df["ta"]
)
rn g h ta le et
0 80.0 5.0 30.0 15.0 45.0 0.065704
1 120.0 8.0 40.0 18.0 72.0 0.105430
Some calculations exist mainly to feed others. The FAO-56 intermediates in
evapotranspiration - saturation vapour pressure, the psychrometric constant, the
slope of the vapour pressure curve - are available individually if you want to inspect them, but
potential_evapotranspiration_30min() computes them internally,
so you do not have to chain them by hand.