refactored findrfc

master
Per A Brodtkorb 9 years ago
parent 884a5588ba
commit 67eb1e6a02

@ -1039,39 +1039,40 @@ def findrfc(tp, h=0.0, method='clib'):
rfcfilter, rfcfilter,
findtp. findtp.
''' '''
# TODO: merge rfcfilter and findrfc y = atleast_1d(tp).ravel()
y1 = atleast_1d(tp).ravel()
n = len(y1) t_start = int(y[0] > y[1]) # first is a max, ignore it
ind = zeros(0, dtype=np.int) y = y[t_start::]
ix = 0 n = len(y)
if y1[0] > y1[1]: NC = np.floor(n / 2) - 1
# first is a max, ignore it
y = y1[1::]
NC = floor((n - 1) / 2) - 1
Tstart = 1
else:
y = y1
NC = floor(n / 2) - 1
Tstart = 0
if (NC < 1): if (NC < 1):
return ind # No RFC cycles*/ return zeros(0, dtype=np.int) # No RFC cycles*/
if (y[0] > y[1]) and (y[1] > y[2]): if (y[0] > y[1] and y[1] > y[2] or
y[0] < y[1] and y[1] < y[2]):
warnings.warn('This is not a sequence of turningpoints, exit') warnings.warn('This is not a sequence of turningpoints, exit')
return ind return zeros(0, dtype=np.int)
if (y[0] < y[1]) and (y[1] < y[2]):
warnings.warn('This is not a sequence of turningpoints, exit')
return ind
if clib is None or method not in ('clib'): if clib is None or method not in ('clib'):
ind, ix = _findrfc(y, h)
else:
ind, ix = clib.findrfc(y, h)
return np.sort(ind[:ix]) + t_start
def _findrfc(y, h):
# TODO: merge rfcfilter and _findrfc
t_start = 0
n = len(y)
NC = np.floor(n / 2) - 1
ind = zeros(n, dtype=np.int) ind = zeros(n, dtype=np.int)
NC = np.int(NC) NC = np.int(NC)
ix = 0
for i in range(NC): for i in range(NC):
Tmi = Tstart + 2 * i Tmi = t_start + 2 * i
Tpl = Tstart + 2 * i + 2 Tpl = t_start + 2 * i + 2
xminus = y[2 * i] xminus = y[2 * i]
xplus = y[2 * i + 2] xplus = y[2 * i + 2]
@ -1080,13 +1081,13 @@ def findrfc(tp, h=0.0, method='clib'):
while ((j >= 0) and (y[2 * j + 1] <= y[2 * i + 1])): while ((j >= 0) and (y[2 * j + 1] <= y[2 * i + 1])):
if (y[2 * j] < xminus): if (y[2 * j] < xminus):
xminus = y[2 * j] xminus = y[2 * j]
Tmi = Tstart + 2 * j Tmi = t_start + 2 * j
j -= 1 j -= 1
if (xminus >= xplus): if (xminus >= xplus):
if (y[2 * i + 1] - xminus >= h): if (y[2 * i + 1] - xminus >= h):
ind[ix] = Tmi ind[ix] = Tmi
ix += 1 ix += 1
ind[ix] = (Tstart + 2 * i + 1) ind[ix] = (t_start + 2 * i + 1)
ix += 1 ix += 1
# goto L180 continue # goto L180 continue
else: else:
@ -1096,13 +1097,13 @@ def findrfc(tp, h=0.0, method='clib'):
break # goto L170 break # goto L170
if((y[2 * j + 2] <= xplus)): if((y[2 * j + 2] <= xplus)):
xplus = y[2 * j + 2] xplus = y[2 * j + 2]
Tpl = (Tstart + 2 * j + 2) Tpl = (t_start + 2 * j + 2)
j += 1 j += 1
else: else:
if ((y[2 * i + 1] - xminus) >= h): if ((y[2 * i + 1] - xminus) >= h):
ind[ix] = Tmi ind[ix] = Tmi
ix += 1 ix += 1
ind[ix] = (Tstart + 2 * i + 1) ind[ix] = (t_start + 2 * i + 1)
ix += 1 ix += 1
# iy = i # iy = i
continue continue
@ -1113,10 +1114,10 @@ def findrfc(tp, h=0.0, method='clib'):
if ((y[2 * i + 1] - xminus) >= h): if ((y[2 * i + 1] - xminus) >= h):
ind[ix] = Tmi ind[ix] = Tmi
ix += 1 ix += 1
ind[ix] = (Tstart + 2 * i + 1) ind[ix] = (t_start + 2 * i + 1)
ix += 1 ix += 1
elif ((y[2 * i + 1] - xplus) >= h): elif ((y[2 * i + 1] - xplus) >= h):
ind[ix] = (Tstart + 2 * i + 1) ind[ix] = (t_start + 2 * i + 1)
ix += 1 ix += 1
ind[ix] = Tpl ind[ix] = Tpl
ix += 1 ix += 1
@ -1124,9 +1125,7 @@ def findrfc(tp, h=0.0, method='clib'):
# L180: # L180:
# iy=i # iy=i
# /* for i */ # /* for i */
else: return ind, ix
ind, ix = clib.findrfc(y, h)
return np.sort(ind[:ix])
def mctp2rfc(fmM, fMm=None): def mctp2rfc(fmM, fMm=None):

Loading…
Cancel
Save