#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Contains proxies to reach resources using Vortex.
"""
import uuid
from vortex import toolbox
import common
import olive
[docs]def set_defaults(**defaults):
"""
Set defaults key/value pairs for get_resource().
"""
_defaults = dict(model='arome',
cutoff='prod',
vapp='arome',
vconf='france',
geometry='franmgsp',
origin='hst')
_defaults.update(defaults)
toolbox.defaults(**_defaults)
[docs]def get_resource(**description):
"""
Get a resource, given its description.
Examples:
- for the analysis of AROME-france from experiment 864G on 2015/08/15/00,
description will look like:
+ experiment='864G', # the experiment id
block='analysis', # the OLIVE block
kind='analysis', # the kind of resource
date='2015081500', # the initial date and time
geometry='franmgsp', # the name of the model domain
local='analysis_[experiment]', # the local filename of the resource, once fetched.
- for the model state at term 18h of ALADIN-reunion oper, production
cutoff, on 2015/08/15/00,
description will look like:
+ suite='oper', # the suite // 'dble' = e-suite
kind='historic', # model state
date='2015081500', # the initial date and time
term=18, # the forecast term
geometry='reunionsp', # the name of the model domain
local='ICMSHALAD_[term]', # the local filename of the resource, once fetched.
cutoff='prod', # type of cutoff
vapp='aladin', # type of application in operations namespace
vconf='reunion', # name of config in operation namespace
model='aladin', # name of the model
- for the GRIB post-processed output on MASCA025 BDAP domain at terms
22->24h of ALADIN-reunion oper, production cutoff, on 2015/08/15/00,
description will look like:
+ suite='oper', # the suite // 'dble' = e-suite
kind='gridpoint', # model state
date='2015081500', # the initial date and time
term=[22,23,24], # the forecast terms
geometry='masca025', # the name of the post-processing domain
local='[geometry]_[term].grb', # the local filename of the resource, once fetched.
nativefmt='grib' # to fetch the gribs and not the FA post-processed files
cutoff='prod', # type of cutoff
vapp='aladin', # type of application in operations namespace
vconf='reunion', # name of config in operation namespace
model='aladin', # name of the model
"""
import common.util.usepygram
if toolbox.defaults == {}:
set_defaults()
# set namespace according to status xp/oper...
if description.get('experiment', None):
description['namespace'] = 'olive.archive.fr'
elif description.get('suite', None) in ('oper, dble'):
description['namespace'] = 'oper.archive.fr'
if not description.get('local', None):
description['local'] = uuid.uuid4()
if description.get('kind', None) in ('analysis', 'historic'):
description['nativefmt'] = 'fa'
elif description.get('nativefmt', None) == 'grib':
description['kind'] = 'gridpoint'
if description.get('model', None):
description['vapp'] = description['model']
r = toolbox.rh(**description)
print r.locate()
if r.get():
return r.contents.data
else:
raise IOError("fetch failed: " + r.locate())