Exemple #1
0
def service(name):
    try:
        return ecmwfapi.ECMWFService(name)
    except Exception as e:
        if ".ecmwfapirc" in str(e):
            MARSAPI().ask_user_and_save()
            return ecmwfapi.ECMWFService(name)

        raise
Exemple #2
0
 def __init__(self, key=None, email=None):
     """
         Set up a connection to the MARS data service.
     """
     import ecmwfapi
     if key is not None and email is not None:
         self.service = ecmwfapi.ECMWFService('mars', key=key, email=email)
     else:
         self.service = ecmwfapi.ECMWFService('mars')
Exemple #3
0
def test_mars():
    while True:
        try:
            c = ecmwfapi.ECMWFService("mars")
            c.execute({"date": "2000-01-01"}, "mars.grib")
            assert os.path.getsize("mars.grib") == 1238868

            return
        except ecmwfapi.api.APIException as e:
            print(e)
            msg = str(e)
            if "USER_QUEUED_LIMIT_EXCEEDED" not in msg:
                raise

        time.sleep(120)
Exemple #4
0
    expver  = 1,
    time    = 00/12,
    step    = 1/2/3/4/5/6/7/8/9/10/11/12,
    type    = fc,
    param   = 228.128,
    grid    = 0.1/0.1,
    format  = netcdf,
    target  = \"/g/data/fj4/ECMWF/HRES/precip_{2}.nc\"""".format(
        d0.strftime('%Y-%m-%d'), d1.strftime('%Y-%m-%d'), d0.strftime('%Y%m'))
    print(req)

    if "WEBMARS_TARGET" in os.environ:
        target = os.environ["WEBMARS_TARGET"]
    else:
        m = re.search(
            '\\btar(g(e(t)?)?)?\s*=\s*([^\'",\s]+|"[^"]*"|\'[^\']*\')', req,
            re.I | re.M)
        if m is None:
            raise Exception("Cannot extract target")

        target = m.group(4)
        if target is None:
            raise Exception("Cannot extract target")

    if target[0] == target[-1]:
        if target[0] in ['"', "'"]:
            target = target[1:-1]

    c = ecmwfapi.ECMWFService('mars')
    c.execute(req, target)
Exemple #5
0
warnings.simplefilter(action='ignore', category=FutureWarning)
import pandas as pd
import xarray as xr
import pygrib
from helper_functions import unitconversionfactors, agg_space, agg_time
from observations import Clustering, EventClassification

# Extended range has 50 perturbed members. and 1 control forecast. Steps: "0/to/1104/by/6"
# Reforecasts have 11 members (stream = "enfh", number "1/to/10"). Probably some duplicates will arise.
# Params: 228.128 : total precipitation (or 228172). 167.128 : T2m
# Native grid O320 (but subsetting is not available for native)
# Grids at the ecmwf are stored with decreasing latitude but increasing longitude.

# Global variables
server = ecmwfapi.ECMWFService(
    "mars"
)  # Setup parallel requests by splitting the batches in multiple consoles. (total: max 3 active and 20 queued requests allowed)
for_netcdf_encoding = {
    't2m': {
        'dtype': 'int16',
        'scale_factor': 0.002,
        'add_offset': 273,
        '_FillValue': -32767
    },
    'mx2t6': {
        'dtype': 'int16',
        'scale_factor': 0.002,
        'add_offset': 273,
        '_FillValue': -32767
    },
    'tp': {
Exemple #6
0
def test_mars():
    c = ecmwfapi.ECMWFService("mars")
    c.execute({"date": "2000-01-01"}, "mars.grib")