Skip to content

Commit 6cd816c

Browse files
authored
Merge pull request #85 from marqh/opt-in-ref
Opt in ref
2 parents c6b8cb1 + 2b10e98 commit 6cd816c

File tree

7 files changed

+200
-145
lines changed

7 files changed

+200
-145
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,41 @@
22

33
[![Build Status](https://api.travis-ci.org/repositories/binary-array-ld/bald.svg?branch=master)](http://travis-ci.org/binary-array-ld/bald/branches)
44

5-
A Python library for validating and managing binary array linked data files.
5+
A Python library for managing binary array linked data files.
6+
7+
8+
## Parsing
9+
10+
This library processes payloads of various encodings and produces metadata graphs, in RDF, of the contents.
11+
12+
Input payloads are provided with an identity, elements within the payload are identified, with respect to that payload identity, unless they are otherwise identified, by prefix or by alias.
13+
14+
Only Object values (attribute values) may be literals, consistent with the RDF interpretation. All Subjects and Predicates are identified with URIs.
15+
16+
Some format specific implementation exists, due to the different capabilities available from different encodings.
17+
18+
### netCDF
19+
20+
For netCDF files, no variable to variable reference definitions are provided by the API.
21+
22+
For a variable to variable reference to be interpreted, an externally provided alias or predicate graph must explicitly state that a particular attribute has an rdfs:range of http://binary-array-ld.net/latest/Subject or a subclass of that class.
23+
24+
netCDF parsing is working to support the emerging draft Open Geospaatial Consortium approach to netCDF-Linked-Data: https://github.com/opengeospatial/netCDF-Classic-LD/
25+
26+
### HDF
27+
28+
HDF files and APIs have an object reference, indicating a reference from one element in the file to another.
29+
30+
These object refernces shall always be interpreted as references, regardless of the semantics of predicates (attribute names) provided by external graphs.
31+
32+
33+
## Validation
34+
35+
This library provides some limited validation capabilities.
36+
37+
It is expected that a valid input payload will be able to be processed into a graph.
38+
39+
Validation rules are limited in this implementation to require that provided HTTP URIs resolve.
640

741
## Pre-requisites
842

lib/bald/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,22 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
918918
refs = reference_graph.query(qstr)
919919

920920
non_ref_prefs = [str(ref[0]) for ref in list(refs)]
921+
922+
qstr = ('prefix bald: <http://binary-array-ld.net/latest/> '
923+
'prefix skos: <http://www.w3.org/2004/02/skos/core#> '
924+
'prefix owl: <http://www.w3.org/2002/07/owl#> '
925+
'select ?s '
926+
'where { '
927+
' {?s rdfs:range bald:Subject .} '
928+
' UNION '
929+
' {?s rdfs:range ?as . '
930+
' ?as rdfs:subClassOf bald:Subject .} '
931+
'}')
921932

933+
refs = reference_graph.query(qstr)
934+
935+
ref_prefs = [str(ref[0]) for ref in list(refs)]
936+
922937
# cycle again and find references
923938
for name in fhandle.variables:
924939
if name == prefix_var_name:
@@ -933,7 +948,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
933948

934949
# for sattr in sattrs:
935950
for sattr in (sattr for sattr in sattrs if
936-
root_container.unpack_predicate(sattr) not in non_ref_prefs):
951+
root_container.unpack_predicate(sattr) in ref_prefs):
937952

938953
if (isinstance(sattrs[sattr], six.string_types) and
939954
file_variables.get(sattrs[sattr])):

lib/bald/tests/integration/TTL/ProcessChain0300.ttl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
bald:isPrefixedBy "prefix_list" .
1919

2020
this:gfsmos_process_chain a bald:Subject ;
21-
this:OM_Process ( this:step1 this:step2 ) .
21+
this:OM_Process "(step1 step2)" .
2222

2323
this:step1 a bald:Subject ;
2424
this:LE_ProcessStep <https://codes.nws.noaa.gov/NumericalWeatherPrediction/Models/GFS13> ;
Lines changed: 117 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
@prefix CFTerms: <http://def.scitools.org.uk/CFTerms/> .
2+
@prefix NetCDF: <http://def.scitools.org.uk/NetCDF/> .
13
@prefix bald: <http://binary-array-ld.net/latest/> .
4+
@prefix cf_sname: <http://vocab.nerc.ac.uk/standard_name/> .
25
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
36
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
47
@prefix this: <file://CDL/ereefs_gbr4_ncld.cdl/> .
58
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
69
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
710

811
<file://CDL/ereefs_gbr4_ncld.cdl> a bald:Container ;
9-
this:Conventions "CF-1.0" ;
1012
this:Run_ID 1.85 ;
1113
this:hasVocab "1" ;
1214
this:metadata_link <http://marlin.csiro.au/geonetwork/srv/eng/search?&uuid=72020224-f086-434a-bbe9-a222c8e5cf0d> ;
1315
this:paramfile "in.prm" ;
1416
this:paramhead "GBR 4km resolution grid" ;
1517
this:shoc_version "v1.1 rev(5249)" ;
16-
this:title "GBR4 Hydro" ;
1718
bald:contains this:botz,
1819
this:eta,
1920
this:eta_time_ref,
@@ -33,89 +34,129 @@
3334
this:wspeed_v,
3435
this:wspeed_v_time_ref,
3536
this:zc ;
36-
bald:isPrefixedBy "prefix_list" .
37+
bald:isPrefixedBy "prefix_list" ;
38+
NetCDF:Conventions "CF-1.0" ;
39+
NetCDF:title "GBR4 Hydro" .
3740

3841
this:botz a bald:Array ;
39-
this:coordinates this:latitude,
40-
this:longitude ;
41-
this:long_name "Depth of sea-bed" ;
42-
this:missing_value -99.0 ;
4342
this:outside "9999" ;
44-
this:positive "down" ;
45-
this:standard_name "depth" ;
46-
this:units "metre" ;
47-
bald:shape "(180, 600)" .
43+
bald:shape "(180, 600)" ;
44+
CFTerms:coordinates this:latitude,
45+
this:longitude ;
46+
CFTerms:missing_value -99.0 ;
47+
CFTerms:positive "down" ;
48+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/depth/> ;
49+
NetCDF:long_name "Depth of sea-bed" ;
50+
NetCDF:units "metre" .
4851

4952
this:eta a bald:Array ;
50-
this:coordinates this:latitude,
51-
this:longitude,
52-
this:time ;
53-
this:long_name "Surface elevation" ;
5453
this:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
55-
this:missing_value "1e+35" ;
56-
this:positive "up" ;
5754
this:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_surface_elevation> ;
58-
this:standard_name "sea_surface_height_above_sea_level" ;
5955
this:substanceOrTaxon_id <http://environment.data.gov.au/def/feature/ocean_near_surface> ;
6056
this:unit_id <http://qudt.org/vocab/unit#Meter> ;
61-
this:units "metre" ;
62-
this:valid_range ( -10.0 10.0 ) ;
6357
bald:references this:eta_time_ref ;
64-
bald:shape "(5, 180, 600)" .
58+
bald:shape "(5, 180, 600)" ;
59+
CFTerms:coordinates this:latitude,
60+
this:longitude,
61+
this:time ;
62+
CFTerms:missing_value "1e+35" ;
63+
CFTerms:positive "up" ;
64+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/sea_surface_height_above_sea_level/> ;
65+
NetCDF:long_name "Surface elevation" ;
66+
NetCDF:units "metre" ;
67+
NetCDF:valid_range ( -10.0 10.0 ) .
6568

6669
this:salt a bald:Array ;
67-
this:coordinates this:latitude,
68-
this:longitude,
69-
this:time,
70-
this:zc ;
71-
this:long_name "Salinity" ;
7270
this:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
73-
this:missing_value "1e+35" ;
7471
this:scaledQuantityKind_id <http://environment.data.gov.au/def/property/practical_salinity> ;
7572
this:substanceOrTaxon_id <http://sweet.jpl.nasa.gov/2.2/matrWater.owl#SaltWater> ;
7673
this:unit_id <http://environment.data.gov.au/water/quality/def/unit/PSU> ;
77-
this:units "PSU" ;
78-
this:valid_range ( 0.0 40.0 ) ;
7974
bald:references this:salt_time_ref ;
80-
bald:shape "(5, 47, 180, 600)" .
81-
82-
this:temp a bald:Array ;
83-
this:coordinates this:latitude,
75+
bald:shape "(5, 47, 180, 600)" ;
76+
CFTerms:coordinates this:latitude,
8477
this:longitude,
8578
this:time,
8679
this:zc ;
87-
this:long_name "Temperature" ;
80+
CFTerms:missing_value "1e+35" ;
81+
NetCDF:long_name "Salinity" ;
82+
NetCDF:units "PSU" ;
83+
NetCDF:valid_range ( 0.0 40.0 ) .
84+
85+
this:temp a bald:Array ;
8886
this:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
89-
this:missing_value "1e+35" ;
9087
this:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_water_temperature> ;
9188
this:substanceOrTaxon_id <http://sweet.jpl.nasa.gov/2.2/matrWater.owl#SaltWater> ;
9289
this:unit_id <http://qudt.org/vocab/unit#DegreeCelsius> ;
93-
this:units "degrees C" ;
94-
this:valid_range ( 0.0 40.0 ) ;
9590
bald:references this:temp_time_ref ;
96-
bald:shape "(5, 47, 180, 600)" .
91+
bald:shape "(5, 47, 180, 600)" ;
92+
CFTerms:coordinates this:latitude,
93+
this:longitude,
94+
this:time,
95+
this:zc ;
96+
CFTerms:missing_value "1e+35" ;
97+
NetCDF:long_name "Temperature" ;
98+
NetCDF:units "degrees C" ;
99+
NetCDF:valid_range ( 0.0 40.0 ) .
100+
101+
this:u a bald:Array ;
102+
this:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
103+
this:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_water_velocity_eastward> ;
104+
this:substanceOrTaxon_id <http://environment.data.gov.au/def/feature/ocean_current> ;
105+
this:unit_id <http://qudt.org/vocab/unit#MeterPerSecond> ;
106+
this:vector_components "u v" ;
107+
this:vector_name "Currents" ;
108+
bald:references this:u_time_ref ;
109+
bald:shape "(5, 47, 180, 600)" ;
110+
CFTerms:coordinates this:latitude,
111+
this:longitude,
112+
this:time,
113+
this:zc ;
114+
CFTerms:missing_value "1e+35" ;
115+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/eastward_sea_water_velocity/> ;
116+
NetCDF:long_name "Eastward current" ;
117+
NetCDF:units "ms-1" ;
118+
NetCDF:valid_range ( -100.0 100.0 ) .
119+
120+
this:v a bald:Array ;
121+
this:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
122+
this:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_water_velocity_northward> ;
123+
this:substanceOrTaxon_id <http://environment.data.gov.au/def/feature/ocean_current> ;
124+
this:unit_id <http://qudt.org/vocab/unit#MeterPerSecond> ;
125+
this:vector_components "u v" ;
126+
this:vector_name "Currents" ;
127+
bald:references this:v_time_ref ;
128+
bald:shape "(5, 47, 180, 600)" ;
129+
CFTerms:coordinates this:latitude,
130+
this:longitude,
131+
this:time,
132+
this:zc ;
133+
CFTerms:missing_value "1e+35" ;
134+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/northward_sea_water_velocity/> ;
135+
NetCDF:long_name "Northward current" ;
136+
NetCDF:units "ms-1" ;
137+
NetCDF:valid_range ( -100.0 100.0 ) .
97138

98139
this:wspeed_u a bald:Array ;
99-
this:coordinates this:latitude,
140+
bald:references this:wspeed_u_time_ref ;
141+
bald:shape "(5, 180, 600)" ;
142+
CFTerms:coordinates this:latitude,
100143
this:longitude,
101144
this:time ;
102-
this:long_name "eastward_wind" ;
103-
this:missing_value "1e+35" ;
104-
this:units "ms-1" ;
105-
this:valid_range ( -1000.0 1000.0 ) ;
106-
bald:references this:wspeed_u_time_ref ;
107-
bald:shape "(5, 180, 600)" .
145+
CFTerms:missing_value "1e+35" ;
146+
NetCDF:long_name "eastward_wind" ;
147+
NetCDF:units "ms-1" ;
148+
NetCDF:valid_range ( -1000.0 1000.0 ) .
108149

109150
this:wspeed_v a bald:Array ;
110-
this:coordinates this:latitude,
151+
bald:references this:wspeed_v_time_ref ;
152+
bald:shape "(5, 180, 600)" ;
153+
CFTerms:coordinates this:latitude,
111154
this:longitude,
112155
this:time ;
113-
this:long_name "northward_wind" ;
114-
this:missing_value "1e+35" ;
115-
this:units "ms-1" ;
116-
this:valid_range ( -1000.0 1000.0 ) ;
117-
bald:references this:wspeed_v_time_ref ;
118-
bald:shape "(5, 180, 600)" .
156+
CFTerms:missing_value "1e+35" ;
157+
NetCDF:long_name "northward_wind" ;
158+
NetCDF:units "ms-1" ;
159+
NetCDF:valid_range ( -1000.0 1000.0 ) .
119160

120161
this:eta_time_ref a bald:Reference,
121162
bald:Subject ;
@@ -132,25 +173,10 @@ this:temp_time_ref a bald:Reference,
132173
bald:array this:time ;
133174
bald:childBroadcast "(5, 1, 1, 1)" .
134175

135-
this:u a bald:Array ;
136-
this:coordinates this:latitude,
137-
this:longitude,
138-
this:time,
139-
this:zc ;
140-
this:long_name "Eastward current" ;
141-
this:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
142-
this:missing_value "1e+35" ;
143-
this:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_water_velocity_eastward> ;
144-
this:standard_name "eastward_sea_water_velocity" ;
145-
this:substanceOrTaxon_id <http://environment.data.gov.au/def/feature/ocean_current> ;
146-
this:unit_id <http://qudt.org/vocab/unit#MeterPerSecond> ;
147-
this:units "ms-1" ;
148-
this:valid_range ( -100.0 100.0 ) ;
149-
this:vector_components this:u,
150-
this:v ;
151-
this:vector_name "Currents" ;
152-
bald:references this:u_time_ref ;
153-
bald:shape "(5, 47, 180, 600)" .
176+
this:u_time_ref a bald:Reference,
177+
bald:Subject ;
178+
bald:array this:time ;
179+
bald:childBroadcast "(5, 1, 1, 1)" .
154180

155181
this:v_time_ref a bald:Reference,
156182
bald:Subject ;
@@ -167,61 +193,36 @@ this:wspeed_v_time_ref a bald:Reference,
167193
bald:array this:time ;
168194
bald:childBroadcast "(5, 1, 1)" .
169195

170-
this:u_time_ref a bald:Reference,
171-
bald:Subject ;
172-
bald:array this:time ;
173-
bald:childBroadcast "(5, 1, 1, 1)" .
174-
175-
this:v a bald:Array ;
176-
this:coordinates this:latitude,
177-
this:longitude,
178-
this:time,
179-
this:zc ;
180-
this:long_name "Northward current" ;
181-
this:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
182-
this:missing_value "1e+35" ;
183-
this:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_water_velocity_northward> ;
184-
this:standard_name "northward_sea_water_velocity" ;
185-
this:substanceOrTaxon_id <http://environment.data.gov.au/def/feature/ocean_current> ;
186-
this:unit_id <http://qudt.org/vocab/unit#MeterPerSecond> ;
187-
this:units "ms-1" ;
188-
this:valid_range ( -100.0 100.0 ) ;
189-
this:vector_components this:u_time_ref,
190-
this:v ;
191-
this:vector_name "Currents" ;
192-
bald:references this:v_time_ref ;
193-
bald:shape "(5, 47, 180, 600)" .
194-
195196
this:zc a bald:Array ;
196-
this:axis "Z" ;
197197
this:coordinate_type "Z" ;
198-
this:long_name "Z coordinate" ;
199-
this:positive "up" ;
200-
this:units "m" ;
201-
bald:shape "(47,)" .
198+
bald:shape "(47,)" ;
199+
CFTerms:axis "Z" ;
200+
CFTerms:positive "up" ;
201+
NetCDF:long_name "Z coordinate" ;
202+
NetCDF:units "m" .
202203

203204
this:latitude a bald:Array ;
204-
this:coordinate_type this:latitude ;
205-
this:long_name "Latitude" ;
205+
this:coordinate_type "latitude" ;
206206
this:projection "geographic" ;
207-
this:standard_name this:latitude ;
208-
this:units "degrees_north" ;
209-
bald:shape "(180, 600)" .
207+
bald:shape "(180, 600)" ;
208+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/latitude/> ;
209+
NetCDF:long_name "Latitude" ;
210+
NetCDF:units "degrees_north" .
210211

211212
this:longitude a bald:Array ;
212-
this:coordinate_type this:longitude ;
213-
this:long_name "Longitude" ;
213+
this:coordinate_type "longitude" ;
214214
this:projection "geographic" ;
215-
this:standard_name this:longitude ;
216-
this:units "degrees_east" ;
217-
bald:shape "(180, 600)" .
215+
bald:shape "(180, 600)" ;
216+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/longitude/> ;
217+
NetCDF:long_name "Longitude" ;
218+
NetCDF:units "degrees_east" .
218219

219220
this:time a bald:Array,
220221
bald:Reference ;
221-
this:coordinate_type this:time ;
222-
this:long_name "Time" ;
223-
this:standard_name this:time ;
224-
this:units "days since 1990-01-01 00:00:00 +10" ;
222+
this:coordinate_type "time" ;
225223
bald:array this:time ;
226-
bald:shape "(5,)" .
224+
bald:shape "(5,)" ;
225+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/time/> ;
226+
NetCDF:long_name "Time" ;
227+
NetCDF:units "days since 1990-01-01 00:00:00 +10" .
227228

0 commit comments

Comments
 (0)