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)
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)
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, run_type, x): if run_type == 'model': lat_i = lat_indices[x] lon_i = lon_indices[x] site_lon = lon_c[lon_i] site_lat = lat_c[lat_i] if run_type == 'obs': site_lon = obs_lons[x] site_lat = obs_lats[x] print obs_refs[x], x, site_lat, site_lon #check obs vals are valid valid = vals >= 0 vals = vals[valid] if run_type == 'obs': orig_time = obs_ref_time valid_times = obs_ref_time[valid] orig_datetimes = obs_datetime_time valid_datetimes = obs_datetime_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] if run_type == 'model': orig_time = model_ref_time valid_times = model_ref_time[valid] orig_datetimes = model_datetime_time valid_datetimes = model_datetime_time[valid] if timeres == 'H': full_times_year = model_ref_time[:8766] elif timeres == 'D': full_times_year = model_ref_time[:365] elif timeres == 'M': full_times_year = model_ref_time[:12] full_times_day = model_ref_time[:24] #convert site_lon to 0 to 360 degs #keep -180 - 180 lon as orig_lon orig_lon = site_lon if site_lon < 0: site_lon = 360 - np.abs(site_lon) #transform factor for conversion from UTC time to solar time time_diff = lon_step_time * site_lon if time_diff > 12: time_diff = time_diff - 24 #cut vals into seasons valid_times_spring, vals_spring, valid_inds_spring, valid_times_summer, vals_summer, valid_inds_summer, valid_times_autumn, vals_autumn, valid_inds_autumn, valid_times_winter, vals_winter, valid_inds_winter = modules.cut_season( valid_datetimes, valid_times, vals) #cut vals into day/night (use -180 - 180 lons) valid_times_day, vals_day, valid_times_night, vals_night = modules.cut_daynight( valid_datetimes, valid_times, vals, site_lat, orig_lon, timeres) #make time start from 0 valid_times_from0 = modules.time_from0(valid_times) valid_times_from0_spring = modules.time_from0(valid_times_spring) valid_times_from0_summer = modules.time_from0(valid_times_summer) valid_times_from0_autumn = modules.time_from0(valid_times_autumn) valid_times_from0_winter = modules.time_from0(valid_times_winter) valid_times_from0_day = modules.time_from0(valid_times_day) valid_times_from0_night = modules.time_from0(valid_times_night) key_diurnal_periods = [ 1. / 12., 1. / 11., 1. / 10., 1. / 9., 1. / 8., 1. / 7., 1. / 6., 1. / 5., 1. / 4., 1. / 3., 1. / 2., 1. ] #key_seasonal_periods = [365.25/12.,365.25/11.,365.25/10.,365.25/9.,365.25/8.,365.25/7.,365.25/6.,365.25/5.,365.25/4.,365.25/3.,365.25/2.,365.25] key_seasonal_periods = [365.25 / 4., 365.25 / 3., 365.25 / 2., 365.25] #periodic_periods = [1./12.,1./11.,1./10.,1./9.,1./8.,1./7.,1./6.,1./5.,1./4.,1./3.,1./2.,1.,365.25/12.,365.25/11.,365.25/10.,365.25/9.,365.25/8.,365.25/7.,365.25/6.,365.25/5.,365.25/4.,365.25/3.,365.25/2.,365.25] periodic_periods = [ 1. / 12., 1. / 11., 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 = modules.lomb_specific( valid_times_from0, vals, w=True, key_periods=periodic_periods) periods_spring, mag_spring, ph_spring, fr_spring, fi_spring = modules.lomb_specific( valid_times_from0_spring, vals_spring, w=True, key_periods=key_diurnal_periods) periods_summer, mag_summer, ph_summer, fr_summer, fi_summer = modules.lomb_specific( valid_times_from0_summer, vals_summer, w=True, key_periods=key_diurnal_periods) periods_autumn, mag_autumn, ph_autumn, fr_autumn, fi_autumn = modules.lomb_specific( valid_times_from0_autumn, vals_autumn, w=True, key_periods=key_diurnal_periods) periods_winter, mag_winter, ph_winter, fr_winter, fi_winter = modules.lomb_specific( valid_times_from0_winter, vals_winter, w=True, key_periods=key_diurnal_periods) periods_day, mag_day, ph_day, fr_day, fi_day = modules.lomb_specific( valid_times_from0_day, vals_day, w=True, key_periods=key_seasonal_periods) periods_night, mag_night, ph_night, fr_night, fi_night = modules.lomb_specific( valid_times_from0_night, vals_night, w=True, key_periods=key_seasonal_periods) #process RAW STATS #STANDARD mean, p1, p5, p25, p50, p75, p95, p99 = modules.raw_stats(vals) #SEASON mean_spring, p1_spring, p5_spring, p25_spring, p50_spring, p75_spring, p95_spring, p99_spring = modules.raw_stats( vals_spring) mean_summer, p1_summer, p5_summer, p25_summer, p50_summer, p75_summer, p95_summer, p99_summer = modules.raw_stats( vals_summer) mean_autumn, p1_autumn, p5_autumn, p25_autumn, p50_autumn, p75_autumn, p95_autumn, p99_autumn = modules.raw_stats( vals_autumn) mean_winter, p1_winter, p5_winter, p25_winter, p50_winter, p75_winter, p95_winter, p99_winter = modules.raw_stats( vals_winter) #DAY/NIGHT mean_day, p1_day, p5_day, p25_day, p50_day, p75_day, p95_day, p99_day = modules.raw_stats( vals_day) mean_night, p1_night, p5_night, p25_night, p50_night, p75_night, p95_night, p99_night = modules.raw_stats( vals_night) #correct all phases for start point (not actually being from 0 - just corrected to be) ph = modules.phase_start_time_relative_correct(periodic_periods, ph, valid_times) ph_spring = modules.phase_start_time_relative_correct( key_diurnal_periods, ph_spring, valid_times_spring) ph_summer = modules.phase_start_time_relative_correct( key_diurnal_periods, ph_summer, valid_times_summer) ph_autumn = modules.phase_start_time_relative_correct( key_diurnal_periods, ph_autumn, valid_times_autumn) ph_winter = modules.phase_start_time_relative_correct( key_diurnal_periods, ph_winter, valid_times_winter) ph_day = modules.phase_start_time_relative_correct(key_seasonal_periods, ph_day, valid_times_day) ph_night = modules.phase_start_time_relative_correct( key_seasonal_periods, ph_night, valid_times_night) #put mags and phases into appropriate arrays diurnal_mags = mag[:12] diurnal_phs = ph[:12] diurnal_mags_spring = mag_spring[:] diurnal_phs_spring = ph_spring[:] diurnal_mags_summer = mag_summer[:] diurnal_phs_summer = ph_summer[:] diurnal_mags_autumn = mag_autumn[:] diurnal_phs_autumn = ph_autumn[:] diurnal_mags_winter = mag_winter[:] diurnal_phs_winter = ph_winter[:] seasonal_mags = mag[12:] seasonal_mags_day = mag_day[:] seasonal_mags_night = mag_night[:] seasonal_phs = ph[12:] seasonal_phs_day = ph_day[:] seasonal_phs_night = ph_night[:] all_mags_spring = np.concatenate((diurnal_mags_spring, seasonal_mags)) all_mags_summer = np.concatenate((diurnal_mags_summer, seasonal_mags)) all_mags_autumn = np.concatenate((diurnal_mags_autumn, seasonal_mags)) all_mags_winter = np.concatenate((diurnal_mags_winter, seasonal_mags)) all_phs_spring = np.concatenate((diurnal_phs_spring, seasonal_phs)) all_phs_summer = np.concatenate((diurnal_phs_summer, seasonal_phs)) all_phs_autumn = np.concatenate((diurnal_phs_autumn, seasonal_phs)) all_phs_winter = np.concatenate((diurnal_phs_winter, seasonal_phs)) all_mags_day = np.concatenate((diurnal_mags, seasonal_mags_day)) all_mags_night = np.concatenate((diurnal_mags, seasonal_mags_night)) #set key individual mags and phases daily_h11_mag = mag[0] daily_h10_mag = mag[1] daily_h9_mag = mag[2] daily_h8_mag = mag[3] daily_h7_mag = mag[4] daily_h6_mag = mag[5] daily_h5_mag = mag[6] daily_h4_mag = mag[7] daily_h3_mag = mag[8] daily_h2_mag = mag[9] daily_h1_mag = mag[10] orig_daily_mag = mag[11] #seasonal_h11_mag = mag[12] #seasonal_h10_mag = mag[13] #seasonal_h9_mag = mag[14] #seasonal_h8_mag = mag[15] #seasonal_h7_mag = mag[16] #seasonal_h6_mag = mag[17] #seasonal_h5_mag = mag[18] #seasonal_h4_mag = mag[12] seasonal_h3_mag = mag[12] seasonal_h2_mag = mag[13] seasonal_h1_mag = mag[14] annual_mag = mag[15] #convolve annual cycle and harmonics to seasonal waveform for 1 year seasonal_mag, seasonal_ph, seasonal_waveform = modules.period_convolution( key_seasonal_periods, full_times_year, seasonal_mags, seasonal_phs, mean) seasonal_mag_day, seasonal_ph_day, seasonal_waveform_day = modules.period_convolution( key_seasonal_periods, full_times_year, seasonal_mags_day, seasonal_phs_day, mean_day) seasonal_mag_night, seasonal_ph_night, seasonal_waveform_night = modules.period_convolution( key_seasonal_periods, full_times_year, seasonal_mags_night, seasonal_phs_night, mean_night) remainder = np.mod(len(orig_time), len(seasonal_waveform)) if remainder > 0: seasonal_waveform_extended = np.append( list(seasonal_waveform) * (len(orig_time) // len(seasonal_waveform)), seasonal_waveform[-remainder:]) else: seasonal_waveform_extended = np.array( list(seasonal_waveform) * (len(orig_time) // len(seasonal_waveform))) #convolve diurnal cycle and harmonics to diurnal waveform for 1 day diurnal_mag, diurnal_ph, diurnal_ave_waveform = modules.period_convolution( key_diurnal_periods, full_times_day, diurnal_mags, diurnal_phs, mean) diurnal_mag_spring, diurnal_ph_spring, diurnal_waveform_spring = modules.period_convolution( key_diurnal_periods, full_times_day, diurnal_mags_spring, diurnal_phs_spring, mean_spring) diurnal_mag_summer, diurnal_ph_summer, diurnal_waveform_summer = modules.period_convolution( key_diurnal_periods, full_times_day, diurnal_mags_summer, diurnal_phs_summer, mean_summer) diurnal_mag_autumn, diurnal_ph_autumn, diurnal_waveform_autumn = modules.period_convolution( key_diurnal_periods, full_times_day, diurnal_mags_autumn, diurnal_phs_autumn, mean_autumn) diurnal_mag_winter, diurnal_ph_winter, diurnal_waveform_winter = modules.period_convolution( key_diurnal_periods, full_times_day, diurnal_mags_winter, diurnal_phs_winter, mean_winter) remainder = np.mod(len(orig_time), len(diurnal_ave_waveform)) if remainder > 0: diurnal_ave_waveform_extended = np.append( list(diurnal_ave_waveform) * (len(orig_time) // len(diurnal_ave_waveform)), diurnal_ave_waveform[-remainder:]) else: diurnal_ave_waveform_extended = np.array( list(diurnal_ave_waveform) * (len(orig_time) // len(diurnal_ave_waveform))) #convert diurnal phase and waveforms from UTC to local solar time (in radians) diurnal_ph = modules.solar_time_phase_corrector(diurnal_ph, 24., time_diff) diurnal_ph_spring = modules.solar_time_phase_corrector( diurnal_ph_spring, 24., time_diff) diurnal_ph_summer = modules.solar_time_phase_corrector( diurnal_ph_summer, 24., time_diff) diurnal_ph_autumn = modules.solar_time_phase_corrector( diurnal_ph_autumn, 24., time_diff) diurnal_ph_winter = modules.solar_time_phase_corrector( diurnal_ph_winter, 24., time_diff) diurnal_ave_waveform = np.append(diurnal_ave_waveform[-time_diff:], diurnal_ave_waveform[:-time_diff]) diurnal_waveform_spring = np.append(diurnal_waveform_spring[-time_diff:], diurnal_waveform_spring[:-time_diff]) diurnal_waveform_summer = np.append(diurnal_waveform_summer[-time_diff:], diurnal_waveform_summer[:-time_diff]) diurnal_waveform_autumn = np.append(diurnal_waveform_autumn[-time_diff:], diurnal_waveform_autumn[:-time_diff]) diurnal_waveform_winter = np.append(diurnal_waveform_winter[-time_diff:], diurnal_waveform_winter[:-time_diff]) diurnal_ave_waveform_extended = np.append( diurnal_ave_waveform_extended[-time_diff:], diurnal_ave_waveform_extended[:-time_diff]) #convert phase from radians to time #make sure diurnal phases are on hour by rounding - some numerical rounding issues previous diurnal_ph = round(modules.radians_to_time(diurnal_ph, 24.)) diurnal_ph_spring = round(modules.radians_to_time(diurnal_ph_spring, 24.)) diurnal_ph_summer = round(modules.radians_to_time(diurnal_ph_summer, 24.)) diurnal_ph_autumn = round(modules.radians_to_time(diurnal_ph_autumn, 24.)) diurnal_ph_winter = round(modules.radians_to_time(diurnal_ph_winter, 24.)) seasonal_ph = modules.radians_to_time(seasonal_ph, 12.) seasonal_ph_day = modules.radians_to_time(seasonal_ph_day, 12.) seasonal_ph_night = modules.radians_to_time(seasonal_ph_night, 12.) #make extended waveform for diurnal cycle putting together diurnal waveforms from seasons #also make full waveforms combining both seasonal varying diurnal cycles: full_season_waveform & average diurnal cycles: full_ave_waveform #take mean from seasonal_waveform_extended seasonal_waveform_extended_nomean = seasonal_waveform_extended - mean if timeres == 'H': diurnal_season_waveform_extended = [] full_ave_waveform = [] full_season_waveform = [] n_days = len(orig_datetimes) / 24 start_n = 0 end_n = 24 for i in range(n_days): if (int(orig_datetimes[start_n].month) == 3) or (int( orig_datetimes[start_n].month) == 4) or (int( orig_datetimes[start_n].month) == 5): if site_lat >= 0: diurnal_season_waveform_extended = np.append( diurnal_season_waveform_extended, diurnal_waveform_spring) full_ave_waveform = np.append( full_ave_waveform, ((diurnal_ave_waveform - mean) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean) full_season_waveform = np.append( full_season_waveform, ((diurnal_waveform_spring - mean_spring) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean_spring) else: diurnal_season_waveform_extended = np.append( diurnal_season_waveform_extended, diurnal_waveform_autumn) full_ave_waveform = np.append( full_ave_waveform, ((diurnal_ave_waveform - mean) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean) full_season_waveform = np.append( full_season_waveform, ((diurnal_waveform_autumn - mean_autumn) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean_autumn) elif (int(orig_datetimes[start_n].month) == 6) or (int( orig_datetimes[start_n].month) == 7) or (int( orig_datetimes[start_n].month) == 8): if site_lat >= 0: diurnal_season_waveform_extended = np.append( diurnal_season_waveform_extended, diurnal_waveform_summer) full_ave_waveform = np.append( full_ave_waveform, ((diurnal_ave_waveform - mean) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean) full_season_waveform = np.append( full_season_waveform, ((diurnal_waveform_summer - mean_summer) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean_summer) else: diurnal_season_waveform_extended = np.append( diurnal_season_waveform_extended, diurnal_waveform_winter) full_ave_waveform = np.append( full_ave_waveform, ((diurnal_ave_waveform - mean) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean) full_season_waveform = np.append( full_season_waveform, ((diurnal_waveform_winter - mean_winter) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean_winter) elif (int(orig_datetimes[start_n].month) == 9) or (int( orig_datetimes[start_n].month) == 10) or (int( orig_datetimes[start_n].month) == 11): if site_lat >= 0: diurnal_season_waveform_extended = np.append( diurnal_season_waveform_extended, diurnal_waveform_autumn) full_ave_waveform = np.append( full_ave_waveform, ((diurnal_ave_waveform - mean) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean) full_season_waveform = np.append( full_season_waveform, ((diurnal_waveform_autumn - mean_autumn) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean_autumn) else: diurnal_season_waveform_extended = np.append( diurnal_season_waveform_extended, diurnal_waveform_spring) full_ave_waveform = np.append( full_ave_waveform, ((diurnal_ave_waveform - mean) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean) full_season_waveform = np.append( full_season_waveform, ((diurnal_waveform_spring - mean_spring) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean_spring) elif (int(orig_datetimes[start_n].month) == 12) or (int( orig_datetimes[start_n].month) == 1) or (int( orig_datetimes[start_n].month) == 2): if site_lat >= 0: diurnal_season_waveform_extended = np.append( diurnal_season_waveform_extended, diurnal_waveform_winter) full_ave_waveform = np.append( full_ave_waveform, ((diurnal_ave_waveform - mean) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean) full_season_waveform = np.append( full_season_waveform, ((diurnal_waveform_winter - mean_winter) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean_winter) else: diurnal_season_waveform_extended = np.append( diurnal_season_waveform_extended, diurnal_waveform_summer) full_ave_waveform = np.append( full_ave_waveform, ((diurnal_ave_waveform - mean) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean) full_season_waveform = np.append( full_season_waveform, ((diurnal_waveform_summer - mean_summer) + seasonal_waveform_extended_nomean[start_n:end_n] )) #+mean_summer) start_n += 24 end_n += 24 full_ave_waveform = full_ave_waveform + mean full_season_waveform = full_season_waveform + mean elif (timeres == 'D') or (timeres == 'M'): diurnal_season_waveform_extended = diurnal_ave_waveform_extended full_ave_waveform = seasonal_waveform_extended full_season_waveform = seasonal_waveform_extended #get % variability of periodic waveform with raw time series #also get total variance and noise variance % pc_var_daily, na, na = modules.periodic_variance_percent( vals, full_ave_waveform, mag, mag[:12], valid) pc_var_seasonal, na, na = modules.periodic_variance_percent( vals, full_ave_waveform, mag, mag[12:], valid) pc_var_full, pc_var_noise, total_var = modules.periodic_variance_percent( vals, full_ave_waveform, mag, mag, valid) #remove mean from standard diurnal and seasonal waveforms #diurnal_ave_waveform = diurnal_ave_waveform - mean #seasonal_waveform = seasonal_waveform - mean #diurnal_waveform_spring = diurnal_waveform_spring - mean_spring #diurnal_waveform_summer = diurnal_waveform_summer - mean_summer #diurnal_waveform_autummn = diurnal_waveform_autumn - mean_autumn #diurnal_waveform_winter = diurnal_waveform_winter - mean_winter #seasonal_waveform_day = seasonal_waveform_day - mean_day #seasonal_waveform_night = seasonal_waveform_night - mean_night return (x, diurnal_mag, diurnal_ph, seasonal_mag, seasonal_ph, mean, p1, p5, p25, p50, p75, p95, p99, diurnal_ave_waveform, seasonal_waveform, full_ave_waveform, pc_var_daily, pc_var_seasonal, pc_var_full, pc_var_noise, total_var, diurnal_mag_spring, diurnal_ph_spring, mean_spring, p1_spring, p5_spring, p25_spring, p50_spring, p75_spring, p95_spring, p99_spring, diurnal_waveform_spring, diurnal_mag_summer, diurnal_ph_summer, mean_summer, p1_summer, p5_summer, p25_summer, p50_summer, p75_summer, p95_summer, p99_summer, diurnal_waveform_summer, diurnal_mag_autumn, diurnal_ph_autumn, mean_autumn, p1_autumn, p5_autumn, p25_autumn, p50_autumn, p75_autumn, p95_autumn, p99_autumn, diurnal_waveform_autumn, diurnal_mag_winter, diurnal_ph_winter, mean_winter, p1_winter, p5_winter, p25_winter, p50_winter, p75_winter, p95_winter, p99_winter, diurnal_waveform_winter, seasonal_mag_day, seasonal_ph_day, mean_day, p1_day, p5_day, p25_day, p50_day, p75_day, p95_day, p99_day, seasonal_waveform_day, seasonal_mag_night, seasonal_ph_night, mean_night, p1_night, p5_night, p25_night, p50_night, p75_night, p95_night, p99_night, seasonal_waveform_night, daily_h11_mag, daily_h10_mag, daily_h9_mag, daily_h8_mag, daily_h7_mag, daily_h6_mag, daily_h5_mag, daily_h4_mag, daily_h3_mag, daily_h2_mag, daily_h1_mag, orig_daily_mag, seasonal_h3_mag, seasonal_h2_mag, seasonal_h1_mag, annual_mag)