def grid_interactive(event):
    global pl 
    global ind
    global fig2
    
    ind = event.ind
    ind = ind[0]

    #find ind of closest lat/lon
    #ind = modules.find_nearest_point_index(obs_lons,obs_lats,x_data,y_data)
    
    try:
        for i in range(len(pl)):
            pl.pop(0).remove()
            first_run = False  
        
    except:
        first_run = True
        pass
    
    pl = m.plot([linear_lons[ind]], [linear_lats[ind]], 's', ms=20, alpha=0.6, color='yellow',zorder=20)

    #get model spectra for site clicked
    lat_n,lon_n = modules.obs_model_gridbox(lat_e,lon_e,linear_lats[ind],linear_lons[ind])
    period = site_group.variables['period'][:,lat_n,lon_n]
    spectrum = site_group.variables['amplitude'][:,lat_n,lon_n]
    #period = periods[:,lat_n,lon_n]
    #spectrum = amplitude[:,lat_n,lon_n]
    
    fig.canvas.draw()
        
    if first_run == False:
        plt.close(fig2)
        fig2, (ax1) = plt.subplots(1, 1, figsize =(24,12))
        fig2.patch.set_facecolor('white')

        ax1.plot(period, spectrum, color='black', markersize = 3)
        ax1.set_xscale('log')
        ax1.set_yscale('log')
        
        #plt.legend(loc = 'lower right')
        plt.tight_layout()
        ax1.grid()
        
        plt.show()
    else:
        fig2, (ax1) = plt.subplots(1, 1, figsize =(24,12))
        fig2.patch.set_facecolor('white')
        
        ax1.plot(period, spectrum, color='black', markersize = 3)
        ax1.set_xscale('log')
        ax1.set_yscale('log')
        
        #plt.legend(loc = 'lower right')
        plt.tight_layout()
        ax1.grid()
        
        plt.show()
Example #2
0
obs_var = site_group.variables[species.lower()][:]
obs_date = site_group.variables['date'][:]
obs_time = site_group.variables['time'][:]
obs_lat = site_group.latitude
obs_lon = site_group.longitude
obs_alt = site_group.altitude
obs_group = site_group.process_group

obs_var_mask = np.ma.masked_where(obs_var <= 0, obs_var)
obs_var = obs_var[~np.isnan(obs_var_mask)]

#----------------------------------------
#find model data gridbox to compare with obs.

#get model gridbox for obs site
lat_n, lon_n = modules.obs_model_gridbox(lat_e, lon_e, obs_lat, obs_lon)

model_var = model_var[:, lat_n, lon_n]
model_var = model_var * 1e9

model_var_mask = np.ma.masked_where(model_var <= 0, model_var)
model_ave = np.ma.average(model_var_mask)
model_var = model_var[~np.isnan(model_var_mask)]

#--------------------------------------------
#get valid data and process time

obs_time = np.array(modules.date_process(obs_date, obs_time, start_year))
model_time = np.array(modules.date_process(model_date, model_time, start_year))

model_test = model_var >= 0
def onpick(event):
    global pl
    
    global ind
    global fig2
    
    ind = event.ind
    print 'ind = ',ind
    ind = ind[0]
    #x_data = event.xdata
    #y_data = event.ydata

    #find ind of closest lat/lon
    #ind = modules.find_nearest_point_index(obs_lons,obs_lats,x_data,y_data)
    
    try:
        for i in range(len(pl)):
            pl.pop(0).remove()
            first_run = False  
        
    except:
        first_run = True
        pass
    
    pl = m.plot([linear_lons[ind]], [linear_lats[ind]], 's', ms=20, alpha=0.6, color='yellow',zorder=20)

    
    #get model timeseries for site clicked
    lat_n,lon_n = modules.obs_model_gridbox(lat_e,lon_e,linear_lats[ind],linear_lons[ind])
    model_var_pick = model_var[:,lat_n,lon_n]
    model_var_pick = model_var_pick*1e9
    model_var_mask = np.ma.masked_where(model_var_pick<=0,model_var_pick)
    model_time_pd = pd.date_range(start = model_datetimes[0],end = model_datetimes[-1], freq = 'H')
    model_var_pd = pd.Series(model_var_mask, index=model_time_pd)

        
    #create sine wave from amp/phase
    model_date_l = model_date.astype(int)
    model_time_l = model_time.astype(int)
    model_times = modules.date_process(model_date_l,model_time_l,start_year)
    model_times = np.array(model_times)
    pi2 = np.pi*2
    
    ratio = 100./annual_amp[lat_n,lon_n]
    ha_percent = ratio*annual_amp[lat_n,lon_n]
    
    #convert phases to radians
    calc = pi2/24.
    
    calc = pi2/6.
    ha_ph_r = ha_ph[lat_n,lon_n] * calc
    calc = pi2/12.
    annual_ph_r = annual_ph[lat_n,lon_n] * calc
    
    ha_model_wave = ha_amp[lat_n,lon_n]*(np.cos((pi2*model_times/(365.25/2.))-(ha_ph_r)))
    annual_model_wave = annual_amp[lat_n,lon_n]*(np.cos((pi2*model_times/(365.25))-(annual_ph_r)))
    
    ha_primary = p_ha_ph[lat_n,lon_n]
    ha_secondary = s_ha_ph[lat_n,lon_n]
    
    ha_model_wave = ha_model_wave+ave[lat_n,lon_n]
    annual_model_wave = annual_model_wave+ave[lat_n,lon_n]
    
    model_ha_wave_pd = pd.Series(ha_model_wave, index=model_time_pd)
    model_annual_wave_pd = pd.Series(annual_model_wave, index=model_time_pd)
    
    
    fig.canvas.draw()
        
    if first_run == False:
        plt.close(fig2)
        fig2, (axo) = plt.subplots(1,figsize=(24,12))
        fig2.patch.set_facecolor('white')
        
        axo.plot_date(model_time_pd.to_pydatetime(), model_var_pd, color='black', markersize = 3, label = 'Observations')
        axo.plot_date(model_time_pd.to_pydatetime(), model_ha_wave_pd, color='green', markersize = 3, label = 'Ha Waveform',markeredgecolor='None')
        axo.plot_date(model_time_pd.to_pydatetime(), model_annual_wave_pd, color='red', markersize = 3, label = 'Annual Waveform',markeredgecolor='None')
        
        #axo.set_title('Site = %s, Country = %s, Continent = %s, Process Group = %s, Lat = %s, Lon = %s, Alt = %sm,\n Data Completeness = %s%%, Anthrome Class = %s, Raw Class = %s\nPrimary HA Phase = %s,Primary HA Regime = %s, HA Amp to Annual Amp Percent = %s' %(ref,country,continent,group,lat,lon,alt,complete,a_class,r_class,ha_primary,ha_regime,ha_percent)) 
        
        plt.legend(loc = 'lower right')
        plt.tight_layout()
        axo.grid()
        
        plt.show()
    else:
        fig2, (axo) = plt.subplots(1,figsize=(24,12))
        fig2.patch.set_facecolor('white')
        
        axo.plot_date(model_time_pd.to_pydatetime(), model_var_pd, color='black', markersize = 3, label = 'Observations')
        axo.plot_date(model_time_pd.to_pydatetime(), model_ha_wave_pd, color='green', markersize = 3, label = 'Ha Waveform',markeredgecolor='None')
        axo.plot_date(model_time_pd.to_pydatetime(), model_annual_wave_pd, color='red', markersize = 3, label = 'Annual Waveform',markeredgecolor='None')
        
        #axo.set_title('Site = %s, Country = %s, Continent = %s, Process Group = %s, Lat = %s, Lon = %s, Alt = %sm,\n Data Completeness = %s%%, Anthrome Class = %s, Raw Class = %s\nPrimary HA Phase = %s,Primary HA Regime = %s, HA Amp to Annual Amp Percent = %s' %(ref,country,continent,group,lat,lon,alt,complete,a_class,r_class,ha_primary,ha_regime,ha_percent))
        
        plt.legend(loc = 'lower right')
        plt.tight_layout()
        axo.grid()
        
        plt.show()
Example #4
0
#read in variables for site
obs_var = site_group.variables[species.lower()][:]
obs_date = site_group.variables['date'][:]
obs_time = site_group.variables['time'][:]
obs_lat = site_group.latitude
obs_lon = site_group.longitude
obs_alt = site_group.altitude
obs_group = site_group.process_group

obs_var_mask = np.ma.masked_where(obs_var<=0,obs_var)

#----------------------------------------
#find model data gridbox to compare with obs.

#get model gridbox for obs site
lat_n,lon_n = modules.obs_model_gridbox(lat_e,lon_e,obs_lat,obs_lon)

#print 'Obs Lat & Lon = ', obs_lat,obs_lon
#print 'Lat Centre = ',lat_c
#print 'Lon Centre = ',lon_c
#print lat_n,lon_n
#print lat_c[lat_n], lon_c[lon_n]
#print model_var.shape

model_var = model_var[:,lat_n,lon_n]
model_var = model_var*1e9

model_var_mask = np.ma.masked_where(model_var<=0,model_var)

#----------------------------------------
#process obs dates and obs times to datetimes, then process pandas objects
Example #5
0
                    data_valid = False
                    print 'Persisent Data gap > 3 months'
                    break
            if i > 365:
                    data_valid = False
                    print 'Data gap > 1 Year'
                    break
            
        #calc gregorian time
        obs_time = date2num(datetimes, units='hours since 0001-01-01 00:00:00', calendar='gregorian')        
    
        if data_valid == True:  
            #split datasets into model pressure bands by daily timestep
           
            #find lat and lon indices of site
            lat_i,lon_i = modules.obs_model_gridbox(model_lat_edges,model_lon_edges,np.float64(current_lat),np.float64(current_lon))
           
            bad_inds = []
            level_inds = []

            for i in range(len(obs_time)): 
                obs_t = obs_time[i]
                obs_press = all_press[i]
                obs_var = all_var[i]

                time_ind = np.searchsorted(model_time,obs_t)
                if obs_t > model_time[-1]:
                    bad_inds.append(i)
                    continue
                else:
                    time_model_press_edges = model_press_edges[time_ind,:,:,:]            
def onpick(event):
    global pl
    
    global ind
    global fig2
    
    ind = event.ind
    ind = ind[0]
    #x_data = event.xdata
    #y_data = event.ydata

    #find ind of closest lat/lon
    #ind = modules.find_nearest_point_index(obs_lons,obs_lats,x_data,y_data)
    
    try:
        for i in range(len(pl)):
            pl.pop(0).remove()
            first_run = False  
        
    except:
        first_run = True
        pass
    
    pl = m.plot([X[ind]], [Y[ind]], 'o', ms=12, alpha=0.6, color='yellow',zorder=20)
    
    #get model timeseries for site clicked
    lat_n,lon_n = modules.obs_model_gridbox(lat_e,lon_e,obs_lats[ind],obs_lons[ind])
    model_var_pick = model_var[:,lat_n,lon_n]
    model_var_pick = model_var_pick*1e9
    model_var_mask = np.ma.masked_where(model_var_pick<=0,model_var_pick)
   
    if model_name == 'MACC':
        model_time_pd = pd.date_range(start = model_datetimes[0],end = model_datetimes[-1], freq = 'H')
        count = 0
        valids = []
        for i in range(len(model_time_pd)):
            if count == 0:
                valids.append(i)
                count+=1
            elif count == 2:
                count = 0
            else:
                count+=1
        model_time_pd = model_time_pd[valids]
        model_var_pd = pd.Series(model_var_mask, index=model_time_pd) 
    else:    
        model_time_pd = pd.date_range(start = model_datetimes[0],end = model_datetimes[-1], freq = 'H')
        model_var_pd = pd.Series(model_var_mask, index=model_time_pd)
    
    #get obs timeseries for site clicked
    ref = obs_refs[ind]
    obs_ts_group = obs_root_grp.groups[ref]
    obs_var = obs_ts_group.variables[species.lower()][:]
    group = obs_ts_group.process_group
    lat = obs_ts_group.latitude
    lon = obs_ts_group.longitude
    lon = obs_ts_group.longitude
    alt = obs_ts_group.altitude
    complete = obs_ts_group.completeness
    a_class = obs_ts_group.anthrome_class
    r_class = obs_ts_group.raw_class
    continent = loc_dict[tags[ind]]
    country = obs_ts_group.country
    
    obs_var_mask = np.ma.masked_where(obs_var<=0,obs_var)
    obs_time_pd = pd.date_range(start = obs_datetimes[0],end = obs_datetimes[-1], freq = 'H')
    obs_var_pd = pd.Series(obs_var_mask, index=obs_time_pd)
    
    #create sine wave from amp/phase
    obs_date_l = obs_date.astype(int)
    obs_time_l = obs_time.astype(int)
    obs_times = modules.date_process(obs_date_l,obs_time_l,start_year)
    obs_times = np.array(obs_times)
    pi2 = np.pi*2
    
    #convert phases to radians
    calc = pi2/6.
    obs_ha_phase_r = obs_ha_phase[ind] * calc
    calc = pi2/12.
    obs_annual_phase_r = obs_annual_phase[ind] * calc
    
    ha_obs_wave = obs_ha_mag[ind]*(np.cos((pi2*obs_times/(365.25/2.))-(obs_ha_phase_r)))
    annual_obs_wave = obs_annual_mag[ind]*(np.cos((pi2*obs_times/(365.25))-(obs_annual_phase_r)))
    seasonal_obs_wave = (ha_obs_wave+annual_obs_wave)+obs_ave[ind]
    obs_seasonal_wave_pd = pd.Series(seasonal_obs_wave, index=obs_time_pd)
    
    #create sine wave from amp/phase
    mod_date_l = model_date.astype(int)
    mod_time_l = model_time.astype(int)
    mod_times = modules.date_process(mod_date_l,mod_time_l,start_year)
    mod_times = np.array(mod_times)
    pi2 = np.pi*2
    
    #convert phases to radians
    calc = pi2/6.
    model_ha_phase_r = model_ha_phase[ind] * calc
    calc = pi2/12.
    model_annual_phase_r = model_annual_phase[ind] * calc
    
    ha_model_wave = model_ha_mag[ind]*(np.cos((pi2*mod_times/(365.25/2.))-(model_ha_phase_r)))
    annual_model_wave = model_annual_mag[ind]*(np.cos((pi2*mod_times/(365.25))-(model_annual_phase_r)))
    seasonal_model_wave = (ha_model_wave+annual_model_wave)+model_ave[ind]
    model_seasonal_wave_pd = pd.Series(seasonal_model_wave, index=model_time_pd)

    
    #get spectra data
    site_group_obs = root_grp_obs_spec.groups[ref]
    site_group_mod = root_grp_mod_spec.groups[ref]
    
    obs_period = site_group_obs.variables['period'][:]
    mod_period = site_group_mod.variables['period'][:]
    
    obs_amp = site_group_obs.variables['amplitude'][:]
    mod_amp = site_group_mod.variables['amplitude'][:]
    
    fig.canvas.draw()
        
    if first_run == False:
        plt.close(fig2)
        fig2, (axo,axo2) = plt.subplots(2,figsize=(24,12))
        fig2.patch.set_facecolor('white')
        
        #fig2 = plt.figure()
        
        axo.plot_date(obs_time_pd.to_pydatetime(), obs_var_pd, color='black', markersize = 3, label = 'Observations')
        axo.plot_date(model_time_pd.to_pydatetime(), model_var_pd, color='red',alpha=0.5, markersize = 3, label = '%s %s %s %s'%(model_name,version,grid_size,met),markeredgecolor='None')
        axo.plot_date(obs_time_pd.to_pydatetime(), obs_seasonal_wave_pd, color='yellow', markersize = 3, label = 'Obs Seasonal Waveform',markeredgecolor='None')
        axo.plot_date(model_time_pd.to_pydatetime(), model_seasonal_wave_pd, color='green', markersize = 3, label = 'Model Seasonal Waveform',markeredgecolor='None')
        
        axo2.loglog(obs_period,obs_amp,color='black',label='Obs')
        axo2.loglog(mod_period,mod_amp,color='red',label = '%s %s %s %s'%(model_name,version,grid_size,met))

        axo2.text(0.01, 0.95, 'Obs D Amp = %8.2f ppb'%(obs_daily_mag[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.92, 'Model D Amp = %8.2f ppb'%(model_daily_mag[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.85, 'Obs HA Amp = %8.2f ppb'%(obs_ha_mag[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.82, 'Model HA Amp = %8.2f ppb'%(model_ha_mag[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.75, 'Obs A Amp = %8.2f ppb'%(obs_annual_mag[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.72, 'Model A Amp = %8.2f ppb'%(model_annual_mag[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.55, 'Obs D Phase = %8.2f'%(obs_daily_phase[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.52, 'Model D Phase = %8.2f'%(model_daily_phase[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.45, 'Obs HA Phase = %8.2f'%(obs_ha_phase[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.42, 'Model HA Phase = %8.2f'%(model_ha_phase[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        obs_a_ph = obs_annual_phase[ind]
        mod_a_ph = model_annual_phase[ind]
        
        if obs_a_ph > 12:
            obs_a_ph = obs_a_ph-12.
        if mod_a_ph > 12:
            mod_a_ph = mod_a_ph-12.
        
        axo2.text(0.01, 0.35, 'Obs A Phase = %8.2f'%(obs_a_ph),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.32, 'Model A Phase = %8.2f'%(mod_a_ph),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.15, 'Obs Ave = %8.2f ppb'%(obs_ave[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.12, 'Model Ave = %8.2f ppb'%(model_ave[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.axvline(1.,ymin=0,ymax=1,color='blue',linestyle='--')
        axo2.axvline(182.625,ymin=0,ymax=1,color='blue',linestyle='--')
        axo2.axvline(365.25,ymin=0,ymax=1,color='blue',linestyle='--')
        
        axo2.xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
        axo2.yaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
        plt.gca().xaxis.set_major_formatter(FuncFormatter(xformatter))
        plt.gca().yaxis.set_major_formatter(FuncFormatter(yformatter))
        
        
        axo.set_title('Site = %s, Country = %s, Continent = %s, Process Group = %s, Lat = %s, Lon = %s, Alt = %sm,\n Data Completeness = %s%%, Anthrome Class = %s, Raw Class = %s, Grid Index = %s,%s' %(ref,country,continent,group,lat,lon,alt,complete,a_class,r_class,lat_n,lon_n)) 
        
        plt.legend(loc = 'lower right')
        plt.tight_layout()
        axo.grid()
        axo2.grid()
        
        plt.show()
    else:
        #fig2 = plt.figure()
        fig2, (axo,axo2) = plt.subplots(2,figsize=(24,12))
        fig2.patch.set_facecolor('white')
        
        axo.plot_date(obs_time_pd.to_pydatetime(), obs_var_pd, color='black', markersize = 3, label = 'Observations')
        axo.plot_date(model_time_pd.to_pydatetime(), model_var_pd, color='red', markersize = 3,alpha=0.5, label = '%s %s %s %s'%(model_name,version,grid_size,met),markeredgecolor='None')
        axo.plot_date(obs_time_pd.to_pydatetime(), obs_seasonal_wave_pd, color='yellow', markersize = 3, label = 'Obs Seasonal Waveform',markeredgecolor='None')
        axo.plot_date(model_time_pd.to_pydatetime(), model_seasonal_wave_pd, color='green', markersize = 3, label = 'Model Seasonal Waveform',markeredgecolor='None')
        
        axo2.loglog(obs_period,obs_amp,color='black',label='Obs')
        axo2.loglog(mod_period,mod_amp,color='red', label = '%s %s %s %s'%(model_name,version,grid_size,met))

        axo2.text(0.01, 0.95, 'Obs D Amp = %8.2f ppb'%(obs_daily_mag[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.92, 'Model D Amp = %8.2f ppb'%(model_daily_mag[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.85, 'Obs HA Amp = %8.2f ppb'%(obs_ha_mag[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.82, 'Model HA Amp = %8.2f ppb'%(model_ha_mag[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.75, 'Obs A Amp = %8.2f ppb'%(obs_annual_mag[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.72, 'Model A Amp = %8.2f ppb'%(model_annual_mag[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.55, 'Obs D Phase = %8.2f'%(obs_daily_phase[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.52, 'Model D Phase = %8.2f'%(model_daily_phase[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.45, 'Obs HA Phase = %8.2f'%(obs_ha_phase[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.42, 'Model HA Phase = %8.2f'%(model_ha_phase[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        obs_a_ph = obs_annual_phase[ind]
        mod_a_ph = model_annual_phase[ind]
        
        if obs_a_ph > 12:
            obs_a_ph = obs_a_ph-12.
        if mod_a_ph > 12:
            mod_a_ph = mod_a_ph-12.
        
        axo2.text(0.01, 0.35, 'Obs A Phase = %8.2f'%(obs_a_ph),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.32, 'Model A Phase = %8.2f'%(mod_a_ph),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.text(0.01, 0.15, 'Obs Ave = %8.2f ppb'%(obs_ave[ind]),transform=axo2.transAxes,fontweight='bold')
        axo2.text(0.01, 0.12, 'Model Ave = %8.2f ppb'%(model_ave[ind]),transform=axo2.transAxes,fontweight='bold',color='red')
        
        axo2.axvline(1.,ymin=0,ymax=1,color='blue',linestyle='--')
        axo2.axvline(182.625,ymin=0,ymax=1,color='blue',linestyle='--')
        axo2.axvline(365.25,ymin=0,ymax=1,color='blue',linestyle='--')
        
        axo2.xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
        axo2.yaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
        plt.gca().xaxis.set_major_formatter(FuncFormatter(xformatter))
        plt.gca().yaxis.set_major_formatter(FuncFormatter(yformatter))
        
        
        axo.set_title('Site = %s, Country = %s, Continent = %s, Process Group = %s, Lat = %s, Lon = %s, Alt = %sm,\n Data Completeness = %s%%, Anthrome Class = %s, Raw Class = %s, Grid Index = %s,%s' %(ref,country,continent,group,lat,lon,alt,complete,a_class,r_class,lat_n,lon_n))
        
        plt.legend(loc = 'lower right')
        plt.tight_layout()
        axo.grid()
        axo2.grid()
        
        plt.show()
                    data_valid = False
                    print 'Persisent Data gap > 3 months'
                    break
            if i > 365:
                    data_valid = False
                    print 'Data gap > 1 Year'
                    break
            
        #calc gregorian time
        obs_time = date2num(datetimes, units='hours since 0001-01-01 00:00:00', calendar='gregorian')        
    
        if data_valid == True:  
            #split datasets into model pressure bands by daily timestep
           
            #find lat and lon indices of site
            lat_i,lon_i = modules.obs_model_gridbox(model_lat_edges,model_lon_edges,np.float64(current_lat),np.float64(current_lon))
           
            bad_inds = []
            level_inds = []

            for i in range(len(obs_time)): 
                obs_t = obs_time[i]
                obs_press = all_press[i]
                obs_var = all_var[i]

                time_ind = np.searchsorted(model_time,obs_t)
                if obs_t > model_time[-1]:
                    bad_inds.append(i)
                    continue
                else:
                    time_model_press_edges = model_press_edges[time_ind,:,:,:]            
Example #8
0
#get observational location tags
#EU = europe, AF = africa, NA  = north america, SA = south america, ANT = antarctica, ARC = arctic, O = oceanic, OC = oceania, AS = asia
tags = modules.get_tags(obs_refs)

model_time_pd = pd.date_range(start=model_datetime_time[0],
                              end=model_datetime_time[-1],
                              freq='H')
key = [model_time_pd.month]
nox_by_site = []
nox_ave = []
#cut all lat/lon indices
for i in range(len(obs_lons)):
    obs_lat = obs_lats[i]
    obs_lon = obs_lons[i]
    lat_i, lon_i = modules.obs_model_gridbox(lat_e, lon_e, obs_lat, obs_lon)

    nox_model_var_pd = pd.Series(nox_model_std_var[:, lat_i, lon_i],
                                 index=model_time_pd)
    nox_ave.append(np.average(nox_model_std_var[:, lat_i, lon_i]))
    group = nox_model_var_pd.groupby(key)
    nox_monthly_mean = group.mean()

    nox_by_site.append(nox_monthly_mean)

nox_by_site = np.array(nox_by_site)
nox_ave = np.array(nox_ave)

#--------------------------------------------------------
#load in periodic lsp data
Example #9
0
root_grp = Dataset(model_f)
model_var = root_grp.variables[species.lower()][:]
model_date = root_grp.variables['date'][:]
model_time = root_grp.variables['time'][:]
lat_e = root_grp.variables['lat_edges'][:]
lon_e = root_grp.variables['lon_edges'][:]
lat_c = root_grp.variables['lat_centre'][:]
lon_c = root_grp.variables['lon_centre'][:]
grid_size = root_grp.variables['grid_size'][:]
grid_size = grid_size[0]
model_var_mask = np.ma.masked_where(model_var < 0, model_var)

gridbox_count = len(lat_c) * len(lon_c)

lat_n, lon_n = modules.obs_model_gridbox(lat_e, lon_e, 1., 114.)

y = model_var[:, lat_n, lon_n]

y = y * 1e9

#set up plot
fig = plt.figure(figsize=(23, 12.3))
fig.patch.set_facecolor('white')
ax = fig.add_subplot(1, 1, 1)

x = modules.date_process(model_date, model_time, 2005)

ofac = 4

model_periods, model_mag, model_ph, model_fr, model_fi, amp_corr = modules.take_lomb(
    obs_lons = np.append(obs_lons,obs_site_group.longitude)
    obs_alt = np.append(obs_alt,obs_site_group.altitude)
    obs_date = obs_site_group.variables['date'][:]
    obs_time = obs_site_group.variables['time'][:]
    data = obs_site_group.variables[species.lower()][:]
    test = data >= 0
    tests.append(test)
    obs_var.append(data[test])
    
for i in range(len(obs_refs)):
    obs_refs[i] = obs_refs[i].lower()
    
#cut model var
model_var = []
for i in range(len(obs_refs)):
    lat_n,lon_n = modules.obs_model_gridbox(lat_e,lon_e,obs_lats[i],obs_lons[i])
    model_var.append(model_var_all[tests[i],lat_n,lon_n]*1e9)
    
#process obs dates and obs times to datetimes, then process pandas objects
year_val = []
month_val = []
day_val = []
hour_val = []
minute_val = []

#change obs times to datetimes
obs_date = obs_date.astype('str')
obs_time = obs_time.astype('str')

for date in obs_date:
    year_val.append(int(date[0:4]))
Example #11
0
def onpick(event):
    global pl

    global ind
    global fig2

    ind = event.ind
    print 'ind = ', ind
    ind = ind[0]
    #x_data = event.xdata
    #y_data = event.ydata

    #find ind of closest lat/lon
    #ind = modules.find_nearest_point_index(obs_lons,obs_lats,x_data,y_data)

    try:
        for i in range(len(pl)):
            pl.pop(0).remove()
            first_run = False

    except:
        first_run = True
        pass

    pl = m.plot([linear_lons[ind]], [linear_lats[ind]],
                's',
                ms=20,
                alpha=0.6,
                color='yellow',
                zorder=20)

    #get model timeseries for site clicked
    lat_n, lon_n = modules.obs_model_gridbox(lat_e, lon_e, linear_lats[ind],
                                             linear_lons[ind])
    model_var_pick = model_var[:, lat_n, lon_n]
    model_var_pick = model_var_pick * 1e9
    model_var_mask = np.ma.masked_where(model_var_pick <= 0, model_var_pick)
    model_time_pd = pd.date_range(start=model_datetimes[0],
                                  end=model_datetimes[-1],
                                  freq='H')
    model_var_pd = pd.Series(model_var_mask, index=model_time_pd)

    #create sine wave from amp/phase
    model_date_l = model_date.astype(int)
    model_time_l = model_time.astype(int)
    model_times = modules.date_process(model_date_l, model_time_l, start_year)
    model_times = np.array(model_times)
    pi2 = np.pi * 2

    ratio = 100. / annual_amp[lat_n, lon_n]
    ha_percent = ratio * annual_amp[lat_n, lon_n]

    #convert phases to radians
    calc = pi2 / 24.

    calc = pi2 / 6.
    ha_ph_r = ha_ph[lat_n, lon_n] * calc
    calc = pi2 / 12.
    annual_ph_r = annual_ph[lat_n, lon_n] * calc

    ha_model_wave = ha_amp[lat_n, lon_n] * (np.cos((pi2 * model_times /
                                                    (365.25 / 2.)) -
                                                   (ha_ph_r)))
    annual_model_wave = annual_amp[lat_n, lon_n] * (np.cos((pi2 * model_times /
                                                            (365.25)) -
                                                           (annual_ph_r)))

    ha_primary = p_ha_ph[lat_n, lon_n]
    ha_secondary = s_ha_ph[lat_n, lon_n]

    ha_model_wave = ha_model_wave + ave[lat_n, lon_n]
    annual_model_wave = annual_model_wave + ave[lat_n, lon_n]

    model_ha_wave_pd = pd.Series(ha_model_wave, index=model_time_pd)
    model_annual_wave_pd = pd.Series(annual_model_wave, index=model_time_pd)

    fig.canvas.draw()

    if first_run == False:
        plt.close(fig2)
        fig2, (axo) = plt.subplots(1, figsize=(24, 12))
        fig2.patch.set_facecolor('white')

        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_var_pd,
                      color='black',
                      markersize=3,
                      label='Observations')
        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_ha_wave_pd,
                      color='green',
                      markersize=3,
                      label='Ha Waveform',
                      markeredgecolor='None')
        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_annual_wave_pd,
                      color='red',
                      markersize=3,
                      label='Annual Waveform',
                      markeredgecolor='None')

        #axo.set_title('Site = %s, Country = %s, Continent = %s, Process Group = %s, Lat = %s, Lon = %s, Alt = %sm,\n Data Completeness = %s%%, Anthrome Class = %s, Raw Class = %s\nPrimary HA Phase = %s,Primary HA Regime = %s, HA Amp to Annual Amp Percent = %s' %(ref,country,continent,group,lat,lon,alt,complete,a_class,r_class,ha_primary,ha_regime,ha_percent))

        plt.legend(loc='lower right')
        plt.tight_layout()
        axo.grid()

        plt.show()
    else:
        fig2, (axo) = plt.subplots(1, figsize=(24, 12))
        fig2.patch.set_facecolor('white')

        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_var_pd,
                      color='black',
                      markersize=3,
                      label='Observations')
        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_ha_wave_pd,
                      color='green',
                      markersize=3,
                      label='Ha Waveform',
                      markeredgecolor='None')
        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_annual_wave_pd,
                      color='red',
                      markersize=3,
                      label='Annual Waveform',
                      markeredgecolor='None')

        #axo.set_title('Site = %s, Country = %s, Continent = %s, Process Group = %s, Lat = %s, Lon = %s, Alt = %sm,\n Data Completeness = %s%%, Anthrome Class = %s, Raw Class = %s\nPrimary HA Phase = %s,Primary HA Regime = %s, HA Amp to Annual Amp Percent = %s' %(ref,country,continent,group,lat,lon,alt,complete,a_class,r_class,ha_primary,ha_regime,ha_percent))

        plt.legend(loc='lower right')
        plt.tight_layout()
        axo.grid()

        plt.show()
Example #12
0
def grid_interactive(event):
    global pl
    global ind
    global fig2

    ind = event.ind
    ind = ind[0]

    #find ind of closest lat/lon
    #ind = modules.find_nearest_point_index(obs_lons,obs_lats,x_data,y_data)

    try:
        for i in range(len(pl)):
            pl.pop(0).remove()
            first_run = False

    except:
        first_run = True
        pass

    pl = m.plot([linear_lons[ind]], [linear_lats[ind]],
                's',
                ms=20,
                alpha=0.6,
                color='yellow',
                zorder=20)

    #get model spectra for site clicked
    lat_n, lon_n = modules.obs_model_gridbox(lat_e, lon_e, linear_lats[ind],
                                             linear_lons[ind])
    period = site_group.variables['period'][:, lat_n, lon_n]
    spectrum = site_group.variables['amplitude'][:, lat_n, lon_n]
    #period = periods[:,lat_n,lon_n]
    #spectrum = amplitude[:,lat_n,lon_n]

    fig.canvas.draw()

    if first_run == False:
        plt.close(fig2)
        fig2, (ax1) = plt.subplots(1, 1, figsize=(24, 12))
        fig2.patch.set_facecolor('white')

        ax1.plot(period, spectrum, color='black', markersize=3)
        ax1.set_xscale('log')
        ax1.set_yscale('log')

        #plt.legend(loc = 'lower right')
        plt.tight_layout()
        ax1.grid()

        plt.show()
    else:
        fig2, (ax1) = plt.subplots(1, 1, figsize=(24, 12))
        fig2.patch.set_facecolor('white')

        ax1.plot(period, spectrum, color='black', markersize=3)
        ax1.set_xscale('log')
        ax1.set_yscale('log')

        #plt.legend(loc = 'lower right')
        plt.tight_layout()
        ax1.grid()

        plt.show()
Example #13
0
def onpick(event):
    global pl

    global ind
    global fig2

    ind = event.ind
    ind = ind[0]
    #x_data = event.xdata
    #y_data = event.ydata

    #find ind of closest lat/lon
    #ind = modules.find_nearest_point_index(obs_lons,obs_lats,x_data,y_data)

    try:
        for i in range(len(pl)):
            pl.pop(0).remove()
            first_run = False

    except:
        first_run = True
        pass

    pl = m.plot([X[ind]], [Y[ind]],
                'o',
                ms=12,
                alpha=0.6,
                color='yellow',
                zorder=20)

    #get model timeseries for site clicked
    lat_n, lon_n = modules.obs_model_gridbox(lat_e, lon_e, obs_lats[ind],
                                             obs_lons[ind])
    model_var_pick = model_var[:, lat_n, lon_n]
    model_var_pick = model_var_pick * 1e9
    model_var_mask = np.ma.masked_where(model_var_pick <= 0, model_var_pick)

    if model_name == 'MACC':
        model_time_pd = pd.date_range(start=model_datetimes[0],
                                      end=model_datetimes[-1],
                                      freq='H')
        count = 0
        valids = []
        for i in range(len(model_time_pd)):
            if count == 0:
                valids.append(i)
                count += 1
            elif count == 2:
                count = 0
            else:
                count += 1
        model_time_pd = model_time_pd[valids]
        model_var_pd = pd.Series(model_var_mask, index=model_time_pd)
    else:
        model_time_pd = pd.date_range(start=model_datetimes[0],
                                      end=model_datetimes[-1],
                                      freq='H')
        model_var_pd = pd.Series(model_var_mask, index=model_time_pd)

    #get obs timeseries for site clicked
    ref = obs_refs[ind]
    obs_ts_group = obs_root_grp.groups[ref]
    obs_var = obs_ts_group.variables[species.lower()][:]
    group = obs_ts_group.process_group
    lat = obs_ts_group.latitude
    lon = obs_ts_group.longitude
    lon = obs_ts_group.longitude
    alt = obs_ts_group.altitude
    complete = obs_ts_group.completeness
    a_class = obs_ts_group.anthrome_class
    r_class = obs_ts_group.raw_class
    continent = loc_dict[tags[ind]]
    country = obs_ts_group.country

    obs_var_mask = np.ma.masked_where(obs_var <= 0, obs_var)
    obs_time_pd = pd.date_range(start=obs_datetimes[0],
                                end=obs_datetimes[-1],
                                freq='H')
    obs_var_pd = pd.Series(obs_var_mask, index=obs_time_pd)

    #create sine wave from amp/phase
    obs_date_l = obs_date.astype(int)
    obs_time_l = obs_time.astype(int)
    obs_times = modules.date_process(obs_date_l, obs_time_l, start_year)
    obs_times = np.array(obs_times)
    pi2 = np.pi * 2

    #convert phases to radians
    calc = pi2 / 6.
    obs_ha_phase_r = obs_ha_phase[ind] * calc
    calc = pi2 / 12.
    obs_annual_phase_r = obs_annual_phase[ind] * calc

    ha_obs_wave = obs_ha_mag[ind] * (np.cos((pi2 * obs_times / (365.25 / 2.)) -
                                            (obs_ha_phase_r)))
    annual_obs_wave = obs_annual_mag[ind] * (np.cos((pi2 * obs_times /
                                                     (365.25)) -
                                                    (obs_annual_phase_r)))
    seasonal_obs_wave = (ha_obs_wave + annual_obs_wave) + obs_ave[ind]
    obs_seasonal_wave_pd = pd.Series(seasonal_obs_wave, index=obs_time_pd)

    #create sine wave from amp/phase
    mod_date_l = model_date.astype(int)
    mod_time_l = model_time.astype(int)
    mod_times = modules.date_process(mod_date_l, mod_time_l, start_year)
    mod_times = np.array(mod_times)
    pi2 = np.pi * 2

    #convert phases to radians
    calc = pi2 / 6.
    model_ha_phase_r = model_ha_phase[ind] * calc
    calc = pi2 / 12.
    model_annual_phase_r = model_annual_phase[ind] * calc

    ha_model_wave = model_ha_mag[ind] * (np.cos((pi2 * mod_times /
                                                 (365.25 / 2.)) -
                                                (model_ha_phase_r)))
    annual_model_wave = model_annual_mag[ind] * (np.cos(
        (pi2 * mod_times / (365.25)) - (model_annual_phase_r)))
    seasonal_model_wave = (ha_model_wave + annual_model_wave) + model_ave[ind]
    model_seasonal_wave_pd = pd.Series(seasonal_model_wave,
                                       index=model_time_pd)

    #get spectra data
    site_group_obs = root_grp_obs_spec.groups[ref]
    site_group_mod = root_grp_mod_spec.groups[ref]

    obs_period = site_group_obs.variables['period'][:]
    mod_period = site_group_mod.variables['period'][:]

    obs_amp = site_group_obs.variables['amplitude'][:]
    mod_amp = site_group_mod.variables['amplitude'][:]

    fig.canvas.draw()

    if first_run == False:
        plt.close(fig2)
        fig2, (axo, axo2) = plt.subplots(2, figsize=(24, 12))
        fig2.patch.set_facecolor('white')

        #fig2 = plt.figure()

        axo.plot_date(obs_time_pd.to_pydatetime(),
                      obs_var_pd,
                      color='black',
                      markersize=3,
                      label='Observations')
        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_var_pd,
                      color='red',
                      alpha=0.5,
                      markersize=3,
                      label='%s %s %s %s' %
                      (model_name, version, grid_size, met),
                      markeredgecolor='None')
        axo.plot_date(obs_time_pd.to_pydatetime(),
                      obs_seasonal_wave_pd,
                      color='yellow',
                      markersize=3,
                      label='Obs Seasonal Waveform',
                      markeredgecolor='None')
        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_seasonal_wave_pd,
                      color='green',
                      markersize=3,
                      label='Model Seasonal Waveform',
                      markeredgecolor='None')

        axo2.loglog(obs_period, obs_amp, color='black', label='Obs')
        axo2.loglog(mod_period,
                    mod_amp,
                    color='red',
                    label='%s %s %s %s' %
                    (model_name, version, grid_size, met))

        axo2.text(0.01,
                  0.95,
                  'Obs D Amp = %8.2f ppb' % (obs_daily_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.92,
                  'Model D Amp = %8.2f ppb' % (model_daily_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.85,
                  'Obs HA Amp = %8.2f ppb' % (obs_ha_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.82,
                  'Model HA Amp = %8.2f ppb' % (model_ha_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.75,
                  'Obs A Amp = %8.2f ppb' % (obs_annual_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.72,
                  'Model A Amp = %8.2f ppb' % (model_annual_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.55,
                  'Obs D Phase = %8.2f' % (obs_daily_phase[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.52,
                  'Model D Phase = %8.2f' % (model_daily_phase[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.45,
                  'Obs HA Phase = %8.2f' % (obs_ha_phase[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.42,
                  'Model HA Phase = %8.2f' % (model_ha_phase[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        obs_a_ph = obs_annual_phase[ind]
        mod_a_ph = model_annual_phase[ind]

        if obs_a_ph > 12:
            obs_a_ph = obs_a_ph - 12.
        if mod_a_ph > 12:
            mod_a_ph = mod_a_ph - 12.

        axo2.text(0.01,
                  0.35,
                  'Obs A Phase = %8.2f' % (obs_a_ph),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.32,
                  'Model A Phase = %8.2f' % (mod_a_ph),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.15,
                  'Obs Ave = %8.2f ppb' % (obs_ave[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.12,
                  'Model Ave = %8.2f ppb' % (model_ave[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.axvline(1., ymin=0, ymax=1, color='blue', linestyle='--')
        axo2.axvline(182.625, ymin=0, ymax=1, color='blue', linestyle='--')
        axo2.axvline(365.25, ymin=0, ymax=1, color='blue', linestyle='--')

        axo2.xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
        axo2.yaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
        plt.gca().xaxis.set_major_formatter(FuncFormatter(xformatter))
        plt.gca().yaxis.set_major_formatter(FuncFormatter(yformatter))

        axo.set_title(
            'Site = %s, Country = %s, Continent = %s, Process Group = %s, Lat = %s, Lon = %s, Alt = %sm,\n Data Completeness = %s%%, Anthrome Class = %s, Raw Class = %s, Grid Index = %s,%s'
            % (ref, country, continent, group, lat, lon, alt, complete,
               a_class, r_class, lat_n, lon_n))

        plt.legend(loc='lower right')
        plt.tight_layout()
        axo.grid()
        axo2.grid()

        plt.show()
    else:
        #fig2 = plt.figure()
        fig2, (axo, axo2) = plt.subplots(2, figsize=(24, 12))
        fig2.patch.set_facecolor('white')

        axo.plot_date(obs_time_pd.to_pydatetime(),
                      obs_var_pd,
                      color='black',
                      markersize=3,
                      label='Observations')
        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_var_pd,
                      color='red',
                      markersize=3,
                      alpha=0.5,
                      label='%s %s %s %s' %
                      (model_name, version, grid_size, met),
                      markeredgecolor='None')
        axo.plot_date(obs_time_pd.to_pydatetime(),
                      obs_seasonal_wave_pd,
                      color='yellow',
                      markersize=3,
                      label='Obs Seasonal Waveform',
                      markeredgecolor='None')
        axo.plot_date(model_time_pd.to_pydatetime(),
                      model_seasonal_wave_pd,
                      color='green',
                      markersize=3,
                      label='Model Seasonal Waveform',
                      markeredgecolor='None')

        axo2.loglog(obs_period, obs_amp, color='black', label='Obs')
        axo2.loglog(mod_period,
                    mod_amp,
                    color='red',
                    label='%s %s %s %s' %
                    (model_name, version, grid_size, met))

        axo2.text(0.01,
                  0.95,
                  'Obs D Amp = %8.2f ppb' % (obs_daily_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.92,
                  'Model D Amp = %8.2f ppb' % (model_daily_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.85,
                  'Obs HA Amp = %8.2f ppb' % (obs_ha_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.82,
                  'Model HA Amp = %8.2f ppb' % (model_ha_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.75,
                  'Obs A Amp = %8.2f ppb' % (obs_annual_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.72,
                  'Model A Amp = %8.2f ppb' % (model_annual_mag[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.55,
                  'Obs D Phase = %8.2f' % (obs_daily_phase[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.52,
                  'Model D Phase = %8.2f' % (model_daily_phase[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.45,
                  'Obs HA Phase = %8.2f' % (obs_ha_phase[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.42,
                  'Model HA Phase = %8.2f' % (model_ha_phase[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        obs_a_ph = obs_annual_phase[ind]
        mod_a_ph = model_annual_phase[ind]

        if obs_a_ph > 12:
            obs_a_ph = obs_a_ph - 12.
        if mod_a_ph > 12:
            mod_a_ph = mod_a_ph - 12.

        axo2.text(0.01,
                  0.35,
                  'Obs A Phase = %8.2f' % (obs_a_ph),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.32,
                  'Model A Phase = %8.2f' % (mod_a_ph),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.text(0.01,
                  0.15,
                  'Obs Ave = %8.2f ppb' % (obs_ave[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold')
        axo2.text(0.01,
                  0.12,
                  'Model Ave = %8.2f ppb' % (model_ave[ind]),
                  transform=axo2.transAxes,
                  fontweight='bold',
                  color='red')

        axo2.axvline(1., ymin=0, ymax=1, color='blue', linestyle='--')
        axo2.axvline(182.625, ymin=0, ymax=1, color='blue', linestyle='--')
        axo2.axvline(365.25, ymin=0, ymax=1, color='blue', linestyle='--')

        axo2.xaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
        axo2.yaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
        plt.gca().xaxis.set_major_formatter(FuncFormatter(xformatter))
        plt.gca().yaxis.set_major_formatter(FuncFormatter(yformatter))

        axo.set_title(
            'Site = %s, Country = %s, Continent = %s, Process Group = %s, Lat = %s, Lon = %s, Alt = %sm,\n Data Completeness = %s%%, Anthrome Class = %s, Raw Class = %s, Grid Index = %s,%s'
            % (ref, country, continent, group, lat, lon, alt, complete,
               a_class, r_class, lat_n, lon_n))

        plt.legend(loc='lower right')
        plt.tight_layout()
        axo.grid()
        axo2.grid()

        plt.show()
Example #14
0

species_dict = {'O3':'/work/home/db876/plotting_tools/binary_logs/v90103_2x2.5_GRID_O3.npy','CO':'/work/home/db876/plotting_tools/binary_logs/v90103_2x2.5_GRID_CO.npy','NO':'/work/home/db876/plotting_tools/binary_logs/v90103_2x2.5_GRID_NO.npy','NO2':'/work/home/db876/plotting_tools/binary_logs/v90103_2x2.5_GRID_NO2.npy', \
                'PAN':'/work/home/db876/plotting_tools/binary_logs/v90103_2x2.5_GRID_PAN.npy','C2H6':'/work/home/db876/plotting_tools/binary_logs/v90103_2x2.5_GRID_C2H6.npy','C3H8':'/work/home/db876/plotting_tools/binary_logs/v90103_2x2.5_GRID_C3H8.npy','ISOP':'/work/home/db876/plotting_tools/binary_logs/v90103_2x2.5_GRID_ISOP.npy',}
#species = raw_input('Choose species\n%s\n'%('   '.join(i for i in species_dict)))

for species in species_dict:

    model_f = species_dict[species]

    #get model grid dims. for sim. type
    lat_c, lat_e, lon_c, lon_e = modules.model_grids(model_version)
    gridbox_count = len(lat_c) * len(lon_c)

    #get model gridbox for obs site
    gridbox_n = modules.obs_model_gridbox(lat_e, lon_e, -20.2, 57.5)

    model_data = np.load(model_f)
    model_time = np.arange(0, 2191, 1. / 24)

    #get model grid dims. for sim. type
    lat_c, lat_e, lon_c, lon_e = modules.model_grids(model_version)
    gridbox_count = len(lat_c) * len(lon_c)

    model_var = model_data[gridbox_n::gridbox_count]
    model_var = model_var * 1e9

    #set plotting area & background to white
    fig = plt.figure(figsize=(20, 12))
    fig.patch.set_facecolor('white')
    ax = fig.add_subplot(1, 1, 1)