Skip to content

Commit e248387

Browse files
authored
Merge pull request #49 from marqh/usevar
test use of variables for prefix and alias
2 parents 2138350 + 61ac33c commit e248387

File tree

3 files changed

+25
-66
lines changed

3 files changed

+25
-66
lines changed

lib/bald/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,19 +540,25 @@ def load_netcdf(afilepath, uri=None):
540540
prefix_group = (fhandle[fhandle.bald__isPrefixedBy] if
541541
hasattr(fhandle, 'bald__isPrefixedBy') else {})
542542
prefixes = {}
543-
if prefix_group:
543+
544+
skipped_variables = []
545+
if prefix_group != {}:
544546
prefixes = (dict([(prefix, getattr(prefix_group, prefix)) for
545547
prefix in prefix_group.ncattrs()]))
548+
if isinstance(prefix_group, netCDF4._netCDF4.Variable):
549+
skipped_variables.append(prefix_group.name)
546550
else:
547551
for k in fhandle.ncattrs():
548552
if k.endswith('__'):
549553
prefixes[k] = getattr(fhandle, k)
550554
alias_group = (fhandle[fhandle.bald__isAliasedBy]
551555
if hasattr(fhandle, 'bald__isAliasedBy') else {})
552556
aliases = {}
553-
if alias_group:
557+
if alias_group != {}:
554558
aliases = (dict([(alias, getattr(alias_group, alias))
555559
for alias in alias_group.ncattrs()]))
560+
if isinstance(alias_group, netCDF4._netCDF4.Variable):
561+
skipped_variables.append(alias_group.name)
556562

557563
attrs = {}
558564
for k in fhandle.ncattrs():
@@ -577,13 +583,16 @@ def load_netcdf(afilepath, uri=None):
577583
fhandle.variables[name].dimensions[0] == name):
578584
sattrs['bald__array'] = name
579585
sattrs['rdf__type'] = 'bald__Reference'
580-
581586
if fhandle.variables[name].shape:
582587
sattrs['bald__shape'] = fhandle.variables[name].shape
583588
var = Array(identity, sattrs, prefixes=prefixes, aliases=aliases)
584589
else:
585590
var = Subject(identity, sattrs, prefixes=prefixes, aliases=aliases)
586-
root_container.attrs['bald__contains'].append(var)
591+
if name not in skipped_variables:
592+
# Don't include skipped variables, such as prefix or alias
593+
# variables, within the containment relation.
594+
root_container.attrs['bald__contains'].append(var)
595+
587596
file_variables[name] = var
588597

589598

lib/bald/tests/integration/CDL/array_alias.cdl

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,38 +8,19 @@ variables:
88
parent_variable:SDN_ParameterDiscoveryCode = "BactTaxaAbundSed" ;
99
parent_variable:submursible_name = "Nautilus" ;
1010

11+
int prefix_list ;
12+
prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
13+
prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
14+
15+
int alias_list ;
16+
alias_list:SDN_ParameterDiscoveryCode = "http://vocab.nerc.ac.uk/isoCodelists/sdnCodelists/cdicsrCodeList.xml#SDN_ParameterDiscoveryCode" ;
17+
alias_list:BactTaxaAbundSed = "http://vocab.nerc.ac.uk/collection/P02/current/BAUC/" ;
18+
19+
1120
// global attributes:
1221
:_NCProperties = "version=1|netcdflibversion=4.4.1|hdf5libversion=1.8.17" ;
1322
:rdf__type = "bald__Container" ;
1423
:bald__isPrefixedBy = "prefix_list" ;
1524
:bald__isAliasedBy = "alias_list" ;
16-
data:
17-
18-
parent_variable =
19-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
20-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
21-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
22-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
23-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
24-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
25-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
26-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
27-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
28-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
29-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ ;
30-
31-
32-
group: prefix_list {
33-
34-
// group attributes:
35-
:bald__ = "http://binary-array-ld.net/latest/" ;
36-
:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
37-
} // group bald__prefix_list
38-
39-
group: alias_list {
4025

41-
// group attributes:
42-
:SDN_ParameterDiscoveryCode = "http://vocab.nerc.ac.uk/isoCodelists/sdnCodelists/cdicsrCodeList.xml#SDN_ParameterDiscoveryCode" ;
43-
:BactTaxaAbundSed = "http://vocab.nerc.ac.uk/collection/P02/current/BAUC/" ;
44-
} // group bald__alias_list
4526
}

lib/bald/tests/integration/CDL/array_reference.cdl

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,12 @@ variables:
99
int child_variable(pdim0, pdim1) ;
1010
child_variable:rdf__type = "bald__Reference" ;
1111
child_variable:bald__array = "child_variable" ;
12+
int prefix_list ;
13+
prefix_list:bald__ = "http://binary-array-ld.net/latest/" ;
14+
prefix_list:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
1215

1316
// global attributes:
1417
:_NCProperties = "version=1|netcdflibversion=4.4.1|hdf5libversion=1.8.17" ;
1518
:rdf__type = "bald__Container" ;
1619
:bald__isPrefixedBy = "prefix_list" ;
17-
data:
18-
19-
parent_variable =
20-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
21-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
22-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
23-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
24-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
25-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
26-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
27-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
28-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
29-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
30-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ ;
31-
32-
child_variable =
33-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
34-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
35-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
36-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
37-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
38-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
39-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
40-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
41-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
42-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
43-
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _ ;
44-
45-
group: prefix_list {
46-
47-
// group attributes:
48-
:bald__ = "http://binary-array-ld.net/latest/" ;
49-
:rdf__ = "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ;
50-
} // group bald__prefix_list
5120
}

0 commit comments

Comments
 (0)