Last active
May 13, 2021 01:46
-
-
Save Thomas-Moore-Creative/0678b053efc4edcf102dd98124c4ae6c to your computer and use it in GitHub Desktop.
simple code for loading CCiA CMIP5 data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this is specific to needs outlined in this repo: | |
# https://github.com/Thomas-Moore-Creative/NCI-CCiA-ARD | |
import xarray as xr | |
import numpy as np | |
import datetime | |
import intake | |
NCI_catalog = intake.open_catalog('/g/data/hh5/public/apps/nci-intake-catalogue/catalogue.yaml') | |
# build CCiA catalog subset | |
CCiA_catalog = NCI_catalog.esgf.cmip5.search(variable=['psl','pr'], | |
realm=['atmos'], | |
time_frequency='mon', | |
experiment=['rcp85','historical'], | |
ensemble=['r1i1p1'], | |
model=['ACCESS1.0', | |
'CESM1(CAM5)', | |
'CNRM-CM5', | |
'GFDL-ESM2M', | |
'HadGEM2-CC', | |
'CanESM2', | |
'MIROC5', | |
'NorESM1-M']\ | |
) | |
# let's check the models included | |
CCiA_catalog.unique('model') | |
# create the dataset dict | |
CCiA_dataset_dict = CCiA_catalog.to_dataset_dict() | |
# make a list of all the keys | |
CCiA_key_list = list(CCiA_dataset_dict.keys()) | |
CCiA_key_list | |
# define a function to return a CCiA_data_object based on model & experiment & variable | |
# crudely handle datetime issue across models | |
def load_CCiA_data(model,experiment,variable): | |
key_string_list = [i for i in CCiA_key_list if model in i] | |
key_string_list = [i for i in key_string_list if experiment in i] | |
key_string = [i for i in key_string_list if variable in i] | |
CCiA_data_object = CCiA_dataset_dict[key_string.pop()] | |
#check if datetime64 object? | |
if not np.issubdtype(CCiA_data_object.time.dtype, np.datetime64): | |
CCiA_data_object | |
datetimeindex = CCiA_data_object.indexes['time'].to_datetimeindex() | |
CCiA_data_object['time'] = datetimeindex | |
return CCiA_data_object | |
# use the function | |
MIROC5_rcp85_psl_data = load_CCiA_data('MIROC5','rcp85','psl') | |
MIROC5_rcp85_psl_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment