diff --git a/setup.py b/setup.py index 6eefe47..4be34ba 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ def read(fname): return io.open(file_path, encoding="utf-8").read() -version = "0.5.4" +version = "0.6.0" with open("README.md", "r") as fh: long_description = fh.read() @@ -42,7 +42,7 @@ def read(fname): url="https://github.com/sylvielamythepaut/skinnywms", packages=setuptools.find_packages(), include_package_data=True, - install_requires=["magics", "Flask",], + install_requires=["ecmwflibs", "Flask",], entry_points={"console_scripts": ["skinny-wms=skinnywms.skinny:main"],}, tests_require=["pytest",], test_suite="tests", diff --git a/skinnywms/datatypes.py b/skinnywms/datatypes.py index 9170330..df6f302 100644 --- a/skinnywms/datatypes.py +++ b/skinnywms/datatypes.py @@ -169,12 +169,12 @@ def add_field(self, field): "Duplicate date %s in %s (%s, %s)" % (field.time, self, field, self._fields[field.time]) ) - # return - # Why are we sometimes throwing this exception .. : need to be checked - raise Exception( - "Duplicate date %s in %s (%s, %s)" - % (field.time, self, field, self._fields[field.time]) - ) + + # # Why are we sometimes throwing this exception .. : need to be checked + # raise Exception( + # "Duplicate date %s in %s (%s, %s)" + # % (field.time, self, field, self._fields[field.time]) + # ) self._fields[field.time] = field diff --git a/skinnywms/grib_bindings/GribField.py b/skinnywms/grib_bindings/GribField.py index bb090b5..b571284 100644 --- a/skinnywms/grib_bindings/GribField.py +++ b/skinnywms/grib_bindings/GribField.py @@ -239,7 +239,8 @@ def latitudes(self, grib): "regular_gg": RegularGG(), "reduced_ll": ReducedLL(), "reduced_gg": ReducedGG(), - "rotated_ll": RegularLL, # For now, we do not make use of this information . + "rotated_ll": RegularLL(), # For now, we do not make use of this information . + "lambert": RegularLL(), } @@ -284,7 +285,7 @@ def coordinates(self, grib, coords, combine_order, attributes, dims): 1: SingleLevel(), # 1 sfc Ground or water surface 8: SingleLevel(), # 8 sfc Nominal top of the atmosphere 100: PressureLevel(), # 100 pl Isobaric surface (Pa) - 101: SingleLevel(), # 101 sfc Mean sea level + 102: SingleLevel(), # Specific altitude above mean sea level (m) 103: SingleLevel(), # 103 sfc Specified height level above ground (m) 106: SingleLevel(), # 106 sfc Depth below land surface (m) 111: ModelLevel(), # 111 ml Eta level diff --git a/skinnywms/grib_bindings/bindings.py b/skinnywms/grib_bindings/bindings.py index 8cc006b..2c45aaa 100644 --- a/skinnywms/grib_bindings/bindings.py +++ b/skinnywms/grib_bindings/bindings.py @@ -15,7 +15,14 @@ import numpy as np from functools import partial -lib = ctypes.util.find_library("eccodes") +try: + import ecmwflibs + + lib = ecmwflibs.find("eccodes") + +except ModuleNotFoundError: + lib = ctypes.util.find_library("eccodes") + ecmwf_lib = os.path.join(os.environ.get("ECCODES_LIB_DIR", ""), "libeccodes.so") ecmwf_lib_mac = os.path.join(os.environ.get("ECCODES_LIB_DIR", ""), "libeccodes.dylib") diff --git a/skinnywms/plot/magics.py b/skinnywms/plot/magics.py index 04fb862..7997c7e 100644 --- a/skinnywms/plot/magics.py +++ b/skinnywms/plot/magics.py @@ -11,6 +11,7 @@ import os import threading import pprint +import json from Magics import macro @@ -445,7 +446,20 @@ class Styler(datatypes.Styler): log = logging.getLogger(__name__) + def __init__(self, user_style=None): + self.user_style = None + if user_style: + try: + with open(user_style, "r") as f: + self.user_style = json.load(f) + if "name" not in self.user_style: + self.user_style["name"] = "user_style" + except: + self.user_style = None + def netcdf_styles(self, field, ncvar, path, variable): + if self.user_style: + return [MagicsWebStyle(self.user_style["name"])] with LOCK: try: styles = macro.wmsstyles( @@ -461,6 +475,9 @@ def netcdf_styles(self, field, ncvar, path, variable): return [MagicsWebStyle(**s) for s in styles.get("styles", [])] def grib_styles(self, field, grib, path, index): + if self.user_style: + return [MagicsWebStyle(self.user_style["name"])] + with LOCK: try: styles = macro.wmsstyles( @@ -476,6 +493,10 @@ def grib_styles(self, field, grib, path, index): return [MagicsWebStyle(**s) for s in styles.get("styles", [])] def contours(self, field, driver, style, legend={}): + + if self.user_style: + return driver.mcont(self.user_style) + if style is None: return driver.mcont() diff --git a/skinnywms/server.py b/skinnywms/server.py index ae1a0dc..7bbc67c 100644 --- a/skinnywms/server.py +++ b/skinnywms/server.py @@ -42,7 +42,9 @@ def target(self, ext): def content(self): with open(self.fname, "rb") as f: - return f.read() + c = f.read() + os.close(f) + return c def cleanup(self): LOG.debug("Deleting %s" % self.fname) diff --git a/skinnywms/wmssvr.py b/skinnywms/wmssvr.py index 9375493..7916194 100644 --- a/skinnywms/wmssvr.py +++ b/skinnywms/wmssvr.py @@ -34,6 +34,11 @@ parser.add_argument( "--style", default="", help="Path to a directory where to find the styles" ) + +parser.add_argument( + "--user_style", default="", help="Path to a json file containing the style to use" +) + parser.add_argument("--host", default="127.0.0.1", help="Hostname") parser.add_argument("--port", default=5000, help="Port number") parser.add_argument( @@ -51,7 +56,10 @@ if args.style != "": os.environ["MAGICS_STYLE_PATH"] = args.style + ":ecmwf" -server = WMSServer(Availability(args.path), Plotter(args.baselayer), Styler()) +if args.user_style != "": + os.environ["MAGICS_USER_STYLE_PATH"] = args.user_style + +server = WMSServer(Availability(args.path), Plotter(args.baselayer), Styler(args.user_style)) server.magics_prefix = args.magics_prefix diff --git a/skinnywms/wmssvr.pyc b/skinnywms/wmssvr.pyc new file mode 100644 index 0000000..784c357 Binary files /dev/null and b/skinnywms/wmssvr.pyc differ