def run_LSP(vals,x):

    print obs_refs[x]
    
    #check obs vals are valid
    valid = vals >= 0
    vals = vals[valid]
    valid_times = obs_ref_time[valid]

    #full_times = modules.date_process(obs_dates,obs_times,start_year)
    full_times_year = obs_ref_time[:8766]
    full_times_day = obs_ref_time[:24]
    
    #make time start from 0    
    valid_times_from0 = modules.phase_start_correct(valid_times)
    
    samp_step = 1./24
    f = interpolate.interp1d(valid_times_from0, vals)
    valid_times_from0 = np.arange(np.min(valid_times_from0),np.max(valid_times_from0),samp_step) 
    vals =  f(valid_times_from0)
      
    site_lon = obs_lons[x]

    #convert site_lon to 0 to 360 degs
    if site_lon < 0:
        site_lon = 360-np.abs(site_lon)
    
    #transform from UTC time to solar time 
    sun_time = lon_step_time*site_lon
    time_diff = sun_time - 0
    if time_diff > 12:
        time_diff = time_diff-24

    #take obs lsp
    ofac = 1
    periodic_periods = [1./10.,1./9.,1./8.,1./7.,1./6.,1./5.,1./4.,1./3.,1./2.,1.,365.25/4.,365.25/3.,365.25/2.,365.25]
    
    #periods,mag,ph,fr,fi,amp_corr = modules.take_lomb(valid_times_from0,vals,ofac,samp_step,w=True,kp=periodic_periods)
    periods,mag,ph,fr,fi,fft_array,amp_corr = modules.take_fft(valid_times_from0,vals,ofac,samp_step,w=True,kp=periodic_periods)
    
    #convert mag to normalised psd
    psd_mag = mag**2
    freq =  1./periods
    diff = freq[1] - freq[0]
    psd_mag = psd_mag/diff
    
    #get info of weather regimes through model fit.
    grad1,grad2,bp1,line1_periods,line1_mag,line2_periods,line2_mag,ave1,ave2,med1,med2,sum1,sum2,line1_s,line1_e,line2_s,line2_e = modules.spectra_fit_fixed_piecewise(periods,psd_mag,ofac,3.0,100.0,10.0)
    
    #get mean of values
    mean_array = np.average(vals)

    #correct all phases for start point (not actually being from 0 - just corrected to be)
    ph = modules.phase_start_point_correct_all(periods,ph,valid_times)

    #convert phase to time(days)
    ph = modules.convert_phase_units_actual_all(ph,periods)
        
    return (x,periods,psd_mag,ph,grad1,grad2,bp1,line1_periods,line1_mag,line2_periods,line2_mag,ave1,ave2,med1,med2,sum1,sum2,line1_s,line1_e,line2_s,line2_e)
def run_LSP(vals,x):

    lat_i = lat_indices[x]
    lon_i = lon_indices[x]

    print lat_i,lon_i

    current_lat = lat_c[lat_i]
    current_lon = lon_c[lon_i]
    site_lon = lon_c[lon_i]
    
    valid = vals >= 0
    vals = vals[valid]
    valid_times = model_ref_time[valid]
 
    full_times_year = model_ref_time[:8766]
    full_times_day = model_ref_time[:24]
      
    #convert site_lon to 0 to 360 degs
    if site_lon < 0:
        site_lon = 360-np.abs(site_lon)
    
    #transform from UTC time to solar time 
    sun_time = lon_step_time*site_lon
    time_diff = sun_time - 0
    if time_diff > 12:
        time_diff = time_diff-24
             
    #make time start from 0    
    valid_times_from0 = modules.phase_start_correct(valid_times)

    ofac = 1
    samp_step = 1./24
    periodic_periods = [1./10.,1./9.,1./8.,1./7.,1./6.,1./5.,1./4.,1./3.,1./2.,1.,365.25/4.,365.25/3.,365.25/2.,365.25]
    #periods,mag,ph,fr,fi,amp_corr = modules.take_lomb(valid_times_from0,vals,ofac,samp_step,w=True,kp=periodic_periods)
    periods,mag,ph,fr,fi,fft_array,amp_corr = modules.take_fft(valid_times_from0,vals,ofac,samp_step,w=True,kp=periodic_periods)
    
    #convert mag to normalised psd
    psd_mag = mag**2
    freq =  1./periods
    diff = freq[1] - freq[0]
    psd_mag = psd_mag/diff
    
    #get info of weather regimes through model fit.
    grad1,grad2,bp1,line1_periods,line1_mag,line2_periods,line2_mag,ave1,ave2,med1,med2,sum1,sum2,line1_s,line1_e,line2_s,line2_e = modules.spectra_fit_fixed_piecewise(periods,psd_mag,ofac,3.0,100.0,10.0)
    
    #get mean of values
    mean_array = np.average(vals)

    #correct all phases for start point (not actually being from 0 - just corrected to be)
    ph = modules.phase_start_point_correct_all(periods,ph,valid_times)

    #convert phase to time(days)
    ph = modules.convert_phase_units_actual_all(ph,periods)
        
    return (x,periods,psd_mag,ph,grad1,grad2,bp1,line1_periods,line1_mag,line2_periods,line2_mag,ave1,ave2,med1,med2,sum1,sum2,line1_s,line1_e,line2_s,line2_e)
Exemplo n.º 3
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)
def run_LSP(vals,x):

    lat_i = lat_indices[x]
    lon_i = lon_indices[x]

    print lat_i,lon_i

    current_lat = lat_c[lat_i]
    current_lon = lon_c[lon_i]
    site_lon = lon_c[lon_i]
 
    #check model vals are valid
    valid = vals >= 0
    vals = vals[valid]
    valid_times = model_ref_time[valid]
    
    full_times_year = model_ref_time[:8766]
    full_times_day = model_ref_time[:24] 
    
    #convert site_lon to 0 to 360 degs
    if site_lon < 0:
        site_lon = 360-np.abs(site_lon)
    
    #transform from UTC time to solar time 
    sun_time = lon_step_time*site_lon
    time_diff = sun_time - 0
    if time_diff > 12:
        time_diff = time_diff-24
             
    #make time start from 0    
    valid_times_from0 = modules.phase_start_correct(valid_times)

    ofac = 4
    samp_step = 1./24
    periods,mag,ph,fr,fi,amp_corr = modules.take_lomb(valid_times_from0,vals,ofac,samp_step,w=True,kp=[1./4.,1./3.,1./2.,1.,365.25/4.,365.25/3.,365.25/2.,365.25])
    
    #get info of weather regimes through model fit.
    grad1,grad2,grad3,bp1,bp2,bp_periods,bp_mag = modules.spectra_fit(periods,mag,ofac)
    
    #get mean of values
    mean_array = np.average(vals)

    #correct all phases for start point
    ph = modules.phase_start_point_correct_all(periods,ph,valid_times)

    #convert phase to time(days)
    ph = modules.convert_phase_units_actual_all(ph,periods)
        
    return (x,periods,mag,ph,grad1,grad2,grad3,bp1,bp2,bp_mag)
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)
Exemplo n.º 6
0
def run_LSP(model_data, x):

    print obs_refs[x]

    vals = model_data

    #check obs vals are valid
    valid = vals >= 0
    vals = vals[valid]
    model_time_val = model_time[valid]
    model_date_val = model_date[valid]

    full_times = modules.date_process(model_date, model_time, start_year)
    if timeres == 'M':
        full_times_year = full_times[:12]
    else:
        full_times_year = full_times[:8766]
    full_times_day = full_times[:24]

    valid_times = modules.date_process(model_date_val, model_time_val,
                                       start_year)

    site_lon = obs_lons[x]

    #convert site_lon to 0 to 360 degs
    if site_lon < 0:
        site_lon = 360 - np.abs(site_lon)

    #transform from UTC time to solar time
    sun_time = lon_step_time * site_lon
    time_diff = sun_time - 0
    if time_diff > 12:
        time_diff = time_diff - 24

    #make time start from 0
    valid_times_from0 = modules.phase_start_correct(valid_times)

    periodic_periods = [
        1. / 4., 1. / 3., 1. / 2., 1., 365.25 / 4., 365.25 / 3., 365.25 / 2.,
        365.25
    ]
    periods, mag, ph, fr, fi = modules.take_lomb_spec(
        valid_times_from0, vals, w=True, key_periods=periodic_periods)

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

    #correct all phases for start point (not actually being from 0 - just corrected to be)
    ph = modules.phase_start_point_correct_all(periodic_periods, ph,
                                               valid_times)

    key_diurnal_periods = [1. / 4., 1. / 3., 1. / 2., 1.]
    key_seasonal_periods = [365.25 / 4., 365.25 / 3., 365.25 / 2., 365.25]

    diurnal_mags = mag[:4]
    seasonal_mags = mag[4:]
    seasonal_phs = ph[4:]

    #get individual mags and phases
    daily_h3_mag = mag[0]
    daily_h2_mag = mag[1]
    daily_h1_mag = mag[2]
    orig_daily_mag = mag[3]
    daily_h3_ph = ph[0]
    daily_h2_ph = ph[1]
    daily_h1_ph = ph[2]
    orig_daily_ph = ph[3]

    seasonal_h3_mag = mag[4]
    seasonal_h2_mag = mag[5]
    seasonal_h1_mag = mag[6]
    annual_mag = mag[7]
    seasonal_h3_ph = ph[4]
    seasonal_h2_ph = ph[5]
    seasonal_h1_ph = ph[6]
    annual_ph = ph[7]

    #convert sub diurnal phases from UTC to solar time
    daily_h3_ph = modules.solar_time_phase_corrector(daily_h3_ph, 6, time_diff)
    daily_h2_ph = modules.solar_time_phase_corrector(daily_h2_ph, 24. / 3.,
                                                     time_diff)
    daily_h1_ph = modules.solar_time_phase_corrector(daily_h1_ph, 12,
                                                     time_diff)
    orig_daily_ph = modules.solar_time_phase_corrector(orig_daily_ph, 24,
                                                       time_diff)
    diurnal_phs = [daily_h3_ph, daily_h2_ph, daily_h1_ph, orig_daily_ph]

    #convolve annual cycle and harmonics to seasonal waveform for 1 year
    seasonal_mag, seasonal_min_ph, seasonal_max_ph, seasonal_waveform, seasonal_ff = modules.period_convolution(
        key_seasonal_periods, full_times_year, seasonal_mags, seasonal_phs,
        mean_array)

    #convolve diurnal cycle and harmonics to diurnal waveform for 1 day
    diurnal_mag, diurnal_min_ph, diurnal_max_ph, diurnal_waveform, diurnal_ff = modules.period_convolution(
        key_diurnal_periods, full_times_day, diurnal_mags, diurnal_phs,
        mean_array)

    #convolve all
    full_mag, full_min_ph, full_max_ph, full_waveform, full_ff = modules.period_convolution(
        periodic_periods, full_times, mag, ph, mean_array)

    #convert phase to time
    daily_h3_ph = modules.convert_phase_units_actual_single(daily_h3_ph, 6.)
    daily_h2_ph = modules.convert_phase_units_actual_single(
        daily_h2_ph, 24. / 3.)
    daily_h1_ph = modules.convert_phase_units_actual_single(daily_h1_ph, 12.)
    orig_daily_ph = modules.convert_phase_units_actual_single(
        orig_daily_ph, 24.)
    diurnal_min_ph = modules.convert_phase_units_actual_single(
        diurnal_min_ph, 24.)
    diurnal_max_ph = modules.convert_phase_units_actual_single(
        diurnal_max_ph, 24.)
    seasonal_h3_ph = modules.convert_phase_units_actual_single(
        seasonal_h3_ph, 3.)
    seasonal_h2_ph = modules.convert_phase_units_actual_single(
        seasonal_h2_ph, 4.)
    seasonal_h1_ph = modules.convert_phase_units_actual_single(
        seasonal_h1_ph, 6.)
    annual_ph = modules.convert_phase_units_actual_single(annual_ph, 12.)
    seasonal_min_ph = modules.convert_phase_units_actual_single(
        seasonal_min_ph, 12.)
    seasonal_max_ph = modules.convert_phase_units_actual_single(
        seasonal_max_ph, 12.)

    return (x, daily_h3_mag, daily_h3_ph, daily_h2_mag, daily_h2_ph,
            daily_h1_mag, daily_h1_ph, orig_daily_mag, orig_daily_ph,
            diurnal_mag, diurnal_min_ph, diurnal_max_ph, seasonal_h3_mag,
            seasonal_h3_ph, seasonal_h2_mag, seasonal_h2_ph, seasonal_h1_mag,
            seasonal_h1_ph, annual_mag, annual_ph, seasonal_mag,
            seasonal_min_ph, seasonal_max_ph, mean_array, diurnal_waveform,
            seasonal_waveform, full_waveform)
Exemplo n.º 7
0
def run_LSP(obs_time,site_lon,x):

    data_valid = True

    #print 'lev %s'%(x)
    
    full_times_year = np.arange(0,365,1.)
    
    #check obs vals are valid
    valid = vals >= 0
    vals = vals[valid]
    valid_times = obs_time[valid]

    #if length of vals is zero then class as invalid immediately
    if len(vals) == 0:
        data_valid = False
    else:
        #test if there if data is valid to process at each height for each site
        #data should not have gaps > 1 year or 
        time_gaps = np.diff(valid_times)                
        inv_count = 0
        max_count = round(n_years/2.)
        for i in time_gaps:
            if i > 90:
                inv_count+=1
                if inv_count >= max_count:
                    data_valid = False
                    print 'Persisent Data gap > 3 months'
                    break
            if i > 365:
                    data_valid = False
                    print 'Data gap > 1 Year'
                    break

    if data_valid == True:
    
        #convert site_lon to 0 to 360 degs
        if site_lon < 0:
            site_lon = 360-np.abs(site_lon)

        #make time start from 0    
        valid_times_from0 = modules.phase_start_correct(valid_times)

        periodic_periods = [365.25/4.,365.25/3.,365.25/2.,365.25]
        periods,mag,ph,fr,fi = modules.take_lomb_spec(valid_times_from0,vals,w=True,key_periods=periodic_periods)

        #get mean of values
        mean_array = np.average(vals)
    
        #correct all phases for start point (not actually being from 0 - just corrected to be)
        ph = modules.phase_start_point_correct_all(periodic_periods,ph,valid_times)

        key_seasonal_periods = [365.25/4.,365.25/3.,365.25/2.,365.25]

        seasonal_mags = mag[:]
        seasonal_phs = ph[:]

        seasonal_h3_mag = mag[0]
        seasonal_h2_mag = mag[1]
        seasonal_h1_mag = mag[2]
        annual_mag = mag[3]
        seasonal_h3_ph = ph[0]
        seasonal_h2_ph = ph[1]
        seasonal_h1_ph = ph[2]
        annual_ph = ph[3]

        #convolve annual cycle and harmonics to seasonal waveform for 1 year
        seasonal_mag,seasonal_min_ph,seasonal_max_ph,seasonal_waveform,seasonal_ff = modules.period_convolution(key_seasonal_periods,full_times_year,seasonal_mags,seasonal_phs,mean_array)
        
        #convert phase to time
        seasonal_h3_ph = modules.convert_phase_units_actual_single(seasonal_h3_ph,3.)
        seasonal_h2_ph = modules.convert_phase_units_actual_single(seasonal_h2_ph,4.)
        seasonal_h1_ph = modules.convert_phase_units_actual_single(seasonal_h1_ph,6.)
        annual_ph = modules.convert_phase_units_actual_single(annual_ph,12.)
        seasonal_min_ph = modules.convert_phase_units_actual_single(seasonal_min_ph,12.)
        seasonal_max_ph = modules.convert_phase_units_actual_single(seasonal_max_ph,12.)

    else:
        seasonal_h3_mag = -99999
        seasonal_h2_mag = -99999
        seasonal_h1_mag = -99999
        annual_mag = -99999
        seasonal_mag = -99999
        
        seasonal_h3_ph = -99999
        seasonal_h2_ph = -99999
        seasonal_h1_ph = -99999
        annual_ph = -99999
        seasonal_max_ph = -99999
        seasonal_min_ph = -99999

        seasonal_waveform = np.array([-99999]*len(full_times_year))

        mean_array = -99999
    
    return x,seasonal_h3_mag,seasonal_h3_ph,seasonal_h2_mag,seasonal_h2_ph,seasonal_h1_mag,seasonal_h1_ph,annual_mag,annual_ph,seasonal_mag,seasonal_max_ph,seasonal_min_ph,seasonal_waveform,mean_array
def run_LSP(vals, x):

    print obs_refs[x]
    
    #check obs vals are valid
    valid = vals >= 0
    vals = vals[valid]
    valid_times = obs_ref_time[valid]

    if timeres == 'H':
        full_times_year = obs_ref_time[:8766]
    elif timeres == 'D':
        full_times_year = obs_ref_time[:365]
    elif timeres == 'M':
        full_times_year = obs_ref_time[:12]
    full_times_day = obs_ref_time[:24] 
      
    site_lon = obs_lons[x]

    #convert site_lon to 0 to 360 degs
    if site_lon < 0:
        site_lon = 360-np.abs(site_lon)
    
    #transform from UTC time to solar time 
    sun_time = lon_step_time*site_lon
    time_diff = sun_time - 0
    if time_diff > 12:
        time_diff = time_diff-24

    #make time start from 0    
    valid_times_from0 = modules.phase_start_correct(valid_times)

    print valid_times_from0

    periodic_periods = [1./4.,1./3.,1./2.,1.,365.25/4.,365.25/3.,365.25/2.,365.25]
    periods,mag,ph,fr,fi = modules.take_lomb_spec(valid_times_from0,vals,w=True,key_periods=periodic_periods)
    
    #get mean of values
    mean_array = np.average(vals)
    
    #correct all phases for start point (not actually being from 0 - just corrected to be)
    ph = modules.phase_start_point_correct_all(periodic_periods,ph,valid_times)

    key_diurnal_periods = [1./4.,1./3.,1./2.,1.]
    key_seasonal_periods = [365.25/4.,365.25/3.,365.25/2.,365.25]

    diurnal_mags = mag[:4]
    seasonal_mags = mag[4:]
    seasonal_phs = ph[4:]

    #get individual mags and phases
    daily_h3_mag = mag[0]
    daily_h2_mag = mag[1]
    daily_h1_mag = mag[2]
    orig_daily_mag = mag[3]
    daily_h3_ph = ph[0]
    daily_h2_ph = ph[1]
    daily_h1_ph = ph[2]
    orig_daily_ph = ph[3]
    
    seasonal_h3_mag = mag[4]
    seasonal_h2_mag = mag[5]
    seasonal_h1_mag = mag[6]
    annual_mag = mag[7]
    seasonal_h3_ph = ph[4]
    seasonal_h2_ph = ph[5]
    seasonal_h1_ph = ph[6]
    annual_ph = ph[7]

    #convert sub diurnal phases from UTC to solar time
    daily_h3_ph = modules.solar_time_phase_corrector(daily_h3_ph,6,time_diff)
    daily_h2_ph = modules.solar_time_phase_corrector(daily_h2_ph,24./3.,time_diff)
    daily_h1_ph = modules.solar_time_phase_corrector(daily_h1_ph,12,time_diff)
    orig_daily_ph = modules.solar_time_phase_corrector(orig_daily_ph,24,time_diff)
    diurnal_phs = [daily_h3_ph,daily_h2_ph,daily_h1_ph,orig_daily_ph]

    #convolve annual cycle and harmonics to seasonal waveform for 1 year
    seasonal_mag,seasonal_min_ph,seasonal_max_ph,seasonal_waveform,seasonal_ff = modules.period_convolution(key_seasonal_periods,full_times_year,seasonal_mags,seasonal_phs,mean_array)

    #convolve diurnal cycle and harmonics to diurnal waveform for 1 day
    diurnal_mag,diurnal_min_ph,diurnal_max_ph,diurnal_waveform,diurnal_ff = modules.period_convolution(key_diurnal_periods,full_times_day,diurnal_mags,diurnal_phs,mean_array)
    
    #convolve all 
    full_mag,full_min_ph,full_max_ph,full_waveform,full_ff = modules.period_convolution(periodic_periods,obs_ref_time,mag,ph,mean_array)

    #convert phase to time
    daily_h3_ph = modules.convert_phase_units_actual_single(daily_h3_ph,6.)
    daily_h2_ph = modules.convert_phase_units_actual_single(daily_h2_ph,24./3.)
    daily_h1_ph = modules.convert_phase_units_actual_single(daily_h1_ph,12.)
    orig_daily_ph = modules.convert_phase_units_actual_single(orig_daily_ph,24.)
    diurnal_min_ph = modules.convert_phase_units_actual_single(diurnal_min_ph,24.)
    diurnal_max_ph = modules.convert_phase_units_actual_single(diurnal_max_ph,24.)
    seasonal_h3_ph = modules.convert_phase_units_actual_single(seasonal_h3_ph,3.)
    seasonal_h2_ph = modules.convert_phase_units_actual_single(seasonal_h2_ph,4.)
    seasonal_h1_ph = modules.convert_phase_units_actual_single(seasonal_h1_ph,6.)
    annual_ph = modules.convert_phase_units_actual_single(annual_ph,12.)
    seasonal_min_ph = modules.convert_phase_units_actual_single(seasonal_min_ph,12.)
    seasonal_max_ph = modules.convert_phase_units_actual_single(seasonal_max_ph,12.)

    return (x,daily_h3_mag,daily_h3_ph,daily_h2_mag,daily_h2_ph,daily_h1_mag,daily_h1_ph,orig_daily_mag,orig_daily_ph,diurnal_mag,diurnal_min_ph,diurnal_max_ph,seasonal_h3_mag,seasonal_h3_ph,seasonal_h2_mag,seasonal_h2_ph,seasonal_h1_mag,seasonal_h1_ph,annual_mag,annual_ph,seasonal_mag,seasonal_min_ph,seasonal_max_ph,mean_array,diurnal_waveform,seasonal_waveform,full_waveform,diurnal_ff,seasonal_ff,full_ff)
Exemplo n.º 9
0
model_var = model_data[gridbox_n::gridbox_count]
model_var = model_var*1e9

#----------------------------------------
model_time = model_time[valids]
model_var = model_var[valids]


#take lomb for obs and model
ofac = raw_input('\nChoose oversampling factor. (Typically 4.)\n')

#shift times to start from 0
obs_time = np.array(obs_time)
model_time = np.array(model_time)
obs_time_from0 = modules.phase_start_correct(obs_time)
model_time_from0 = modules.phase_start_correct(model_time)

#obs lomb
obs_periods,obs_mag,obs_ph,obs_fr,obs_fi,obs_amp_corr = modules.take_lomb(obs_time_from0,obs_var,ofac,1./24)

#model lomb
model_periods,model_mag,model_ph,model_fr,model_fi,model_amp_corr = modules.take_lomb(model_time_from0,model_var,ofac,1./24)

obs_time = np.array(obs_time)
obs_var = np.array(obs_var)

lon_step_time  = 24./360.

#convert site_lon to 0 to 360 degs
if obs_lon < 0:
Exemplo n.º 10
0
        minute_val.append(int(time[-2:]))

full_obs_datetimes = [
    datetime.datetime(year=year_val[i],
                      month=month_val[i],
                      day=day_val[i],
                      hour=hour_val[i],
                      minute=minute_val[i]) for i in range(len(year_val))
]
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)
Exemplo n.º 11
0
daily_period = 1
annual_period = 365.25

hourly_step = 1. / 24

b = np.arange(200.75, 500, hourly_step)

pi2 = np.pi * 2

daily_amplitude = 10
half_annual_amplitude = 1
annual_amplitude = 1

#shift times to start from 0
b = modules.phase_start_correct(b)
print 'First time = ', b[0]
#b = b-b[0]
print b

cos_waveform1 = daily_amplitude * (np.cos((pi2 * b / 1.1) - (np.pi / 2)))
#cos_waveform2 = half_annual_amplitude*(np.cos((pi2*b/(365.25/2))-0))
cos_waveform3 = annual_amplitude * (np.cos((pi2 * b / 365.25) - (0)))
#cos_waveform4 = daily_amplitude*(np.cos((pi2*b/1.0001)-(np.pi)))

#vals = 50 + (cos_waveform1+cos_waveform2+cos_waveform3)

vals = 50 + (cos_waveform1 + cos_waveform3)

total_len = len(vals)