Skip to content

Commit 03d1047

Browse files
authored
Merge pull request #168 from dopplershift/tds5-fixes
TDS5 NCSS fixes
2 parents 7c3df4f + e7a95b2 commit 03d1047

File tree

4 files changed

+2797
-21
lines changed

4 files changed

+2797
-21
lines changed

siphon/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@
77
from ._version import get_versions
88
__version__ = get_versions()['version']
99
del get_versions
10-
11-
__all__ = ['catalog', 'testing', 'http_util', 'upperair']

siphon/ncss_dataset.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from __future__ import print_function
77

88
import logging
9+
import re
910

1011
import numpy as np
1112

@@ -14,6 +15,13 @@
1415
log.addHandler(logging.StreamHandler())
1516

1617

18+
def _without_namespace(tagname):
19+
"""Remove the xml namespace from a tag name."""
20+
if '}' in tagname:
21+
return tagname.rsplit('}', 1)[-1]
22+
return tagname
23+
24+
1725
class _Types(object):
1826
@staticmethod
1927
def handle_typed_values(val, type_name, value_type):
@@ -69,16 +77,14 @@ def handle_typed_values(val, type_name, value_type):
6977
"""
7078
if value_type in ['byte', 'short', 'int', 'long']:
7179
try:
72-
val = val.split()
73-
val = list(map(int, val))
80+
val = [int(v) for v in re.split('[ ,]', val) if v]
7481
except ValueError:
75-
log.warning('Cannot convert %s to int. Keeping type as str.', val)
82+
log.warning('Cannot convert "%s" to int. Keeping type as str.', val)
7683
elif value_type in ['float', 'double']:
7784
try:
78-
val = val.split()
79-
val = list(map(float, val))
85+
val = [float(v) for v in re.split('[ ,]', val) if v]
8086
except ValueError:
81-
log.warning('Cannot convert %s to float. Keeping type as str.', val)
87+
log.warning('Cannot convert "%s" to float. Keeping type as str.', val)
8288
elif value_type == 'boolean':
8389
try:
8490
# special case for boolean type
@@ -191,6 +197,14 @@ def handle_featureDataset(element): # noqa
191197
def handle_variable(self, element):
192198
return self.handle_grid(element)
193199

200+
def lookup(self, handler_name):
201+
handler_name = 'handle_' + _without_namespace(handler_name)
202+
if handler_name in dir(self):
203+
return getattr(self, handler_name)
204+
else:
205+
msg = 'cannot find handler for element {}'.format(handler_name)
206+
log.warning(msg)
207+
194208

195209
class NCSSDataset(object):
196210
"""Hold information contained in the dataset.xml NCSS document.
@@ -245,7 +259,6 @@ def __init__(self, element):
245259
246260
"""
247261
self._types = _Types()
248-
self._types_methods = _Types.__dict__
249262

250263
self.gridsets = {}
251264
self.variables = {}
@@ -279,12 +292,7 @@ def __init__(self, element):
279292
delattr(self, thing)
280293

281294
def _get_handler(self, handler_name):
282-
handler_name = 'handle_' + handler_name
283-
if handler_name in self._types_methods:
284-
return getattr(self._types, handler_name)
285-
else:
286-
msg = 'cannot find handler for element {}'.format(handler_name)
287-
log.warning(msg)
295+
return self._types.lookup(handler_name)
288296

289297
def _parse_element(self, element):
290298
element_name = element.tag

0 commit comments

Comments
 (0)