def running_harmonic(self,omega,windowlength=3*86400.0,overlap=12*3600.0, plot=True): """ Running harmonic fit of the time series at frequency, omega. windowlength - length of each time window [seconds] overlap - overlap between windows [seconds] """ # Make sure that omega is a list try: len(omega) except: omega=[omega] pt1,pt2 = window_index_time(self.t,windowlength,overlap) npt = len(pt1) tmid = [] amp = np.zeros((npt,)) phs = np.zeros((npt,)) ymean = np.zeros((npt,)) ii=-1 for t1,t2 in zip(pt1,pt2): ii+=1 # Perform the harmonic fit on the segment U = uspectra(self.t[t1:t2],self.y[t1:t2],frq=omega,method='lsqfast') # Reference the phase to the start of the time series amp[ii],phs[ii] = U.phsamp(phsbase = self.t[0]) # Return the mid time point ind = np.floor(t1 + (t2-t1)/2) tmid.append(self.t[ind]) # Return the fitted time series ymean[ii] = self.y[t1:t2].mean() #yout[t1:t2] += ymean + U.invfft() tmid = np.asarray(tmid) if plot: plt.subplot(211) self.plot() plt.plot(tmid,ymean,'r') plt.fill_between(tmid,ymean-amp,y2=ymean+amp,color=[0.5,0.5,0.5],alpha=0.5) plt.legend(('Original Signal','Harmonic reconstruction')) ax=plt.subplot(212) plt.fill_between(tmid,amp,alpha=0.5) plt.xticks(rotation=17) plt.ylabel('Amplitude') ax.set_xlim([self.t[0],self.t[-1]]) return tmid, amp, phs
def tidefit(self,frqnames=None,basetime=None,axis=-1): """ Perform a tidal harmonic fit to the data Returns the amp, phase, frequencies and fitted time series """ # Get the tidal fruequencies if frqnames == None: # This returns the default frequencies from the uspectra class frq,frqnames = getTideFreq(Fin=None) else: frq,frqnames = getTideFreq(Fin=frqnames) # Call the uspectra method U = uspectra(self.tsec,self.y,frq=frq,method='lsqfast') amp,phs = U.phsamp(phsbase=basetime) return amp, phs, frq, frqnames, U.invfft()
def tidefit(self, frqnames=None, basetime=None, axis=-1): """ Perform a tidal harmonic fit to the data Returns the amp, phase, frequencies and fitted time series """ # Get the tidal fruequencies if frqnames == None: # This returns the default frequencies from the uspectra class frq, frqnames = getTideFreq(Fin=None) else: frq, frqnames = getTideFreq(Fin=frqnames) # Call the uspectra method U = uspectra(self.tsec, self.y, frq=frq, method='lsqfast') amp, phs = U.phsamp(phsbase=basetime) return amp, phs, frq, frqnames, U.invfft()
def running_harmonic(self, omega, windowlength=3 * 86400.0, overlap=12 * 3600.0, plot=True): """ Running harmonic fit of the time series at frequency, omega. windowlength - length of each time window [seconds] overlap - overlap between windows [seconds] """ # Make sure that omega is a list try: len(omega) except: omega = [omega] pt1, pt2 = window_index_time(self.t, windowlength, overlap) npt = len(pt1) tmid = [] amp = np.zeros((npt, )) phs = np.zeros((npt, )) ymean = np.zeros((npt, )) ii = -1 for t1, t2 in zip(pt1, pt2): ii += 1 # Perform the harmonic fit on the segment U = uspectra(self.t[t1:t2], self.y[t1:t2], frq=omega, method='lsqfast') # Reference the phase to the start of the time series amp[ii], phs[ii] = U.phsamp(phsbase=self.t[0]) # Return the mid time point ind = np.floor(t1 + (t2 - t1) / 2) tmid.append(self.t[ind]) # Return the fitted time series ymean[ii] = self.y[t1:t2].mean() #yout[t1:t2] += ymean + U.invfft() tmid = np.asarray(tmid) if plot: plt.subplot(211) self.plot() plt.plot(tmid, ymean, 'r') plt.fill_between(tmid, ymean - amp, y2=ymean + amp, color=[0.5, 0.5, 0.5], alpha=0.5) plt.legend(('Original Signal', 'Harmonic reconstruction')) ax = plt.subplot(212) plt.fill_between(tmid, amp, alpha=0.5) plt.xticks(rotation=17) plt.ylabel('Amplitude') ax.set_xlim([self.t[0], self.t[-1]]) return tmid, amp, phs