Basic example

FaIR v2.2 is object-oriented and designed to be more flexible than its predecessors. This does mean that setting up a problem is different to before - gone are the days of 60 keyword arguments to fair_scm and we now use classes and functions with fewer arguments that in the long run should be easier to use. Of course, there is a learning curve, and will take some getting used to. This tutorial aims to walk through a simple problem using FaIR 2.2.

The structure of FaIR 2.2 centres around the FAIR class, which contains all information about the scenario(s), the forcer(s) we want to investigate, and any configurations specific to each species and the response of the climate.

Note

The code in this introductory block is explanatory and if you try to copy and paste it it you’ll get errors. The code in this file is self-contained below the heading “1. Create FaIR instance” below. Alternatively, check out the repository from GitHub and run this example notebook in jupyter. Details here.

Some basics

There are two main parts to running fair. The first is setting up the problem definition. This tells fair what you’re including in the run, how long you are running for, how many scenarios and how many (climate) ensemble members (known as configs).

Setting up the run

First make a new instance:

from fair import FAIR
f = FAIR()

Then, we need to add some information about the time horizon of our model, forcers we want to run with, their configuration (and the configuration of the climate), and optionally some model control options:

from fair.io import read_properties
f.define_time(2000, 2050, 1)
f.define_scenarios(['abrupt', 'ramp'])
f.define_configs(['high', 'central', 'low'])
species, properties = read_properties()
f.define_species(species, properties)
f.ghg_method='Myhre1998'

Finally, we tell fair to generate some empty (all NaN) array variables: emissions, concentrations, forcing, temperature etc.:

f.allocate()

That’s all you need to set up the run.

Fill in data

The f.allocate() step creates xarray DataArrays, some of which need to be populated. For example, to fill a constant 40 GtCO2/yr emissions rate for fossil CO2 emissions into the ‘abrupt’ scenario, we can do

from fair.interface import fill
fill(f.emissions, 40, scenario='abrupt', specie='CO2 FFI')
...

In this section we also want to tell fair things such as the climate feedback parameter, carbon cycle sensitivities, aerosol forcing parameters, and literally hundreds of other things you can vary. There are convenience functions for reading in emissions and parameter sets from external files.

Run and analyse model

Finally, the model is run with

f.run()

Results are stored within the FAIR instance as xarray DataArrays or Dataset, and can be obtained such as

print(fair.temperature)

Multiple scenarios and configs can be supplied in a FAIR instance, and due to internal parallelisation is the fastest way to run the model (100 ensemble members per second for 1750-2100 on my Mac for an emissions driven run). The total number of scenarios that will be run is the product of scenarios and configs. For example we might want to run three emissions scenarios – let’s say SSP1-2.6, SSP2-4.5 and SSP3-7.0 – using climate calibrations (configs) from the UKESM, GFDL, MIROC and NorESM climate models. This would give us a total of 12 ensemble members in total which are run in parallel.