@@ -199,7 +199,66 @@ def shape(self):
199199 return self .observations .shape
200200
201201 def __repr__ (self ):
202- return "%d observations" % len (self .observations )
202+ """
203+ return general informations on dataset as a string
204+
205+ :return: informations on datasets
206+ :rtype: str
207+ """
208+ t0 , t1 = self .period
209+ period = t1 - t0 + 1
210+ bins_lat = (- 90 , - 60 , - 15 , 15 , 60 , 90 )
211+ bins_amplitude = array ((0 , 1 , 2 , 3 , 4 , 5 , 10 , 500 ))
212+ bins_radius = array ((0 , 15 , 30 , 45 , 60 , 75 , 100 , 200 , 2000 ))
213+ nb_obs = self .observations .shape [0 ]
214+
215+ def hist (varname , x = "lat" , bins = bins_lat , percent = False , mean = False , nb = False ):
216+ """
217+ :param str varname: variable to use to compute stat
218+ :param str x: variable to use to know in which bins
219+ :param array bins:
220+ :param bool percent: normalize by sum of all bins
221+ :param bool mean: compute mean by bins
222+ :param nb mean: only count by bins
223+ :return: value by bins
224+ :rtype: array
225+ """
226+ if nb :
227+ v = histogram (self [x ], bins = bins )[0 ]
228+ else :
229+ v = histogram (self [x ], bins = bins , weights = self [varname ])[0 ]
230+ if percent :
231+ v = v .astype ("f4" ) / v .sum () * 100
232+ elif mean :
233+ v /= histogram (self [x ], bins = bins )[0 ]
234+ return v
235+
236+ def box_display (value ):
237+ """Return value evenly spaced with few numbers"""
238+ return "" .join ([f"{ v_ :10.2f} " for v_ in value ])
239+
240+ return f"""{ nb_obs } observations from { t0 } to { t1 } ({ period } days, ~{ nb_obs / period :.0f} obs/day)
241+ Speed area : { self ["speed_area" ].sum () / period / 1e12 :.2f} Mkm²/day
242+ Effective area : { self ["effective_area" ].sum () / period / 1e12 :.2f} Mkm²/day
243+
244+ Distribution in Amplitude:
245+ Amplitude bounds (cm) { box_display (bins_amplitude )}
246+ Percent of eddies : { box_display (hist ('time' , 'amplitude' , bins_amplitude / 100. , percent = True , nb = True ))}
247+
248+ Distribution in Radius:
249+ Speed radius (km) { box_display (bins_radius )}
250+ Percent of eddies : { box_display (hist ('time' , 'radius_s' , bins_radius * 1000. , percent = True , nb = True ))}
251+
252+ Distribution in Latitude
253+ Latitude bounds { box_display (bins_lat )}
254+ Percent of eddies : { box_display (hist ('time' , percent = True , nb = True ))}
255+ Percent of speed area : { box_display (hist ('speed_area' , percent = True ))}
256+ Percent of effective area : { box_display (hist ('effective_area' , percent = True ))}
257+
258+ Mean speed radius (km) : { box_display (hist ('radius_s' , mean = True ) / 1000. )}
259+ Mean effective radius (km): { box_display (hist ('radius_e' , mean = True ) / 1000. )}
260+ Mean amplitude (cm) : { box_display (hist ('amplitude' , mean = True ) * 100. )}
261+ """
203262
204263 def __getitem__ (self , attr ):
205264 if attr in self .elements :
@@ -1366,6 +1425,16 @@ def interp_grid(
13661425 else :
13671426 raise Exception (f'method "{ method } " unknown' )
13681427
1428+ @property
1429+ def period (self ):
1430+ """
1431+ Give time coverage
1432+
1433+ :return: first and last date
1434+ :rtype: (int,int)
1435+ """
1436+ return self .time .min (), self .time .max ()
1437+
13691438
13701439@njit (cache = True )
13711440def grid_count_ (grid , i , j ):
0 commit comments