@@ -112,6 +112,11 @@ def shifted_ellipsoid_degrees_mask2(lon0, lat0, lon1, lat1, minor=1.5, major=1.5
112
112
return m
113
113
114
114
115
+ @njit (cache = True )
116
+ def hist_numba (x , bins ):
117
+ return histogram (x , bins )
118
+
119
+
115
120
class EddiesObservations (object ):
116
121
"""
117
122
Class to hold eddy properties *amplitude* and counts of
@@ -199,6 +204,22 @@ def sign_legend(self):
199
204
def shape (self ):
200
205
return self .observations .shape
201
206
207
+ def get_infos (self ):
208
+ infos = dict (
209
+ bins_lat = (- 90 , - 60 , - 15 , 15 , 60 , 90 ),
210
+ bins_amplitude = array ((0 , 1 , 2 , 3 , 4 , 5 , 10 , 500 )),
211
+ bins_radius = array ((0 , 15 , 30 , 45 , 60 , 75 , 100 , 200 , 2000 )),
212
+ nb_obs = self .observations .shape [0 ],
213
+ )
214
+ t0 , t1 = self .period
215
+ infos ["t0" ], infos ["t1" ] = t0 , t1
216
+ infos ["period" ] = t1 - t0 + 1
217
+ return infos
218
+
219
+ def _repr_html_ (self ):
220
+ infos = self .get_infos ()
221
+ return f"""<b>{ infos ['nb_obs' ]} observations from { infos ['t0' ]} to { infos ['t1' ]} </b>"""
222
+
202
223
def __repr__ (self ):
203
224
"""
204
225
return general informations on dataset as a string
@@ -225,13 +246,13 @@ def hist(varname, x="lat", bins=bins_lat, percent=False, mean=False, nb=False):
225
246
:rtype: array
226
247
"""
227
248
if nb :
228
- v = histogram (self [x ], bins = bins )[0 ]
249
+ v = hist_numba (self [x ], bins = bins )[0 ]
229
250
else :
230
251
v = histogram (self [x ], bins = bins , weights = self [varname ])[0 ]
231
252
if percent :
232
253
v = v .astype ("f4" ) / v .sum () * 100
233
254
elif mean :
234
- v /= histogram (self [x ], bins = bins )[0 ]
255
+ v /= hist_numba (self [x ], bins = bins )[0 ]
235
256
return v
236
257
237
258
def box_display (value ):
@@ -241,25 +262,20 @@ def box_display(value):
241
262
return f"""{ nb_obs } observations from { t0 } to { t1 } ({ period } days, ~{ nb_obs / period :.0f} obs/day)
242
263
Speed area : { self ["speed_area" ].sum () / period / 1e12 :.2f} Mkm²/day
243
264
Effective area : { self ["effective_area" ].sum () / period / 1e12 :.2f} Mkm²/day
244
-
245
- Distribution in Amplitude:
265
+ ----Distribution in Amplitude:
246
266
Amplitude bounds (cm) { box_display (bins_amplitude )}
247
267
Percent of eddies : { box_display (hist ('time' , 'amplitude' , bins_amplitude / 100. , percent = True , nb = True ))}
248
-
249
- Distribution in Radius:
268
+ ----Distribution in Radius:
250
269
Speed radius (km) { box_display (bins_radius )}
251
270
Percent of eddies : { box_display (hist ('time' , 'radius_s' , bins_radius * 1000. , percent = True , nb = True ))}
252
-
253
- Distribution in Latitude
271
+ ----Distribution in Latitude
254
272
Latitude bounds { box_display (bins_lat )}
255
273
Percent of eddies : { box_display (hist ('time' , percent = True , nb = True ))}
256
274
Percent of speed area : { box_display (hist ('speed_area' , percent = True ))}
257
275
Percent of effective area : { box_display (hist ('effective_area' , percent = True ))}
258
-
259
276
Mean speed radius (km) : { box_display (hist ('radius_s' , mean = True ) / 1000. )}
260
277
Mean effective radius (km): { box_display (hist ('radius_e' , mean = True ) / 1000. )}
261
- Mean amplitude (cm) : { box_display (hist ('amplitude' , mean = True ) * 100. )}
262
- """
278
+ Mean amplitude (cm) : { box_display (hist ('amplitude' , mean = True ) * 100. )} """
263
279
264
280
def __getitem__ (self , attr ):
265
281
if attr in self .elements :
@@ -1367,9 +1383,10 @@ def grid_count(self, bins, intern=False, center=False):
1367
1383
grid .mask = grid .data == 0
1368
1384
else :
1369
1385
x_ref = ((self .longitude - x0 ) % 360 + x0 - 180 ).reshape (- 1 , 1 )
1370
- x , y = (self [x_name ] - x_ref ) % 360 + x_ref , self [y_name ]
1386
+ # x, y = (self[x_name] - x_ref) % 360 + x_ref, self[y_name]
1371
1387
nb = x_ref .shape [0 ]
1372
- for i_ , (x_ , y_ ) in enumerate (zip (x , y )):
1388
+ for i_ , (x , y_ ) in enumerate (zip (self [x_name ], self [y_name ])):
1389
+ x_ = (x - x_ref [i_ ]) % 360 + x_ref [i_ ]
1373
1390
if debug_active and i_ % 10000 == 0 :
1374
1391
print (f"{ i_ } /{ nb } " , end = "\r " )
1375
1392
i , j = BasePath (create_vertice (x_ , y_ )).pixels_in (regular_grid )
0 commit comments