Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Sep 3, 2020
1 parent f0fb09d commit 898e25a
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 2 deletions.
46 changes: 46 additions & 0 deletions climetlab/core/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# (C) Copyright 2020 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#

import json


class Annotation:
def __init__(self, **kwargs):
self._kwargs = kwargs

def get(self, name):
return self._kwargs.get(name)


def annotate(pd, **kargs):

kargs["climetlab"] = "annotation"

for i, a in enumerate(pd._metadata):
try:
a = json.loads(a)
if a["climetlab"] == "annotation":
pd._metadata[i] = json.dumps(kargs)
return pd
except Exception:
pass

pd._metadata.append(json.dumps(kargs))
return pd


def annotation(pd):
for a in pd._metadata:
try:
a = json.loads(a)
if a["climetlab"] == "annotation":
return Annotation(**a)
except Exception:
pass
return Annotation()
13 changes: 11 additions & 2 deletions climetlab/datasets/hurricane_database.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# (C) Copyright 2020 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#

# See https://www.aoml.noaa.gov/hrd/hurdat/Data_Storm.html

import pandas as pd
import numpy as np
from . import Dataset
from climetlab.utils import download_and_cache
from climetlab.utils.datetime import parse_date

from climetlab.core.metadata import annotate

SIGN = {"N": 1, "W": -1, "E": 1, "S": -1}

Expand Down Expand Up @@ -112,7 +121,7 @@ def __init__(self, bassin="atlantic", url=None):
)
)

self.cyclones = pd.DataFrame(p)
self.cyclones = annotate(pd.DataFrame(p), style="cyclone-track")

def to_pandas(self):
return self.cyclones
Expand Down
7 changes: 7 additions & 0 deletions climetlab/plotting/drivers/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from climetlab.core.caching import temp_file
from climetlab.core.ipython import SVG, Image
from climetlab.core.data import get_data_entry
from climetlab.core.metadata import annotation

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -321,6 +322,12 @@ def plot_pandas(self, frame, latitude: str, longitude: str, variable: str):
frame[[latitude, longitude, variable]].to_csv(tmp, header=False, index=False)
self.plot_csv(tmp, variable)

print(frame._metadata)

style = annotation(frame).get("style")
if style is not None:
self.style(style)

def _apply(self, collection, value, action):

if value is None:
Expand Down
181 changes: 181 additions & 0 deletions docs/_static/irma.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 898e25a

Please sign in to comment.