def detide_all(): print "download_data = ",download_data print "save_detided_txt = ",save_detided_txt print "save_plot = ",save_plot p = {k:TG.periods[k] for k in TG.constituents_hawaii} print "Detiding using only harmonic constituents \n %s" % p.keys() plt.figure(1,figsize=(10,10)) plt.figure(2,figsize=(10,10)) for k,gaugeno in enumerate([1612340, 1615680, 1617760]): fname = os.path.join(TGdir, "TG_%s_raw.csv" % gaugeno) if download_data: TG.get_coops_gauge(gaugeno, "20110311","20110313",file_name=fname, verbose=True) t,tsec,eta,pred,res = TG.read_tide_gauge(fname, "05:46:24 UTC on March 11, 2011") print "Read data from ",fname thours = tsec / 3600. eta_fit, eta_offset, eta_amplitude, eta_phase= \ TG.fit_tide_harmonic(thours, eta, periods=p, t0=0, svd_tol=1e-5) if save_detided_txt: fname = os.path.join(TGdir, "TG_%s_detided.txt" % gaugeno) d = numpy.vstack((tsec, eta-eta_fit)).T numpy.savetxt(fname, d) plt.figure(1) plt.subplot(3,1,k+1) plt.plot(thours,eta,'b',label='raw data') plt.plot(thours,eta_fit,'k',label='fit to tide') plt.legend() plt.title("TG %s" % gaugeno) if k==2: plt.xlabel('Hours post quake') plt.figure(2) plt.subplot(3,1,k+1) plt.plot(thours,eta-eta_fit,'b') plt.xlim(6,20) plt.title("Detided data TG %s" % gaugeno) if k==2: plt.xlabel('Hours post quake') plt.show() if save_plot: fname = os.path.join(TGdir, "TG_raw.png") plt.figure(1) plt.savefig(fname) print "Created ",fname fname = os.path.join(TGdir, "TG_detided.png") plt.figure(2) plt.savefig(fname) print "Created ",fname
def detide_u(t,u,gaugeno,component): """ Detide one of the components *u* or *v*. :Input: - *t*, *u* arrays of data - *gaugeno* (int) gauge number, e.g. 1107 - *component* (str) is 'u' or 'v' """ j = ((t>=-20) & (t<=28)) t1 = t[j] u1 = u[j] u1_poly_fit = TG.fit_tide_poly(t1,u1,15) j = find((t>=0) & (t<=25)) t2 = t1[j] u2 = u1[j] u2_poly_fit = u1_poly_fit[j] p = {k:TG.periods[k] for k in TG.constituents_hawaii} print "Using only constituents %s" % p.keys() u1_harmonic_fit, u1_offset, u1_amplitude, u1_phase= \ TG.fit_tide_harmonic(t1, u1, periods=p, t0=0, svd_tol=1e-5) u2_harmonic_fit = u1_harmonic_fit[j] if component=='u': plt.figure(310,figsize=(10,10)) else: plt.figure(311,figsize=(10,10)) plt.clf() plt.subplot(211) plt.plot(t,u,'k',label='Observations') plt.plot(t1,u1_harmonic_fit,'b',label='Harmonic fit') plt.plot(t1,u1_poly_fit,'r',label='Polynomial fit') plt.title('%s-component of velocity at HAI%s' % (component,gaugeno)) plt.legend() plt.subplot(212) plt.plot(t2,u2 - u2_harmonic_fit,'b',label='Residual: harmonic fit') plt.plot(t2,u2 - u2_poly_fit,'r',label='Residual: polynomial fit') plt.xlim(7,14) plt.legend() return t2, u2-u2_harmonic_fit, u2-u2_poly_fit
def detide_u(t, u, gaugeno, component): """ Detide one of the components *u* or *v*. :Input: - *t*, *u* arrays of data - *gaugeno* (int) gauge number, e.g. 1107 - *component* (str) is 'u' or 'v' """ j = ((t >= -20) & (t <= 28)) t1 = t[j] u1 = u[j] u1_poly_fit = TG.fit_tide_poly(t1, u1, 15) j = find((t >= 0) & (t <= 25)) t2 = t1[j] u2 = u1[j] u2_poly_fit = u1_poly_fit[j] p = {k: TG.periods[k] for k in TG.constituents_hawaii} print "Using only constituents %s" % p.keys() u1_harmonic_fit, u1_offset, u1_amplitude, u1_phase= \ TG.fit_tide_harmonic(t1, u1, periods=p, t0=0, svd_tol=1e-5) u2_harmonic_fit = u1_harmonic_fit[j] if component == 'u': plt.figure(310, figsize=(10, 10)) else: plt.figure(311, figsize=(10, 10)) plt.clf() plt.subplot(211) plt.plot(t, u, 'k', label='Observations') plt.plot(t1, u1_harmonic_fit, 'b', label='Harmonic fit') plt.plot(t1, u1_poly_fit, 'r', label='Polynomial fit') plt.title('%s-component of velocity at HAI%s' % (component, gaugeno)) plt.legend() plt.subplot(212) plt.plot(t2, u2 - u2_harmonic_fit, 'b', label='Residual: harmonic fit') plt.plot(t2, u2 - u2_poly_fit, 'r', label='Residual: polynomial fit') plt.xlim(7, 14) plt.legend() return t2, u2 - u2_harmonic_fit, u2 - u2_poly_fit
def detide_and_plot(t,u,gaugeno,component,axes): """ Detide one of the components *u* or *v*. :Input: - *t*, *u* arrays of data - *gaugeno* (int) gauge number, e.g. 1107 - *component* (str) is 'u' or 'v' """ j = ((t>=-20) & (t<=28)) t1 = t[j] u1 = u[j] u1_poly_fit = TG.fit_tide_poly(t1,u1,15) j = find((t>=0) & (t<=25)) t2 = t1[j] u2 = u1[j] u2_poly_fit = u1_poly_fit[j] p = {k:TG.periods[k] for k in TG.constituents_hawaii} print "Using only constituents %s" % p.keys() u1_harmonic_fit, u1_offset, u1_amplitude, u1_phase= \ TG.fit_tide_harmonic(t1, u1, periods=p, t0=0, svd_tol=1e-5) u2_harmonic_fit = u1_harmonic_fit[j] axes.plot(t,u,'k',label='Observations (depth-averaged)') axes.plot(t1,u1_harmonic_fit,'b',label='Harmonic fit to tide') axes.plot(t1,u1_poly_fit,'r',label='Polynomial fit to tide') if component=='u': axes.set_title('u (east-west velocity) at HAI%s' % gaugeno) else: axes.set_title('v (north-south velocity) at HAI%s' % gaugeno) axes.legend(loc='lower left') plt.xlabel("Hours post-quake") plt.ylabel("Speed in cm/sec") return t2, u2-u2_harmonic_fit, u2-u2_poly_fit
def detide_and_plot(t, u, gaugeno, component, axes): """ Detide one of the components *u* or *v*. :Input: - *t*, *u* arrays of data - *gaugeno* (int) gauge number, e.g. 1107 - *component* (str) is 'u' or 'v' """ j = ((t >= -20) & (t <= 28)) t1 = t[j] u1 = u[j] u1_poly_fit = TG.fit_tide_poly(t1, u1, 15) j = find((t >= 0) & (t <= 25)) t2 = t1[j] u2 = u1[j] u2_poly_fit = u1_poly_fit[j] p = {k: TG.periods[k] for k in TG.constituents_hawaii} print "Using only constituents %s" % p.keys() u1_harmonic_fit, u1_offset, u1_amplitude, u1_phase= \ TG.fit_tide_harmonic(t1, u1, periods=p, t0=0, svd_tol=1e-5) u2_harmonic_fit = u1_harmonic_fit[j] axes.plot(t, u, 'k', label='Observations (depth-averaged)') axes.plot(t1, u1_harmonic_fit, 'b', label='Harmonic fit to tide') axes.plot(t1, u1_poly_fit, 'r', label='Polynomial fit to tide') if component == 'u': axes.set_title('u (east-west velocity) at HAI%s' % gaugeno) else: axes.set_title('v (north-south velocity) at HAI%s' % gaugeno) axes.legend(loc='lower left') plt.xlabel("Hours post-quake") plt.ylabel("Speed in cm/sec") return t2, u2 - u2_harmonic_fit, u2 - u2_poly_fit