Skip to content

Commit 96123dc

Browse files
committed
first_value, last_value
1 parent a4bfb2c commit 96123dc

File tree

4 files changed

+218
-0
lines changed

4 files changed

+218
-0
lines changed

lib/bald/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,9 @@ def load_netcdf(afilepath, baseuri=None, alias_dict=None, cache=None):
750750
fhandle.variables[name].dimensions[0] == name):
751751
sattrs['bald__array'] = name
752752
sattrs['rdf__type'] = 'bald__Reference'
753+
sattrs['bald__first_value'] = fhandle.variables[name][0]
754+
if len(fhandle.variables[name]) > 1:
755+
sattrs['bald__last_value'] = fhandle.variables[name][-1]
753756

754757
if fhandle.variables[name].shape:
755758
sattrs['bald__shape'] = fhandle.variables[name].shape
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
netcdf GEMS_CO2_Apr2006 {
2+
dimensions:
3+
longitude = 360 ;
4+
latitude = 181 ;
5+
levelist = 60 ;
6+
time = 1 ;
7+
variables:
8+
float longitude(longitude) ;
9+
longitude:units = "degrees_east" ;
10+
longitude:standard_name = "longitude" ;
11+
float latitude(latitude) ;
12+
latitude:units = "degrees_north" ;
13+
latitude:standard_name = "latitude" ;
14+
int levelist(levelist) ;
15+
levelist:long_name = "model_level_number" ;
16+
int time(time) ;
17+
time:units = "hours since 1900-01-01 00:00:0.0" ;
18+
time:standard_name = "time" ;
19+
short co2(time, levelist, latitude, longitude) ;
20+
co2:scale_factor = 0.000981685145029486 ;
21+
co2:add_offset = 403.192219379918 ;
22+
co2:_FillValue = -32767s ;
23+
co2:missing_value = -32767s ;
24+
co2:units = "kg kg**-1" ;
25+
co2:long_name = "Carbon Dioxide" ;
26+
co2:standard_name = "mass_fraction_of_carbon_dioxide_in_air" ;
27+
short lnsp(time, levelist, latitude, longitude) ;
28+
lnsp:scale_factor = 1.03952457840347e-05 ;
29+
lnsp:add_offset = 11.2087164280841 ;
30+
lnsp:_FillValue = -32767s ;
31+
lnsp:missing_value = -32767s ;
32+
lnsp:long_name = "Logarithm of surface pressure" ;
33+
34+
// global attributes:
35+
:Conventions = "CF-1.0" ;
36+
37+
data:
38+
39+
longitude = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
40+
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
41+
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
42+
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
43+
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
44+
90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
45+
106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
46+
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
47+
134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147,
48+
148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161,
49+
162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
50+
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
51+
190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203,
52+
204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
53+
218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231,
54+
232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
55+
246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259,
56+
260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273,
57+
274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287,
58+
288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301,
59+
302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315,
60+
316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329,
61+
330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343,
62+
344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357,
63+
358, 359 ;
64+
65+
latitude = 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75,
66+
74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57,
67+
56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39,
68+
38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
69+
20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,
70+
-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16,
71+
-17, -18, -19, -20, -21, -22, -23, -24, -25, -26, -27, -28, -29, -30,
72+
-31, -32, -33, -34, -35, -36, -37, -38, -39, -40, -41, -42, -43, -44,
73+
-45, -46, -47, -48, -49, -50, -51, -52, -53, -54, -55, -56, -57, -58,
74+
-59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69, -70, -71, -72,
75+
-73, -74, -75, -76, -77, -78, -79, -80, -81, -82, -83, -84, -85, -86,
76+
-87, -88, -89, -90 ;
77+
78+
levelist = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
79+
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
80+
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
81+
55, 56, 57, 58, 59, 60 ;
82+
83+
time = 931344 ;
84+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
@prefix CFTerms: <http://def.scitools.org.uk/CFTerms/> .
2+
@prefix bald: <http://binary-array-ld.net/latest/> .
3+
@prefix cf_sname: <http://vocab.nerc.ac.uk/standard_name/> .
4+
@prefix ns1: <file://CDL/GEMS_CO2_Apr2006.cdl/> .
5+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
6+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
7+
@prefix xml: <http://www.w3.org/XML/1998/namespace> .
8+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
9+
10+
<file://CDL/GEMS_CO2_Apr2006.cdl> a bald:Container ;
11+
ns1:Conventions "CF-1.0" ;
12+
bald:contains ns1:co2,
13+
ns1:co2_latitude_ref,
14+
ns1:co2_levelist_ref,
15+
ns1:co2_time_ref,
16+
ns1:latitude,
17+
ns1:levelist,
18+
ns1:lnsp,
19+
ns1:lnsp_latitude_ref,
20+
ns1:lnsp_levelist_ref,
21+
ns1:lnsp_time_ref,
22+
ns1:longitude,
23+
ns1:time .
24+
25+
ns1:co2 a bald:Array ;
26+
ns1:_FillValue "-32767" ;
27+
bald:references ns1:co2_latitude_ref,
28+
ns1:co2_levelist_ref,
29+
ns1:co2_time_ref,
30+
ns1:longitude ;
31+
bald:shape "(1, 60, 181, 360)" ;
32+
CFTerms:add_offset 4.031922e+02 ;
33+
CFTerms:long_name "Carbon Dioxide" ;
34+
CFTerms:missing_value "-32767" ;
35+
CFTerms:scale_factor 9.816851e-04 ;
36+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/mass_fraction_of_carbon_dioxide_in_air/> ;
37+
CFTerms:units "kg kg**-1" .
38+
39+
ns1:lnsp a bald:Array ;
40+
ns1:_FillValue "-32767" ;
41+
bald:references ns1:lnsp_latitude_ref,
42+
ns1:lnsp_levelist_ref,
43+
ns1:lnsp_time_ref,
44+
ns1:longitude ;
45+
bald:shape "(1, 60, 181, 360)" ;
46+
CFTerms:add_offset 1.120872e+01 ;
47+
CFTerms:long_name "Logarithm of surface pressure" ;
48+
CFTerms:missing_value "-32767" ;
49+
CFTerms:scale_factor 1.039525e-05 .
50+
51+
ns1:co2_latitude_ref a bald:Reference,
52+
bald:Subject ;
53+
bald:array ns1:latitude ;
54+
bald:childBroadcast "(1, 1, 181, 1)" .
55+
56+
ns1:co2_levelist_ref a bald:Reference,
57+
bald:Subject ;
58+
bald:array ns1:levelist ;
59+
bald:childBroadcast "(1, 60, 1, 1)" .
60+
61+
ns1:co2_time_ref a bald:Reference,
62+
bald:Subject ;
63+
bald:array ns1:time ;
64+
bald:childBroadcast "(1, 1, 1, 1)" .
65+
66+
ns1:lnsp_latitude_ref a bald:Reference,
67+
bald:Subject ;
68+
bald:array ns1:latitude ;
69+
bald:childBroadcast "(1, 1, 181, 1)" .
70+
71+
ns1:lnsp_levelist_ref a bald:Reference,
72+
bald:Subject ;
73+
bald:array ns1:levelist ;
74+
bald:childBroadcast "(1, 60, 1, 1)" .
75+
76+
ns1:lnsp_time_ref a bald:Reference,
77+
bald:Subject ;
78+
bald:array ns1:time ;
79+
bald:childBroadcast "(1, 1, 1, 1)" .
80+
81+
ns1:latitude a bald:Array,
82+
bald:Reference ;
83+
bald:array ns1:latitude ;
84+
bald:first_value "90.0" ;
85+
bald:last_value "-90.0" ;
86+
bald:shape "(181,)" ;
87+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/latitude/> ;
88+
CFTerms:units "degrees_north" .
89+
90+
ns1:levelist a bald:Array,
91+
bald:Reference ;
92+
bald:array ns1:levelist ;
93+
bald:first_value "1" ;
94+
bald:last_value "60" ;
95+
bald:shape "(60,)" ;
96+
CFTerms:long_name "model_level_number" .
97+
98+
ns1:longitude a bald:Array,
99+
bald:Reference ;
100+
bald:array ns1:longitude ;
101+
bald:first_value "0.0" ;
102+
bald:last_value "359.0" ;
103+
bald:shape "(360,)" ;
104+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/longitude/> ;
105+
CFTerms:units "degrees_east" .
106+
107+
ns1:time a bald:Array,
108+
bald:Reference ;
109+
bald:array ns1:time ;
110+
bald:first_value "931344" ;
111+
bald:shape "(1,)" ;
112+
CFTerms:standard_name <http://vocab.nerc.ac.uk/standard_name/time/> ;
113+
CFTerms:units "hours since 1900-01-01 00:00:0.0" .
114+

lib/bald/tests/integration/test_cdl_rdfgraph.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ def test_point_template(self):
7272
expected_ttl = sf.read()
7373
self.assertEqual(expected_ttl, ttl)
7474

75+
def test_gems_co2(self):
76+
with self.temp_filename('.nc') as tfile:
77+
cdlname = 'GEMS_CO2_Apr2006.cdl'
78+
cdl_file = os.path.join(self.cdl_path, cdlname)
79+
subprocess.check_call(['ncgen', '-o', tfile, cdl_file])
80+
cdl_file_uri = 'file://CDL/{}'.format(cdlname)
81+
alias_dict = {'CFTerms': 'http://def.scitools.org.uk/CFTerms',
82+
'cf_sname': 'http://vocab.nerc.ac.uk/standard_name/'
83+
}
84+
root_container = bald.load_netcdf(tfile, baseuri=cdl_file_uri,
85+
alias_dict=alias_dict, cache=self.acache)
86+
ttl = root_container.rdfgraph().serialize(format='n3').decode("utf-8")
87+
# with open(os.path.join(self.ttl_path, 'GEMS_CO2_Apr2006.ttl'), 'w') as sf:
88+
# sf.write(ttl)
89+
with open(os.path.join(self.ttl_path, 'GEMS_CO2_Apr2006.ttl'), 'r') as sf:
90+
expected_ttl = sf.read()
91+
self.assertEqual(expected_ttl, ttl)
7592

7693
def test_ereefs(self):
7794
with self.temp_filename('.nc') as tfile:

0 commit comments

Comments
 (0)