Skip to content

Commit 15afaf4

Browse files
committed
bugs: isuri, datetime
1 parent 81f6611 commit 15afaf4

File tree

1 file changed

+38
-24
lines changed

1 file changed

+38
-24
lines changed

lib/bald/__init__.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,17 @@ def _network_js_close():
225225

226226

227227
def is_http_uri(item):
228-
return isinstance(item, six.string_types) and (item.startswith('http://') or item.startswith('https://'))
228+
result = True
229+
if not isinstance(item, six.string_types):
230+
result = False
231+
else:
232+
if not (item.startswith('http://') or item.startswith('https://')):
233+
result = False
234+
if ',' in item:
235+
result = False
236+
if ' ' in item:
237+
result = False
238+
return result
229239

230240

231241
class HttpCache(object):
@@ -236,7 +246,7 @@ def __init__(self):
236246
self.cache = {}
237247

238248
def is_http_uri(self, item):
239-
return isinstance(item, six.string_types) and (item.startswith('http://') or item.startswith('https://'))
249+
return is_http_uri(item)
240250

241251
def __getitem__(self, item):
242252

@@ -527,6 +537,9 @@ def rdfnode(self, graph):
527537
else:
528538
rdfobj = self.unpack_rdfobject(obj, rdfpred)
529539
if is_http_uri(rdfobj):
540+
# if rdfobj == 'http://www.ecmwf.int/research/EU_projects/ENSEMBLES/index.html, http://www.ecmwf.int/research/EU_projects/ENSEMBLES/experiments/index.html':
541+
# import pdb; pdb.set_trace()
542+
530543
rdfobj = rdflib.URIRef(rdfobj)
531544
else:
532545
rdfobj = rdflib.Literal(rdfobj)
@@ -783,30 +796,31 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
783796
ig = terra.datetime.ISOGregorian()
784797
tog = terra.datetime.parse_datetime(origin,
785798
calendar=ig)
786-
dtype = '{}{}'.format(fhandle.variables[name].dtype.kind,
787-
fhandle.variables[name].dtype.itemsize)
788-
fv = netCDF4.default_fillvals.get(dtype)
789-
if fhandle.variables[name][0] == fv:
790-
first = np.ma.MaskedArray(fhandle.variables[name][0],
791-
mask=True)
792-
else:
793-
first = fhandle.variables[name][0]
794-
795-
edate_first = terra.datetime.EpochDateTimes(first,
796-
quantity,
797-
epoch=tog)
798-
799-
sattrs['bald__first_value'] = str(edate_first)
800-
if len(fhandle.variables[name]) > 1:
799+
if tog is not None:
800+
dtype = '{}{}'.format(fhandle.variables[name].dtype.kind,
801+
fhandle.variables[name].dtype.itemsize)
802+
fv = netCDF4.default_fillvals.get(dtype)
801803
if fhandle.variables[name][0] == fv:
802-
last = np.ma.MaskedArray(fhandle.variables[name][-1],
803-
mask=True)
804+
first = np.ma.MaskedArray(fhandle.variables[name][0],
805+
mask=True)
804806
else:
805-
last = fhandle.variables[name][-1]
806-
edate_last = terra.datetime.EpochDateTimes(last,
807-
quantity,
808-
epoch=tog)
809-
sattrs['bald__last_value'] = str(edate_last)
807+
first = fhandle.variables[name][0]
808+
809+
edate_first = terra.datetime.EpochDateTimes(first,
810+
quantity,
811+
epoch=tog)
812+
813+
sattrs['bald__first_value'] = str(edate_first)
814+
if len(fhandle.variables[name]) > 1:
815+
if fhandle.variables[name][0] == fv:
816+
last = np.ma.MaskedArray(fhandle.variables[name][-1],
817+
mask=True)
818+
else:
819+
last = fhandle.variables[name][-1]
820+
edate_last = terra.datetime.EpochDateTimes(last,
821+
quantity,
822+
epoch=tog)
823+
sattrs['bald__last_value'] = str(edate_last)
810824

811825

812826

0 commit comments

Comments
 (0)