Skip to content

Commit c644a46

Browse files
committed
list handling
1 parent d450dc0 commit c644a46

File tree

6 files changed

+294
-34
lines changed

6 files changed

+294
-34
lines changed

lib/bald/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,11 @@ def __getitem__(self, item):
259259
# print('trying: {}'.format(item))
260260

261261
headers = {'Accept': 'application/rdf+xml'}
262-
self.cache[item] = requests.get(item, headers=headers, timeout=11)
262+
self.cache[item] = requests.get(item, headers=headers, timeout=17)
263263
except Exception:
264264
# print('retrying: {}'.format(item))
265265
headers = {'Accept': 'text/html'}
266-
self.cache[item] = requests.get(item, headers=headers, timeout=11)
266+
self.cache[item] = requests.get(item, headers=headers, timeout=17)
267267

268268
# print('in {} seconds'.format(time.time() - then))
269269
return self.cache[item]
@@ -774,7 +774,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
774774
root_container = Container(baseuri, '', attrs, prefixes=prefixes,
775775
aliases=aliases, alias_graph=aliasgraph)
776776

777-
root_container.attrs['bald__contains'] = []
777+
root_container.attrs['bald__contains'] = set()
778778
file_variables = {}
779779
for name in fhandle.variables:
780780
if name == prefix_var_name:
@@ -866,7 +866,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
866866
else:
867867
var = Subject(baseuri, name, sattrs, prefixes=prefixes,
868868
aliases=aliases, alias_graph=aliasgraph)
869-
root_container.attrs['bald__contains'].append(var)
869+
root_container.attrs['bald__contains'].add(var)
870870
file_variables[name] = var
871871

872872

@@ -979,7 +979,7 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
979979
prefixes=prefixes,
980980
aliases=aliases,
981981
alias_graph=aliasgraph)
982-
root_container.attrs['bald__contains'].append(ref_node)
982+
root_container.attrs['bald__contains'].add(ref_node)
983983
file_variables[name] = ref_node
984984
refset.add(ref_node)
985985
var.attrs['bald__references'] = refset
@@ -1018,7 +1018,7 @@ def validate(root_container, sval=None, cache=None):
10181018

10191019
root_val = bv.ContainerValidation(subject=root_container, httpcache=cache)
10201020
sval.stored_exceptions += root_val.exceptions()
1021-
for subject in root_container.attrs.get('bald__contains', []):
1021+
for subject in root_container.attrs.get('bald__contains', set()):
10221022
if isinstance(subject, Array):
10231023
array_val = bv.ArrayValidation(subject, httpcache=cache)
10241024
sval.stored_exceptions += array_val.exceptions()
@@ -1078,7 +1078,7 @@ def _hdf_group(fhandle, identity='root', baseuri=None, prefixes=None,
10781078
root_container = Container(baseuri, identity, attrs, prefixes=prefixes,
10791079
aliases=aliases, alias_graph=aliasgraph)
10801080

1081-
root_container.attrs['bald__contains'] = []
1081+
root_container.attrs['bald__contains'] = set()
10821082

10831083
file_variables = {}
10841084
# iterate through the datasets and groups
@@ -1089,14 +1089,14 @@ def _hdf_group(fhandle, identity='root', baseuri=None, prefixes=None,
10891089
if not skip:
10901090
if isinstance(dataset, h5py._hl.group.Group):
10911091
new_cont, new_fvars = _hdf_group(dataset, name, baseuri, prefixes, aliases)
1092-
root_container.attrs['bald__contains'].append(new_cont)
1092+
root_container.attrs['bald__contains'].add(new_cont)
10931093
file_variables = careful_update(file_variables, new_fvars)
10941094
#if hasattr(dataset, 'shape'):
10951095
elif isinstance(dataset, h5py._hl.dataset.Dataset):
10961096
sattrs = dict(dataset.attrs)
10971097
sattrs['bald__shape'] = dataset.shape
10981098
dset = Array(baseuri, name, sattrs, prefixes, aliases, aliasgraph)
1099-
root_container.attrs['bald__contains'].append(dset)
1099+
root_container.attrs['bald__contains'].add(dset)
11001100
file_variables[dataset.name] = dset
11011101
return root_container, file_variables
11021102

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ variables:
3636
set_collection:bald__references = "data_variable1 data_variable2" ;
3737

3838
int list_collection ;
39-
list_collection:bald__references = "data_variable1,data_variable2" ;
39+
list_collection:bald__references = "( data_variable1 data_variable2 )" ;
4040

4141

4242
// global attributes:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
@prefix CFTerms: <http://def.scitools.org.uk/CFTerms/> .
2+
@prefix DA: <https://codes.nws.noaa.gov/DataAssimilation> .
3+
@prefix NWP: <https://codes.nws.noaa.gov/NumericalWeatherPrediction> .
4+
@prefix StatPP: <https://codes.nws.noaa.gov/StatisticalPostProcessing> .
5+
@prefix bald: <http://binary-array-ld.net/latest/> .
6+
@prefix cf_sname: <http://vocab.nerc.ac.uk/standard_name/> .
7+
@prefix ns1: <file://CDL/ProcessChain0300.cdl/> .
8+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
9+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
10+
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
11+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
12+
13+
<file://CDL/ProcessChain0300.cdl> a bald:Container ;
14+
ns1:process_chain "gfsmos_process_chain" ;
15+
bald:contains ns1:gfsmos_process_chain,
16+
ns1:step1,
17+
ns1:step2 ;
18+
bald:isPrefixedBy "prefix_list" .
19+
20+
ns1:gfsmos_process_chain a bald:Subject ;
21+
ns1:OM_Process ( ns1:step1 ns1:step2 ) .
22+
23+
ns1:step1 a bald:Subject ;
24+
ns1:LE_ProcessStep <https://codes.nws.noaa.gov/NumericalWeatherPrediction/Models/GFS13> ;
25+
ns1:LE_Source <https://codes.nws.noaa.gov/DataAssimilation/Methods/GDAS13> .
26+
27+
ns1:step2 a bald:Subject ;
28+
ns1:LE_ProcessStep <https://codes.nws.noaa.gov/StatisticalPostProcessing/Methods/GFSMOS05> ;
29+
ns1:LE_Source <https://codes.nws.noaa.gov/NumericalWeatherPrediction/Models/GFS13> .
30+
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
@prefix bald: <http://binary-array-ld.net/latest/> .
2+
@prefix ns1: <file://CDL/ereefs_gbr4_ncld.cdl/> .
3+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
4+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
5+
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
6+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
7+
8+
<file://CDL/ereefs_gbr4_ncld.cdl> a bald:Container ;
9+
ns1:Conventions "CF-1.0" ;
10+
ns1:Run_ID 1.85 ;
11+
ns1:hasVocab "1" ;
12+
ns1:metadata_link <http://marlin.csiro.au/geonetwork/srv/eng/search?&uuid=72020224-f086-434a-bbe9-a222c8e5cf0d> ;
13+
ns1:paramfile "in.prm" ;
14+
ns1:paramhead "GBR 4km resolution grid" ;
15+
ns1:shoc_version "v1.1 rev(5249)" ;
16+
ns1:title "GBR4 Hydro" ;
17+
bald:contains ns1:botz,
18+
ns1:eta,
19+
ns1:eta_time_ref,
20+
ns1:latitude,
21+
ns1:longitude,
22+
ns1:salt,
23+
ns1:salt_time_ref,
24+
ns1:temp,
25+
ns1:temp_time_ref,
26+
ns1:time,
27+
ns1:u,
28+
ns1:u_time_ref,
29+
ns1:v,
30+
ns1:v_time_ref,
31+
ns1:wspeed_u,
32+
ns1:wspeed_u_time_ref,
33+
ns1:wspeed_v,
34+
ns1:wspeed_v_time_ref,
35+
ns1:zc ;
36+
bald:isPrefixedBy "prefix_list" .
37+
38+
ns1:botz a bald:Array ;
39+
ns1:coordinates ns1:latitude,
40+
ns1:longitude ;
41+
ns1:long_name "Depth of sea-bed" ;
42+
ns1:missing_value -99.0 ;
43+
ns1:outside "9999" ;
44+
ns1:positive "down" ;
45+
ns1:standard_name "depth" ;
46+
ns1:units "metre" ;
47+
bald:shape "(180, 600)" .
48+
49+
ns1:eta a bald:Array ;
50+
ns1:coordinates ns1:latitude,
51+
ns1:longitude,
52+
ns1:time ;
53+
ns1:long_name "Surface elevation" ;
54+
ns1:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
55+
ns1:missing_value "1e+35" ;
56+
ns1:positive "up" ;
57+
ns1:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_surface_elevation> ;
58+
ns1:standard_name "sea_surface_height_above_sea_level" ;
59+
ns1:substanceOrTaxon_id <http://environment.data.gov.au/def/feature/ocean_near_surface> ;
60+
ns1:unit_id <http://qudt.org/vocab/unit#Meter> ;
61+
ns1:units "metre" ;
62+
ns1:valid_range ( -10.0 10.0 ) ;
63+
bald:references ns1:eta_time_ref ;
64+
bald:shape "(5, 180, 600)" .
65+
66+
ns1:salt a bald:Array ;
67+
ns1:coordinates ns1:latitude,
68+
ns1:longitude,
69+
ns1:time,
70+
ns1:zc ;
71+
ns1:long_name "Salinity" ;
72+
ns1:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
73+
ns1:missing_value "1e+35" ;
74+
ns1:scaledQuantityKind_id <http://environment.data.gov.au/def/property/practical_salinity> ;
75+
ns1:substanceOrTaxon_id <http://sweet.jpl.nasa.gov/2.2/matrWater.owl#SaltWater> ;
76+
ns1:unit_id <http://environment.data.gov.au/water/quality/def/unit/PSU> ;
77+
ns1:units "PSU" ;
78+
ns1:valid_range [ rdf:first 0.0 ;
79+
rdf:rest ( 40.0 ) ] ;
80+
bald:references ns1:salt_time_ref ;
81+
bald:shape "(5, 47, 180, 600)" .
82+
83+
ns1:temp a bald:Array ;
84+
ns1:coordinates ns1:latitude,
85+
ns1:longitude,
86+
ns1:time,
87+
ns1:zc ;
88+
ns1:long_name "Temperature" ;
89+
ns1:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
90+
ns1:missing_value "1e+35" ;
91+
ns1:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_water_temperature> ;
92+
ns1:substanceOrTaxon_id <http://sweet.jpl.nasa.gov/2.2/matrWater.owl#SaltWater> ;
93+
ns1:unit_id <http://qudt.org/vocab/unit#DegreeCelsius> ;
94+
ns1:units "degrees C" ;
95+
ns1:valid_range [ rdf:first 0.0 ;
96+
rdf:rest ( 40.0 ) ] ;
97+
bald:references ns1:temp_time_ref ;
98+
bald:shape "(5, 47, 180, 600)" .
99+
100+
ns1:wspeed_u a bald:Array ;
101+
ns1:coordinates ns1:latitude,
102+
ns1:longitude,
103+
ns1:time ;
104+
ns1:long_name "eastward_wind" ;
105+
ns1:missing_value "1e+35" ;
106+
ns1:units "ms-1" ;
107+
ns1:valid_range ( -1000.0 1000.0 ) ;
108+
bald:references ns1:wspeed_u_time_ref ;
109+
bald:shape "(5, 180, 600)" .
110+
111+
ns1:wspeed_v a bald:Array ;
112+
ns1:coordinates ns1:latitude,
113+
ns1:longitude,
114+
ns1:time ;
115+
ns1:long_name "northward_wind" ;
116+
ns1:missing_value "1e+35" ;
117+
ns1:units "ms-1" ;
118+
ns1:valid_range ( -1000.0 1000.0 ) ;
119+
bald:references ns1:wspeed_v_time_ref ;
120+
bald:shape "(5, 180, 600)" .
121+
122+
ns1:eta_time_ref a bald:Reference,
123+
bald:Subject ;
124+
bald:array ns1:time ;
125+
bald:childBroadcast "(5, 1, 1)" .
126+
127+
ns1:salt_time_ref a bald:Reference,
128+
bald:Subject ;
129+
bald:array ns1:time ;
130+
bald:childBroadcast "(5, 1, 1, 1)" .
131+
132+
ns1:temp_time_ref a bald:Reference,
133+
bald:Subject ;
134+
bald:array ns1:time ;
135+
bald:childBroadcast "(5, 1, 1, 1)" .
136+
137+
ns1:u a bald:Array ;
138+
ns1:coordinates ns1:latitude,
139+
ns1:longitude,
140+
ns1:time,
141+
ns1:zc ;
142+
ns1:long_name "Eastward current" ;
143+
ns1:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
144+
ns1:missing_value "1e+35" ;
145+
ns1:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_water_velocity_eastward> ;
146+
ns1:standard_name "eastward_sea_water_velocity" ;
147+
ns1:substanceOrTaxon_id <http://environment.data.gov.au/def/feature/ocean_current> ;
148+
ns1:unit_id <http://qudt.org/vocab/unit#MeterPerSecond> ;
149+
ns1:units "ms-1" ;
150+
ns1:valid_range ( -100.0 100.0 ) ;
151+
ns1:vector_components ns1:u,
152+
ns1:v ;
153+
ns1:vector_name "Currents" ;
154+
bald:references ns1:u_time_ref ;
155+
bald:shape "(5, 47, 180, 600)" .
156+
157+
ns1:v_time_ref a bald:Reference,
158+
bald:Subject ;
159+
bald:array ns1:time ;
160+
bald:childBroadcast "(5, 1, 1, 1)" .
161+
162+
ns1:wspeed_u_time_ref a bald:Reference,
163+
bald:Subject ;
164+
bald:array ns1:time ;
165+
bald:childBroadcast "(5, 1, 1)" .
166+
167+
ns1:wspeed_v_time_ref a bald:Reference,
168+
bald:Subject ;
169+
bald:array ns1:time ;
170+
bald:childBroadcast "(5, 1, 1)" .
171+
172+
ns1:u_time_ref a bald:Reference,
173+
bald:Subject ;
174+
bald:array ns1:time ;
175+
bald:childBroadcast "(5, 1, 1, 1)" .
176+
177+
ns1:v a bald:Array ;
178+
ns1:coordinates ns1:latitude,
179+
ns1:longitude,
180+
ns1:time,
181+
ns1:zc ;
182+
ns1:long_name "Northward current" ;
183+
ns1:medium_id <http://environment.data.gov.au/def/feature/ocean> ;
184+
ns1:missing_value "1e+35" ;
185+
ns1:scaledQuantityKind_id <http://environment.data.gov.au/def/property/sea_water_velocity_northward> ;
186+
ns1:standard_name "northward_sea_water_velocity" ;
187+
ns1:substanceOrTaxon_id <http://environment.data.gov.au/def/feature/ocean_current> ;
188+
ns1:unit_id <http://qudt.org/vocab/unit#MeterPerSecond> ;
189+
ns1:units "ms-1" ;
190+
ns1:valid_range ( -100.0 100.0 ) ;
191+
ns1:vector_components ns1:u_time_ref,
192+
ns1:v ;
193+
ns1:vector_name "Currents" ;
194+
bald:references ns1:v_time_ref ;
195+
bald:shape "(5, 47, 180, 600)" .
196+
197+
ns1:zc a bald:Array ;
198+
ns1:axis "Z" ;
199+
ns1:coordinate_type "Z" ;
200+
ns1:long_name "Z coordinate" ;
201+
ns1:positive "up" ;
202+
ns1:units "m" ;
203+
bald:shape "(47,)" .
204+
205+
ns1:latitude a bald:Array ;
206+
ns1:coordinate_type ns1:latitude ;
207+
ns1:long_name "Latitude" ;
208+
ns1:projection "geographic" ;
209+
ns1:standard_name ns1:latitude ;
210+
ns1:units "degrees_north" ;
211+
bald:shape "(180, 600)" .
212+
213+
ns1:longitude a bald:Array ;
214+
ns1:coordinate_type ns1:longitude ;
215+
ns1:long_name "Longitude" ;
216+
ns1:projection "geographic" ;
217+
ns1:standard_name ns1:longitude ;
218+
ns1:units "degrees_east" ;
219+
bald:shape "(180, 600)" .
220+
221+
ns1:time a bald:Array,
222+
bald:Reference ;
223+
ns1:coordinate_type ns1:time ;
224+
ns1:long_name "Time" ;
225+
ns1:standard_name ns1:time ;
226+
ns1:units "days since 1990-01-01 00:00:00 +10" ;
227+
bald:array ns1:time ;
228+
bald:shape "(5,)" .
229+

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ ns1:data_variable2 a bald:Array ;
3636
bald:shape "(11, 17)" .
3737

3838
ns1:list_collection a bald:Subject ;
39-
bald:references ns1:data_variable1_pdim0_ref,
40-
ns1:data_variable2_pdim0_ref .
39+
bald:references ( ns1:data_variable1_pdim0_ref ns1:data_variable2_pdim0_ref ) .
4140

4241
ns1:set_collection a bald:Subject ;
4342
bald:references ns1:data_variable1_pdim0_ref,

0 commit comments

Comments
 (0)