30
30
from matplotlib .dates import julian2num , num2date
31
31
32
32
from py_eddy_tracker .observations import EddiesObservations , VirtualEddiesObservations , TrackEddiesObservations
33
- from numpy import bool_ , array , arange , ones , setdiff1d , zeros , uint16 , where , empty , isin , unique , concatenate , ma
34
- from netCDF4 import Dataset
33
+ from numpy import bool_ , array , arange , ones , setdiff1d , zeros , uint16 , where , empty , isin , unique , concatenate , \
34
+ ma
35
+ from netCDF4 import Dataset , default_fillvals
35
36
import logging
36
37
import platform
37
38
@@ -55,7 +56,9 @@ def __init__(self, datasets, virtual=0, class_method=None, previous_correspondan
55
56
# Correspondance dtype
56
57
self .correspondance_dtype = [('in' , 'u2' ),
57
58
('out' , 'u2' ),
58
- ('id' , self .ID_DTYPE )]
59
+ ('id' , self .ID_DTYPE ),
60
+ ('cost_value' , 'f4' )
61
+ ]
59
62
if class_method is None :
60
63
self .class_method = EddiesObservations
61
64
else :
@@ -168,7 +171,7 @@ def merge_correspondance(self, other):
168
171
# We set new id available
169
172
self .current_id = translate [- 1 ] + 1
170
173
171
- def store_correspondance (self , i_previous , i_current , nb_real_obs ):
174
+ def store_correspondance (self , i_previous , i_current , nb_real_obs , association_cost ):
172
175
"""Storing correspondance in an array
173
176
"""
174
177
# Create array to store correspondance data
@@ -177,6 +180,7 @@ def store_correspondance(self, i_previous, i_current, nb_real_obs):
177
180
correspondance ['virtual_length' ][:] = 255
178
181
# index from current_obs
179
182
correspondance ['out' ] = i_current
183
+ correspondance ['cost_value' ] = association_cost
180
184
181
185
if self .virtual :
182
186
# if index in previous dataset is bigger than real obs number
@@ -314,10 +318,10 @@ def track(self):
314
318
if flg_virtual :
315
319
logging .debug ('%d virtual obs will be add to previous' , len (self .virtual_obs ))
316
320
self .previous_obs = self .previous_obs .merge (self .virtual_obs )
317
- i_previous , i_current = self .previous_obs .tracking (self .current_obs )
321
+ i_previous , i_current , association_cost = self .previous_obs .tracking (self .current_obs )
318
322
319
323
# return true if the first time (previous2obs is none)
320
- if self .store_correspondance (i_previous , i_current , nb_real_obs ):
324
+ if self .store_correspondance (i_previous , i_current , nb_real_obs , association_cost ):
321
325
continue
322
326
323
327
self .recense_dead_id_to_extend ()
@@ -376,7 +380,11 @@ def save(self, filename, dict_completion=None):
376
380
for name , _ in self .correspondance_dtype :
377
381
datas [name ][i , :nb_elt ] = correspondance [name ]
378
382
for name , data in datas .items ():
379
- h_nc .variables [name ][:] = data
383
+ h_v = h_nc .variables [name ]
384
+ h_v [:] = data
385
+ if 'File' not in name :
386
+ h_v .min = h_v [:].min ()
387
+ h_v .max = h_v [:].max ()
380
388
381
389
h_nc .virtual_use = str (self .virtual )
382
390
h_nc .virtual_max_segment = self .nb_virtual
@@ -512,6 +520,8 @@ def merge(self, until=-1):
512
520
track_array_variables = self .current_obs .track_array_variables ,
513
521
array_variables = self .current_obs .array_variables )
514
522
523
+ # All the value put at nan, necessary only for all end of track
524
+ eddies ['cost_association' ][:] = default_fillvals ['f4' ]
515
525
# Calculate the index in each tracks, we compute in u4 and translate
516
526
# in u2 (which are limited to 65535)
517
527
logging .debug ('Compute global index array (N)' )
@@ -547,6 +557,8 @@ def merge(self, until=-1):
547
557
# Copy all variable
548
558
for field in fields :
549
559
var = field [0 ]
560
+ if var == 'cost_association' :
561
+ continue
550
562
eddies [var ][index_final [m_first_obs ]] = self .previous_obs [var ][index_in ]
551
563
# Increment
552
564
self .i_current_by_tracks [i_id [m_first_obs ]] += 1
@@ -570,7 +582,10 @@ def merge(self, until=-1):
570
582
# Copy all variable
571
583
for field in fields :
572
584
var = field [0 ]
573
- eddies [var ][index_final ] = self .current_obs [var ][index_current ]
585
+ if var == 'cost_association' :
586
+ eddies [var ][index_final - 1 ] = self [i ]['cost_value' ]
587
+ else :
588
+ eddies [var ][index_final ] = self .current_obs [var ][index_current ]
574
589
575
590
# Add increment for each index used
576
591
self .i_current_by_tracks [i_id ] += 1
0 commit comments