70
70
reverse_index ,
71
71
get_pixel_in_regular ,
72
72
bbox_indice_regular ,
73
+ hist_numba ,
73
74
)
74
75
from ..poly import bbox_intersection , vertice_overlap , create_vertice
75
76
@@ -112,11 +113,6 @@ def shifted_ellipsoid_degrees_mask2(lon0, lat0, lon1, lat1, minor=1.5, major=1.5
112
113
return m
113
114
114
115
115
- @njit (cache = True )
116
- def hist_numba (x , bins ):
117
- return histogram (x , bins )
118
-
119
-
120
116
class EddiesObservations (object ):
121
117
"""
122
118
Class to hold eddy properties *amplitude* and counts of
@@ -220,6 +216,32 @@ def _repr_html_(self):
220
216
infos = self .get_infos ()
221
217
return f"""<b>{ infos ['nb_obs' ]} observations from { infos ['t0' ]} to { infos ['t1' ]} </b>"""
222
218
219
+ def hist (self , varname , x , bins , percent = False , mean = False , nb = False ):
220
+ """
221
+ :param str varname: variable to use to compute stat
222
+ :param str x: variable to use to know in which bins
223
+ :param array bins:
224
+ :param bool percent: normalize by sum of all bins
225
+ :param bool mean: compute mean by bins
226
+ :param nb mean: only count by bins
227
+ :return: value by bins
228
+ :rtype: array
229
+ """
230
+ if nb :
231
+ v = hist_numba (self [x ], bins = bins )[0 ]
232
+ else :
233
+ v = histogram (self [x ], bins = bins , weights = self [varname ])[0 ]
234
+ if percent :
235
+ v = v .astype ("f4" ) / v .sum () * 100
236
+ elif mean :
237
+ v /= hist_numba (self [x ], bins = bins )[0 ]
238
+ return v
239
+
240
+ @staticmethod
241
+ def box_display (value ):
242
+ """Return value evenly spaced with few numbers"""
243
+ return "" .join ([f"{ v_ :10.2f} " for v_ in value ])
244
+
223
245
def __repr__ (self ):
224
246
"""
225
247
return general informations on dataset as a string
@@ -234,48 +256,25 @@ def __repr__(self):
234
256
bins_radius = array ((0 , 15 , 30 , 45 , 60 , 75 , 100 , 200 , 2000 ))
235
257
nb_obs = self .observations .shape [0 ]
236
258
237
- def hist (varname , x = "lat" , bins = bins_lat , percent = False , mean = False , nb = False ):
238
- """
239
- :param str varname: variable to use to compute stat
240
- :param str x: variable to use to know in which bins
241
- :param array bins:
242
- :param bool percent: normalize by sum of all bins
243
- :param bool mean: compute mean by bins
244
- :param nb mean: only count by bins
245
- :return: value by bins
246
- :rtype: array
247
- """
248
- if nb :
249
- v = hist_numba (self [x ], bins = bins )[0 ]
250
- else :
251
- v = histogram (self [x ], bins = bins , weights = self [varname ])[0 ]
252
- if percent :
253
- v = v .astype ("f4" ) / v .sum () * 100
254
- elif mean :
255
- v /= hist_numba (self [x ], bins = bins )[0 ]
256
- return v
257
-
258
- def box_display (value ):
259
- """Return value evenly spaced with few numbers"""
260
- return "" .join ([f"{ v_ :10.2f} " for v_ in value ])
261
-
262
- return f"""{ nb_obs } observations from { t0 } to { t1 } ({ period } days, ~{ nb_obs / period :.0f} obs/day)
263
- Speed area : { self ["speed_area" ].sum () / period / 1e12 :.2f} Mkm²/day
264
- Effective area : { self ["effective_area" ].sum () / period / 1e12 :.2f} Mkm²/day
265
- ----Distribution in Amplitude:
266
- Amplitude bounds (cm) { box_display (bins_amplitude )}
267
- Percent of eddies : { box_display (hist ('time' , 'amplitude' , bins_amplitude / 100. , percent = True , nb = True ))}
268
- ----Distribution in Radius:
269
- Speed radius (km) { box_display (bins_radius )}
270
- Percent of eddies : { box_display (hist ('time' , 'radius_s' , bins_radius * 1000. , percent = True , nb = True ))}
271
- ----Distribution in Latitude
272
- Latitude bounds { box_display (bins_lat )}
273
- Percent of eddies : { box_display (hist ('time' , percent = True , nb = True ))}
274
- Percent of speed area : { box_display (hist ('speed_area' , percent = True ))}
275
- Percent of effective area : { box_display (hist ('effective_area' , percent = True ))}
276
- Mean speed radius (km) : { box_display (hist ('radius_s' , mean = True ) / 1000. )}
277
- Mean effective radius (km): { box_display (hist ('radius_e' , mean = True ) / 1000. )}
278
- Mean amplitude (cm) : { box_display (hist ('amplitude' , mean = True ) * 100. )} """
259
+ return f""" | { nb_obs } observations from { t0 } to { t1 } ({ period } days, ~{ nb_obs / period :.0f} obs/day)
260
+ | Speed area : { self ["speed_area" ].sum () / period / 1e12 :.2f} Mkm²/day
261
+ | Effective area : { self ["effective_area" ].sum () / period / 1e12 :.2f} Mkm²/day
262
+ ----Distribution in Amplitude:
263
+ | Amplitude bounds (cm) { self .box_display (bins_amplitude )}
264
+ | Percent of eddies : {
265
+ self .box_display (self .hist ('time' , 'amplitude' , bins_amplitude / 100. , percent = True , nb = True ))}
266
+ ----Distribution in Radius:
267
+ | Speed radius (km) { self .box_display (bins_radius )}
268
+ | Percent of eddies : {
269
+ self .box_display (self .hist ('time' , 'radius_s' , bins_radius * 1000. , percent = True , nb = True ))}
270
+ ----Distribution in Latitude
271
+ Latitude bounds { self .box_display (bins_lat )}
272
+ Percent of eddies : { self .box_display (self .hist ('time' , 'lat' , bins_lat , percent = True , nb = True ))}
273
+ Percent of speed area : { self .box_display (self .hist ('speed_area' , 'lat' , bins_lat , percent = True ))}
274
+ Percent of effective area : { self .box_display (self .hist ('effective_area' , 'lat' , bins_lat , percent = True ))}
275
+ Mean speed radius (km) : { self .box_display (self .hist ('radius_s' , 'lat' , bins_lat , mean = True ) / 1000. )}
276
+ Mean effective radius (km): { self .box_display (self .hist ('radius_e' , 'lat' , bins_lat , mean = True ) / 1000. )}
277
+ Mean amplitude (cm) : { self .box_display (self .hist ('amplitude' , 'lat' , bins_lat , mean = True ) * 100. )} """
279
278
280
279
def __getitem__ (self , attr ):
281
280
if attr in self .elements :
0 commit comments