Skip to content

Commit

Permalink
Version 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
b8raoult committed Jan 16, 2021
1 parent ab5e591 commit 5e4c0e1
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 93 deletions.
2 changes: 1 addition & 1 deletion climetlab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

# import logging

__version__ = "0.1.2"
__version__ = "0.1.3"


# if ipython_active:
Expand Down
3 changes: 3 additions & 0 deletions climetlab/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def _repr_html_(self):
def annotate(self, data, **kargs):
return annotate(data, self, **kargs)

def check_parameter(self, name, value, *values):
pass


def _module_callback(plugin):
return import_module(plugin, package=__name__).dataset
Expand Down
24 changes: 24 additions & 0 deletions climetlab/datasets/weather_bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,30 @@ class WeatherBench(Dataset):
"""

def __init__(self, parameter="geopotential_500", resolution=5.625):

self.check_parameter(
"parameter",
parameter,
"10m_u_component_of_wind",
"10m_v_component_of_wind",
"2m_temperature",
"constants",
"geopotential" "geopotential_500",
"potential_vorticity",
"relative_humidity",
"specific_humidity",
"temperature",
"temperature_850",
"toa_incident_solar_radiation",
"total_cloud_cover",
"total_precipitation",
"u_component_of_wind",
"v_component_of_wind",
"vorticity",
)

self.check_parameter("resolution", resolution, 1.40625, 2.8125, 5.625)

url = "https://dataserv.ub.tum.de/s/m1524895/download?path=%2F{resolution}deg%2F{parameter}&files={parameter}_{resolution}deg.zip".format(
resolution=resolution, parameter=parameter
)
Expand Down
3 changes: 3 additions & 0 deletions climetlab/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def helper(data, *args, **kwargs):
to support
"""

if hasattr(data, "helper"):
return data.helper(*args, **kwargs)

fullname = ".".join([data.__class__.__module__, data.__class__.__qualname__])

name = HELPERS.get(fullname)
Expand Down
26 changes: 9 additions & 17 deletions climetlab/helpers/ndarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,28 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#
from climetlab.helpers import helper as get_helper


class NumpyArrayHelper:
def __init__(self, data):
self.data = data

def plot_map(self, driver):
field = driver.option("field")
grid = driver.option("grid")
metadata = driver.option("metadata")

if metadata is None and field is not None:
metadata = field.metadata()

if grid is None and field is not None:
grid = field.grid_definition()
# field = driver.option("field")
# grid = driver.option("grid")
metadata = get_helper(driver.option("metadata"))
metadata = metadata.field_metadata()

driver.bounding_box(
north=grid["north"],
south=grid["south"],
west=grid["west"],
east=grid["east"],
north=metadata.get("north", 90),
south=metadata.get("south", -90),
west=metadata.get("west", 0),
east=metadata.get("east", 360),
)

driver.plot_numpy(
self.data,
north=grid["north"],
west=grid["west"],
south_north_increment=grid["south_north_increment"],
west_east_increment=grid["west_east_increment"],
metadata=metadata,
)

Expand Down
3 changes: 3 additions & 0 deletions climetlab/helpers/none.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ def __init__(self, data):
def plot_map(self, driver):
pass

def field_metadata(self):
return {}


helper = NoneHelper
11 changes: 11 additions & 0 deletions climetlab/helpers/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ def plot_map(self, driver):

driver.plot_xarray(self.data, self.name, dimension_settings)

def field_metadata(self):
return dict(
north=self.north,
south=self.south,
east=self.east,
west=self.west,
# # TODO:
# south_north_increment=None,
# west_east_increment=None,
)


def helper(data, *args, **kwargs):
import xarray as xr
Expand Down
20 changes: 16 additions & 4 deletions climetlab/plotting/drivers/magics/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,27 @@ def plot_netcdf(self, path: str, variable: str, dimensions: dict = None):
def plot_numpy(
self,
data,
north: float,
west: float,
south_north_increment: float,
west_east_increment: float,
metadata: dict = None,
):
if metadata is None:
metadata = {}

# TODO: issue warnings
north = metadata.get("north", 90)
west = metadata.get("west", 0)
south_north_increment = metadata.get("south_north_increment")
west_east_increment = metadata.get("west_east_increment")

if south_north_increment is None:
south_north_increment = (north - metadata.get("south", -90)) / (
data.shape[-2] - 1
)

if west_east_increment is None:
west_east_increment = (metadata.get("east", 360) - west) / (
data.shape[-1] - 1
)

self._push_layer(
minput(
input_field=data,
Expand Down
9 changes: 6 additions & 3 deletions climetlab/sources/readers/grib.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def __repr__(self):
self.handle.get("number"),
)

def grid_definition(self):
def _grid_definition(self):
return dict(
north=self.handle.get("latitudeOfFirstGridPointInDegrees"),
south=self.handle.get("latitudeOfLastGridPointInDegrees"),
Expand All @@ -119,14 +119,17 @@ def grid_definition(self):
west_east_increment=self.handle.get("iDirectionIncrementInDegrees"),
)

def metadata(self):
m = {}
def field_metadata(self):
m = self._grid_definition()
for n in ("shortName", "units", "paramId"):
p = self.handle.get(n)
if p is not None:
m[n] = str(p)
return m

def helper(self):
return self

def datetime(self):
date = self.handle.get("date")
time = self.handle.get("time")
Expand Down
138 changes: 70 additions & 68 deletions docs/examples/06-era5-temperature.ipynb

Large diffs are not rendered by default.

Empty file added tests/__init__.py
Empty file.

0 comments on commit 5e4c0e1

Please sign in to comment.