Working with carbon dioxide#

In this tutorial, we will compare carbon dioxide (\(\mathrm{CO_2}\)) emissions with flux data. For carbon dioxide data, the natural diurnal cycle must be taken into account when comparing any expected measurements against our observations.

Carbon dioxide calculations can use time-resolved sensitivities for fluxes whose sub-daily variability is important and integrated sensitivities for lower-frequency fluxes. For the time-resolved calculation, NAME footprints contain an additional H_back dimension storing hourly sensitivities over an initial period before each release time, and the corresponding flux data should have a frequency of less than 24 hours. A shared footprint dataset that contains both representations can use a different calculation for each flux source, as shown in section 4.

Note

Operations involving \(\mathrm{CO}_2\) and high resolution data may run slowly at the moment.

Note

Plots created within this tutorial may not show up on the online documentation.

Using the tutorial object store#

As in the previous tutorial, we will use the tutorial object store to avoid cluttering your personal object store.

from openghg.tutorial import use_tutorial_store

use_tutorial_store()

1. Loading data sources into the object store#

We will use a helper function from the openghg.tutorial submodule to add surface, flux, and footprint data to the object store.

You might get a message telling you that a file has already been added if you’ve been through one of the other tutorials previously.

from openghg.tutorial import populate_flux_data, populate_surface_data, populate_footprint_data
populate_surface_data()

populate_flux_data()

populate_footprint_data()

2. Creating a model scenario#

To link our observations to our ancillary data we can create a ModelScenario object, as shown in the previous tutorial, using suitable keywords to grab the data from the object store.

from openghg.analyse import ModelScenario

site = "TAC"
domain = "EUROPE"
species = "co2"
height = "185m"
source_natural = "natural"
start_date = "2017-07-01"
end_date = "2017-07-07"

scenario = ModelScenario(site=site,
                         inlet=height,
                         domain=domain,
                         species=species,
                         source=source_natural,
                         start_date=start_date,
                         end_date=end_date)

We can plot our observation timeseries using the ModelScenario.plot_timeseries() method as before:

scenario.plot_timeseries()

We can also check trace details of the extracted data by checking the available metadata. For instance for our footprint data we would expect this to have an associated species and for this to be labelled as “co2”:

footprint_metadata = scenario.footprint.metadata
footprint_species = footprint_metadata["species"]
print(f"Our linked footprint has an associated species of '{footprint_species}'")

3. Comparing data sources#

Once suitable emissions and footprint sensitivities have been linked for our carbon dioxide data, we can start to plot comparisons between the sources and our measurement data.

scenario.plot_comparison(baseline="percentile")

As in the previous tutorial, multiple fluxes can be linked to your ModelScenario object if required. This can include additional high frequency (less than 24 hourly) or low frequency flux data. In this case we have added monthly “fossil fuel” emissions:

source_fossil = "ff-edgar-bp"

scenario.add_flux(species=species,
                  source=source_fossil,
                  domain=domain)
fossil_flux = scenario.fluxes[source_fossil]
fossil_flux

If we plot the modelled measurement comparison, this will stack the natural and fossil fuel flux sources and combine with the footprint data in an appropriate way:

# scenario.plot_comparison(baseline="percentile", recalculate=True)

4. Choosing the calculation pathway for each flux sector#

The footprint belongs to the observation site or satellite sounding, not to a flux sector. All flux sources therefore use the same retrieved footprint dataset. If it contains both integrated fp and time-resolved sensitivities, you can select which calculation to use for each flux source:

modelled = scenario.calc_modelled_obs(
    time_resolved_by_sector={source_natural: True, source_fossil: False},
    split_by_sectors=True,
    output_fp_x_flux=True,
)

Here, True uses the existing lag-resolved calculation for natural fluxes. False uses integrated fp for fossil-fuel fluxes, with monthly-mean fluxes by default for CO2. This does not retrieve another footprint, create a sector-specific footprint, or infer a pathway from the flux frequency. use_low_freq_flux=False retains the existing option to use release-time fluxes for integrated calculations instead of monthly means.

Unspecified sources follow the existing default determined by the shared footprint’s sensitivity variables. Supplying None or an empty mapping preserves the original public calculation pathway and output names.

For an explicitly configured calculation, the total is returned as mf_mod. split_by_sectors=True additionally returns mf_mod_sectoral with a source dimension. output_fp_x_flux=True returns fp_x_flux and, when sectoral output is enabled, fp_x_flux_sectoral. The total is calculated from the same sector contributions whether or not sectoral output is requested. The effective selection is recorded as a JSON string in the dataset attribute time_resolved_by_sector.

The same option is available through scenario.footprints_data_merge(...). Surface and satellite observations retain their existing alignment rules.

Note

Integrated sectors require fp. Time-resolved sectors require either legacy fp_HiTRes or both fp_time_resolved and fp_residual. The sensitivity variables and fluxes must have correctly declared physical units. Legacy fp_HiTRes can inherit its units from fp. The calculation reports missing or incompatible units before combining sector contributions.

5. Cleanup#

If you’re finished with the data in this tutorial you can cleanup the tutorial object store using the clear_tutorial_store function.

from openghg.tutorial import clear_tutorial_store
clear_tutorial_store()