From dbfdc1b92c47cd2ee34f71b24db9b3590ed4a39a Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Thu, 3 Sep 2020 13:57:42 +0100 Subject: [PATCH] Fix --- climetlab/__init__.py | 2 +- climetlab/core/data.py | 15 +++++++++++---- climetlab/core/ipython.py | 2 +- climetlab/core/metadata.py | 12 ++++++++++++ climetlab/datasets/meteonet/dataset.yaml | 5 +++-- climetlab/helpers/xarray.py | 2 ++ docs/firststeps.rst | 2 ++ 7 files changed, 32 insertions(+), 8 deletions(-) diff --git a/climetlab/__init__.py b/climetlab/__init__.py index fd028e6a..271bfe3f 100644 --- a/climetlab/__init__.py +++ b/climetlab/__init__.py @@ -18,7 +18,7 @@ from climetlab.datasets import Dataset # import logging -__version__ = "0.0.84" +__version__ = "0.0.85" # if ipython_active: # logging. diff --git a/climetlab/core/data.py b/climetlab/core/data.py index 53d47591..fa196420 100644 --- a/climetlab/core/data.py +++ b/climetlab/core/data.py @@ -20,7 +20,7 @@ YAML_FILES = None -def _guess(data): +def _guess(data, path): if "dataset" in data: return "datasets" @@ -29,7 +29,7 @@ def _guess(data): if "msymb" in data["magics"]: return "styles" - if "mcount" in data["magics"]: + if "mcont" in data["magics"]: return "styles" if "mcoast" in data["magics"]: @@ -38,6 +38,7 @@ def _guess(data): if "mmap" in data["magics"]: return "projections" + LOG.warning("Cannot guess collection for %s", path) return "unknown" @@ -76,7 +77,7 @@ def _load_yaml_files(): with open(path) as f: data = yaml.load(f.read(), Loader=yaml.SafeLoader) name, _ = os.path.splitext(os.path.basename(path)) - kind = _guess(data) + kind = _guess(data, path) collection = YAML_FILES[kind] if name in collection: LOG.warning( @@ -96,7 +97,13 @@ def _load_yaml_files(): def get_data_entry(kind, name): - return _load_yaml_files()[kind][name] + files = _load_yaml_files() + if kind not in files: + raise Exception("No collection named '%s'" % (kind,)) + if name not in files[kind]: + raise Exception("No object '%s' in collection named '%s'" % (name, kind,)) + + return files[kind][name] def data_entries(kind=None): diff --git a/climetlab/core/ipython.py b/climetlab/core/ipython.py index 0b1802ac..0ce8334c 100644 --- a/climetlab/core/ipython.py +++ b/climetlab/core/ipython.py @@ -48,7 +48,7 @@ def _identity(x, **kwargs): if ipython_active: from IPython.display import display, Image, SVG, HTML, Markdown - enable_ipython_login() + # enable_ipython_login() else: Image = _identity SVG = _identity diff --git a/climetlab/core/metadata.py b/climetlab/core/metadata.py index 3dd36c5e..0157e446 100644 --- a/climetlab/core/metadata.py +++ b/climetlab/core/metadata.py @@ -10,6 +10,18 @@ import json +# import xarray as xr + + +# @xr.register_dataset_accessor("climetlab") +# class CliMetLabAccessor: +# def __init__(self, xarray_obj): +# self._obj = xarray_obj +# print("CliMetLabAccessor") +# def foo(self, v): +# print("foo", v) + + class Annotation: def __init__(self, **kwargs): self._kwargs = kwargs diff --git a/climetlab/datasets/meteonet/dataset.yaml b/climetlab/datasets/meteonet/dataset.yaml index ac7a1f6e..30839568 100644 --- a/climetlab/datasets/meteonet/dataset.yaml +++ b/climetlab/datasets/meteonet/dataset.yaml @@ -1,3 +1,4 @@ --- -home_page: https://meteofrance.github.io/meteonet/ -licence: https://meteonet.umr-cnrm.fr/dataset/LICENCE.md +dataset: + home_page: https://meteofrance.github.io/meteonet/ + licence: https://meteonet.umr-cnrm.fr/dataset/LICENCE.md diff --git a/climetlab/helpers/xarray.py b/climetlab/helpers/xarray.py index e9140b3a..042f7024 100644 --- a/climetlab/helpers/xarray.py +++ b/climetlab/helpers/xarray.py @@ -14,6 +14,8 @@ class XArrayHelper: def __init__(self, data): + data.climetlab.foo(42) + self.data = data for name, var in data.data_vars.items(): self.name = name diff --git a/docs/firststeps.rst b/docs/firststeps.rst index 0ca80028..801077f6 100644 --- a/docs/firststeps.rst +++ b/docs/firststeps.rst @@ -78,6 +78,8 @@ on plotting below). Datasets ^^^^^^^^ +Datasets are a higher-level concept compared to data sources. + The following Python code: