@@ -264,7 +264,7 @@ def get_infos(self):
264
264
bins_lat = (- 90 , - 60 , - 15 , 15 , 60 , 90 ),
265
265
bins_amplitude = array ((0 , 1 , 2 , 3 , 4 , 5 , 10 , 500 )),
266
266
bins_radius = array ((0 , 15 , 30 , 45 , 60 , 75 , 100 , 200 , 2000 )),
267
- nb_obs = self . observations . shape [ 0 ] ,
267
+ nb_obs = len ( self ) ,
268
268
)
269
269
t0 , t1 = self .period
270
270
infos ["t0" ], infos ["t1" ] = t0 , t1
@@ -341,7 +341,7 @@ def __repr__(self):
341
341
bins_lat = (- 90 , - 60 , - 15 , 15 , 60 , 90 )
342
342
bins_amplitude = array ((0 , 1 , 2 , 3 , 4 , 5 , 10 , 500 ))
343
343
bins_radius = array ((0 , 15 , 30 , 45 , 60 , 75 , 100 , 200 , 2000 ))
344
- nb_obs = self . observations . shape [ 0 ]
344
+ nb_obs = len ( self )
345
345
346
346
return f""" | { nb_obs } observations from { t0 } to { t1 } ({ period } days, ~{ nb_obs / period :.0f} obs/day)
347
347
| Speed area : { self .speed_area .sum () / period / 1e12 :.2f} Mkm²/day
@@ -416,7 +416,7 @@ def remove_fields(self, *fields):
416
416
"""
417
417
Copy with fields listed remove
418
418
"""
419
- nb_obs = self . obs . shape [ 0 ]
419
+ nb_obs = len ( self )
420
420
fields = set (fields )
421
421
only_variables = set (self .fields ) - fields
422
422
track_extra_variables = set (self .track_extra_variables ) - fields
@@ -439,7 +439,7 @@ def add_fields(self, fields=list(), array_fields=list()):
439
439
"""
440
440
Add a new field.
441
441
"""
442
- nb_obs = self . obs . shape [ 0 ]
442
+ nb_obs = len ( self )
443
443
new = self .__class__ (
444
444
size = nb_obs ,
445
445
track_extra_variables = list (
@@ -547,9 +547,9 @@ def merge(self, other):
547
547
nb_obs_self = len (self )
548
548
nb_obs = nb_obs_self + len (other )
549
549
eddies = self .new_like (self , nb_obs )
550
- other_keys = other .obs . dtype . fields . keys ()
551
- self_keys = self .obs . dtype . fields . keys ()
552
- for key in eddies .obs . dtype . fields . keys () :
550
+ other_keys = other .fields
551
+ self_keys = self .fields
552
+ for key in eddies .fields :
553
553
eddies .obs [key ][:nb_obs_self ] = self .obs [key ][:]
554
554
if key in other_keys :
555
555
eddies .obs [key ][nb_obs_self :] = other .obs [key ][:]
@@ -657,8 +657,8 @@ def insert_observations(self, other, index):
657
657
"""Insert other obs in self at the given index."""
658
658
if not self .coherence (other ):
659
659
raise Exception ("Observations with no coherence" )
660
- insert_size = len (other . obs )
661
- self_size = len (self . obs )
660
+ insert_size = len (other )
661
+ self_size = len (self )
662
662
new_size = self_size + insert_size
663
663
if self_size == 0 :
664
664
self .observations = other .obs
@@ -1542,8 +1542,7 @@ def to_zarr(self, handler, **kwargs):
1542
1542
handler .attrs ["track_array_variables" ] = self .track_array_variables
1543
1543
handler .attrs ["array_variables" ] = "," .join (self .array_variables )
1544
1544
# Iter on variables to create:
1545
- fields = [field [0 ] for field in self .observations .dtype .descr ]
1546
- for ori_name in fields :
1545
+ for ori_name in self .fields :
1547
1546
# Patch for a transition
1548
1547
name = ori_name
1549
1548
#
@@ -1588,12 +1587,11 @@ def to_netcdf(self, handler, **kwargs):
1588
1587
handler .track_array_variables = self .track_array_variables
1589
1588
handler .array_variables = "," .join (self .array_variables )
1590
1589
# Iter on variables to create:
1591
- fields = [field [0 ] for field in self .observations .dtype .descr ]
1592
1590
fields_ = array (
1593
- [VAR_DESCR [field [ 0 ]] ["nc_name" ] for field in self .observations . dtype . descr ]
1591
+ [VAR_DESCR [field ] ["nc_name" ] for field in self .fields ]
1594
1592
)
1595
1593
i = fields_ .argsort ()
1596
- for ori_name in array (fields )[i ]:
1594
+ for ori_name in array (self . fields )[i ]:
1597
1595
# Patch for a transition
1598
1596
name = ori_name
1599
1597
#
@@ -1865,10 +1863,9 @@ def extract_with_mask(self, mask):
1865
1863
if nb_obs == 0 :
1866
1864
logger .warning ("Empty dataset will be created" )
1867
1865
else :
1868
- for field in self .obs . dtype . descr :
1866
+ for field in self .fields :
1869
1867
logger .debug ("Copy of field %s ..." , field )
1870
- var = field [0 ]
1871
- new .obs [var ] = self .obs [var ][mask ]
1868
+ new .obs [field ] = self .obs [field ][mask ]
1872
1869
return new
1873
1870
1874
1871
def scatter (self , ax , name = None , ref = None , factor = 1 , ** kwargs ):
0 commit comments