Skip to content

Commit b02dc94

Browse files
committed
Merge branch 'pre-fix-ndbug' into test1
2 parents cd88109 + 661e06e commit b02dc94

File tree

3 files changed

+65
-5
lines changed

3 files changed

+65
-5
lines changed

lib/bald/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ def rdfnode(self, graph):
415415
selfnode = rdflib.URIRef(self.identity)
416416
for attr in self.attrs:
417417
objs = self.attrs[attr]
418+
if(isinstance(objs, np.ndarray)):
419+
#print("Found np.ndarray")
420+
#print(objs)
421+
#print(attr)
422+
#try to convert np.ndarray to a list
423+
objs = objs.tolist()
418424
if not (isinstance(objs, set) or isinstance(objs, list)):
419425
objs = set([objs])
420426
for obj in objs:
@@ -614,16 +620,13 @@ def load_netcdf(afilepath, uri=None, baseuri=None):
614620
#sattrs['bald__array'] = name
615621
sattrs['bald__array'] = identity
616622
sattrs['rdf__type'] = 'bald__Reference'
623+
617624
if fhandle.variables[name].shape:
618625
sattrs['bald__shape'] = fhandle.variables[name].shape
619626
var = Array(identity, sattrs, prefixes=prefixes, aliases=aliases)
620627
else:
621628
var = Subject(identity, sattrs, prefixes=prefixes, aliases=aliases)
622-
if name not in skipped_variables:
623-
# Don't include skipped variables, such as prefix or alias
624-
# variables, within the containment relation.
625-
root_container.attrs['bald__contains'].append(var)
626-
629+
root_container.attrs['bald__contains'].append(var)
627630
file_variables[name] = var
628631

629632

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
netcdf tmpMwXy8U {
2+
dimensions:
3+
pdim0 = 11 ;
4+
pdim1 = 17 ;
5+
variables:
6+
int prefix_list ;
7+
prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
8+
prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
9+
prefix_list:rdfs__ = "http://www.w3.org/2000/01/rdf-schema#" ;
10+
prefix_list:cf__ = "http://def.scitools.org.uk/CFTerms/" ;
11+
prefix_list:geo__ = "http://www.opengis.net/ont/geosparql#" ;
12+
13+
int temp(pdim0, pdim1) ;
14+
temp:cf__standard_name = "air_temperature" ;
15+
temp:cf__long_name = "Air temperature obs example at point" ;
16+
temp:rdfs__label = "Air temperature obs example at point" ;
17+
temp:geo__asWKT = "POINT(-77.03524 38.889468)" ;
18+
19+
int pressure(pdim0, pdim1) ;
20+
pressure:cf__standard_name = "air_pressure" ;
21+
pressure:cf__long_name = "Air pressure at UCAR Centre Green" ;
22+
pressure:rdfs__label = "Air pressure at UCAR Centre Green" ;
23+
pressure:geo__asWKT = "POINT(-105.24584700000003 40.0315278)" ;
24+
25+
// global attributes:
26+
:_NCProperties = "version=1|netcdflibversion=4.4.1|hdf5libversion=1.8.17" ;
27+
:rdf__type = "bald__Container" ;
28+
:bald__isPrefixedBy = "prefix_list" ;
29+
data:
30+
31+
temp =
32+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
33+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
34+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
35+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
36+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
37+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
38+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
39+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
40+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
41+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
42+
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ ;
43+
44+
45+
}

lib/bald/tests/integration/test_cdl_rdfgraph.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,15 @@ def test_multi_array_reference(self):
3636
with open(os.path.join(self.ttl_path, 'multi_array_reference.ttl'), 'r') as sf:
3737
expected_ttl = sf.read()
3838
self.assertEqual(expected_ttl, ttl)
39+
40+
def test_ereefs(self):
41+
with self.temp_filename('.nc') as tfile:
42+
cdl_file = os.path.join(self.cdl_path, 'ereefs_gbr4_ncld.cdl')
43+
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
44+
root_container = bald.load_netcdf(tfile)
45+
try:
46+
g = root_container.rdfgraph()
47+
ttl = g.serialize(format='n3').decode("utf-8")
48+
except TypeError:
49+
self.fail("Test case could not convert ereefs CDL to RDF")
50+

0 commit comments

Comments
 (0)