Exemple #1
0
def run_LSP(valid_times, vals, start_point, end_point, x, max_size, site_ref,
            s_time, time_diff):

    vals = vals[start_point:end_point]
    valid_times = valid_times[start_point:end_point]

    #test if sufficient amount of data is present
    limit = (max_size / 100) * 80
    if len(valid_times) >= limit:

        #change times to go from 0 - for accurate phase
        first_time = s_time
        valid_times = valid_times - s_time

        #window
        window = np.hamming(len(vals))
        mean = np.mean(vals)
        vals = vals - mean
        vals = vals * window

        NOUT = 0.5 * 4 * 1 * len(vals)
        NOUT = int(NOUT)

        #take lomb
        fa, fb, mag, ph = lomb_phase.lomb(valid_times, vals, NOUT)
        periods = 1. / fa
        amp_corr = 1. / (sum(window) / len(window))
        mag = mag * amp_corr

        #calculations for mags and phases of key periods

        closest_daily_period_index = min(
            range(len(periods)), key=lambda i: abs(periods[i] - daily_period))

        #print closest_daily_period_index
        daily_mag = mag[closest_daily_period_index]
        daily_phase = ph[closest_daily_period_index]

        #correct phase from UTC to solar time

        correction_f = ((2 * np.pi) / 24) * time_diff
        daily_phase = daily_phase + (correction_f)
        if daily_phase < -np.pi:
            diff = np.abs(daily_phase) - np.pi
            daily_phase = np.pi - diff
        if daily_phase > np.pi:
            diff = np.abs(daily_phase) - np.pi
            daily_phase = -np.pi + diff

        #convert phase to hours

        daily_phase = modules.convert_phase_units_actual_single(
            daily_phase, 24)

    else:
        print 'nan'
        daily_mag = float('NaN')
        daily_phase = float('NaN')

    return (daily_mag, daily_phase, site_ref)
Exemple #2
0
        #Obs. lomb
        window = signal.hamming(len(obs_vals))
        obs_mean = np.mean(obs_vals)
        obs_vals = obs_vals - obs_mean
        obs_vals = obs_vals * window

        #processing to determine freq range
        OFAC = 1
        HIFAC = 1

        NOUT = 0.5 * OFAC * HIFAC * len(obs_vals)
        NOUT = int(NOUT)
        SAMP_R = 1. / 24

        #take lomb
        fa, fb, mag, ph, sig, i_freq, s_val_ind, end_val_ind = lomb_phase.lomb(
            obs_time, obs_vals, NOUT, OFAC, SAMP_R)
        #limit arrays by valid indices determine in fortran code
        fa = fa[s_val_ind:end_val_ind]
        fb = fb[s_val_ind:end_val_ind]
        mag = mag[s_val_ind:end_val_ind]
        ph = ph[s_val_ind:end_val_ind]
        sig = sig[s_val_ind:end_val_ind]

        obs_periods = 1. / fa

        obs_periods = np.log(obs_periods)
        mag = np.log(mag)

        reversed_obs_periods = obs_periods[::-1]
        reversed_obs_amp = mag[::-1]
        reversed_sig = sig[::-1]
Exemple #3
0
    #model_frequencies, fft_model, fft_phase = model_frequencies[keep_freq], fft_model[keep_freq], fft_phase[keep_freq]
    #model_periods = 1 /model_frequencies

    #fft_model = fft_model/(len(read)/2)
    #fft_model = np.array(fft_model)

    #LSP
    window = np.kaiser(len(read), 4)
    obs_mean = np.mean(read)
    read = read - obs_mean
    read = read * window

    NOUT = 0.5 * 1 * 1 * len(read)
    NOUT = int(NOUT)

    fa, fb, fft_model, fft_phase = lomb_phase.lomb(times, read, NOUT)
    model_periods = 1. / fa
    amp_corr = 1. / (sum(window) / len(window))
    fft_model = fft_model * amp_corr

    #calculations for mags and phases of key periods

    closest_daily_period_index = min(
        range(len(model_periods)),
        key=lambda i: abs(model_periods[i] - daily_period))
    closest_half_annual_period_index = min(
        range(len(model_periods)),
        key=lambda i: abs(model_periods[i] - half_annual_period))
    closest_annual_period_index = min(
        range(len(model_periods)),
        key=lambda i: abs(model_periods[i] - annual_period))
Exemple #4
0
cos_waveform2 = half_annual_amplitude * (np.cos((pi2 * b / (365.25 / 2)) - 0))
cos_waveform3 = annual_amplitude * (np.sin((pi2 * b / 365.25) + (0)))

#cos_waveform1 = daily_amplitude*(np.cos((pi2*b/10)+(0)))
#cos_waveform1 = daily_amplitude*(np.cos((pi2*b/1)-(0)))
vals = 50 + (cos_waveform1 + cos_waveform2 + cos_waveform3)

window = np.hanning(len(vals))
mean = np.mean(vals)
vals = vals - mean
vals = vals * window

NOUT = 0.5 * 4 * 1 * len(vals)
NOUT = int(NOUT)

fa, fb, mag, ph = lomb_phase.lomb(b, vals, NOUT)
periods = 1. / fa
amp_corr = 1. / (sum(window) / len(window))
mag = mag * amp_corr

print np.min(ph)
print np.max(ph)

closest_daily_period_index = min(range(len(periods)),
                                 key=lambda i: abs(periods[i] - daily_period))

print periods[closest_daily_period_index + 1]

daily_mag = mag[closest_daily_period_index]
daily_phase = ph[closest_daily_period_index]
Exemple #5
0
        #window = np.kaiser(len(obs_vals),4)
        #window = signal.flattop(len(obs_vals))
        obs_mean = np.mean(obs_vals)
        obs_vals = obs_vals - obs_mean
        obs_vals = obs_vals * window
        #fa, fb, obs_amp, ph= lomb.fasper(obs_time,obs_vals)
        #annual_index = np.argmin(np.abs(1./fa - 365.25))
        #print 1./(fa[annual_index])
        #obs_periods = 1./fa
        NOUT = 0.5 * 4 * 1 * len(obs_vals)
        NOUT = int(NOUT)
        #take lomb
        print NOUT
        print len(obs_time)
        print len(obs_vals)
        fa, fb, mag, ph, sig = lomb_phase.lomb(obs_time, obs_vals, NOUT)
        print sig
        amp_corr = 1. / (sum(window) / len(window))
        obs_amp = mag * amp_corr

        #annual_index = np.argmin(np.abs(obs_periods - 1))
        #print 'annual obs= ', obs_amp[annual_index]
        #sigs = lomb.getSignificance(fa,fb,nout,ofac)
        #Divide output by sampling frequency
        #fb = fb/samp_freq
        #print len(fa)
        #print len(sigs)

        #signi_99, signi_95, signi_90, signi_50 = lomb.false_alarm_threshold_first_approx(nout)

        #print signi_95
Exemple #6
0
frequencies = fftfreq(cosine_wave.size, d=samp_spacing)
keep_freq = frequencies > 0
frequencies, fft_model = frequencies[keep_freq], fft_model[keep_freq]
model_periods = 1 / frequencies
fft_model = fft_model / len(cosine_wave)
#fft_model = fft_model/samp_freq

#Calculate Nyquist frequency, Si and Si x 2 for normalisation checks.
#nyquist_freq_lomb_model = frequencies[-1]
#Si_lomb_model = np.mean(fft_model)*nyquist_freq_lomb_model
#print nyquist_freq_lomb_model, Si_lomb_model, Si_lomb_model*2

#print 'Time series amplitude = ', np.var(cosine_wave)

#Model lomb
fx, fy, vari, F = lomb_phase.lomb(time, cosine_wave)

#print F

magnitude = np.abs(F[1:])

#Divide output by sampling frequency
#fy = fy/samp_freq

#get amplitude
#amplitude = [np.sqrt(a**2 + b**2) for a,b in zip(real,imag)]
#amplitude = np.array(amplitude)
#amplitude = np.sqrt(fy*2*vari*2/float(len(cosine_wave)))
magnitude = magnitude / len(cosine_wave)

#print amplitude
Exemple #7
0
        valid = vals > 0
        vals = vals[valid]
        #print 'vals len =', len(vals)
        valid_times = chunk_times[valid]

        if len(valid_times) > 0:
            window = np.hamming(len(vals))
            mean = np.mean(vals)
            vals = vals - mean
            vals = vals * window

            NOUT = 0.5 * 4 * 1 * len(vals)
            NOUT = int(NOUT)

            #print NOUT
            fa, fb, mag, ph = lomb_phase.lomb(valid_times, vals, NOUT)
            periods = 1. / fa
            amp_corr = 1. / (sum(window) / len(window))
            mag = mag * amp_corr

            #calculations for mags and phases of key periods

            closest_daily_period_index = min(
                range(len(periods)),
                key=lambda i: abs(periods[i] - daily_period))

            #print closest_daily_period_index
            daily_mag = mag[closest_daily_period_index]
            daily_phase = ph[closest_daily_period_index]

        else: