Ejemplo n.º 1
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)
Ejemplo n.º 2
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)
Ejemplo n.º 4
0
        lsp4_diff_a1.append(diff_a1)
        lsp4_diff_a2.append(diff_a2)
        lsp4_diff_p1.append(diff_p1)
        lsp4_diff_p2.append(diff_p2)
        
        #print '\nLOMB WINDOWED, OVERSAMPLED, INTERPOLATED'
        #print 'Est. Amplitude 1 = ',mag1
        #print 'Est. Phase 1 = ',phase1
        #print 'Est. Amplitude 2 = ',mag2
        #print 'Est. Phase 2 = ',phase2
        #print '------------------------------------------\n'
        
        #Lomb WINDOWED, SPECIFIC FREQUENCIES
        #-----------------------------------------------
        
        periods,mag,ph,fr,fi = modules.take_lomb_spec(b,vals,w=True,key_periods=[p1,p2])
        
        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))

        mag1 = mag[closest_period_1]
        phase1 = ph[closest_period_1]
        mag2 = mag[closest_period_2]
        phase2 = ph[closest_period_2]
        
        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))
        elif diff_p1 < -np.pi:
Ejemplo n.º 5
0
                                                       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
    print 'Est. Phase 2 = ', daily_phase2
    print '------------------------------------------\n'

    #Lomb WINDOWED, SPECIFIC FREQUENCIES
    #-----------------------------------------------

    periods, mag, ph, fr, fi = modules.take_lomb_spec(b,
                                                      vals,
                                                      w=True,
                                                      key_periods=[p1, p2])

    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 = mag[closest_period_1]
    daily_phase1 = ph[closest_period_1]
    daily_mag2 = mag[closest_period_2]
    daily_phase2 = ph[closest_period_2]

    print '\nLOMB WINDOWED, SPECIFIC FREQUENCIES'

    print 'Est. Amplitude 1 = ', daily_mag1