def tracksep_indices(data, LATCOL, inmemory): """Find the indices in `data` for ascending/descending tracks. """ N = data.shape[0] i_asc = np.zeros(N, np.bool_) # data in-memory i_des = np.zeros(N, np.bool_) # all false if cmodule and inmemory: # C function C.tracksep_indices(data, LATCOL, i_asc, i_des) else: # Py function i_beg = 0 for i_end in xrange(N - 1): if (data[i_end + 1, TIMECOL] - data[i_end, TIMECOL]) > TIMELAG or i_end == N - 2: # if break in time or last track i_min = np.argmin(data[i_beg:i_end + 1, LATCOL]) i_min = np.unravel_index(i_min, data[i_beg:i_end + 1, LATCOL].shape)[0] i_min += i_beg if i_beg != i_min and i_min != i_end: # asc + des if data[i_beg, LATCOL] < data[i_min, LATCOL]: i_asc[i_beg:i_min + 1] = True # first segment asc i_des[i_min + 1:i_end + 1] = True # second segment des else: i_des[i_beg:i_min + 1] = True i_asc[i_min + 1:i_end + 1] = True elif i_beg == i_min: # all asc i_asc[i_beg:i_end + 1] = True elif i_min == i_end: # all des i_des[i_beg:i_end + 1] = True else: pass # all remains false i_beg = i_end + 1 i_asc[-1] = i_asc[-2] # set last element i_des[-1] = i_des[-2] i_asc, = np.where(i_asc == True) # bool -> indices i_des, = np.where(i_des == True) return i_asc, i_des
def tracksep_indices(lat, time, timelag=10): """ Finds the indices for asc/des tracks using latitude and time. """ N = lat.shape[0] i_asc = np.zeros(N, np.bool_) # data in-memory i_des = np.zeros(N, np.bool_) # all false if cmodule: # C function mod.tracksep_indices(lat, time, i_asc, i_des) else: # Py function i_beg = 0 for i_end in xrange(N-1): # if break in time or last track if (time[i_end+1] - time[i_end]) > timelag or (i_end == N-2): i_min = np.argmin(lat[i_beg:i_end+1]) i_min += i_beg if (i_beg != i_min) and (i_min != i_end): # asc + des if lat[i_beg] < lat[i_min]: i_asc[i_beg:i_min+1] = True # first segment asc i_des[i_min+1:i_end+1] = True # second segment des else: i_des[i_beg:i_min+1] = True i_asc[i_min+1:i_end+1] = True elif i_beg == i_min: # all asc i_asc[i_beg:i_end+1] = True elif i_min == i_end: # all des i_des[i_beg:i_end+1] = True else: pass # all remains false i_beg = i_end + 1 i_asc[-1] = i_asc[-2] # set last element i_des[-1] = i_des[-2] i_asc, = np.where(i_asc == True) # bool -> indices i_des, = np.where(i_des == True) return i_asc, i_des
def tracksep_indices(lat, time, timelag=10): """ Finds the indices for asc/des tracks using latitude and time. """ N = lat.shape[0] i_asc = np.zeros(N, np.bool_) # data in-memory i_des = np.zeros(N, np.bool_) # all false if cmodule: # C function mod.tracksep_indices(lat, time, i_asc, i_des) else: # Py function i_beg = 0 for i_end in xrange(N - 1): # if break in time or last track if (time[i_end + 1] - time[i_end]) > timelag or (i_end == N - 2): i_min = np.argmin(lat[i_beg:i_end + 1]) i_min += i_beg if (i_beg != i_min) and (i_min != i_end): # asc + des if lat[i_beg] < lat[i_min]: i_asc[i_beg:i_min + 1] = True # first segment asc i_des[i_min + 1:i_end + 1] = True # second segment des else: i_des[i_beg:i_min + 1] = True i_asc[i_min + 1:i_end + 1] = True elif i_beg == i_min: # all asc i_asc[i_beg:i_end + 1] = True elif i_min == i_end: # all des i_des[i_beg:i_end + 1] = True else: pass # all remains false i_beg = i_end + 1 i_asc[-1] = i_asc[-2] # set last element i_des[-1] = i_des[-2] i_asc, = np.where(i_asc == True) # bool -> indices i_des, = np.where(i_des == True) return i_asc, i_des
def tracksep_indices(data, LATCOL, inmemory): """Find the indices in `data` for ascending/descending tracks. """ N = data.shape[0] i_asc = np.zeros(N, np.bool_) # data in-memory i_des = np.zeros(N, np.bool_) # all false if cmodule and inmemory: # C function C.tracksep_indices(data, LATCOL, i_asc, i_des) else: # Py function i_beg = 0 for i_end in xrange(N-1): if (data[i_end+1,TIMECOL] - data[i_end,TIMECOL]) > TIMELAG or i_end == N-2: # if break in time or last track i_min = np.argmin(data[i_beg:i_end+1,LATCOL]) i_min = np.unravel_index(i_min, data[i_beg:i_end+1,LATCOL].shape)[0] i_min += i_beg if i_beg != i_min and i_min != i_end: # asc + des if data[i_beg,LATCOL] < data[i_min,LATCOL]: i_asc[i_beg:i_min+1] = True # first segment asc i_des[i_min+1:i_end+1] = True # second segment des else: i_des[i_beg:i_min+1] = True i_asc[i_min+1:i_end+1] = True elif i_beg == i_min: # all asc i_asc[i_beg:i_end+1] = True elif i_min == i_end: # all des i_des[i_beg:i_end+1] = True else: pass # all remains false i_beg = i_end + 1 i_asc[-1] = i_asc[-2] # set last element i_des[-1] = i_des[-2] i_asc, = np.where(i_asc == True) # bool -> indices i_des, = np.where(i_des == True) return i_asc, i_des