55
66from .template import DatasetTemplate
77
8- IMOS_GLOBAL_JSON = resource_filename (__name__ , ' imos_global.json' )
8+ IMOS_GLOBAL_JSON = resource_filename (__name__ , " imos_global.json" )
99IMOS_GLOBAL_ATTRIBUTES = DatasetTemplate .from_json (IMOS_GLOBAL_JSON ).global_attributes
1010
11- TIMESTAMP_FORMAT = ' %Y-%m-%dT%H:%M:%SZ'
11+ TIMESTAMP_FORMAT = " %Y-%m-%dT%H:%M:%SZ"
1212
1313
1414class ImosTemplate (DatasetTemplate ):
@@ -19,7 +19,9 @@ def __init__(self, global_attributes=None, *args, **kwargs):
1919 combined_attributes = IMOS_GLOBAL_ATTRIBUTES .copy ()
2020 if global_attributes is not None :
2121 combined_attributes .update (global_attributes )
22- super (ImosTemplate , self ).__init__ (global_attributes = combined_attributes , * args , ** kwargs )
22+ super (ImosTemplate , self ).__init__ (
23+ global_attributes = combined_attributes , * args , ** kwargs
24+ )
2325 self ._date_created = None
2426
2527 @property
@@ -30,9 +32,13 @@ def date_created(self):
3032 return self ._date_created
3133
3234 def add_date_created_attribute (self ):
33- self .global_attributes ['date_created' ] = self .date_created .strftime (TIMESTAMP_FORMAT )
35+ self .global_attributes ["date_created" ] = self .date_created .strftime (
36+ TIMESTAMP_FORMAT
37+ )
3438
35- def add_extent_attributes (self , time_var = 'TIME' , vert_var = 'DEPTH' , lat_var = 'LATITUDE' , lon_var = 'LONGITUDE' ):
39+ def add_extent_attributes (
40+ self , time_var = "TIME" , vert_var = "DEPTH" , lat_var = "LATITUDE" , lon_var = "LONGITUDE"
41+ ):
3642 """
3743 Calculate spatial and temporal extents from coordinate variables in the template and add/update
3844 the relevant global attributes. Set an input variable name to None to skip that coordinate.
@@ -46,28 +52,33 @@ def add_extent_attributes(self, time_var='TIME', vert_var='DEPTH', lat_var='LATI
4652 if time_var :
4753 data_range = self .get_data_range (time_var )
4854 time = self .variables [time_var ]
49- units = time .get (' units' )
55+ units = time .get (" units" )
5056 if not units :
51- raise ValueError ("Time variable '{time_var}' has no units" .format (time_var = time_var ))
52- calendar = time .get ('calendar' , 'gregorian' )
57+ raise ValueError (
58+ "Time variable '{time_var}' has no units" .format (time_var = time_var )
59+ )
60+ calendar = time .get ("calendar" , "gregorian" )
5361 time_range = num2date (data_range , units , calendar )
54- self .global_attributes ['time_coverage_start' ] = time_range [0 ].strftime (TIMESTAMP_FORMAT )
55- self .global_attributes ['time_coverage_end' ] = time_range [1 ].strftime (TIMESTAMP_FORMAT )
62+ self .global_attributes ["time_coverage_start" ] = time_range [0 ].strftime (
63+ TIMESTAMP_FORMAT
64+ )
65+ self .global_attributes ["time_coverage_end" ] = time_range [1 ].strftime (
66+ TIMESTAMP_FORMAT
67+ )
5668
5769 if vert_var :
5870 vmin , vmax = self .get_data_range (vert_var )
59- self .global_attributes [' geospatial_vertical_min' ] = vmin
60- self .global_attributes [' geospatial_vertical_max' ] = vmax
71+ self .global_attributes [" geospatial_vertical_min" ] = vmin
72+ self .global_attributes [" geospatial_vertical_max" ] = vmax
6173
6274 if lat_var :
6375 vmin , vmax = self .get_data_range (lat_var )
64- self .global_attributes [' geospatial_lat_min' ] = vmin
65- self .global_attributes [' geospatial_lat_max' ] = vmax
76+ self .global_attributes [" geospatial_lat_min" ] = vmin
77+ self .global_attributes [" geospatial_lat_max" ] = vmax
6678
6779 if lon_var :
6880 vmin , vmax = self .get_data_range (lon_var )
69- self .global_attributes [' geospatial_lon_min' ] = vmin
70- self .global_attributes [' geospatial_lon_max' ] = vmax
81+ self .global_attributes [" geospatial_lon_min" ] = vmin
82+ self .global_attributes [" geospatial_lon_max" ] = vmax
7183
7284 # TODO: def set_imos_filename(self):
73-
0 commit comments