Skip to content

Commit 9ca9758

Browse files
author
adelepoulle
committed
introduction of a cost function
1 parent 20ac627 commit 9ca9758

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/py_eddy_tracker/observations.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,36 @@ def load_from_netcdf(filename):
236236
eddies.sign_type = h_nc.variables['cyc'][0]
237237
return eddies
238238

239+
def cost_function(self, records_in, records_out):
240+
cost = ((records_in['amplitude'] - records_out['amplitude']
241+
) / records_in['amplitude']
242+
) ** 2
243+
cost += ((records_in['radius_s'] - records_out['radius_s']
244+
) / records_in['radius_s']
245+
) ** 2
246+
return cost ** 0.5
247+
239248
def tracking(self, other):
240249
"""Track obs between self and other
241250
"""
242-
cost = self.distance(other)
251+
dist = self.distance(other)
252+
# Links available which are close (circle area selection)
253+
mask_accept_dist = dist < 100
254+
indexs_closest = where(mask_accept_dist)
255+
cost_values = self.cost_function(
256+
self.obs[indexs_closest[0]],
257+
other.obs[indexs_closest[1]])
258+
259+
cost_mat = ma.empty(dist.shape, dtype='f4')
260+
cost_mat.mask = -mask_accept_dist
261+
cost_mat[mask_accept_dist] = cost_values
243262
# Links available which respect a maximal cost
244-
mask_accept_cost = cost < 40
263+
cost = dist
264+
mask_accept_cost = cost < 100
245265
cost = ma.array(cost, mask=-mask_accept_cost, dtype='i2')
246266

267+
mask_accept_cost = mask_accept_dist
268+
cost = cost_mat
247269
# Count number of link by self obs and other obs
248270
self_links = mask_accept_cost.sum(axis=1)
249271
other_links = mask_accept_cost.sum(axis=0)

src/py_eddy_tracker/tracking.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ def recense_dead_id_to_extend(self):
186186
self.previous_virtual_obs = self.virtual_obs
187187
# Creation of an virtual step for dead one
188188
self.virtual_obs = VirtualEddiesObservations(
189-
size=nb_dead + nb_virtual_extend)
189+
size=nb_dead + nb_virtual_extend,
190+
track_extra_variables=self.previous_obs.track_extra_variables,
191+
track_array_variables=self.previous_obs.track_array_variables,
192+
array_variables=self.previous_obs.array_variables)
190193

191194
# Find mask/index on previous correspondance to extrapolate
192195
# position
@@ -200,6 +203,11 @@ def recense_dead_id_to_extend(self):
200203
# Position N-1 : B
201204
# Virtual Position : C
202205
# New position C = B + AB
206+
for key in obs_b.dtype.fields.keys():
207+
if key in ['lon', 'lat', 'time', 'track', 'segment_size',
208+
'dlon', 'dlat'] or 'contour_' in key:
209+
continue
210+
self.virtual_obs[key][:nb_dead] = obs_b[key]
203211
self.virtual_obs['dlon'][:nb_dead] = obs_b['lon'] - obs_a['lon']
204212
self.virtual_obs['dlat'][:nb_dead] = obs_b['lat'] - obs_a['lat']
205213
self.virtual_obs['lon'][:nb_dead

0 commit comments

Comments
 (0)