예제 #1
0
	""" This function returns a string with 3 decimal places, given the input x"""
	return '%.2f' % x	

def form5(x, pos):
	""" This function returns a string with 3 decimal places, given the input x"""
	return '%.7f' % x

xformatter = FuncFormatter(form2)
yformatter = FuncFormatter(form5)

#get species from current directory
present_dir = os.getcwd()
obs_fname,species,start_year,end_year,vres,timeres = modules.get_obs_info(present_dir)
model_fname,species,start_year,end_year = modules.get_model_info(present_dir)

obs_refs,obs_raw_time,obs_ref_time,obs_datetime_time,obs_std_var,obs_lats,obs_lons,obs_alt,obs_gap_inds = modules.read_obs_all(obs_fname,species,start_year,end_year)
model_raw_time,model_ref_time,model_datetime_time,model_std_var,lat_e,lon_e,lat_c,lon_c,grid_size,gridbox_count = modules.read_model_all(model_fname,species,start_year,end_year)

#get obs lat_lon grid central points
obs_lats_centre, obs_lons_centre, model_indices = modules.grid_obs_centre_convergance(lat_e,lon_e,obs_lats,obs_lons) 


#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(np.copy(obs_refs))

#--------------------------------------------------------
#load in periodic lsp data
obs_period_grp = Dataset('../obs_%s_%s/obs_sig_periods.nc'%(vres,timeres))
model_period_grp = Dataset('model_sig_periods.nc')
예제 #2
0
def interactive(event):
    modules.clicker_interactive_map_obsmodel(
        event, species, lat_e, lon_e, obs_datetimes, model_datetimes,
        obs_ts_grp, model_ts_grp, obs_period_grp, model_period_grp, obs_refs,
        tags, loc_dict, obs_d_waveform, obs_s_waveform, obs_all_waveform,
        model_d_waveform, model_s_waveform, model_all_waveform, fig, all_m)


#get species from current directory
present_dir = os.getcwd()
obs_fname, species, start_year, end_year, vres, timeres = modules.get_obs_info(
    present_dir)
model_fname, species, start_year, end_year = modules.get_model_info(
    present_dir)

obs_refs, obs_raw_time, obs_ref_time, obs_datetime_time, obs_std_var, obs_lats, obs_lons, obs_alt, obs_gap_inds = modules.read_obs_all(
    obs_fname, species, start_year, end_year)
model_raw_time, model_ref_time, model_datetime_time, model_std_var, lat_e, lon_e, lat_c, lon_c, grid_size, gridbox_count = modules.read_model_all(
    model_fname, species, start_year, end_year)

#get obs lat_lon grid central points
obs_lats_centre, obs_lons_centre, model_indices = modules.grid_obs_centre_convergance(
    lat_e, lon_e, obs_lats, obs_lons)

#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(np.copy(obs_refs))

#--------------------------------------------------------
#load in periodic lsp data
obs_period_grp = Dataset('../obs_%s_%s/obs_sig_periods.nc' % (vres, timeres))
model_period_grp = Dataset('model_sig_periods.nc')
예제 #3
0
import pandas as pd
import matplotlib.dates as dates
import seaborn as sns

models = [
    'CESMCAM', 'CMAM', 'GFDLAM3', 'GISSE2R', 'MIROCCHEM', 'MOCAGE', 'UMCAM'
]

#get color set for models
cmaplist = plt.cm.get_cmap('Set1')
array = np.linspace(0, 1, len(models))
cmaplist = [cmaplist(i) for i in array]

#read in obs
fobs = '/work/home/db876/observations/surface/O3/process/GLOBAL_SURFACE_O3_2000_2003_H_HP.nc'
obs_refs, obs_raw_time, obs_ref_time, obs_datetime_time, obs_std_var, obs_lats, obs_lons, obs_alt, obs_process_groups, obs_raw_class, obs_anthrome_class, obs_gap_inds = modules.read_obs_all(
    fobs, 'O3', 2000, 2003)

#obs_std_var[obs_std_var < 0] = np.NaN

tags = modules.get_tags(obs_refs)
areas = [
    'ANT', 'S_O', 'AF', 'SW_NA', 'NW_NA', 'NE_NA', 'CE_NA', 'SE_NA', 'C_NA',
    'S_EU', 'SW_EU', 'CW_EU', 'CS_EU', 'C_EU', 'E_EU', 'NW_EU', 'N_EU',
    'SE_AS', 'NE_AS', 'N_O', 'AL', 'ARC'
]
area_boundaries, area_tags, area_labels = modules.area_dicts()

for i in range(len(models)):

    fig, axes = plt.subplots(nrows=6, ncols=4, figsize=(19, 13))
    fig.patch.set_facecolor('white')
예제 #4
0
import matplotlib.dates as dates
import psutil
import gc
import matplotlib.gridspec as gridspec

present_dir = os.getcwd()
paths = present_dir.split("/")
species = paths[-4]

start_year = 2009
end_year = 2011

#read in obs ts data
obs_fname = '/work/home/db876/observations/surface/%s/process/GLOBAL_SURFACE_%s_2009_2011_H_HP.nc' % (
    species, species)
obs_refs, obs_raw_time, obs_ref_time, obs_datetime_time, obs_var, obs_lats, obs_lons, obs_alt, obs_groups, obs_raw_class, obs_anthrome_class, gap_inds = modules.read_obs_all(
    obs_fname, species, start_year, end_year)

#read in std model data
model_fname = '/work/home/db876/plotting_tools/model_files/GEOSCHEM_SURFACE_2009_2011_v1001_4x5_GEOS5_H_STD.nc'
model_raw_time, model_ref_time, model_datetime_time, model_std_var, lat_e, lon_e, lat_c, lon_c, grid_size, gridbox_count = modules.read_model_all(
    model_fname, species, start_year, end_year)

#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)

#--------------------------------------------------------
#load in periodic lsp data

obs_grp = Dataset('../obs_SURFACE_H/LSP_stats.nc')
예제 #5
0
def data_gen(f):
    print f

    ax = plt.subplot2grid((2,2), (0,0), colspan=2, rowspan=2)
    ax1 = plt.subplot2grid((2,2), (0,0), colspan=1)
    ax2 = plt.subplot2grid((2,2), (0,1), colspan=1)
    ax3 = plt.subplot2grid((2,2), (1,0), colspan=1)
    ax4 = plt.subplot2grid((2,2), (1,1), colspan=1)
    ax_list = [ax1,ax2,ax3,ax4]

    a = Basemap(projection='cyl',llcrnrlat=latlower_setup[0],urcrnrlat=latupper_setup[0],llcrnrlon=lonwest_setup[0],urcrnrlon=loneast_setup[0],resolution='c',ax = ax1)
    b = Basemap(projection='cyl',llcrnrlat=latlower_setup[1],urcrnrlat=latupper_setup[1],llcrnrlon=lonwest_setup[1],urcrnrlon=loneast_setup[1],resolution='c',ax = ax2)
    c = Basemap(projection='cyl',llcrnrlat=latlower_setup[2],urcrnrlat=latupper_setup[2],llcrnrlon=lonwest_setup[2],urcrnrlon=loneast_setup[2],resolution='c',ax = ax3)
    d = Basemap(projection='cyl',llcrnrlat=latlower_setup[3],urcrnrlat=latupper_setup[3],llcrnrlon=lonwest_setup[3],urcrnrlon=loneast_setup[3],resolution='c',ax = ax4)

    a.drawcoastlines()
    a.drawmapboundary()
    b.drawcoastlines()
    b.drawmapboundary()
    c.drawcoastlines()
    c.drawmapboundary()
    d.drawcoastlines()
    d.drawmapboundary()

    count = 0
    for ax in ax_list:
        if (count == 0) or (count == 3):
            ax.text(0.03, 0.18, label[count], transform=ax.transAxes,fontsize=30, va='top')
        if (count == 1) or (count == 2):
            ax.text(0.03, 0.97, label[count], transform=ax.transAxes,fontsize=30, va='top')
        count+=1

    obs_ts_fname = ts_files[f]
    last_split = obs_ts_fname.split('/')[-1]
    start_year = last_split.split('_')[3] 
    end_year = last_split.split('_')[4]
    obs_lsp_fname = 'obs_sig_periods_%s_%s.nc'%(start_year,end_year)
    print ts_files[f]
    print obs_lsp_fname
    print start_year,end_year
    
    title.set_text('%s - %s'%(start_year,end_year))

    obs_refs,obs_raw_time,obs_ref_time,obs_datetime_time,obs_std_var,obs_lats,obs_lons,obs_alt,obs_process_groups,obs_raw_class,obs_anthrome_class,obs_gap_inds = modules.read_obs_all(obs_ts_fname,species,start_year,end_year)

    #screen data for urban/high altitude sites
    
    #if type is urban then just keep low altitude urban sites 
    #if type is altitude then just keep rural high altitude sites
    #if type is rural then just keep low altitude rural sites
    #if type is all then do not checks
    
    bad_inds = []
    for x in range(len(obs_process_groups)):
        raw_class = obs_raw_class[x]
        process_group = obs_process_groups[x]
        obs_a = obs_alt[x]
        anthrome_class = obs_anthrome_class[x]
        
        #urban check
        if (output_set == 'rural') or (output_set == 'highalt') or (output_set == 'urban'):
            if (process_group == 'AirBase') or (process_group == 'EPA AQS') or (process_group == 'CAPMON') or (process_group == 'CASTNET') or (process_group == 'EANET') or (process_group == 'SEARCH'):
                if ('urban' in raw_class.lower()) or ('traffic' in raw_class.lower()) or ('industrial' in raw_class.lower()):
                    if (output_set == 'rural') or (output_set == 'highalt'):
                        bad_inds.append(x)
                else:
                    if output_set == 'urban':
                        bad_inds.append(x)
                
            elif (process_group == 'NAPS'):
                if ('i' == raw_class.lower()) or ('c' == raw_class.lower()):
                    if (output_set == 'rural') or (output_set == 'highalt'):
                        bad_inds.append(x)
                    
                else:
                    if output_set == 'urban':
                        bad_inds.append(x) 
        

            if anthrome_class == 'Dense Settlement':
                if (output_set == 'rural') or (output_set == 'highalt'):
                    bad_inds.append(x)
                
            else:
                if output_set == 'urban':
                    bad_inds.append(x)
        
        #altitude check
        if (output_set == 'urban') or (output_set == 'rural'):
            if int(obs_a) >= 1000:
                bad_inds.append(x)

        elif (output_set == 'highalt'):
            if int(obs_a) < 1000:    
                bad_inds.append(x)            

    #print obs_refs
    #print bad_inds
        
    bad_inds = np.array(list(set(bad_inds)))
    obs_refs = np.delete(obs_refs,bad_inds)
    obs_lats = np.delete(obs_lats,bad_inds)
    obs_lons = np.delete(obs_lons,bad_inds)
    
    #print obs_refs
    
    if len(obs_refs) == 0:
        return

    tags = modules.get_tags(obs_refs)

    obs_daily_mag,obs_daily_mag_spring,obs_daily_mag_summer,obs_daily_mag_autumn,obs_daily_mag_winter,obs_daily_phase\
    ,obs_daily_phase_spring,obs_daily_phase_spring,obs_daily_phase_summer,obs_daily_phase_autumn,obs_daily_phase_winter\
    ,obs_daily_phase_min,obs_daily_phase_min_spring,obs_daily_phase_min_summer,obs_daily_phase_min_autumn,obs_daily_phase_min_winter\
    ,obs_ave,obs_ave_spring,obs_ave_summer,obs_ave_autumn,obs_ave_winter,obs_ave_day,obs_ave_night,obs_seasonal_mag,obs_seasonal_mag_day\
    ,obs_seasonal_mag_night,obs_seasonal_phase,obs_seasonal_phase_day,obs_seasonal_phase_night,obs_seasonal_phase_min\
    ,obs_seasonal_phase_min_day,obs_seasonal_phase_min_night,obs_daily_ff,obs_daily_ff_spring,obs_daily_ff_summer,obs_daily_ff_autumn\
    ,obs_daily_ff_winter,obs_seasonal_ff,obs_seasonal_ff_day,obs_seasonal_ff_night,obs_daily_waveform,obs_daily_waveform_spring\
    ,obs_daily_waveform_summer,obs_daily_waveform_autumn,obs_daily_waveform_winter,obs_seasonal_waveform,obs_seasonal_waveform_day\
    ,obs_seasonal_waveform_night,obs_full_waveform,obs_periodic_variance_daily,obs_periodic_variance_daily_spring,obs_periodic_variance_daily_summer\
    ,obs_periodic_variance_daily_autumn,obs_periodic_variance_daily_winter,obs_periodic_variance_seasonal,obs_periodic_variance_seasonal_day\
    ,obs_periodic_variance_seasonal_night,obs_periodic_variance_all = modules.get_obs_specific(obs_lsp_fname,obs_refs)
    
    if output_type == 'amplitude':
        if period_type == 'd':
            param = obs_daily_mag
        elif period_type == 's':    
            param = obs_seasonal_mag
    if output_type == 'phase':
        if period_type == 'd':
            param = obs_daily_phase
        elif period_type == 's':    
            param = obs_seasonal_phase
    if output_type == 'average':
        param = obs_ave

    #plot
    #---------------------------------------
    count = 0

    for ax in ax_list:

        if count == 3:
            test = []
            other_tags = ['AF','ANT','ARC','OC','O','SA','MA']
            for i in tags:
                if i in other_tags:
                    test.append(True)
                else:
                    test.append(False)
            test = np.array(test)
        else:
            current_tag = label_out[count] 
            test = tags == current_tag
    
        current_lons = obs_lons[test]
        current_lats = obs_lats[test]
        current_refs = obs_refs[test]
        current_param = param[test]

        if count == 0:
            if int(start_year) < 1980:
                m_size = 200
            else:
                m_size= 50
        if count == 1:
            if int(start_year) < 1986:
                m_size = 200
            else:
                m_size = 30
        if count == 2:
            m_size = 250
        if count == 3:
            m_size = 300
        
        if count == 0:
            X,Y = a(current_lons,current_lats)
            for i in range(len(current_lons)):
                all = a.scatter(X[i],Y[i],c=current_param[i], s=m_size, vmin = min,vmax = max, marker = 'o',edgecolor='black',linewidth=0.5,cmap=cm,zorder=10)
        
        elif count == 1:
            X,Y = b(current_lons,current_lats)
            for i in range(len(current_lons)):
                all = b.scatter(X[i],Y[i],c=current_param[i], s=m_size, vmin = min,vmax = max, marker = 'o',edgecolor='black',linewidth=0.5,cmap=cm,zorder=10)
        
        elif count == 2:
            X,Y = c(current_lons,current_lats)
            for i in range(len(current_lons)):
                all = c.scatter(X[i],Y[i],c=current_param[i], s=m_size, vmin = min,vmax = max, marker = 'o',edgecolor='black',linewidth=0.5,cmap=cm,zorder=10)
        
        elif count == 3:
            X,Y = d(current_lons,current_lats)
            for i in range(len(current_lons)):
                all = d.scatter(X[i],Y[i],c=current_param[i], s=m_size, vmin = min,vmax = max, marker = 'o',edgecolor='black',linewidth=0.5,cmap=cm,zorder=10)
        
        count+=1
    
    cb = fig.colorbar(all, cax=cbar_ax,orientation ='horizontal')
    if output_type == 'phase':
        if period_type == 'd':
            cb.set_label('Hour', fontsize = 24)
        elif period_type == 's':
            cb.set_label('Month', fontsize = 24)
    elif output_type == 'amplitude':
        cb.set_label('Amplitude (ppb)', fontsize = 24)
    elif output_type == 'average':
        cb.set_label('Average (ppb)', fontsize = 24)    
        
    cb.ax.tick_params(labelsize=22)