Skip to content

Commit

Permalink
Adding support for lambert
Browse files Browse the repository at this point in the history
Adding optopn --user_style -> path to a json file containing the contour definition
  • Loading branch information
sylvielamythepaut committed Nov 18, 2020
1 parent c2144a7 commit 56c2c59
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 13 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions skinnywms/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions skinnywms/grib_bindings/GribField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}


Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion skinnywms/grib_bindings/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
21 changes: 21 additions & 0 deletions skinnywms/plot/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import threading
import pprint
import json

from Magics import macro

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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()

Expand Down
4 changes: 3 additions & 1 deletion skinnywms/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion skinnywms/wmssvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
Binary file added skinnywms/wmssvr.pyc
Binary file not shown.

0 comments on commit 56c2c59

Please sign in to comment.