63
63
64
64
LOGGER = logging .getLogger (__name__ )
65
65
66
- WMO_REGION_ENUM = Enum ('I' , 'II' , 'III' , 'IV' , 'V' , 'VI' , name = 'wmo_region' )
66
+ WMO_REGION_ENUM = Enum ('I' , 'II' , 'III' , 'IV' , 'V' , 'VI' , 'Antarctica' ,
67
+ name = 'wmo_region' )
67
68
68
69
69
70
class Geometry (geoalchemy2 .types .Geometry ):
@@ -79,17 +80,22 @@ def get_col_spec(self):
79
80
80
81
81
82
class Country (base ):
82
- """Data Registry Country"""
83
+ """
84
+ Data Registry Country
85
+
86
+ https://www.wmo.int/cpdb/data/membersandterritories.json
87
+
88
+ """
83
89
84
90
__tablename__ = 'countries'
85
91
86
92
identifier = Column (String , nullable = False , primary_key = True )
87
93
country_name = Column (String , nullable = False , unique = True )
88
94
french_name = Column (String , nullable = False , unique = True )
89
- wmo_region_id = Column (String , nullable = False )
90
- regional_involvement = Column (String , nullable = False )
91
- wmo_membership = Column (Date , nullable = True )
92
- link = Column (String , nullable = True )
95
+ wmo_region_id = Column (WMO_REGION_ENUM , nullable = False )
96
+ regional_involvement = Column (WMO_REGION_ENUM , nullable = False )
97
+ wmo_membership = Column (Date , nullable = False )
98
+ link = Column (String , nullable = False )
93
99
94
100
def __init__ (self , dict_ ):
95
101
self .identifier = dict_ ['id' ]
@@ -101,7 +107,7 @@ def __init__(self, dict_):
101
107
self .link = dict_ ['link' ]
102
108
103
109
def __repr__ (self ):
104
- return 'Country ({}, {})' .format (self .identifier , self .name )
110
+ return 'Country ({}, {})' .format (self .identifier , self .country_name )
105
111
106
112
107
113
class Contributor (base ):
@@ -175,7 +181,7 @@ class Station(base):
175
181
176
182
stn_type_enum = Enum ('STN' , 'SHP' , name = 'type' )
177
183
178
- identifier = Column (Integer , primary_key = True )
184
+ identifier = Column (String , primary_key = True )
179
185
name = Column (String , nullable = False )
180
186
contributor_id = Column (String , ForeignKey ('contributors.identifier' ),
181
187
nullable = True )
@@ -201,6 +207,7 @@ class Station(base):
201
207
def __init__ (self , dict_ ):
202
208
"""serializer"""
203
209
210
+ self .identifier = dict_ ['identifier' ]
204
211
self .name = dict_ ['name' ]
205
212
self .stn_type = dict_ ['stn_type' ]
206
213
self .gaw_id = dict_ ['gaw_id' ]
@@ -212,7 +219,7 @@ def __init__(self, dict_):
212
219
self .location = util .point2ewkt (dict_ ['x' ], dict_ ['y' ], dict_ ['z' ])
213
220
214
221
def __repr__ (self ):
215
- return 'Station ({}, {})' .format (self .stn_identifier , self .name )
222
+ return 'Station ({}, {})' .format (self .identifier , self .name )
216
223
217
224
218
225
class DataRecord (base ):
@@ -440,7 +447,7 @@ def init(ctx, datadir):
440
447
if datadir is None :
441
448
raise click .ClickException ('Missing required data directory' )
442
449
443
- countries = os .path .join (datadir , 'countries.json' )
450
+ countries = os .path .join (datadir , 'wmo- countries.json' )
444
451
contributors = os .path .join (datadir , 'contributors.csv' )
445
452
stations = os .path .join (datadir , 'stations.csv' )
446
453
datasets = os .path .join (datadir , 'datasets.csv' )
@@ -456,6 +463,19 @@ def init(ctx, datadir):
456
463
continue
457
464
country = Country (country_data )
458
465
registry_ .save (country )
466
+ # Antarctica is not a recognized country per se but is
467
+ # provided in WOUDC
468
+ antarctica = {
469
+ 'id' : 'ATA' ,
470
+ 'country_name' : 'Antarctica' ,
471
+ 'french_name' : 'Antarctique' ,
472
+ 'wmo_region_id' : 'Antarctica' ,
473
+ 'regional_involvement' : 'Antarctica' ,
474
+ 'wmo_membership' : '1970-01-01' ,
475
+ 'link' : 'https://www.wmo.int/pages/prog/www/Antarctica/Purpose.html'
476
+ }
477
+ country = Country (antarctica )
478
+ registry_ .save (country )
459
479
460
480
click .echo ('Loading datasets metadata' )
461
481
with open (datasets ) as csvfile :
0 commit comments