Skip to content

Instantly share code, notes, and snippets.

@jbusecke
Last active August 8, 2024 19:29
Show Gist options
  • Save jbusecke/da29a41fd855f1a1ad0d00cbdc7086c4 to your computer and use it in GitHub Desktop.
Save jbusecke/da29a41fd855f1a1ad0d00cbdc7086c4 to your computer and use it in GitHub Desktop.
Minimal CMIP example
import xarray as xr
from xmip.preprocessing import combined_preprocessing
data_url = 'gs://cmip6/CMIP6/CMIP/IPSL/IPSL-CM6A-LR/historical/r4i1p1f1/Omon/tos/gn/v20180803/'
# Run the same thing with another dataset?
#data_url = 'gs://cmip6/CMIP6/CMIP/MPI-M/MPI-ESM1-2-LR/historical/r4i1p1f1/Omon/tos/gn/v20190710/'
# read into xarray dataset
ds = xr.open_dataset(data_url, engine='zarr', chunks={})
# preprocessing to harmonize naming
ds = combined_preprocessing(ds)
spatial_mean = ds.mean(['x', 'y'])
# spatial mean could be saved out to disk/cloud/... separately
mean = spatial_mean.mean(['time'])
mean.to_zarr('mean_number.zarr')
@jbusecke
Copy link
Author

jbusecke commented Aug 8, 2024

I am running this on the 'pangeo-notebook' image (see here). But I think for this to run you should get along with

pip install xarray gcsfs zarr xmip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment