コード例 #1
0
def main_arg(x, y, grid_count):
    print grid_count
    ofac = 4

    #average dt of entire time series
    diffs = [x[i + 1] - x[i] for i in range(len(x) - 1)]
    avgdt = np.average(diffs)

    #make time start from 0
    x_from0 = modules.phase_start_correct(x)

    periods, mag, ph, fr, fi, amp_corr = modules.take_lomb(
        x_from0, y, ofac, avgdt)

    #get mean of values
    mean_array = np.average(y)

    #correct magnitude and phase for spectral leakage
    zoomfact = 1000
    half_annual_mag, half_annual_phase = modules.periodic_interp(
        fr, fi, zoomfact, periods, 365.25 / 2., len(y), amp_corr)
    annual_mag, annual_phase = modules.periodic_interp(fr, fi, zoomfact,
                                                       periods, 365.25, len(y),
                                                       amp_corr)

    #correct for phase shift as data starts in Oct 2004
    n_off = 273.25

    if n_off > 365.25 / 2:
        n_off = n_off - (365.25 / 2)
    offset = ((np.pi * 2) / (365.25 / 2)) * n_off
    half_annual_phase = half_annual_phase + offset
    if half_annual_phase > np.pi:
        half_annual_phase = -np.pi + (half_annual_phase - np.pi)

    n_off = 273.25
    offset = ((np.pi * 2) / (365.25)) * n_off
    annual_phase = annual_phase + offset
    if annual_phase > np.pi:
        annual_phase = -np.pi + (annual_phase - np.pi)

    #convert phase to time
    half_annual_phase = modules.convert_phase_units_actual_single(
        half_annual_phase, 6)
    annual_phase = modules.convert_phase_units_actual_single(annual_phase, 12)

    #np.save('mags_phases/mag_spectrums/%i'%(grid_count),mag)
    #np.save('mags_phases/phase_spectrums/%i'%(grid_count),ph)
    #np.save('mags_phases/periods',periods)
    return (half_annual_mag, half_annual_phase, annual_mag, annual_phase,
            mean_array)
コード例 #2
0
def main_arg(x,y,grid_count):  
    print grid_count
    ofac = 4

    #average dt of entire time series
    diffs = [x[i+1]-x[i] for i in range(len(x)-1)]  
    avgdt = np.average(diffs)

    #make time start from 0    
    x_from0 = modules.phase_start_correct(x)

    periods,mag,ph,fr,fi,amp_corr = modules.take_lomb(x_from0,y,ofac,avgdt)

    #get mean of values
    mean_array = np.average(y)

    #correct magnitude and phase for spectral leakage 
    zoomfact = 1000
    half_annual_mag,half_annual_phase = modules.periodic_interp(fr,fi,zoomfact,periods,365.25/2.,len(y),amp_corr)
    annual_mag,annual_phase = modules.periodic_interp(fr,fi,zoomfact,periods,365.25,len(y),amp_corr)

    #correct for phase shift as data starts in Oct 2004 
    n_off = 273.25
    
    if n_off > 365.25/2:
        n_off = n_off-(365.25/2)
    offset = ((np.pi*2)/(365.25/2))*n_off
    half_annual_phase = half_annual_phase + offset
    if half_annual_phase > np.pi:
        half_annual_phase = -np.pi + (half_annual_phase - np.pi)

    n_off = 273.25
    offset = ((np.pi*2)/(365.25))*n_off
    annual_phase = annual_phase + offset
    if annual_phase > np.pi:
        annual_phase = -np.pi + (annual_phase - np.pi)

    #convert phase to time
    half_annual_phase = modules.convert_phase_units_actual_single(half_annual_phase,6)
    annual_phase = modules.convert_phase_units_actual_single(annual_phase,12)
    
    #np.save('mags_phases/mag_spectrums/%i'%(grid_count),mag)
    #np.save('mags_phases/phase_spectrums/%i'%(grid_count),ph)
    #np.save('mags_phases/periods',periods)
    return (half_annual_mag,half_annual_phase,annual_mag,annual_phase,mean_array)
コード例 #3
0
 #print '\nLOMB WINDOWED, OVERSAMPLED'
 #print 'Est. Amplitude 1 = ',mag1
 #print 'Est. Phase 1 = ',phase1
 #print 'Est. Amplitude 2 = ',mag2
 #print 'Est. Phase 2 = ',phase2
 #print '------------------------------------------\n'
 
 #Lomb WINDOWED, OVERSAMPLED, INTERPOLATED
 #-----------------------------------------------
 ofac = 4
 periods,mag,ph,fr,fi,amp_corr = modules.take_lomb(b,vals,ofac,hourly_step,w=True)   
 closest_period_1 = min(range(len(periods)), key=lambda i: abs(periods[i]-p1))
 closest_period_2 = min(range(len(periods)), key=lambda i: abs(periods[i]-p2)) 
 
 try:
     mag1,phase1 = modules.periodic_interp(fr,fi,1000,periods,p1,len(vals),amp_corr,window='hanning')
 except:
     mag1 = np.nan
     phase1 = np.nan
 
 try:
     mag2,phase2 = modules.periodic_interp(fr,fi,1000,periods,p2,len(vals),amp_corr,window='hanning')        
 except:
     mag2 = np.nan
     phase2 = np.nan
     
 diff_a1 = (mag1/amp1)*100.
 diff_a2 = (mag2/amp2)*100.
 diff_p1 = phase_1 - phase1
 if diff_p1 > np.pi:
     diff_p1 = np.abs(-np.pi + (diff_p1 - np.pi))
コード例 #4
0
#convert site_lon to 0 to 360 degs
if obs_lon < 0:
    obs_lon = 360-np.abs(obs_lon)
    
#transform from UTC time to solar time 
sun_time = lon_step_time*obs_lon
print 'sun time = ', sun_time
time_diff = sun_time - 0
if time_diff > 12:
    time_diff = time_diff-24
print 'time diff =', time_diff


#correct magnitude and phase for spectral leakage 
zoomfact = 1000
daily_obs_mag,daily_obs_phase = modules.periodic_interp(obs_fr,obs_fi,zoomfact,obs_periods,1.,len(obs_var),obs_amp_corr)
daily_model_mag,daily_model_phase = modules.periodic_interp(model_fr,model_fi,zoomfact,model_periods,1.,len(model_var),model_amp_corr)
ha_obs_mag,ha_obs_phase = modules.periodic_interp(obs_fr,obs_fi,zoomfact,obs_periods,(365.25/2.),len(obs_var),obs_amp_corr)
ha_model_mag,ha_model_phase = modules.periodic_interp(model_fr,model_fi,zoomfact,model_periods,(365.25/2.),len(model_var),model_amp_corr)
annual_obs_mag,annual_obs_phase = modules.periodic_interp(obs_fr,obs_fi,zoomfact,obs_periods,365.25,len(obs_var),obs_amp_corr)
annual_model_mag,annual_model_phase = modules.periodic_interp(model_fr,model_fi,zoomfact,model_periods,365.25,len(model_var),model_amp_corr)

#correct for phase shift from sites where raw times do not start from 0
daily_obs_phase = modules.phase_start_point_correct(1.,daily_obs_phase,obs_time)
daily_model_phase = modules.phase_start_point_correct(1.,daily_model_phase,model_time)
ha_obs_phase = modules.phase_start_point_correct((365.25/2.),ha_obs_phase,obs_time)
ha_model_phase = modules.phase_start_point_correct((365.25/2.),ha_model_phase,model_time)
annual_obs_phase = modules.phase_start_point_correct(365.25,annual_obs_phase,obs_time)
annual_model_phase = modules.phase_start_point_correct(365.25,annual_model_phase,model_time)

#convert phase to time
コード例 #5
0
 #Lomb WINDOWED, OVERSAMPLED, INTERPOLATED
 #-----------------------------------------------
 ofac = 4
 periods, mag, ph, fr, fi, amp_corr = modules.take_lomb(b,
                                                        vals,
                                                        ofac,
                                                        hourly_step,
                                                        w=True)
 closest_period_1 = min(range(len(periods)),
                        key=lambda i: abs(periods[i] - p1))
 closest_period_2 = min(range(len(periods)),
                        key=lambda i: abs(periods[i] - p2))
 daily_mag1, daily_phase1 = modules.periodic_interp(fr,
                                                    fi,
                                                    1000,
                                                    periods,
                                                    p1,
                                                    len(vals),
                                                    amp_corr,
                                                    window='hanning')
 daily_mag2, daily_phase2 = modules.periodic_interp(fr,
                                                    fi,
                                                    1000,
                                                    periods,
                                                    p2,
                                                    len(vals),
                                                    amp_corr,
                                                    window='hanning')
 print '\nLOMB WINDOWED, OVERSAMPLED, INTERPOLATED'
 print 'Est. Amplitude 1 = ', daily_mag1
 print 'Est. Phase 1 = ', daily_phase1
 print 'Est. Amplitude 2 = ', daily_mag2
コード例 #6
0
]
full_obs_datetimes = np.array(full_obs_datetimes)
obs_datetimes = full_obs_datetimes[valids]

obs_ave = np.mean(obs_var)

#make time start from 0
obs_times_from0 = modules.phase_start_correct(obs_times)

#remove invalid data
periods, mag, ph, fr, fi, amp_corr = modules.take_lomb(obs_times_from0,
                                                       obs_var, 4, 1. / 24)

zoomfact = 1000

daily_amp, daily_phase = modules.periodic_interp(fr, fi, zoomfact, periods, 1.,
                                                 len(obs_var), amp_corr)
ha_amp, ha_phase = modules.periodic_interp(fr, fi, zoomfact, periods,
                                           365.25 / 2., len(obs_var), amp_corr)
annual_amp, annual_phase = modules.periodic_interp(fr, fi,
                                                   zoomfact, periods, 365.25,
                                                   len(obs_var), amp_corr)

#correct for phase shift from sites where raw times do not start from 0
daily_phase = modules.phase_start_point_correct(1., daily_phase, obs_times)
ha_phase = modules.phase_start_point_correct(365.25 / 2., ha_phase, obs_times)
annual_phase = modules.phase_start_point_correct(365.25, annual_phase,
                                                 obs_times)

lon_step_time = 24. / 360.

#convert site_lon to 0 to 360 degs
コード例 #7
0
interp_fr_peak = interp_fr[closest_period_index_3]
interp_fi_peak = interp_fi[closest_period_index_3]

plt.plot(new_periods, interp_fi, label='Cubic Spline Interpolation')

print 'Cubic Spline Interpolated fr = ', interp_fr_peak
print 'Cubic Spline Interpolated fi = ', interp_fi_peak

print 'Cubic Spline Interpolated Amp = ', np.abs(
    complex(interp_fr_peak, interp_fi_peak))
print 'Cubic Spline Interpolated Phase = ', np.angle(
    complex(interp_fr_peak, interp_fi_peak))

zoomfact = 998

interp_amp, interp_phase, newreal, newx = modules.periodic_interp(
    fr, fi, zoomfact, periods, 1.1, len(vals), amp_corr)

plt.axvline(1.1)
plt.plot(newx, newreal, label='Hann Window Interpolation')
plt.legend()

plt.show()

print 'Hann Interpolated Amp = ', interp_amp
print 'Hann Interpolated Phase = ', interp_phase

#print 'yeah =', np.abs(complex(peak_real_max,peak_imag_max))

#peak_real = peak_fr
#peak_imag = peak_fi