import numpy as npimport matplotlib.pyplot as pltfrom labellines import labelLine, labelLinesfrom mpl_toolkits.axes_grid1.inset_locator import inset_axesfrom matplotlib import transformsfrom scipy.integrate import quadFIGURE_WIDTH =4.5FIGURE_HEIGHT =3# Adjust global params here to enforce consistent figuresplt.rcParams['figure.figsize'] = (FIGURE_WIDTH, FIGURE_HEIGHT) # Fixed default size for all figuresplt.rcParams['figure.constrained_layout.use'] =True# Auto-adjust spacingplt.rcParams['figure.dpi'] =150## Constants:R_earth =6400e3#mS_earth =4*np.pi*R_earth**2year_to_s =365*24*3600Wyear_m2earth_to_J = year_to_s*S_earth
Code
class Forcer:"""Base class for any climate forcer (gas, aerosol, contrail, etc.)"""def__init__(self, name):self.name = nameself.latex_name =self._to_latex(name)def _to_latex(self, name):"""Convert simple chemical names to LaTeX-friendly strings for plotting."""# e.g., CH4 -> CH$_4$, CO2 -> CO$_2$import re# add LaTeX subscript for digits latex_name = re.sub(r"(\d+)", r"$_\1$", name)return latex_namedef radiative_forcing(self, t, pulse):"""Compute radiative forcing over time. Override in subclass."""raiseNotImplementedErrordef IRF(self, t):"""Impulse Response Function. Override in subclass if needed."""raiseNotImplementedErrordef AGWP(self, H, pulse_kg=1.0):"""Absolute Global Warming Potential over horizon H (years). Default is for a 1 kg pulse.""" integrand =lambda t: self.radiative_forcing(t, pulse_kg) result, _ = quad(integrand, 0, H)return resultclass Gas(Forcer):"""Generic gas forcer with flexible IRF (single- or multi-exponential).""" M_air_kg_mol =28.97e-3 m_atm_kg =5.135e18def__init__(self, name, M_gas_kg_mol, RE_ppb, tau=None, feedbacks=None, IRF_params=None):super().__init__(name)self.M_gas_kg_mol = M_gas_kg_molself.RE_ppb = RE_ppbif feedbacks:self.RE_ppb *= (1+sum(feedbacks))self.tau = tauself.IRF_params = IRF_paramsdef mass_to_mixing_ratio(self, m_kg):"""Convert from mass of gas emission in kg to mixing ratio in standard atmosphere in ppb""" delta_X = (m_kg /self.m_atm_kg) * (self.M_air_kg_mol /self.M_gas_kg_mol)return delta_X *1e9def IRF(self, t):ifself.IRF_params: # multi-exponential IRF a =self.IRF_params['a'] tau_array =self.IRF_params['tau'] long_term =self.IRF_params.get('long_term', 0)return long_term +sum(ai * np.exp(-t/ti) for ai, ti inzip(a, tau_array))elifself.tau: # simple exponential IRFreturn np.exp(-t/self.tau)else:raiseValueError("No IRF defined for this gas")def radiative_forcing(self, t, pulse_kg): pulse_ppb =self.mass_to_mixing_ratio(pulse_kg)return pulse_ppb *self.IRF(t) *self.RE_ppbclass Contrail(Forcer):"""Short-lived forcer from aviation contrails"""def__init__(self, name, RE_per_unit, lifetime_days):super().__init__(name)self.RE_per_unit = RE_per_unitself.tau_days = lifetime_daysdef IRF(self, t):# decay in years; tau_days / 365 converts lifetime to years tau_years =self.tau_days /365return np.exp(-t / tau_years)def radiative_forcing(self, t, units):returnself.RE_per_unit * units *self.IRF(t)CH4 = Gas("CH4", M_gas_kg_mol=16.04e-3, RE_ppb=3.63e-4, tau=12.4, feedbacks=[0.5, 0.15])CO2_IRF_params = {'a': [0.224037, 0.282381, 0.276303],'tau': [394.409, 36.5393, 4.30365],'long_term': 0.217278}CO2 = Gas("CO2", M_gas_kg_mol=44.01e-3, RE_ppb=1.37e-5, IRF_params=CO2_IRF_params)
However, the Earth’s temperature response is far more complex than that with energy exchanges between the atmosphere, land, ocean mixed layer and the deep ocean. So this is often modeled using coupled Atmosphere-Ocean General Circulation Models (AOGCMs). With these models we can estimate a climate response to a unit of energy forcing as a function \(R_T(t)\):
A simple two-box model of the Earth can be represented as a sum of exponentials, \[
\color{red}R_T\color{black}({\color{brown}t}) = \lambda\left[f\,\frac{1}{\color{brown}\tau_1}e^{-{\color{brown}t/\tau_1}} \;+\; (1-f)\,\frac{1}{\color{brown}\tau_2}e^{-{\color{brown}t/\tau_2}}\right],
\]
so that \(\displaystyle \int_0^\infty R(t)\,dt = \lambda\) (the equilibrium temperature change per unit forcing) and the parameters \(f\), \(\tau_i\) need to be calibrated against full AOGCMs.
The IPCC AR5 (2013) shows the climate response function in a similar manner: \[
\color{red}R_T\color{black}({\color{brown}t}) = \sum_{j=1}^{M} \frac{c_j}{\color{brown}\tau_j} \exp \left(-{\color{brown}\frac{t}{\tau_j}}\right),
\] where,
These numbers correspond to a climate sensitivity \(\lambda = 1.06\; \text{K(W m}^{-2})^{-1}\) and a equilibrium temperature response of 3.9 K for a doubling of \(\ce{CO2}\) abundance. The two forms of this model are essentially the same, \(c_1 = \lambda f\), and \(c_2 = \lambda (1-f)\), but the second form is more general and can have more terms.