diff --git a/.gitignore b/.gitignore index f9f6551..9124b7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,14 @@ # Processed data data/national/ceds/processed data/national/gfed/processed +data/national/gfed-bb4cmip/processed # CEDS data data/national/ceds/data_raw # GFED data data/national/gfed/data_raw +data/national/gfed-bb4cmip/data_raw # pixi stuff .pixi diff --git a/data/national/gfed-bb4cmip/data_raw/README.md b/data/national/gfed-bb4cmip/data_raw/README.md new file mode 100644 index 0000000..797e9df --- /dev/null +++ b/data/national/gfed-bb4cmip/data_raw/README.md @@ -0,0 +1,51 @@ +Biomass burning data is on the ESGF here: https://aims2.llnl.gov/search?project=input4MIPs&activeFacets=%7B%22mip_era%22%3A%22CMIP6Plus%22%2C%22institution_id%22%3A%22DRES%22%7D + +Download the data of interest here. +This can be done with the following commands +and [esgpull](https://esgf.github.io/esgf-download/) +(if you're not on a unix-based system, +create a virtual environment using whatever environment manager you like +then remove `venv/bin/` from all the commands below). + +```sh +# Install esgpull +# (see note above for non-unix systems) +python3 -m venv venv +venv/bin/pip install esgpull +venv/bin/esgpull self install + +# In the diaglog that pops up, install here +# to ensure that the paths in the notebooks behave. +venv/bin/esgpull config api.index_node esgf-node.llnl.gov +``` + +Then, check that the installation worked correctly by running + +```sh +venv/bin/esgpull config +``` + +The output should look something like + +``` +─────────────────── /path/to/emissions_harmonization_historical/data/national/gfed-bb4cmip/data_raw/config.toml ─────────────────── +[paths] +... +data = "/path/to/emissions_harmonization_historical/data/national/gfed-bb4cmip/data_raw/data" +... + +[api] +index_node = "esgf-node.llnl.gov" +... +``` + +Then, download the data + +```sh +# Comma-separated list +# You can search with esgpull search e.g. `venv/bin/esgpull search --all project:input4MIPs mip_era:CMIP6Plus source_id:DRES-CMIP-BB4CMIP7-1-0 grid_label:gn` +variable_ids_to_grab="BC,CH4,CO,CO2,N2O,NH3,NOx,OC,SO2,gridcellarea" +venv/bin/esgpull add --tag bb4cmip --track variable_id:"${variable_ids_to_grab}" project:input4MIPs mip_era:CMIP6Plus source_id:DRES-CMIP-BB4CMIP7-1-0 grid_label:gn +venv/bin/esgpull update -y --tag bb4cmip +venv/bin/esgpull download +``` diff --git a/notebooks/0103_GFED4-BB4CMIP-prepare.py b/notebooks/0103_GFED4-BB4CMIP-prepare.py new file mode 100644 index 0000000..ff900ad --- /dev/null +++ b/notebooks/0103_GFED4-BB4CMIP-prepare.py @@ -0,0 +1,59 @@ +# --- +# jupyter: +# jupytext: +# text_representation: +# extension: .py +# format_name: percent +# format_version: '1.3' +# jupytext_version: 1.16.4 +# kernelspec: +# display_name: Python 3 (ipykernel) +# language: python +# name: python3 +# --- + +# %% +from collections import defaultdict + +import xarray as xr + +from emissions_harmonization_historical.constants import DATA_ROOT + +# %% +raw_data_path = DATA_ROOT / "national/gfed-bb4cmip/data_raw/data" +raw_data_path + +# %% [markdown] +# Group raw data into variable groups which can be used for processing. + +# %% +bb4cmip_files = list(raw_data_path.rglob("*.nc")) +bb4cmip_file_groups = defaultdict(list) + +for file in bb4cmip_files: + variable = file.name.split("_")[0] + bb4cmip_file_groups[variable].append(file) + +bb4cmip_file_groups.keys() + +# %% [markdown] +# An example of loading data. + +# %% +cell_area = xr.open_mfdataset(bb4cmip_file_groups["gridcellarea"]) +cell_area + +# %% +gas = "BC" +gas_ds = xr.open_mfdataset(bb4cmip_file_groups["BC"]) +gas_ds + +# %% +global_sum_emissions = (gas_ds["BC"] * cell_area["gridcellarea"]).sum(["latitude", "longitude"]).compute() +global_sum_emissions + +# %% +global_sum_emissions.plot() + +# %% +global_sum_emissions.groupby("time.year").mean().plot() diff --git a/pixi.lock b/pixi.lock index e76cd70..4dde2ff 100644 --- a/pixi.lock +++ b/pixi.lock @@ -211,6 +211,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/nbclient-0.10.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbconvert-core-7.16.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbformat-5.10.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/nc-time-axis-1.4.1-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/linux-64/ncurses-6.5-he02047a_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nest-asyncio-1.6.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-64/netcdf4-1.7.1-nompi_py311hae66bec_102.conda @@ -541,6 +542,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/nbclient-0.10.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbconvert-core-7.16.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbformat-5.10.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/nc-time-axis-1.4.1-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/ncurses-6.5-hcccb83c_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nest-asyncio-1.6.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/linux-aarch64/netcdf4-1.7.1-nompi_py311h054e472_102.conda @@ -863,6 +865,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/nbclient-0.10.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbconvert-core-7.16.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbformat-5.10.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/nc-time-axis-1.4.1-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/osx-64/ncurses-6.5-hf036a51_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nest-asyncio-1.6.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-64/netcdf4-1.7.1-nompi_py311h79bb2b8_102.conda @@ -1186,6 +1189,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/nbclient-0.10.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbconvert-core-7.16.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbformat-5.10.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/nc-time-axis-1.4.1-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/osx-arm64/ncurses-6.5-h7bae524_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nest-asyncio-1.6.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/osx-arm64/netcdf4-1.7.1-nompi_py311he40982b_102.conda @@ -1497,6 +1501,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/nbclient-0.10.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbconvert-core-7.16.4-pyhd8ed1ab_1.conda - conda: https://conda.anaconda.org/conda-forge/noarch/nbformat-5.10.4-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/nc-time-axis-1.4.1-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/nest-asyncio-1.6.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/win-64/netcdf4-1.7.1-nompi_py311hbdc12eb_102.conda - conda: https://conda.anaconda.org/conda-forge/noarch/networkx-3.4.1-pyhd8ed1ab_0.conda @@ -5328,7 +5333,7 @@ packages: name: emissions-harmonization-historical version: 0.1.0 path: . - sha256: 09a5f9062745cb28ba38b844fb46a715039a220ee585d78c443f136c90b492e6 + sha256: a39544f1c2ae595e86530a72b8b9014f3d9d6d3015ce5e5b2297339cff77b37f requires_dist: - pre-commit==3.3.1 - ptolemy-iamc @ git+https://github.com/gidden/ptolemy.git@015aa843c340bd57464eb7cfd5f3c8e397201266 @@ -14327,6 +14332,26 @@ packages: - pkg:pypi/nbformat?source=hash-mapping size: 101232 timestamp: 1712239122969 +- kind: conda + name: nc-time-axis + version: 1.4.1 + build: pyhd8ed1ab_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/nc-time-axis-1.4.1-pyhd8ed1ab_0.tar.bz2 + sha256: 345d51b39f603a6717e43a998adaac35764467a4cf2bfec8f1963b9a7ced2a36 + md5: 281b58948bf60a2582de9e548bcc5369 + depends: + - cftime >=1.5 + - matplotlib-base + - numpy + - python >=3.7 + license: BSD-3-Clause + license_family: BSD + purls: + - pkg:pypi/nc-time-axis?source=hash-mapping + size: 18555 + timestamp: 1650472902858 - kind: conda name: ncurses version: '6.5' diff --git a/pyproject.toml b/pyproject.toml index a3542e0..92063d1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ h5py = ">=3.11.0,<4" netcdf4 = ">=1.7.1,<2" h5netcdf = ">=1.4.0,<2" pooch = ">=1.8.2,<2" +nc-time-axis = ">=1.4.1,<2" [tool.pixi.pypi-dependencies] emissions_harmonization_historical = { path = ".", editable = true }