def ampoffset(time, data): pt, pv = peaks.conservative_peaks(time, data, pktype="peak") tt, tv = peaks.conservative_peaks(time, data, pktype="trough") tspl = UnivariateSpline(tt, tv, k=4, s=0) pspl = UnivariateSpline(pt, pv, k=4, s=0) off = tspl(time) + 0.5 * (pspl(time) - tspl(time)) amp = 0.5 * (pspl(time) - tspl(time)) return amp, off
def get_peaks(time, data, pktype="peak", refine=True, refine_pktype="peak", Npk=5, polyorder=3, splorder=3, minidx=200, peak_method="spline"): if pktype == "joined": pt, pv = peak.joined_peaks(time, data, refine=refine, refine_pktype=refine_pktype, Npk=Npk, polyorder=polyorder, splorder=splorder, minidx=minidx, peak_method=peak_method) joined = True else: pt, pv = peak.conservative_peaks(time, data, refine=refine, refine_pktype=refine_pktype, Npk=Npk, polyorder=polyorder, splorder=splorder, minidx=minidx, peak_method=peak_method) joined = False return pt, pv, joined
def resonant_trajectory(t, x1, x2, t_left, t_right, Npts=10000, refinex1=False, t_res=None): if refinex1: pt, pv, p_ref, pv_unref = pk.conservative_peaks(t, x1, returnrefined=True) x1spl = UnivariateSpline(t, p_ref, k=4, s=0) else: x1spl = UnivariateSpline(t, x1, k=4, s=0) x2spl = UnivariateSpline(t, x2, k=4, s=0) t_traj = np.linspace(t_left, t_right, Npts) x1_traj = x1spl(t_traj) x2_traj = x2spl(t_traj) return [x1_traj, x2_traj]
def even_sampled_omega(orbpath, ptsperorbit=1000, method="savgol", return_cos=False): rraw = loadfile(orbpath) rmagraw = np.sqrt(rraw[:, 1]**2 + rraw[:, 2]**2 + rraw[:, 3]**2) pt, pv = peaks.conservative_peaks(rraw[:, 0], rmagraw, refine=False) norbits = len(pt) print "Norbits: ", norbits npts = norbits * ptsperorbit return even_sampled_omega_npts(orbpath, npts, method=method, return_cos=return_cos)
def omega_theta(thtime, theta, pktime, pkdata, N=1, minidx=200, refine=True): #Njoined = N*2 #Njoined = N pkt, pkv = peaks.conservative_peaks(pktime, pkdata, refine=True, minidx=minidx) chi = monotonic_acos(thtime, theta, tnew=pkt, unwrap=True) t0s, tfs, dT, tmids = window_ranges(pkt, N) dChi = np.array(chi[N:] - chi[:-N]) omths = dChi / dT outarr = np.column_stack((tmids, omths)) return outarr
def orbits_on_resonance(t, r, t_left, t_right, refine=True): pt, pv = pk.conservative_peaks(t, r, refine=refine, minidx=200) argl = np.argmin(np.abs(pt - t_left)) argr = np.argmin(np.abs(pt - t_right)) return argr-argl