def dbsource(dbname, var, resolution=None, tscale=None):
"""
Temporary solution, just to move on with CoTeDe.
"""
db_cfg = {}
cfg_dir = 'datasource'
for src_cfg in pkg_resources.resource_listdir('oceansdb', cfg_dir):
text = pkg_resources.resource_string(
'oceansdb', os.path.join(cfg_dir, src_cfg))
text = text.decode('UTF-8', 'replace')
cfg = json.loads(text)
for c in cfg:
assert c not in db_cfg, "Trying to overwrite %s"
db_cfg[c] = cfg[c]
dbpath = oceansdb_dir()
datafiles = []
cfg = db_cfg[dbname]
if (resolution is None):
resolution = cfg['vars'][var]['default_resolution']
if (tscale is None):
tscale = cfg['vars'][var][resolution]["default_tscale"]
for c in cfg['vars'][var][resolution][tscale]:
download_file(outputdir=dbpath, **c)
if 'filename' in c:
filename = os.path.join(dbpath, c['filename'])
else:
filename = os.path.join(dbpath,
os.path.basename(urlparse(c['url']).path))
if 'varnames' in cfg['vars'][var][resolution]:
datafiles.append(Dataset_flex(filename,
aliases=cfg['vars'][var][resolution]['varnames']))
else:
datafiles.append(Dataset_flex(filename))
return datafiles
评论列表
文章目录