22"""
33Class to create network of observations
44"""
5- from glob import glob
65import logging
76import time
7+ from glob import glob
88
99import netCDF4
10- from numba import njit , types as nb_types
11- from numba .typed import List
12- from numpy import (
13- arange ,
14- array ,
15- bincount ,
16- bool_ ,
17- concatenate ,
18- empty ,
19- nan ,
20- ones ,
21- percentile ,
22- uint16 ,
23- uint32 ,
24- unique ,
25- where ,
26- zeros ,
27- )
2810import zarr
11+ from numba import njit
12+ from numba import types as nb_types
13+ from numba .typed import List
14+ from numpy import (arange , array , bincount , bool_ , concatenate , empty , nan ,
15+ ones , percentile , uint16 , uint32 , unique , where , zeros )
2916
3017from ..dataset .grid import GridCollection
3118from ..generic import build_index , wrap_longitude
3219from ..poly import bbox_intersection , vertice_overlap
33- from .groups import GroupEddiesObservations , get_missing_indices , particle_candidate
20+ from .groups import (GroupEddiesObservations , get_missing_indices ,
21+ particle_candidate )
3422from .observation import EddiesObservations
35- from .tracking import TrackEddiesObservations , track_loess_filter , track_median_filter
23+ from .tracking import (TrackEddiesObservations , track_loess_filter ,
24+ track_median_filter )
3625
3726logger = logging .getLogger ("pet" )
3827
@@ -280,6 +269,15 @@ def longer_than(self, nb_day_min=-1, nb_day_max=-1):
280269 """
281270 Select network on time duration
282271
272+ :param int nb_day_min: Minimal number of days covered by one network, if negative -> not used
273+ :param int nb_day_max: Maximal number of days covered by one network, if negative -> not used
274+ """
275+ return self .extract_with_mask (self .mask_longer_than (nb_day_min , nb_day_max ))
276+
277+ def mask_longer_than (self , nb_day_min = - 1 , nb_day_max = - 1 ):
278+ """
279+ Select network on time duration
280+
283281 :param int nb_day_min: Minimal number of days covered by one network, if negative -> not used
284282 :param int nb_day_max: Maximal number of days covered by one network, if negative -> not used
285283 """
@@ -293,7 +291,7 @@ def longer_than(self, nb_day_min=-1, nb_day_max=-1):
293291 continue
294292 if nb_day_min <= (ptp (t [i ]) + 1 ) <= nb_day_max :
295293 mask [i ] = True
296- return self . extract_with_mask ( mask )
294+ return mask
297295
298296 @classmethod
299297 def from_split_network (cls , group_dataset , indexs , ** kwargs ):
@@ -800,7 +798,7 @@ def display_timeline(
800798 if field is not None :
801799 field = self .parse_varname (field )
802800 for i , b0 , b1 in self .iter_on ("segment" ):
803- x = self .time [i ]
801+ x = self .time_datetime64 [i ]
804802 if x .shape [0 ] == 0 :
805803 continue
806804 if field is None :
@@ -831,7 +829,7 @@ def event_timeline(self, ax, field=None, method=None, factor=1, colors_mode="rol
831829
832830 # TODO : fill mappables dict
833831 y_seg = dict ()
834- _time = self .time
832+ _time = self .time_datetime64
835833
836834 if field is not None and method != "all" :
837835 for i , b0 , _ in self .iter_on ("segment" ):
@@ -1011,7 +1009,7 @@ def scatter_timeline(
10111009 if "c" not in kwargs :
10121010 v = self .parse_varname (name )
10131011 kwargs ["c" ] = v * factor
1014- mappables ["scatter" ] = ax .scatter (self .time , y , ** kwargs )
1012+ mappables ["scatter" ] = ax .scatter (self .time_datetime64 , y , ** kwargs )
10151013 return mappables
10161014
10171015 def event_map (self , ax , ** kwargs ):
@@ -1244,7 +1242,7 @@ def networks_mask(self, id_networks, segment=False):
12441242
12451243 def networks (self , id_networks ):
12461244 return self .extract_with_mask (
1247- generate_mask_from_ids (id_networks , self .track .size , * self .index_network )
1245+ generate_mask_from_ids (array ( id_networks ) , self .track .size , * self .index_network )
12481246 )
12491247
12501248 @property
@@ -1423,10 +1421,10 @@ def plot(self, ax, ref=None, color_cycle=None, **kwargs):
14231421 :param dict kwargs: keyword arguments for Axes.plot
14241422 :return: a list of matplotlib mappables
14251423 """
1426- nb_colors = 0
1427- if color_cycle is not None :
1428- kwargs = kwargs . copy ()
1429- nb_colors = len (color_cycle )
1424+ kwargs = kwargs . copy ()
1425+ if color_cycle is None :
1426+ color_cycle = self . COLORS
1427+ nb_colors = len (color_cycle )
14301428 mappables = list ()
14311429 if "label" in kwargs :
14321430 kwargs ["label" ] = self .format_label (kwargs ["label" ])
0 commit comments