Skill from ECMWF downloaded with herbie

!pip install herbie-data --quiet
# linting
%load_ext nb_black
%load_ext lab_black
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 2
      1 # linting
----> 2 get_ipython().run_line_magic('load_ext', 'nb_black')
      3 get_ipython().run_line_magic('load_ext', 'lab_black')

File ~/checkouts/readthedocs.org/user_builds/climpred/conda/latest/lib/python3.9/site-packages/IPython/core/interactiveshell.py:2456, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2454     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2455 with self.builtin_trap:
-> 2456     result = fn(*args, **kwargs)
   2458 # The code below prevents the output from being displayed
   2459 # when using magics with decorator @output_can_be_silenced
   2460 # when the last Python token in the expression is a ';'.
   2461 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/checkouts/readthedocs.org/user_builds/climpred/conda/latest/lib/python3.9/site-packages/IPython/core/magics/extension.py:33, in ExtensionMagics.load_ext(self, module_str)
     31 if not module_str:
     32     raise UsageError('Missing module name.')
---> 33 res = self.shell.extension_manager.load_extension(module_str)
     35 if res == 'already loaded':
     36     print("The %s extension is already loaded. To reload it, use:" % module_str)

File ~/checkouts/readthedocs.org/user_builds/climpred/conda/latest/lib/python3.9/site-packages/IPython/core/extensions.py:76, in ExtensionManager.load_extension(self, module_str)
     69 """Load an IPython extension by its module name.
     70 
     71 Returns the string "already loaded" if the extension is already loaded,
     72 "no load function" if the module doesn't have a load_ipython_extension
     73 function, or None if it succeeded.
     74 """
     75 try:
---> 76     return self._load_extension(module_str)
     77 except ModuleNotFoundError:
     78     if module_str in BUILTINS_EXTS:

File ~/checkouts/readthedocs.org/user_builds/climpred/conda/latest/lib/python3.9/site-packages/IPython/core/extensions.py:91, in ExtensionManager._load_extension(self, module_str)
     89 with self.shell.builtin_trap:
     90     if module_str not in sys.modules:
---> 91         mod = import_module(module_str)
     92     mod = sys.modules[module_str]
     93     if self._call_load_ipython_extension(mod):

File ~/checkouts/readthedocs.org/user_builds/climpred/conda/latest/lib/python3.9/importlib/__init__.py:127, in import_module(name, package)
    125             break
    126         level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1030, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1007, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:984, in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'nb_black'

Skill from ECMWF downloaded with herbie#

herbie downloads forecasts data easily. The resulting datasets is out-of-the-box compatible with climpred.

import xarray as xr
import numpy as np

import climpred  # forecast verification
from herbie import Herbie

H = Herbie(date="2022-01-27 00:00", model="ecmwf", product="enfo", fxx=24 * 1)
ds = H.xarray(":2t:")
ds
# take the first with multiple members as forecast
init = ds[0][["t2m"]]
H = Herbie(date="2022-01-28 00:00", model="ecmwf", product="enfo", fxx=0)
ds = H.xarray(":2t:")
ds
# take first and make ensemble member mean as observations
obs = ds[0].mean("number").drop(["step", "valid_time"]).expand_dims("time")[["t2m"]]

Forecast skill verification#

Using using HindcastEnsemble.

climpred expects init, lead and optional member as dimensions, see setting-up-your-dataset. Existing dimensions are renamed automatically if CF standard_names match.

hindcast = climpred.HindcastEnsemble(
    init.expand_dims(["time", "step"])
).add_observations(obs)

hindcast
skill = hindcast.verify(
    metric="crps", comparison="m2o", dim=["init", "member"], alignment="same_init"
)
skill.t2m.plot(robust=True)