43
43
44
44
45
45
def browse_dataset_in (data_dir , files_model , date_regexp , date_model ,
46
- start_date = None , end_date = None , sub_sampling_step = 1 ):
46
+ start_date = None , end_date = None , sub_sampling_step = 1 ):
47
47
pattern_regexp = re_compile ('.*/' + date_regexp )
48
48
full_path = join_path (data_dir , files_model )
49
49
logging .info ('Search files : %s' , full_path )
@@ -75,7 +75,7 @@ def browse_dataset_in(data_dir, files_model, date_regexp, date_model,
75
75
result = pattern_regexp .match (str (item ['filename' ]))
76
76
if result :
77
77
str_date = result .groups ()[0 ]
78
-
78
+
79
79
if str_date is not None :
80
80
item ['date' ] = datetime .strptime (str_date , date_model ).date ()
81
81
@@ -120,7 +120,7 @@ class BaseData(object):
120
120
ROMS: get_ROMS_f_pm_pn
121
121
122
122
"""
123
-
123
+
124
124
__slots__ = (
125
125
'zero_crossing' ,
126
126
'slice_i' ,
@@ -154,8 +154,8 @@ class BaseData(object):
154
154
'pad' ,
155
155
'shape' ,
156
156
'mask' ,
157
- )
158
-
157
+ )
158
+
159
159
GRAVITY = 9.81
160
160
earth_radius = 6371315.0
161
161
@@ -229,11 +229,11 @@ def read_nc_att(self, varname, att):
229
229
230
230
@property
231
231
def is_regular (self ):
232
- steps_lon = unique (self ._lon [0 , 1 :] - self ._lon [0 ,:- 1 ])
232
+ steps_lon = unique (self ._lon [0 , 1 :] - self ._lon [0 , :- 1 ])
233
233
steps_lat = unique (self ._lat [1 :, 0 ] - self ._lat [:- 1 , 0 ])
234
234
return len (steps_lon ) == 1 and len (steps_lat ) == 1 and \
235
- steps_lon [0 ] != 0. and steps_lat [0 ] != 0.
236
-
235
+ steps_lon [0 ] != 0. and steps_lat [0 ] != 0.
236
+
237
237
def set_initial_indices (self ):
238
238
"""
239
239
Set indices for desired domain
@@ -276,18 +276,19 @@ def kdt(lon, lat, limits, k=4):
276
276
"""
277
277
if self .is_regular :
278
278
i_1 = int (floor (interp ((lonmin - 0.5 ) % 360 ,
279
- self ._lon [0 ],
280
- arange (len (self ._lon [0 ])))))
279
+ self ._lon [0 ],
280
+ arange (len (self ._lon [0 ])))))
281
281
i_0 = int (floor (interp ((lonmax + 0.5 ) % 360 ,
282
- self ._lon [0 ],
283
- arange (len (self ._lon [0 ])))
284
- ) + 1 )
282
+ self ._lon [0 ],
283
+ arange (len (self ._lon [0 ])))
284
+ ) + 1 )
285
285
else :
286
286
def half_limits (lon , lat ):
287
287
return array ([[lon .min (), lon .max (),
288
- lon .max (), lon .min ()],
289
- [lat .min (), lat .min (),
290
- lat .max (), lat .max ()]]).T
288
+ lon .max (), lon .min ()],
289
+ [lat .min (), lat .min (),
290
+ lat .max (), lat .max ()]]).T
291
+
291
292
# Get bounds for right part of grid
292
293
lat = self ._lat [self ._lon >= 360 + lonmin - 0.5 ]
293
294
lon = self ._lon [self ._lon >= 360 + lonmin - 0.5 ]
@@ -415,12 +416,14 @@ def u2rho_2d(self, uu_in):
415
416
"""
416
417
Convert a 2D field at u_val points to a field at rho points
417
418
"""
419
+
418
420
def uu2ur (uu_in , m_p , l_p ):
419
421
u_out = zeros ((m_p , l_p ))
420
422
u_out [:, 1 :- 1 ] = self .half_interp (uu_in [:, :- 1 ], uu_in [:, 1 :])
421
423
u_out [:, 0 ] = u_out [:, 1 ]
422
424
u_out [:, - 1 ] = u_out [:, - 2 ]
423
425
return u_out .squeeze ()
426
+
424
427
mshp , lshp = uu_in .shape
425
428
return uu2ur (uu_in , mshp , lshp + 1 )
426
429
@@ -432,6 +435,7 @@ def vv2vr(vv_in, m_p, l_p):
432
435
v_out [0 ] = v_out [1 ]
433
436
v_out [- 1 ] = v_out [- 2 ]
434
437
return v_out .squeeze ()
438
+
435
439
mshp , lshp = vv_in .shape
436
440
return vv2vr (vv_in , mshp + 1 , lshp )
437
441
@@ -458,7 +462,7 @@ def set_basemap(self, with_pad=True):
458
462
llcrnrlat = self .latmin - 1 ,
459
463
urcrnrlat = self .latmax + 1 ,
460
464
lat_ts = 0.5 * (self .latmin + self .latmax )
461
- )
465
+ )
462
466
463
467
if with_pad :
464
468
x_val , y_val = self .m_val (self .lonpad , self .latpad )
@@ -475,13 +479,13 @@ def set_geostrophic_velocity(self, zeta):
475
479
zeta1 , zeta2 = zeta .data [1 :].view (), zeta .data [:- 1 ].view ()
476
480
pn1 , pn2 = self .p_n [1 :].view (), self .p_n [:- 1 ].view ()
477
481
self .upad [:] = self .v2rho_2d (
478
- ma .array ((zeta1 - zeta2 ) * 0.5 * (pn1 + pn2 ), mask = self .vmask ))
482
+ ma .array ((zeta1 - zeta2 ) * 0.5 * (pn1 + pn2 ), mask = self .vmask ))
479
483
self .upad *= - self .gof
480
484
481
485
zeta1 , zeta2 = zeta .data [:, 1 :].view (), zeta .data [:, :- 1 ].view ()
482
486
pm1 , pm2 = self .p_m [:, 1 :].view (), self .p_m [:, :- 1 ].view ()
483
487
self .vpad [:] = self .u2rho_2d (
484
- ma .array ((zeta1 - zeta2 ) * 0.5 * (pm1 + pm2 ), mask = self .umask ))
488
+ ma .array ((zeta1 - zeta2 ) * 0.5 * (pm1 + pm2 ), mask = self .umask ))
485
489
self .vpad *= self .gof
486
490
487
491
def set_u_v_eke (self , pad = 2 ):
@@ -495,7 +499,7 @@ def set_u_v_eke(self, pad=2):
495
499
self .upad = ma .concatenate ((u_0 , u_1 ), axis = 1 )
496
500
else :
497
501
self .upad = empty ((j_size ,
498
- self .slice_i_pad .stop - self .slice_i_pad .start ))
502
+ self .slice_i_pad .stop - self .slice_i_pad .start ))
499
503
self .vpad = empty (self .upad .shape )
500
504
501
505
def get_eke (self ):
@@ -532,7 +536,7 @@ def create_index_inverse(slice_to_inverse, size):
532
536
"""Return an array of index
533
537
"""
534
538
index = concatenate ((arange (slice_to_inverse .stop , size ),
535
- arange (slice_to_inverse .start )))
539
+ arange (slice_to_inverse .start )))
536
540
return index
537
541
538
542
def gaussian_resolution (self , zwl , mwl ):
0 commit comments