Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
LOCA, 16th degree downscaled climate data (2016-04-02) S3 file lists
# A simple example showing a top level search on
# LOCA's S3 cache copy. See
# for the official distribution and general information.
# See the select_loca_data routine.
import urllib2, json, random
def get_json(ilink):
return json.loads( urllib2.urlopen(ilink).read() )
def select_loca_data(jidx, model, vname, exprid, rtag, addhist=None):
"""Select LOCA S3 keys/files given a set of criteria.
This routine builds a list of S3 keys, or web links, from the basic
LOCA json index. One might use this to determine an appropriate
listing of some model, ~experiment, variable name and resolution tag.
jidx: The loaded json index from the LOCA S3 cache
model: The name of the model of interest (see listing s3://nasanex/LOCA/models.json)
vname: The variable of the model of interest (DTR, pr, tasmax, tasmin)
exprid: The expriment id of interest, loosely defined here. Available
exprids are rcp45, rcp85, historical
rtag: The resolution tag, 1x1 or 16th
addhist: If this is not None then the history keys from model,vname,exprid,rtag
will be prepended to the returned list.
A list of LOCA keys/web links of interest
if addhist:
l = [ k for k in jidx.keys() if jidx[k]['model'] == model and jidx[k]['variable'] == vname \
and (jidx[k]['experiment_id'] == exprid or jidx[k]['experiment_id'] == 'historical') and \
jidx[k]['rtag'] == rtag ]
l = [ k for k in jidx.keys() if jidx[k]['model'] == model and jidx[k]['variable'] == vname \
and jidx[k]['experiment_id'] == exprid and jidx[k]['rtag'] == rtag ]
return l
if __name__ == '__main__':
idx = get_json(INVENTORY)
models = get_json(MODELS)
m = random.choice(models['models'])
# find what we're after.
kys = select_loca_data(idx, m, 'tasmax', 'rcp45', '16th', addhist=1)
for k in kys:
print k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment