def cleaningTrack(track, minTrackLength=3):
 nFrames = track.size
 cleanTrack = np.copy(track)
 trackBegs = (np.nonzero(((track[:(nFrames - 1)] <= 0) & (track[1:] > 0)))[0] + 1)
 if (track[0] > 0):
  trackBegs = np.insert(trackBegs, 0, 0)
 trackEnds = (np.nonzero(((track[:(nFrames - 1)] > 0) & (track[1:] <= 0)))[0] + 1)
 if (track[(nFrames - 1)] > 0):
  trackEnds = np.append(trackEnds, (nFrames - 1))
 trackLengths = ((1 + trackEnds) - trackBegs)
 for (i, j) in zip(trackBegs, trackLengths):
  if (j <= minTrackLength):
   cleanTrack[i:(i + j)] = 0
 return cleanTrack

def cleaningTrack ( track , minTrackLength = 3 ) : nFrames = track . size cleanTrack = np . copy ( track ) trackBegs = ( np . nonzero ( ( ( track [ : ( nFrames - 1 ) ] <= 0 ) & ( track [ 1 : ] > 0 ) ) ) [ 0 ] + 1 ) if ( track [ 0 ] > 0 ) : trackBegs = np . insert ( trackBegs , 0 , 0 ) trackEnds = ( np . nonzero ( ( ( track [ : ( nFrames - 1 ) ] > 0 ) & ( track [ 1 : ] <= 0 ) ) ) [ 0 ] + 1 ) if ( track [ ( nFrames - 1 ) ] > 0 ) : trackEnds = np . append ( trackEnds , ( nFrames - 1 ) ) trackLengths = ( ( 1 + trackEnds ) - trackBegs ) for ( i , j ) in zip ( trackBegs , trackLengths ) : if ( j <= minTrackLength ) : cleanTrack [ i : ( i + j ) ] = 0 return cleanTrack
delete fragments of one single track smaller than mintracklength track: array of values; mintracklength: minimum duration of tracks in number of frames returns cleantrack: array of clean values .