Skip to content

Commit e5af5ad

Browse files
author
adelepoulle
committed
End : move action in class method
1 parent e9ad8c5 commit e5af5ad

File tree

1 file changed

+31
-49
lines changed

1 file changed

+31
-49
lines changed

src/py_eddy_tracker/tracking.py

Lines changed: 31 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def store_correspondance(self, i_previous, i_current, nb_real_obs):
112112
# Set an id for each match
113113
correspondance['id'] = self.id_generator(nb_match)
114114
self.append(correspondance)
115-
return
115+
return True
116116

117117
# We set all id to UINT32_MAX
118118
id_previous = ones(len(self.previous_obs),
@@ -123,6 +123,33 @@ def store_correspondance(self, i_previous, i_current, nb_real_obs):
123123
# track it before
124124
correspondance['id'] = id_previous[correspondance['in']]
125125

126+
# We set correspondance data for virtual obs : ID/LENGTH
127+
if self.previous2_obs is not None and self.virtual:
128+
nb_rebirth = correspondance['virtual'].sum()
129+
if nb_rebirth != 0:
130+
logging.debug('%d re-birth due to prolongation with'
131+
' virtual observations', nb_rebirth)
132+
## Set id for virtual
133+
# get correspondance mask using virtual obs
134+
m_virtual = correspondance['virtual']
135+
# index of virtual in virtual obs
136+
i_virtual = correspondance['in'][m_virtual] - nb_real_obs
137+
correspondance['id'][m_virtual] = \
138+
self.virtual_obs['track'][i_virtual]
139+
correspondance['virtual_length'][m_virtual] = \
140+
self.virtual_obs['segment_size'][i_virtual]
141+
142+
# new_id is equal to UINT32_MAX we must add a new ones
143+
# we count the number of new
144+
mask_new_id = correspondance['id'] == self.UINT32_MAX
145+
nb_new_tracks = mask_new_id.sum()
146+
logging.debug('%d birth in this step', nb_new_tracks)
147+
# Set new id
148+
correspondance['id'][mask_new_id] = self.id_generator(nb_new_tracks)
149+
150+
self.append(correspondance)
151+
152+
return False
126153

127154
def id_generator(self, nb_id):
128155
"""Generation id and incrementation
@@ -134,14 +161,14 @@ def id_generator(self, nb_id):
134161
def recense_dead_id_to_extend(self):
135162
"""Recense dead id to extend in virtual observation
136163
"""
137-
nb_virtual_extend = 0
138164
# List previous id which are not use in the next step
139165
dead_id = setdiff1d(self[-2]['id'], self[-1]['id'])
140166
nb_dead = dead_id.shape[0]
141167
logging.debug('%d death of real obs in this step', nb_dead)
142168
if not self.virtual:
143169
return
144-
#
170+
# get id already dead from few time
171+
nb_virtual_extend = 0
145172
if self.virtual_obs is not None:
146173
virtual_dead_id = setdiff1d(self.virtual_obs['track'],
147174
self[-1]['id'])
@@ -192,7 +219,6 @@ def recense_dead_id_to_extend(self):
192219
def track(self):
193220
"""Run tracking
194221
"""
195-
START = True
196222
FLG_VIRTUAL = False
197223
self.reset_dataset_cache()
198224
self.swap_dataset(self.datasets[0])
@@ -210,54 +236,10 @@ def track(self):
210236
self.previous_obs = self.previous_obs.merge(self.virtual_obs)
211237

212238
i_previous, i_current = self.previous_obs.tracking(self.current_obs)
213-
nb_match = i_previous.shape[0]
214239

215-
#~ self.store_correspondance(i_previous, i_current, nb_real_obs)
216-
correspondance = array(i_previous, dtype=self.correspondance_dtype)
217-
correspondance['out'] = i_current
218-
219-
if self.virtual:
220-
correspondance['virtual'] = i_previous >= nb_real_obs
221-
222-
if START:
223-
START = False
224-
# Set an id for each match
225-
correspondance['id'] = self.id_generator(nb_match)
226-
self.append(correspondance)
240+
if self.store_correspondance(i_previous, i_current, nb_real_obs):
227241
continue
228242

229-
# We set all id to UINT32_MAX
230-
id_previous = ones(len(self.previous_obs), dtype=self.ID_DTYPE) * self.UINT32_MAX
231-
# We get old id for previously eddies tracked
232-
previous_id = self[-1]['id']
233-
id_previous[self[-1]['out']] = previous_id
234-
correspondance['id'] = id_previous[correspondance['in']]
235-
236-
# We set correspondance data for virtual obs : ID/LENGTH
237-
if FLG_VIRTUAL:
238-
nb_rebirth = correspondance['virtual'].sum()
239-
if nb_rebirth != 0:
240-
logging.debug('%d re-birth due to prolongation with'
241-
' virtual observations', nb_rebirth)
242-
# Set id for virtual
243-
m_virtual = correspondance['virtual']
244-
# index of virtual in virtual obs
245-
i_virtual = correspondance['in'][m_virtual] - nb_real_obs
246-
correspondance['id'][m_virtual] = \
247-
self.virtual_obs['track'][i_virtual]
248-
correspondance['virtual_length'][m_virtual] = \
249-
self.virtual_obs['segment_size'][i_virtual]
250-
251-
# new_id is equal to UINT32_MAX we must add a new ones
252-
# we count the number of new
253-
mask_new_id = correspondance['id'] == self.UINT32_MAX
254-
nb_new_tracks = mask_new_id.sum()
255-
logging.debug('%d birth in this step', nb_new_tracks)
256-
# Set new id
257-
correspondance['id'][mask_new_id] = self.id_generator(nb_new_tracks)
258-
259-
self.append(correspondance)
260-
261243
self.recense_dead_id_to_extend()
262244

263245
if self.virtual:

0 commit comments

Comments
 (0)