def create_an_empty_map(plot_four_maps=False,ncols=None): start_year=1947 input_folder='/ptmp/Alon.Stern/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg_bergs_Delta2/' letter_labels=np.array(['(a)','(b)','(c)','(d)','(e)','(f)','(g)','(h)','(i)']) field='CN' months_str='all' file_type='ice_month' pole='south' (All_data, lat, lon,z) =generate_data_file(start_year, start_year,input_folder,field, months_str,file_type,section_axes='xy',lat_lon_bounds=None) projection = 'splaea' boundinglat=-45 #boundinglat=-57.5 data_mean=None #Plot blank map. if plot_four_maps==True: for k in range(ncols): subplot(1,ncols,k+1) plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title='',\ p_values=None,cscale=None,field=None,colorbar_on=True,return_data_map=False,plot_lat_lon_lines=True,boundinglat=boundinglat) ax=gca() text(1,1,letter_labels[k], ha='right', va='bottom',transform=ax.transAxes,fontsize=15) else: plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title='',\ p_values=None,cscale=None,field=None,colorbar_on=True,return_data_map=False,plot_lat_lon_lines=True,boundinglat=boundinglat) m = Basemap(projection=projection, boundinglat=boundinglat, lon_0=180) #x, y = m(lon, lat) #x, y = m(0, -70) #m.scatter(x,y,3,marker='o',color='black') return [lat,lon,m]
def produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list,datapath, file_extension,cscale, row_num,difference_on,pole,field_name,boundinglat): letter_labels=np.array(['(a)','(b)','(c)','(d)','(e)','(f)','(g)','(h)','(i)']) title=None for k in range(ncols): print 'Plotting ' + field_name + ' fields for ' + Delta_list[k] subplot(nrows,ncols,(row_num-1)*ncols+(k+1)) filename=datapath + Delta_list[k] + file_extension (lat ,lon, data, p_values,field)=load_data_from_mat_file(filename) if field=='melt': data=data*(60*60*24*356.25) #Multiply to get units /year rather than /s data=data/850 # Multiply to get units of m/year (cscale,datamap)=plot_polar_field(lat,lon,data,pole,difference_on,title,p_values,cscale,field,colorbar_on=False,return_data_map=True,\ plot_lat_lon_lines=True,boundinglat=boundinglat) if k==0: plt.ylabel(y_title_list[row_num-1], fontsize=20, labelpad=25, multialignment='center') ax=gca() text(1,1,letter_labels[(row_num-1)*ncols+(k)], ha='right', va='bottom',transform=ax.transAxes,fontsize=15) #Creating colorbar fig.subplots_adjust(right=0.85) cbar_ax = fig.add_axes([0.85,0.11 , 0.03, 0.22]) cbar=fig.colorbar(datamap, cax=cbar_ax) cbar.set_label(colorbar_unit_list[row_num-1], rotation=90,fontsize=20) cbar.ax.tick_params(labelsize=20) if field!='melt': tick_locator = ticker.MaxNLocator(nbins=5) cbar.locator = tick_locator cbar.update_ticks()
def produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list,datapath, file_extension,cscale, row_num,\ difference_on,pole,field_name,significant_only,y_title_list2): title=None letter_labels=np.array(['(a)','(b)','(c)','(d)','(e)','(f)','(g)','(h)','(i)']) for k in range(ncols): print 'Plotting ' + field_name + ' fields for ' + Delta_list[k] ax=subplot(nrows,ncols,(row_num-1)*ncols+(k+1)) filename=datapath + Delta_list[k] + file_extension (lat ,lon, data, p_values,field)=load_data_from_mat_file(filename) #print min(p_values) if significant_only==False: p_values=None if field=='melt': data=data*(60*60*24*356.25) #Multiply to get units /year rather than /s data=data/850 # Multiply to get units of m/year (cscale,datamap)=plot_polar_field(lat,lon,data,pole,difference_on,title,p_values,cscale,field,colorbar_on=False,return_data_map=True) if k==0: plt.ylabel(y_title_list[row_num-1], fontsize=20, labelpad=25, multialignment='center') #ax.annotate(y_title_list[row_num-1], xy=(-0.4, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') #ax.annotate(y_title_list2[row_num-1], xy=(-0.25, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') if row_num==1: ax.set_title(title_list[Delta_list[k]], fontsize=20,y=1.13) text(1,1,letter_labels[(row_num-1)*ncols+(k)], ha='right', va='bottom',transform=ax.transAxes,fontsize=15) #Creating colorbar fig.subplots_adjust(right=0.8) #cbar_ax = fig.add_axes([0.85, 0.103+((nrows-row_num)*0.165), 0.03, 0.13]) cbar_ax = fig.add_axes([0.825, 0.115+((nrows-row_num)*0.435), 0.03, 0.33]) if row_num==1: ticks=np.array([-0.04 ,-0.02 ,0 ,0.02,0.04]) if row_num==2: ticks=np.array([-0.1 ,-0.05 ,0 ,0.05,0.1]) cbar=fig.colorbar(datamap, cax=cbar_ax,ticks=ticks) cbar.set_label(colorbar_unit_list[row_num-1], rotation=90,fontsize=20) cbar.ax.tick_params(labelsize=20)
def produce_figure_panel(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list,datapath, file_extension,cscale, panel_num, \ difference_on,pole,field_name,field_type_list,axes_direction='xy',significant_only=False,boundinglat=-45.): title = None letter_labels = np.array( ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)']) print 'Plotting ' + field_name + ' fields for ' + Delta_list[0] ax = subplot(nrows, ncols, panel_num) filename = datapath + Delta_list[0] + file_extension #print filename (lat, lon, data, p_values, field, layer_interface, lat_lon_bounds) = load_data_from_mat_file(filename) if significant_only == False: p_values = None if field == 'melt': data = data * (60 * 60 * 24 * 356.25 ) #Multiply to get units /year rather than /s data = data / 850 # Multiply to get units of m/year if axes_direction == 'xy': (cscale,datamap)=plot_polar_field(lat,lon,data,pole,difference_on,title,p_values,cscale,field,colorbar_on=False,return_data_map=True\ ,plot_lat_lon_lines=True,boundinglat=boundinglat) else: file_type = 'ocean_month_z' datamap=plot_vertical_section(lon,lat,data,difference_on,title,p_values,cscale,field,layer_interface,axes_direction,lat_lon_bounds,file_type,\ colorbar_on=False,return_data_map=True) #if panel_num==1: # ax.set_title(title_list[Delta_list[k]], fontsize=18, y=1.13) #Creating colorbar if panel_num > 1: #cbar_ax=fig.add_axes([0.41+((panel_num-2)*0.28),0.15,0.2,0.05]) #cbar=fig.colorbar(datamap, cax=cbar_ax, orientation="horizontal") if panel_num == 2: ticks = np.array([10**-6, 10**-4, 10**-2, 10**0]) if panel_num == 3: ticks = np.array([-0.04, -0.02, 0, 0.02, 0.04]) cbar = fig.colorbar(datamap, orientation="horizontal", pad=0.05, ticks=ticks) cbar.set_label(colorbar_unit_list[panel_num - 1], fontsize=20) cbar.ax.tick_params(labelsize=20) #if panel_num!=2: # tick_locator = ticker.MaxNLocator(nbins=5) # cbar.locator = tick_locator # cbar.update_ticks() text(1, 1, letter_labels[panel_num - 1], ha='right', va='bottom', transform=ax.transAxes, fontsize=15)
def produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list,datapath, file_extension,cscale, plot_num, \ difference_on,pole,field_name,axes_direction='xy', significant_only='True'): title=None letter_labels=np.array(['(a)','(b)','(c)','(d)','(e)','(f)','(g)','(h)','(i)']) ncols=1 nrows= 3 for k in range(ncols): print 'Plotting ' + field_name + ' fields for ' + Delta_list[k] ax=subplot(ncols,nrows,plot_num) filename=datapath + Delta_list[k] + file_extension #print filename (lat ,lon, data, p_values,field,layer_interface,lat_lon_bounds)=load_data_from_mat_file(filename) if significant_only==False: p_values=None if axes_direction=='xy': (cscale,datamap)=plot_polar_field(lat,lon,data,pole,difference_on,title,p_values,cscale,field,colorbar_on=False,return_data_map=True) else: file_type='ocean_month_z' datamap=plot_vertical_section(lon,lat,data,difference_on,title,p_values,cscale,field,layer_interface,axes_direction,lat_lon_bounds,file_type,\ colorbar_on=False,return_data_map=True) #print y_title_list #ax.set_title(y_title_list[plot_num-1], fontsize=18, y=1.13) ax.set_title(y_title_list[plot_num-1], fontsize=20) if k>0: ax.set_yticks([]) #plt.title( #ax.annotate(y_title_list[plot_num-1], xy=(-0.6, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') if plot_num==1: plt.ylabel('depth (m)', fontsize=20) #ax.annotate(y_title_list[plot_num-1], xy=(-0.6, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') if plot_num!=1: ax.set_yticks([]) plt.xlabel('latitude (deg)', fontsize=20) ax.set_xticks([-40 ,-60, -80]) text(1,1,letter_labels[(plot_num-1)*ncols+(k)], ha='right', va='bottom',transform=ax.transAxes,fontsize=15) #Creating colorbar fig.subplots_adjust(right=0.8) if plot_num==3: cbar_ax = fig.add_axes([0.85, 0.1, 0.033, 0.8]) cbar=fig.colorbar(datamap, cax=cbar_ax) cbar.set_label(colorbar_unit_list[plot_num-1], rotation=90,fontsize=20) cbar.ax.tick_params(labelsize=20) tick_locator = ticker.MaxNLocator(nbins=5) cbar.locator = tick_locator cbar.update_ticks() for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] + ax.get_xticklabels() + ax.get_yticklabels()): item.set_fontsize(20)
def produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list,datapath, file_extension,cscale, row_num, \ difference_on,pole,field_name,axes_direction='xy', significant_only='True'): title=None letter_labels=np.array(['(a)','(b)','(c)','(d)','(e)','(f)','(g)','(h)','(i)']) for k in range(ncols): print 'Plotting ' + field_name + ' fields for ' + Delta_list[k] ax=subplot(nrows,ncols,(row_num-1)*ncols+(k+1)) filename=datapath + Delta_list[k] + file_extension #print filename (lat ,lon, data, p_values,field,layer_interface,lat_lon_bounds)=load_data_from_mat_file(filename) if significant_only==False: p_values=None if axes_direction=='xy': (cscale,datamap)=plot_polar_field(lat,lon,data,pole,difference_on,title,p_values,cscale,field,colorbar_on=False,return_data_map=True) else: file_type='ocean_month_z' datamap=plot_vertical_section(lon,lat,data,difference_on,title,p_values,cscale,field,layer_interface,axes_direction,lat_lon_bounds,file_type,\ colorbar_on=False,return_data_map=True) if row_num==1: #ax.set_title(title_list[k], fontsize=18, y=1.13) ax.set_title(title_list[Delta_list[k]], fontsize=18, y=1.13) #if k==0: # plt.ylabel(y_title_list[row_num-1], fontsize=18, labelpad=25) if k>0: ax.set_yticks([]) if k==0 and row_num<4: ax.annotate(y_title_list[row_num-1], xy=(-0.6, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') #ax.annotate('Sector', xy=(-0.45, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') # plt.ylabel(y_title_list[i], fontsize=18, labelpad=25) if k==0 and row_num>0: plt.ylabel('depth (m)', fontsize=14) ax.annotate(y_title_list[row_num-1], xy=(-0.6, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') if row_num!=nrows: ax.set_xticks([]) else: plt.xlabel('latitude (deg)', fontsize=14) ax.set_xticks([-40 ,-60, -80]) text(1,1,letter_labels[(row_num-1)*ncols+(k)], ha='right', va='bottom',transform=ax.transAxes) #Creating colorbar fig.subplots_adjust(right=0.8) cbar_ax = fig.add_axes([0.85, 0.12+((nrows-row_num)*0.28), 0.033, 0.2]) cbar=fig.colorbar(datamap, cax=cbar_ax) cbar.set_label(colorbar_unit_list[row_num-1], rotation=90) tick_locator = ticker.MaxNLocator(nbins=5) cbar.locator = tick_locator cbar.update_ticks()
def produce_figure_panel(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list,datapath, file_extension,cscale, panel_num, \ difference_on,pole,field_name,field_type_list,axes_direction='xy'): title = None print 'Plotting ' + field_name + ' fields for ' + Delta_list[0] ax = subplot(nrows, ncols, panel_num) filename = datapath + Delta_list[0] + file_extension #print filename (lat, lon, data, p_values, field, layer_interface, lat_lon_bounds) = load_data_from_mat_file(filename) if field == 'melt': data = data * (60 * 60 * 24 * 356.25 ) #Multiply to get units /year rather than /s data = data / 850 # Multiply to get units of m/year data = data * (0.00069) field = 'iron' if axes_direction == 'xy': (cscale, datamap) = plot_polar_field(lat, lon, data, pole, difference_on, title, p_values, cscale, field, colorbar_on=False, return_data_map=True) else: file_type = 'ocean_month_z' datamap=plot_vertical_section(lon,lat,data,difference_on,title,p_values,cscale,field,layer_interface,axes_direction,lat_lon_bounds,file_type,\ colorbar_on=False,return_data_map=True) #if panel_num==1: # ax.set_title(title_list[Delta_list[k]], fontsize=18, y=1.13) #Creating colorbar if panel_num > 0: #cbar_ax=fig.add_axes([0.41+((panel_num-2)*0.28),0.15,0.2,0.05]) #cbar=fig.colorbar(datamap, cax=cbar_ax, orientation="horizontal") cbar = fig.colorbar(datamap, orientation="horizontal") cbar.set_label(colorbar_unit_list[panel_num - 1])
def main(): parser = argparse.ArgumentParser() args = parser.parse_args() #Flags save_figure = True significant_vals_only = False plot_traj_fields = False plot_melt_fields = True plot_traj_AB_fields = False plot_sea_ice_conc_fields = False plot_sea_ice_thickness_fields = False plot_all_panels_without_data = False #False makes the real figure #Parameters; pole = 'north' title = None cscale = None Delta_list = np.array(['Delta1', 'Delta3', 'Delta9']) #Title_list=np.array(['Delta1 (Area=0.0026km^2)', 'Delta6 (Area=0.029km^2)', 'Delta9 (Area=1.8km^2)']) #Title_list=np.array(['Area=0.0026km^2', 'Area=0.35km^2', 'Area=1.8km^2']) #title_list = {'Delta1': 'Area=0.0026km^2', 'Delta3':'Area=0.029km^2', 'Delta4':'Area=0.12km^2' , 'Delta6': 'Area=0.35km^2' , 'Delta9': 'Area=1.8km^2'} title_list = { 'Delta1': 'Length=60m', 'Delta3': 'Length=200m', 'Delta4': 'Length=350m$', 'Delta6': 'Length=700m$', 'Delta9': 'Length=1600m' } color_vec = np.array([ 'blue', 'red', 'green', 'grey', 'purple', 'cyan', 'magenta', 'black', 'orange', 'coral', 'yellow', 'orchid', 'black', 'orange', 'coral', 'yellow', 'orchid' ]) letter_labels = np.array( ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)']) y_title_list = np.array([ 'Iceberg\n Trajectories', 'AB+Ross\nIcebergs Trajectories', 'Iceberg Melt' ]) #colorbar_unit_list=np.array(['', 'melt (kg/m^2/s)', 'Conc (non-dim)', 'Thickness (m)','']) colorbar_unit_list = np.array( ['', '', 'melt (m/year)', 'Conc (non-dim)', 'Thickness (m)', '']) nrows = 1 ncols = len(Delta_list) #3 boundinglat = 45 projection = 'nplaea' datapath = '/home/Alon.Stern/Iceberg_Project/iceberg_scripts/python_scripts/size_matters_paper/processed_data/' #Setting up the figure fig, axes = plt.subplots(nrows=nrows, ncols=ncols) #This is used to plot the figure without the data for playing this anotations. if plot_all_panels_without_data == True: save_figure = False else: #Plotting Trajectory Fields if plot_traj_fields == True: row_num = 1 for k in range(ncols): print 'Plotting Traj Fields for ' + Delta_list[k] ax = subplot(nrows, ncols, (row_num - 1) * ncols + (k + 1)) filename = datapath + Delta_list[ k] + '_traj_1994_to_1995_all_south.mat' (lat, lon, Total_berg_lon, Total_berg_lat) = load_traj_data_from_mat_file(filename) m = Basemap(projection=projection, boundinglat=boundinglat, lon_0=180) plot_polar_field(lat,lon,None,pole,difference_on=0.,title=None,\ p_values=None,cscale=None,field=None,colorbar_on=True,return_data_map=False,plot_lat_lon_lines=True,boundinglat=boundinglat) m.scatter(Total_berg_lon, Total_berg_lat, 1, marker='o', color=color_vec[k]) ax.set_title(title_list[Delta_list[k]], fontsize=20, y=1.13) text(1, 1, letter_labels[k], ha='right', va='bottom', transform=ax.transAxes, fontsize=15) if k == 0: plt.ylabel(y_title_list[k], fontsize=20, labelpad=25, multialignment='center') fig.subplots_adjust(right=0.8) #Plotting Melt Fields if plot_melt_fields == True: cscale = None row_num = 1 difference_on = 0 field_name = 'melt' file_extension = '_melt_1959_to_2019_all_south_xy.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, \ file_extension,cscale, row_num,difference_on, pole,field_name,boundinglat) #Plotting Sea Ice Conc Fields if plot_sea_ice_conc_fields == True: cscale = 0.04 row_num = 1 difference_on = 1 field_name = 'Sea Ice Conc' file_extension = '_CN_1959_to_2019_all_south_xy_anomaly.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath,\ file_extension,cscale, row_num,difference_on, pole,field_name,boundinglat) #Plotting Sea Ice Thickness Fields if plot_sea_ice_thickness_fields == True: cscale = 0.1 row_num = 2 difference_on = 1 field_name = 'Sea Ice Thickness' file_extension = '_HI_1959_to_2019_all_south_xy_anomaly.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list,\ datapath, file_extension,cscale, row_num,difference_on, pole,field_name, boundinglat) #Plotting Trajectory Fields if plot_traj_AB_fields == True: boundinglat = -45 projection = 'splaea' row_num = 2 for k in range(ncols): print 'Plotting Traj Fields for ' + Delta_list[k] ax = subplot(nrows, ncols, (row_num - 1) * ncols + (k + 1)) #filename=datapath + Delta_list[k] + '_traj_1994_to_1995_all_south_AB_plus_Ross.mat' filename = datapath + Delta_list[ k] + '_traj_1994_to_1995_all_south_AB.mat' (lat, lon, Total_berg_lon, Total_berg_lat) = load_traj_data_from_mat_file(filename) m = Basemap(projection=projection, boundinglat=boundinglat, lon_0=180) plot_polar_field(lat,lon,None,pole,difference_on=0.,title=None,\ p_values=None,cscale=None,field=None,colorbar_on=True,return_data_map=False,plot_lat_lon_lines=True,boundinglat=boundinglat) m.scatter(Total_berg_lon, Total_berg_lat, 1, marker='o', color=color_vec[k]) text(1, 1, letter_labels[3 + k], ha='right', va='bottom', transform=ax.transAxes, fontsize=15) if k == 0: plt.ylabel(y_title_list[row_num - 1], fontsize=20, labelpad=25, multialignment='center') fig.subplots_adjust(right=0.8) subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) fig.set_size_inches(21.0, 8.5, forward=True) if save_figure == True: plt.savefig('figures/Northern_melt_D1_D3_D9_trajAB.png', dpi=300, bbox_inches='tight') plt.show()
def main(): #Clear screen #os.system('clear') start_year=1915 end_year0=1992 Number_of_years=0 input_folder='/ptmp/Alon.Stern/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg_bergs_Delta9/' second_folder=None field='CN' months_str='all' constraint_name=None months=range(0,11) file_type='ice_month' pole='north' pole=None save_traj_data=False Title_list={'Delta1':'$L_{0}=60m$','Delta2':'$L_{0}=100m$','Delta3':'$L_{0}=200m$','Delta4':'$L_{0}=350m$','Delta5':'$L_{0}=500m$',\ 'Delta6':'$L_{0}=700m$','Delta7':'$L_{0}=900m$','Delta8':'$L_{0}=1200m$','Delta9':'$L_{0}=1600m$','Delta10':'$L_{0}=2200m$'} color_vec=np.array(['blue', 'red', 'green', 'grey','purple', 'cyan', 'magenta', 'black', 'orange', 'coral', 'yellow', 'orchid', 'black', 'orange', 'coral', 'yellow', 'orchid' ]) cNorm = mpl.colors.LogNorm(vmin=8.8e7, vmax=7.4e11) plot_each_time=False # The constraint has the form [field_name, lower_bonud, upper_bound] #constraint1=np.array(['lat',-65.,-10.]) # Latituds north of -60 in the southern hemisphere constraint_depth = {'Constraint_field_name': 'depth', 'lower_bound': 3000 , 'upper_bound': 8000, 'original_values': True} constraint_dist_from_calving = {'Constraint_field_name': 'distance_from_calving', 'lower_bound': 1000000 , 'upper_bound': 10000000000000, 'original_values': False} constraint_lon_Rink = {'Constraint_field_name': 'lon', 'lower_bound': -55 , 'upper_bound': -45, 'original_values': True} #Longitude of Rink constraint_lat_Rink = {'Constraint_field_name': 'lat', 'lower_bound': 70.75 , 'upper_bound': 72.75, 'original_values': True} #Longitude of Rink constraints=[] #mass=3.9e11 ;constraint_name='massD9' #mass=8.8e7 ;constraint_name='massD1' #constraint_m = {'Constraint_field_name': 'mass', 'lower_bound': mass-100 , 'upper_bound': mass+100, 'original_values': True} #constraints.append(constraint2) ; constraint_name='AB' #constraints.append(constraint3) ; constraint_name='AB_plus_Ross' #constraints.append(constraint4) #constraints.append(constraint_m) #constraints.append(constraint_depth) #constraints.append(constraint_dist_from_calving) constraints.append(constraint_lon_Rink) constraints.append(constraint_lat_Rink) #constraints.append(constraint_SH) #plot_multiple_panels==1: constraint2 = {'Constraint_field_name': 'lon', 'lower_bound': -150 , 'upper_bound': -65, 'original_values': True} #Longitude of AB root_path='/ptmp/aas/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg' (All_data, lat, lon,z) =generate_data_file(start_year, start_year, input_folder, field, months_str, file_type) data_mean=np.squeeze(np.mean(All_data,axis=0)) data_mean=None #Deciding on the projection. if pole=='south': projection = 'splaea' boundinglat=-45 if pole=='north': projection = 'nplaea' boundinglat=45 if pole==None: projection = 'lcc' lat_1=80 lat_2=60 lat_0=63.5 lon_0=-59. run_names=np.array(['tournadre']) ; naming_flag='Delta' #run_names=np.array(['Delta1', 'Delta3', 'Delta9']) ; naming_flag='Delta' #run_names=np.array(['Delta1', 'Delta2','Delta3','Delta6', 'Delta9','Delta10']) ; naming_flag='Delta' run_names=np.array(['Delta1' ,'Delta3', 'Delta9']) ; naming_flag='Delta' nrows=1 ;ncols=3 fig, axes = plt.subplots(nrows=nrows, ncols=ncols) for k in range(ncols*nrows): input_folder=root_path + '_bergs_' + run_names[k] subplot(nrows,ncols,k+1) print input_folder #Making sure the years work (min_year, max_year)=find_max_min_years(input_folder,'.iceberg_trajectories.nc') end_year=min(max_year,end_year0) start_year=max(end_year-Number_of_years,min_year) title1= run_names[k] + ' (' + str(start_year) + ' to ' + str(end_year) + ')' #plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title=title1\ # ,p_values=None,cscale=None,field=None,colorbar_on=True,return_data_map=False,plot_lat_lon_lines=True,boundinglat=boundinglat) if pole==None: m = Basemap(width=1750000,height=4300000, rsphere=(6378137.00,6356752.3142),resolution='l',area_thresh=1000.,\ projection=projection,lat_1=lat_1,lat_2=lat_2,lat_0=lat_0,lon_0=lon_0) else: m = Basemap(projection=projection, boundinglat=boundinglat, lon_0=180) m.drawcoastlines() m.fillcontinents(color='grey',lake_color='white') count=0 Total_berg_lat=np.array([]) Total_berg_lon=np.array([]) Total_berg_mass0=np.array([]) for year in range(start_year, end_year+1): count=count+1 filename ='/' + str(year) + '0101.iceberg_trajectories.nc' input_file=input_folder + filename print input_file all_bergs_lat = get_valid_data_from_traj_file(input_file,'lat') all_bergs_lon = get_valid_data_from_traj_file(input_file,'lon') all_bergs_mass0 = get_valid_data_from_traj_file(input_file,'mass',subtract_orig=False,get_original_values=True) # Getting iceberg mass too. #Adding constraints to the data: print 'Lendth of original field: ' , len(all_bergs_lat) all_bergs_lat=add_constraint_to_data(input_file,all_bergs_lat,constraints) all_bergs_lon=add_constraint_to_data(input_file,all_bergs_lon,constraints) all_bergs_mass0=add_constraint_to_data(input_file,all_bergs_mass0,constraints) print 'Lendth of field after constraints: ' , len(all_bergs_lat) x, y = m(all_bergs_lon, all_bergs_lat) if plot_each_time==True: plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title=title1\ ,p_values=None,cscale=None,field=None,colorbar_on=True,return_data_map=False,plot_lat_lon_lines=True,boundinglat=boundinglat) m.scatter(x,y,3,marker='o',color=color_vec[k]) #plt.plot(all_bergs_lon,all_bergs_lat,'o') Total_berg_lon=np.concatenate((Total_berg_lon,x),axis=0) Total_berg_lat=np.concatenate((Total_berg_lat,y),axis=0) Total_berg_mass0=np.concatenate((Total_berg_mass0,all_bergs_mass0),axis=0) datamap=m.scatter(Total_berg_lon,Total_berg_lat, c=Total_berg_mass0, marker='o',cmap='jet',norm=cNorm) if run_names[k]=='tournadre': cbar=fig.colorbar(datamap) cbar.set_label('Calving Mass (kg)') else: plt.title(Title_list[run_names[k]]) if save_traj_data==True: save_traj_mat_file(lat,lon, Total_berg_lon, Total_berg_lat, Total_berg_mass0, pole,input_folder,start_year,end_year,months_str,constraint_name) #plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title=title1) #m.scatter(Total_berg_lon,Total_berg_lat,1,marker='o',color=color_vec[k]) output_file= 'figures/Leigh_Rink_figure2.png' #output_file= 'figures/Northern_Trajectories_tournadre.png' #output_file= 'figures/Northern_Trajectories_Deltas.png' fig.set_size_inches(21.0, 8.5,forward=True) plt.savefig(output_file, dpi=150, bbox_inches='tight', pad_inches=0.4) plt.show() print 'Script complete'
def main(): parser = argparse.ArgumentParser() args = parser.parse_args() #Flags save_figure = True significant_vals_only = False plot_traj_fields = False plot_melt_fields = True plot_CN_fields = False plot_all_panels_without_data = False #False makes the real figure #Parameters; pole = 'south' title = None cscale = None Delta_list = np.array(['tournadre']) #yitle_list=np.array(['Delta1 (Area=0.0026km^2)', 'Delta6 (Area=0.029km^2)', 'Delta9 (Area=1.8km^2)']) #title_list = {'Delta1': 'Area=0.0026km^2', 'Delta3':'Area=0.029km^2', 'Delta4':'Area=0.12km^2' , 'Delta6': 'Area=0.35km^2' , 'Delta9': 'Area=1.8km^2'} title_list = { 'Delta1': 'Length=60m', 'Delta3': 'Length=200m', 'Delta4': 'Length=350m$', 'Delta6': 'Length=700m$', 'Delta9': 'Length=1600m' } color_vec = np.array([ 'blue', 'red', 'green', 'grey', 'purple', 'cyan', 'magenta', 'black', 'orange', 'coral', 'yellow', 'orchid', 'black', 'orange', 'coral', 'yellow', 'orchid' ]) #y_title_list=np.array(['Sea Surface Density', 'AB+Ross', 'East Antarctia', 'Weddell','Depth Integrated Density']) y_title_list = np.array(['Sea Surface', 'Sea Surface', 'Sea Surface']) field_type_list = np.array(['Temperature', 'Salinity', 'Density']) #y_title_list=np.array(['SSD','Column Density', 'AB+Ross', 'East Antarctia', 'Weddell']) colorbar_unit_list = np.array([ 'Iron Concentration ($mol$/$m^2$)', 'melt (m/year)', 'Sea Ice Conc anomaly ', 'density (kg/$m^{3}$)', 'density (kg/$m^{3}$)' ]) nrows = 1 ncols = 1 temperature_scale = 0.2 salinity_scale = 0.1 density_scale = 0.04 datapath = '/home/Alon.Stern/Iceberg_Project/iceberg_scripts/python_scripts/size_matters_paper/processed_data/' #Setting up the figure fig, axes = plt.subplots(nrows=nrows, ncols=ncols) #This is used to plot the figure without the data for playing this anotations. if plot_all_panels_without_data == True: save_figure = False else: #Plotting Panels #Plotting Trajectory Fields if plot_traj_fields == True: boundinglat = -45 projection = 'splaea' panel_num = 1 print 'Plotting Traj Fields for ' + Delta_list[0] #ax=subplot(nrows,ncols,(row_num-1)*ncols+(k+1)) filename = datapath + Delta_list[ 0] + '_traj_1994_to_1995_all_south.mat' (lat, lon, Total_berg_lon, Total_berg_lat, mass0) = load_traj_data_from_mat_file(filename) m = Basemap(projection=projection, boundinglat=boundinglat, lon_0=180) ax = subplot(nrows, ncols, panel_num) plot_polar_field(lat, lon, None, pole, difference_on=0., title=None) #m.scatter(Total_berg_lon,Total_berg_lat,1,marker='o',color='black') cNorm = mpl.colors.LogNorm(vmin=8.8e7, vmax=7.4e11) datamap = m.scatter(Total_berg_lon, Total_berg_lat, c=mass0, marker='o', cmap='jet', norm=cNorm) cbar = fig.colorbar(datamap, orientation="horizontal") cbar.set_label('Calving Mass (kg)') #ax.set_title(title_list[Delta_list[k]], fontsize=18,y=1.13) #plt.ylabel(y_title_list[k], fontsize=18, labelpad=25) if plot_melt_fields == True: cscale = None panel_num = 1 difference_on = 0 axes_direction = 'xy' field_name = 'melt' file_extension = '_melt_1959_to_2019_all_south_xy.mat' produce_figure_panel(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, file_extension,cscale, \ panel_num,difference_on, pole,field_name,field_type_list,axes_direction) if plot_CN_fields == True: cscale = None panel_num = 3 difference_on = 1 axes_direction = 'xy' field_name = 'CN' file_extension = '_CN_1959_to_2019_all_south_xy_anomaly.mat' #Remember to change this!!! produce_figure_panel(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, file_extension,cscale, \ panel_num,difference_on, pole,field_name,field_type_list,axes_direction) subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) fig.set_size_inches(10.5, 10.5, forward=True) if save_figure == True: plt.savefig('iron_melt_figure.png') plt.show()
def main(): parser = argparse.ArgumentParser() args = parser.parse_args() #Flags save_figure=True significant_only=False plot_SST_fields=True plot_AB_plus_Ross_Temp_Section=True plot_EastA_plus_Adele_Temp_Section=True plot_Weddell_Temp_Section=True plot_depth_int_temp_fields=True plot_all_panels_without_data=False #False makes the real figure #Parameters; pole='south' title=None cscale=None Delta_list=np.array(['Delta1', 'Delta3', 'Delta9']) #yitle_list=np.array(['Delta1 (Area=0.0026km^2)', 'Delta6 (Area=0.029km^2)', 'Delta9 (Area=1.8km^2)']) #title_list = {'Delta1': 'Area=0.0026km^2', 'Delta3':'Area=0.029km^2', 'Delta4':'Area=0.12km^2' , 'Delta6': 'Area=0.35km^2' , 'Delta9': 'Area=1.8km^2'} title_list = {'Delta1': 'Length=60m', 'Delta3':'Length=200m', 'Delta4':'Length=350m$' , 'Delta6': 'Length=700m$' , 'Delta9': 'Length=1600m'} color_vec=np.array(['blue', 'red', 'green', 'grey','purple', 'cyan', 'magenta', 'black', 'orange', 'coral', 'yellow', 'orchid', 'black', 'orange', 'coral', 'yellow', 'orchid' ]) #y_title_list=np.array(['Sea Surface Temperature', 'AB+Ross', 'East Antarctia', 'Weddell','Depth Integrated Temperature']) y_title_list=np.array(['Sea Surface','Column', 'AB+Ross', 'East Antarctia', 'Weddell']) #y_title_list=np.array(['SST','Column Temperature', 'AB+Ross', 'East Antarctia', 'Weddell']) colorbar_unit_list=np.array(['SST (C)', '(C*m)','temperature (C)', 'temperature (C)','temperature (C)']) nrows=5 ncols=len(Delta_list)#3 temperature_scale=0.2 datapath='/home/Alon.Stern/Iceberg_Project/iceberg_scripts/python_scripts/size_matters_paper/processed_data/' #Setting up the figure fig, axes = plt.subplots(nrows=nrows, ncols=ncols) #This is used to plot the figure without the data for playing this anotations. if plot_all_panels_without_data==True: save_figure=False count=0 cscale=None difference_on=0 boundinglat=-45 projection = 'splaea' m = Basemap(projection=projection, boundinglat=boundinglat, lon_0=180) #filename=datapath + 'Delta9_melt_1959_to_2019_all_south_xy.mat' filename=datapath + 'Delta9_temp_1959_to_2019_all_south_yz_anomaly_EastA_plus_AdeleLand.mat' (lat ,lon, data, p_values,field ,layer_interface,lat_lon_bounds )=load_data_from_mat_file(filename) datamap=plot_vertical_section(lon,lat,data,difference_on,title,p_values,cscale,field,layer_interface,'yz',lat_lon_bounds,'ocean_month_z',\ colorbar_on=False,return_data_map=True) for i in range(nrows): for j in range(ncols): count=count+1 ax=subplot(nrows,ncols,count) print 'Working on subplot ' ,str(count) if i!=0 and i!=1: datamap=plot_vertical_section(lon,lat,data,difference_on,title,p_values,cscale,field,layer_interface,'yz',lat_lon_bounds,'ocean_month_z',\ colorbar_on=False,return_data_map=True) else: plot_polar_field(lat,lon,None,pole,difference_on=0.,title=None) if i==0: ax.set_title(title_list[Delta_list[j]], fontsize=18, y=1.13) if j==0 and i<2: ax.annotate(y_title_list[i], xy=(-0.6, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') ax.annotate('Temperature', xy=(-0.45, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') # plt.ylabel(y_title_list[i], fontsize=18, labelpad=25) if j==0 and i>1: plt.ylabel('depth (m)', fontsize=14) ax.annotate(y_title_list[i], xy=(-0.6, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') if i!=nrows-1: ax.set_xticks([]) else: plt.xlabel('latitude (deg)', fontsize=14) ax.set_xticks([-40 ,-60, -80]) if j>0: ax.set_yticks([]) if j==ncols-1 : fig.subplots_adjust(right=0.8) cbar_ax = fig.add_axes([0.85, 0.11+((nrows-i-1)*0.165), 0.03, 0.13]) cbar=fig.colorbar(datamap, cax=cbar_ax) cbar.set_label(colorbar_unit_list[i], rotation=90) else: #Plotting Melt if plot_SST_fields==True: cscale=temperature_scale row_num=1 difference_on=1 axes_direction='xy' field_name='Sea Surface Temperature' file_extension='_SST_1959_to_2019_all_south_xy_anomaly.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, file_extension,cscale, \ row_num,difference_on, pole,field_name,axes_direction) #Plotting Depth Integrated Temp if plot_depth_int_temp_fields==True: cscale=200 row_num=2 difference_on=1 axes_direction='xy' field_name='Depth Integrated Temperature' file_extension='_temp_1959_to_2019_all_south_xy_anomaly.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, file_extension,cscale, \ row_num,difference_on, pole,field_name) #Plotting AB_plus_Ross Temperature if plot_AB_plus_Ross_Temp_Section==True: cscale=temperature_scale row_num=3 difference_on=1 axes_direction='yz' field_name='AB_plus_Ross Temperature Section' file_extension='_temp_1959_to_2019_all_south_yz_anomaly_AB_plus_Ross.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, file_extension,cscale, \ row_num,difference_on, pole,field_name,axes_direction) #Plotting EastA_plus_Adele Temperature if plot_EastA_plus_Adele_Temp_Section==True: cscale=temperature_scale row_num=4 difference_on=1 axes_direction='yz' field_name='EastA_plus_Adele Temperature Section' file_extension='_temp_1959_to_2019_all_south_yz_anomaly_EastA_plus_AdeleLand.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, file_extension,cscale, \ row_num,difference_on, pole,field_name,axes_direction) #Plotting Weddell Temperature if plot_Weddell_Temp_Section==True: cscale=temperature_scale row_num=5 difference_on=1 axes_direction='yz' field_name='Weddell Temperature Section' file_extension='_temp_1959_to_2019_all_south_yz_anomaly_Weddell.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, file_extension,cscale, \ row_num,difference_on, pole,field_name,axes_direction) subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) fig.set_size_inches(13.5, 20.5,forward=True) if save_figure==True: plt.savefig('paper_figures/Fig_SST_sections_temp_D1_D3_D9.png') plt.show()
def main(): parser = argparse.ArgumentParser() args = parser.parse_args() #Flags save_figure = True significant_vals_only = False plot_melt_fields = True plot_all_panels_without_data = False #False makes the real figure #Parameters; pole = 'south' title = None cscale = None Delta_list = np.array(['Delta1', 'Delta9']) #Title_list=np.array(['Delta1 (Area=0.0026km^2)', 'Delta6 (Area=0.029km^2)', 'Delta9 (Area=1.8km^2)']) #Title_list=np.array(['Area=0.0026km^2', 'Area=1.8km^2']) Title_list = np.array(['DELTA1 - DELTA9', 'DELTA9 -DELTA1']) color_vec = np.array([ 'blue', 'red', 'green', 'grey', 'purple', 'cyan', 'magenta', 'black', 'orange', 'coral', 'yellow', 'orchid', 'black', 'orange', 'coral', 'yellow', 'orchid' ]) letter_labels = np.array( ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)']) y_title_list = np.array(['Iceberg Melt']) colorbar_unit_list = np.array(['melt (m/year)']) nrows = 1 ncols = 2 datapath = '/home/Alon.Stern/Iceberg_Project/iceberg_scripts/python_scripts/size_matters_paper/processed_data/' #Setting up the figure fig, axes = plt.subplots(nrows=nrows, ncols=ncols) #Plotting Trajectory Fields #Plotting Melt Fields if plot_melt_fields == True: cscale = None row_num = 1 difference_on = 0 field_name = 'melt' file_extension = '_melt_1959_to_2019_all_south_xy.mat' title = None filename1 = datapath + Delta_list[0] + file_extension filename2 = datapath + Delta_list[1] + file_extension (lat, lon, data1, p_values, field) = load_data_from_mat_file(filename1) (lat, lon, data2, p_values, field) = load_data_from_mat_file(filename2) #Converting melt rates to m/yr data1 = data1 * (60 * 60 * 24 * 356.25 ) #Multiply to get units /year rather than /s data1 = data1 / 850 # Multiply to get units of m/year data2 = data2 * (60 * 60 * 24 * 356.25 ) #Multiply to get units /year rather than /s data2 = data2 / 850 # Multiply to get units of m/year #Panel 1 print 'Plotting ' + field_name + ' fields for ' + Delta_list[ 0] + ' minus ' + Delta_list[1] ax = subplot(nrows, ncols, 1) (cscale, datamap) = plot_polar_field(lat, lon, data1 - data2, pole, difference_on, title, p_values, cscale, field, colorbar_on=False, return_data_map=True) plt.ylabel(y_title_list[row_num - 1], fontsize=18, labelpad=25) ax.set_title(Title_list[0], fontsize=18, y=1.13) text(1, 1, letter_labels[0], ha='right', va='bottom', transform=ax.transAxes) #Panel 2 print 'Plotting ' + field_name + ' fields for ' + Delta_list[ 1] + ' minus ' + Delta_list[0] ax = subplot(nrows, ncols, 2) (cscale, datamap) = plot_polar_field(lat, lon, data2 - data1, pole, difference_on, title, p_values, cscale, field, colorbar_on=False, return_data_map=True) ax.set_title(Title_list[1], fontsize=18, y=1.13) text(1, 1, letter_labels[1], ha='right', va='bottom', transform=ax.transAxes) #Creating colorbar fig.subplots_adjust(right=0.8) cbar_ax = fig.add_axes([0.85, 0.3, 0.05, 0.4]) cbar = fig.colorbar(datamap, cax=cbar_ax) cbar.set_label(colorbar_unit_list[row_num - 1], rotation=90) if field != 'melt': tick_locator = ticker.MaxNLocator(nbins=5) cbar.locator = tick_locator cbar.update_ticks() subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) #fig.set_size_inches(10.5, 20.5,forward=True) if save_figure == True: plt.savefig('paper_figures/Fig_melt_D9_subtract_D1.png') plt.show()
def main(): #Clear screen #os.system('clear') start_year=1915 end_year0=2019 Number_of_years=0 input_folder='/ptmp/Alon.Stern/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg_bergs_Delta9/' second_folder=None field='CN' months_str='all' constraint_name=None months=range(0,11) file_type='ice_month' pole='north' save_traj_data=False color_vec=np.array(['blue', 'red', 'green', 'grey','purple', 'cyan', 'magenta', 'black', 'orange', 'coral', 'yellow', 'orchid', 'black', 'orange', 'coral', 'yellow', 'orchid' ]) # The constraint has the form [field_name, lower_bonud, upper_bound] #constraint1=np.array(['lat',-65.,-10.]) # Latituds north of -60 in the southern hemisphere constraint_depth = {'Constraint_field_name': 'depth', 'lower_bound': 3000 , 'upper_bound': 8000, 'original_values': True} constraint_dist_from_calving = {'Constraint_field_name': 'distance_from_calving', 'lower_bound': 1000000 , 'upper_bound': 10000000000000, 'original_values': False} constraint2 = {'Constraint_field_name': 'lon', 'lower_bound': -150 , 'upper_bound': -65, 'original_values': True} #Longitude of AB constraint3 = {'Constraint_field_name': 'lon', 'lower_bound': -210 , 'upper_bound': -65, 'original_values': True} #Longitude of AB_plus_Ross constraint_SH = {'Constraint_field_name': 'lat', 'lower_bound': -90 , 'upper_bound': 0, 'original_values': True} #age constraint_age = {'Constraint_field_name': 'age', 'lower_bound': 30 , 'upper_bound': 300, 'original_values': True} #age constraints=[] #mass=3.9e11 ;constraint_name='massD9' #mass=8.8e7 ;constraint_name='massD1' #constraint_m = {'Constraint_field_name': 'mass', 'lower_bound': mass-100 , 'upper_bound': mass+100, 'original_values': True} #constraints.append(constraint2) ; constraint_name='AB' #constraints.append(constraint3) ; constraint_name='AB_plus_Ross' #constraints.append(constraint4) #constraints.append(constraint_m) #constraints.append(constraint_depth) #constraints.append(constraint_dist_from_calving) #constraints.append(constraint_age) #constraints.append(constraint_SH) #plot_multiple_panels==1: constraint2 = {'Constraint_field_name': 'lon', 'lower_bound': -150 , 'upper_bound': -65, 'original_values': True} #Longitude of AB root_path='/ptmp/aas/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg' (All_data, lat, lon,z) =generate_data_file(start_year, start_year, input_folder, field, months_str, file_type) data_mean=np.squeeze(np.mean(All_data,axis=0)) data_mean=None #run_names=np.array(['freq','all_big', 'mass', 'all_small']) ; naming_flag='groups' #run_names=np.array(['Delta1', 'Delta2', 'Delta3', 'Delta6', 'Delta9','Delta10']) ; naming_flag='Delta' #run_names=np.array(['Delta1' ,'Delta10','Delta1_thick', 'Delta10_thick', 'Delta1b_thick', 'Delta10b_thick']) ; naming_flag='Thick' #run_names=np.array(['Delta6', 'Delta6','Delta9']) ; naming_flag='Delta' run_names=np.array(['tournadre']) ; naming_flag='Delta' #run_names=np.array(['Delta1','Delta3','Delta4','Delta5', 'Delta6','Delta9']) ; naming_flag='Delta' for k in range(1): input_folder=root_path + '_bergs_' + run_names[k] subplot(1,1,k) print input_folder #Making sure the years work (min_year, max_year)=find_max_min_years(input_folder,'.iceberg_trajectories.nc') end_year=min(max_year,end_year0) start_year=max(end_year-Number_of_years,min_year) title1= run_names[k] + ' (' + str(start_year) + ' to ' + str(end_year) + ')' #Plot blank map. if pole=='south': projection = 'splaea' boundinglat=-45 if pole=='north': projection = 'nplaea' boundinglat=45 projection = 'nplaea' plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title=title1\ ,p_values=None,cscale=None,field=None,colorbar_on=True,return_data_map=False,plot_lat_lon_lines=True,boundinglat=boundinglat) m = Basemap(projection=projection, boundinglat=boundinglat, lon_0=180) print 'You are here' print projection count=0 Total_berg_lat=np.array([]) Total_berg_lon=np.array([]) Total_berg_mass0=np.array([]) for year in range(start_year, end_year+1): count=count+1 filename ='/' + str(year) + '0101.iceberg_trajectories.nc' input_file=input_folder + filename print input_file all_bergs_lat = get_valid_data_from_traj_file(input_file,'lat') all_bergs_lon = get_valid_data_from_traj_file(input_file,'lon') all_bergs_mass0 = get_valid_data_from_traj_file(input_file,'mass',subtract_orig=False,get_original_values=True) # Getting iceberg mass too. #Adding constraints to the data: print 'Lendth of original field: ' , len(all_bergs_lat) all_bergs_lat=add_constraint_to_data(input_file,all_bergs_lat,constraints) all_bergs_lon=add_constraint_to_data(input_file,all_bergs_lon,constraints) all_bergs_mass0=add_constraint_to_data(input_file,all_bergs_mass0,constraints) print 'Lendth of field after constraints: ' , len(all_bergs_lat) x, y = m(all_bergs_lon, all_bergs_lat) plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title=title1\ ,p_values=None,cscale=None,field=None,colorbar_on=True,return_data_map=False,plot_lat_lon_lines=True,boundinglat=boundinglat) m.scatter(x,y,3,marker='o',color=color_vec[k]) #plt.plot(all_bergs_lon,all_bergs_lat,'o') Total_berg_lon=np.concatenate((Total_berg_lon,x),axis=0) Total_berg_lat=np.concatenate((Total_berg_lat,y),axis=0) Total_berg_mass0=np.concatenate((Total_berg_mass0,all_bergs_mass0),axis=0) if save_traj_data==True: save_traj_mat_file(lat,lon, Total_berg_lon, Total_berg_lat, Total_berg_mass0, pole,input_folder,start_year,end_year,months_str,constraint_name) #plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title=title1) #m.scatter(Total_berg_lon,Total_berg_lat,1,marker='o',color=color_vec[k]) output_file= 'figures/traj_plot_' + str(start_year)+ '_to_' + str(end_year) + '_with_' + run_names[k] + '.png' #plt.savefig(output_file, dpi=150, bbox_inches='tight', pad_inches=0.4) plt.show() print 'Script complete'
def main(): #Clear screen #os.system('clear') start_year = 1995 end_year0 = 1995 Number_of_years = 0 input_folder = '/ptmp/Alon.Stern/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg_bergs_Delta9/' second_folder = None #field0='CN' months_str = 'all' constraint_name = None months = range(0, 11) file_type = 'ice_month' pole = 'south' save_Force_data = False load_data_from_mat = False #load_data_from_mat=True file_path = 'processed_data/' #mat_filename='processed_data/open_ocean_iceberg_forces.mat' mat_filename = 'Forces_on_berg_Tournadre_1995_1995_constraints_depth_8000_to_1000.mat' mat_filename = 'Forces_on_berg_Delta9_1995_1995_constraints_depth_8000_to_1000.mat' mat_filename = 'Forces_on_berg_Delta9_1995_1995_constraints_lon_55_to_65_lat_82_to_78_mass_1000000000000000_to_10000000000.mat' mat_filename = 'Forces_on_berg_Delta9_1995_1995_constraints_depth_8000_to_1000_mass_1000000000000000_to_10000000000.mat' mat_filename = 'Forces_on_berg_Delta9_1990_1995_constraints_lat_0_to_90_depth_8000_to_1000_mass_1000000000000000_to_10000000000.mat' color_vec = np.array([ 'blue', 'red', 'green', 'grey', 'purple', 'cyan', 'magenta', 'black', 'orange', 'coral', 'yellow', 'orchid', 'black', 'orange', 'coral', 'yellow', 'orchid' ]) Force_list = np.array(['Fa', 'Fo', 'Fi', 'Fr', 'Fc', 'Fp', 'F_total']) # The constraint has the form [field_name, lower_bonud, upper_bound] constraint_lon_petermann = { 'Constraint_field_name': 'lon', 'lower_bound': -65, 'upper_bound': -55, 'original_values': True } #Longitude of AB_plus_Ross constraint_lat_petermann = { 'Constraint_field_name': 'lat', 'lower_bound': 78, 'upper_bound': 82, 'original_values': True } #Longitude of AB_plus_Ross constraint_depth = { 'Constraint_field_name': 'depth', 'lower_bound': 1000, 'upper_bound': 8000, 'original_values': False } constraints = [] constraint_mass = { 'Constraint_field_name': 'mass', 'lower_bound': 10**10, 'upper_bound': 10**15, 'original_values': False } constraint_lat_baffin_coast = { 'Constraint_field_name': 'lat', 'lower_bound': 30, 'upper_bound': 80, 'original_values': False } constraint_lat_southern_hemisphere = { 'Constraint_field_name': 'lat', 'lower_bound': -90, 'upper_bound': 0, 'original_values': False } #constraint_m = {'Constraint_field_name': 'mass', 'lower_bound': mass-100 , 'upper_bound': mass+100, 'original_values': True} #constraints.append(constraint_m) #constraints.append(constraint_lon_petermann) #constraints.append(constraint_lat_petermann) #constraints.append(constraint_lat_baffin_coast) constraints.append(constraint_lat_southern_hemisphere) constraints.append(constraint_depth) #constraints.append(constraint_mass) #Definging fields to be used. field_list = np.array([ 'width', 'length', 'mass', 'thickness', 'uvel', 'vvel', 'uo', 'vo', 'ui', 'vi', 'ua', 'va', 'ssh_x', 'ssh_y', 'hi' ]) root_path = '/ptmp/aas/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg' (All_data, lat, lon, z) = generate_data_file(start_year, start_year, input_folder, 'CN', months_str, file_type) data_mean = np.squeeze(np.mean(All_data, axis=0)) data_mean = None #Plot blank map. #plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title=title1) boundinglat = -45 projection = 'splaea' m = Basemap(projection=projection, boundinglat=boundinglat, lon_0=180) #run_names=np.array(['tournadre']) ; naming_flag='Tournadre' run_names = np.array(['Delta1']) naming_flag = 'Delta1' if load_data_from_mat == False: for k in range(1): input_folder = root_path + '_bergs_' + run_names[k] #subplot(2,4,k+1) print input_folder #Making sure the years work (min_year, max_year) = find_max_min_years(input_folder, '.iceberg_trajectories.nc') end_year = min(max_year, end_year0) start_year = max(end_year - Number_of_years, min_year) title1 = run_names[k] + ' (' + str(start_year) + ' to ' + str( end_year) + ')' Total_berg_lat = np.array([]) Total_berg_lon = np.array([]) #Total_berg_mass0=np.array([]) #initializing the Total_berg_list Total_berg_list = {} for k in range(len(field_list)): Total_berg_list['Total_berg_' + field_list[k]] = np.array([]) Total_berg_list[field_list[k]] = np.array([]) #Total_berg_list['Total_berg_'+field_list[k]]=[] count = 0 for year in range(start_year, end_year + 1): count = count + 1 filename = '/' + str(year) + '0101.iceberg_trajectories.nc' input_file = input_folder + filename print input_file #Handling lon and lat first [Total_berg_lon, Total_berg_lat ] = generate_Total_berg_lon_lat(Total_berg_lon, Total_berg_lat, input_file, constraints, m) for k in range(len(field_list)): Total_berg_list[field_list[k]] = get_Total_berg_field( input_file, Total_berg_list[field_list[k]], field_list[k], constraints) [Force_x, Force_y, Force_mod, Force_list, mass] = calculate_forces(Total_berg_list, Total_berg_lat) if save_Force_data == True: mat_filename = 'Forces_on_berg_' + naming_flag + '_' + str( start_year) + '_' + str(end_year) if constraints != None: if len(constraints) > 0: mat_filename = mat_filename + '_constraints' for k in range(len(constraints)): current_constraint = constraints[k] constraint_name = current_constraint[ 'Constraint_field_name'] lower_bound = current_constraint['lower_bound'] upper_bound = current_constraint['upper_bound'] original_values = current_constraint['original_values'] mat_filename = mat_filename + '_' + constraint_name + '_' + str( abs(upper_bound)) + '_to_' + str(abs(lower_bound)) mat_filename = mat_filename + '.mat' print 'Saving file: ', (file_path + mat_filename) sc.savemat(file_path+mat_filename, {'Force_x':Force_x , 'Force_y':Force_y , 'Force_mod':Force_mod, 'mass':mass, 'Force_list':Force_list,'Total_berg_lat':Total_berg_lat,\ 'Total_berg_lon':Total_berg_lon}) if load_data_from_mat == True: print 'Loading file: ', mat_filename mat_contents = sc.loadmat(file_path + mat_filename) Force_x = mat_contents['Force_x'][0][0] Force_y = mat_contents['Force_y'][0][0] Force_mod = mat_contents['Force_mod'][0][0] #Force_list=mat_contents['Force_list'][:] Total_berg_lon = mat_contents['Total_berg_lon'][:] Total_berg_lat = mat_contents['Total_berg_lat'][:] mass = mat_contents['mass'][:] #Converting force to acceleration Accel_x = {} Accel_y = {} Accel_mod = {} for k in range(7): Accel_x[Force_list[k]] = Force_x[Force_list[k]] / mass Accel_y[Force_list[k]] = Force_y[Force_list[k]] / mass Accel_mod[Force_list[k]] = Force_mod[Force_list[k]] / mass #Calculating the mean and std of each force ind_list = np.arange(7) Force_x_mean = ind_list * 0. Force_y_mean = ind_list * 0. Force_mod_mean = ind_list * 0. Accel_x_mean = ind_list * 0. Accel_y_mean = ind_list * 0. Accel_mod_mean = ind_list * 0. Force_x_std = ind_list * 0. Force_y_std = ind_list * 0. Force_mod_std = ind_list * 0. Accel_x_std = ind_list * 0. Accel_y_std = ind_list * 0. Accel_mod_std = ind_list * 0. for k in range(7): Force_x_mean[k] = np.mean(Force_x[Force_list[k]]) Force_y_mean[k] = np.mean(Force_y[Force_list[k]]) Force_mod_mean[k] = np.mean(Force_mod[Force_list[k]]) Accel_x_mean[k] = np.mean(Accel_x[Force_list[k]]) Accel_y_mean[k] = np.mean(Accel_y[Force_list[k]]) Accel_mod_mean[k] = np.mean(Accel_mod[Force_list[k]]) Force_x_std[k] = np.std(Force_x[Force_list[k]]) Force_y_std[k] = np.std(Force_y[Force_list[k]]) Force_mod_std[k] = np.std(Force_mod[Force_list[k]]) Accel_x_std[k] = np.std(Accel_x[Force_list[k]]) Accel_y_std[k] = np.std(Accel_y[Force_list[k]]) Accel_mod_std[k] = np.std(Accel_mod[Force_list[k]]) plot_map_traj = True if plot_map_traj == True: #plt.figure(3) ax1 = subplot(1, 1, 1) plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title=''\ ,p_values=None,cscale=None,field=None,colorbar_on=True,return_data_map=False,plot_lat_lon_lines=True,boundinglat=boundinglat ) m.scatter(Total_berg_lon, Total_berg_lat, 1, marker='o', color=color_vec[k]) #F_max_lim=10**12 F_max_lim = 10**-4 F_min_lim = -10**-4 #F_min_lim=10**(-10) do_scatter_plot = False if do_scatter_plot == True: plt.figure(2) for k in range(7): #for k in np.array([4,5]): #A=Force_y[Force_list[k]] #print Force_list[k],'max', np.max(A,axis=1) ,'min',np.min(A,axis=1) ax = subplot(3, 3, k + 1) ax.scatter(mass[:], Accel_y[Force_list[k]][:], color=color_vec[k], label=Force_list[k]) #plt.plot(mass[:],Accel_y[Force_list[k]][:]) plt.ylim([F_min_lim, F_max_lim]) #ax.set_xscale('log') #ax.set_yscale('log') #plt.legend(loc='upper left', frameon=True) plt.xlabel('Mass (kg)') plt.ylabel('Force (N)') plot_bar_graph = False if plot_bar_graph == True: plt.figure(3) label_list = np.array(['Force_x', 'Force_y', 'Accel_x', 'Accel_y']) Mean_Force_and_Accel = { 'Force_x': Force_x_mean, 'Force_y': Force_y_mean, 'Accel_x': Accel_x_mean, 'Accel_y': Accel_y_mean } for k in range(4): ax = subplot(2, 2, k + 1) width = 3 #ax.bar(ind+((bar_width/2)*j), mean_list[:,j],width=width/2,color=color_vec[j],label=sector_title_list[j]) #ax.bar(ind_list,Force_x_mean) ax.bar(ind_list, Mean_Force_and_Accel[label_list[k]], width=width / 3, label=label_list[k]) plt.title(label_list[k]) ax.set_xticks(ind_list + 0.5) ax.set_xticklabels(Force_list) #output_file= 'figures/traj_plot_' + str(start_year)+ '_to_' + str(end_year) + '_with_' + run_names[k] + '.png' #plt.savefig(output_file, dpi=150, bbox_inches='tight', pad_inches=0.4) plt.show() print 'Script complete'
def main(): #Clear screen #os.system('clear') start_year=1980 end_year0=1980 field='melt' months_str='all' months=range(0,11) file_type='icebergs' pole='south' Number_of_years=20 color_vec=np.array(['blue', 'red', 'green', 'grey','purple', 'cyan', 'magenta', 'black', 'orange', 'coral', 'yellow', 'orchid', 'black', 'orange', 'coral', 'yellow', 'orchid' ]) second_folder=None distribution=np.array([0.24, 0.12, 0.15, 0.18, 0.12, 0.07, 0.03, 0.03, 0.03, 0.02]) initial_mass=np.array([8.8e7, 4.1e8, 3.3e9, 1.8e10, 3.8e10, 7.5e10, 1.2e11, 2.2e11, 3.9e11, 7.4e11]) Total_mass=np.sum(distribution*initial_mass) #plot_multiple_panels==1: root_path='/ptmp/aas/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg' #run_names=np.array(['freq','all_big', 'mass', 'all_small']) ; naming_flag='groups' #run_names=np.array(['Delta1', 'Delta2', 'Delta3', 'Delta6', 'Delta9','Delta10']) ; naming_flag='Delta' run_names=np.array(['Delta1', 'Delta2', 'Delta3','Delta4','Delta5','Delta6','Delta7', 'Delta8', 'Delta9','Delta10']) ; naming_flag='Delta' #run_names=np.array(['Delta1', 'Delta9']) ; naming_flag='Delta' Number_of_files=10 multi_berg_run_name='freq' if multi_berg_run_name=='freq': weights=np.zeros((10,1)) for i in range(10): weights[i]=distribution[i]*initial_mass[i]/Total_mass print sum(weights) count=-1 for k in range(Number_of_files): count=count+1 input_folder=root_path + '_bergs_' + run_names[k] (min_year, max_year)=find_max_min_years(input_folder,'.' + file_type + '_month.nc') end_year=max_year start_year=max(end_year-Number_of_years+1,min_year) (All_data, lat, lon) =generate_data_file(start_year, end_year, input_folder, field,months,file_type) data_mean=np.squeeze(np.mean(All_data,axis=0)) #Set up the matrix on the first time around if count==0: M=data_mean.shape Big_data_matrix=np.zeros((Number_of_files,M[0],M[1])) Big_data_matrix[count,:,:]=data_mean linear_sum_data=construct_linear_sum(Big_data_matrix,weights) #Getting the data for the multi_berg_run input_folder=root_path + '_bergs_' + multi_berg_run_name (min_year, max_year)=find_max_min_years(input_folder,'.' + file_type + '_month.nc') end_year=max_year start_year=max(end_year-Number_of_years+1,min_year) (All_data, lat, lon) =generate_data_file(start_year, end_year, input_folder, field,months,file_type) data_mean=np.squeeze(np.mean(All_data,axis=0)) relative_error=(data_mean-linear_sum_data)#/data_mean #ralative_error=relative_error*np.where(data_mean!=0) #Plotting the linear sum subplot(1,3,1) plot_polar_field(lat,lon,linear_sum_data,pole,difference_on=0.,title='linear combination',p_values=None,cscale=None,field=field) subplot(1,3,2) plot_polar_field(lat,lon,data_mean,pole,difference_on=0.,title=multi_berg_run_name,p_values=None,cscale=None,field=field) subplot(1,3,3) plot_polar_field(lat,lon,-relative_error,pole,difference_on=0.,title='relative_error',p_values=None,cscale=None,field=field) output_file='linearity_test_neg' + multi_berg_run_name + '.png' plt.savefig(output_file, dpi=150, bbox_inches='tight', pad_inches=0.4) plt.show() print 'Script complete'
def main(): #Clear screen #os.system('clear') #Defining possible paths all_paths=define_paths_array() #Flags plot_average_dist=1 plot_full_time_series=0 #Parameters and variables #start_year=1980 end_year0=1985 number_of_bins=100 Number_of_years=25 #Include contraints to use to filter the data # The constraint has the form [field_name, lower_bonud, upper_bound] constraint1=np.array(['lat',-85.,-10.]) # Latituds north of -60 in the southern hemisphere #constraint2=np.array(['lon',-60.,0.]) #Longitude of Weddel Sea , lon appears to go from -270 to 90. #constraint3=np.array(['lon',-120.,-60.]) #Longitude of Weddel Sea , lon appears to go from -270 to 90. constraints=[] constraints.append(constraint1) #constraints.append(constraint2) #constraints.append(constraint3) #contraints mass_scaling=np.array([2000, 200, 50, 20, 10, 5, 2, 1, 1, 1]) #field_name='area'; x_min=1;x_max=1.e9 # Good for area including all Deltas field_name='area'; x_min=1;x_max=1.e7 # Good for area #field_name='mass' ; #x_min=100;x_max=1.e12 # Good for mass #Defining a list of colors color_vec=np.array(['blue', 'red','purple','green', 'coral', 'cyan', 'magenta','orange', 'black', 'grey', 'yellow', 'orchid', 'blue', 'red','purple','green', 'coral', 'cyan' ]) fig = plt.figure(1) input_file='/ptmp/aas/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg_bergs_Delta1/19000101.icebergs_month.nc' area=nc.Dataset(input_file).variables['area'][:, :] lon=nc.Dataset(input_file).variables['xT'][:] lat=nc.Dataset(input_file).variables['yT'][:] count1=0 #for k in range(13):#for k in np.array([3]): #for k in np.array([0 , 8]): for k in np.array([8 ]): #for k in np.array([0,1,2,5,8,9]): count1=count1+1 #for k in range(0,8): input_folder=all_paths[k] #Make sure that data exists of the years allocated, othersize change it. (min_year, max_year)=find_max_min_years(input_folder,'.iceberg_trajectories.nc') end_year=min(max_year,end_year0) start_year=max(end_year-Number_of_years,min_year) #if max_year>=start_year: for year in range(start_year,end_year): #year=1945 filename ='/' + str(year) + '0101.iceberg_trajectories.nc' input_file=input_folder + filename print input_file field_name1='uvel' #field_name1='lon' field_name2='vvel' iceberg_lats = get_valid_data_from_traj_file(input_file,'lat',subtract_orig=False) iceberg_lons = get_valid_data_from_traj_file(input_file,'lon',subtract_orig=False) iceberg_mass = get_valid_data_from_traj_file(input_file,'mass',subtract_orig=False) iceberg_field1 = get_valid_data_from_traj_file(input_file,field_name1,subtract_orig=False) iceberg_field2 = get_valid_data_from_traj_file(input_file,field_name2,subtract_orig=False) print 'Lendth of original field: ' , len(iceberg_field1) #Getting the distributions from the data #Handeling constraints iceberg_lats=add_constraint_to_data(input_file,iceberg_lats,constraints) iceberg_lons=add_constraint_to_data(input_file,iceberg_lons,constraints) iceberg_mass=add_constraint_to_data(input_file,iceberg_mass,constraints) iceberg_field1=add_constraint_to_data(input_file,iceberg_field1,constraints) iceberg_field2=add_constraint_to_data(input_file,iceberg_field2,constraints) print 'Lendth of field after constraints: ' , len(iceberg_field1) (field_gridded1,mass_gridded)=interpolat_bergs_onto_map(lat,lon,area,iceberg_lats,iceberg_lons,iceberg_field1,iceberg_mass,mass_weighted=True) (field_gridded2,mass_gridded)=interpolat_bergs_onto_map(lat,lon,area,iceberg_lats,iceberg_lons,iceberg_field2,iceberg_mass,mass_weighted=True) if year==start_year: Total_gridded1=field_gridded1 Total_gridded2=field_gridded2 Total_mass_gridded= mass_gridded else: Total_gridded1=Total_gridded1+field_gridded1 Total_gridded2=Total_gridded2+field_gridded2 Total_mass_gridded=Total_mass_gridded+ mass_gridded M=field_gridded1.shape norm_field1=np.zeros((M[0],M[1])) norm_field2=np.zeros((M[0],M[1])) for i in range(M[0]): for j in range(M[1]): if mass_gridded[i,j]>0: norm_field1[i,j]=field_gridded1[i,j]/mass_gridded[i,j] norm_field2[i,j]=field_gridded2[i,j]/mass_gridded[i,j] subplot(2,2,1) plot_polar_field(lat,lon,field_gridded1,pole='south',difference_on=1.,title='uvel',p_values=None,cscale=None,field=None) subplot(2,2,2) plot_polar_field(lat,lon,field_gridded2,pole='south',difference_on=1.,title='vvel',p_values=None,cscale=None,field=None) subplot(2,2,3) #plot_polar_field(lat,lon,field_gridded1/mass_gridded,pole='south',difference_on=1.,title='uvel',p_values=None,cscale=None,field=None) plot_polar_field(lat,lon,norm_field1,pole='south',difference_on=1.,title='uvel',p_values=None,cscale=None,field=None) subplot(2,2,4) #plot_polar_field(lat,lon,field_gridded2/mass_gridded,pole='south',difference_on=1.,title='vvel',p_values=None,cscale=None,field=None) plot_polar_field(lat,lon,norm_field2,pole='south',difference_on=1.,title='vvel',p_values=None,cscale=None,field=None) #Plotting the distributions #ax = fig.add_subplot(1,2,count1) #ax = fig.add_subplot(1,1,1) #plt.plot(field1,-field2,'o',color=color_vec[k]) #plt.xlabel(field_name1) #plt.ylabel(field_name2) #plt.ylim([-75., -40]) #For mass #plt.xlim([10.e3, 7.4e11]) #For mass #ax.set_yscale('log') #plt.legend(loc='upper right', frameon=True) #fig = matplotlib.pyplot.gcf() #fig.set_size_inches(9,4.5) plt.show() print 'Script complete'
def main(): parser = argparse.ArgumentParser() args = parser.parse_args() #Flags save_figure = True significant_vals_only = False plot_melt_fields = False plot_split_Tournadre_dist = True plot_split_Tournadre_dist_depth = True plot_all_panels_without_data = False #False makes the real figure #Parameters; pole = 'south' title = None cscale = None Delta_list = np.array(['tournadre']) #Area_list=np.array(['Area$_{1}$=0.0026km$^2$', 'Area$_{2}$=0.0072km$^2$','Area$_{3}$=0.029km$^2$',\ # 'Area$_{4}$=0.12km$^2$','Area$_{5}$=0.18km$^2$', 'Area$_{6}$=0.35km$^2$','Area$_{7}$=0.56km$^2$', 'Area$_{8}$=1.0km$^2$','Area$_{9}$=1.8km$^2$', 'Area$_{10}$=3.5km$^2$']) Area_list=np.array(['0.0026km$^2$', '0.0072km$^2$','0.029km$^2$',\ '0.12km$^2$','0.18km$^2$', '0.35km$^2$','0.56km$^2$', '1.0km$^2$','1.8km$^2$', '3.5km$^2$']) Title_list = np.array(['TOURNADRE distribution']) letter_labels = np.array( ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)', '(g)', '(h)', '(i)']) color_vec = np.array([ 'blue', 'red', 'green', 'grey', 'purple', 'cyan', 'magenta', 'orange', 'coral', 'yellow', 'orchid', 'orange', 'coral', 'yellow', 'orchid' ]) y_title_list = np.array(['Iceberg Melt']) colorbar_unit_list = np.array(['melt (kg/m$^2$)']) nrows = 1 ncols = 2 datapath = '/home/Alon.Stern/Iceberg_Project/iceberg_scripts/python_scripts/size_matters_paper/processed_data/' #Setting up the figure fig, axes = plt.subplots(nrows=nrows, ncols=ncols) ax = subplot(nrows, ncols, 2) fig.delaxes(ax) #Plotting Trajectory Fields #Plotting Melt Fields if plot_melt_fields == True: cscale = None row_num = 1 difference_on = 0 field_name = 'melt' file_extension = '_melt_1959_to_2019_all_south_xy.mat' title = None filename = datapath + Delta_list[0] + file_extension (lat, lon, data, p_values, field) = load_data_from_mat_file(filename) print 'Plotting ' + field_name + ' fields for ' + Delta_list[row_num - 1] ax = subplot(nrows, ncols, row_num) (cscale, datamap) = plot_polar_field(lat, lon, data, pole, difference_on, title, p_values, cscale, field, colorbar_on=False, return_data_map=True) #Creating colorbar cbar_ax = fig.add_axes([0.52, 0.62, 0.04, 0.3]) cbar = fig.colorbar(datamap, cax=cbar_ax) cbar.set_label(colorbar_unit_list[row_num - 1], rotation=90) if plot_split_Tournadre_dist == True: position = 1 field_name = 'size distribution no constrains' label = Delta_list[0] file_extension = '_size_distribution_1959_to_2019.mat' filename = datapath + Delta_list[0] + file_extension produce_distribution_panel(filename, nrows, ncols, position, field_name, Delta_list, Area_list, color_vec, letter_labels) if plot_split_Tournadre_dist_depth == True: position = 2 field_name = 'size distribution no constrains' file_extension = '_size_distribution_1959_to_2019_constraints_lat_10_to_70.mat' file_extension = '_size_distribution_1959_to_2019_constraints_depth_8000_to_1000.mat' filename = datapath + Delta_list[0] + file_extension produce_distribution_panel(filename, nrows, ncols, position, field_name, Delta_list, Area_list, color_vec, letter_labels) fig.subplots_adjust(right=0.65) plt.legend(loc=(1.1, 0.0), frameon=True, prop={'size': 20}) subplots_adjust(left=None, bottom=None, right=0.8, top=None, wspace=None, hspace=None) #fig.tight_layout() fig.set_size_inches(20.5, 10.5, forward=True) if save_figure == True: plt.savefig('paper_figures/Fig_distributions_only_Tournadre.png', dpi=300, bbox_inches='tight') plt.show()
def produce_figure_variable_row(fig,axes,nrows,ncols,file_type_list, title_list,colorbar_unit_list,y_title_list,datapath, file_extension,cscale, row_num, \ difference_on,pole,field_name,variable_list,axes_direction='xy',letter_labels=None): difference_on = 0 title = None for k in range(len(variable_list)): #for k in np.array([0,1,2]): print 'Plotting ' + field_name + ' fields for ' + file_type_list[ variable_list[k]] ax = subplot(nrows, ncols, (row_num - 1) * ncols + (k + 1)) filename = datapath + 'Control_' + file_type_list[ variable_list[k]] + file_extension #print filename (lat, lon, data, p_values, field, layer_interface, lat_lon_bounds) = load_data_from_mat_file(filename) if axes_direction == 'xy': (cscale, datamap) = plot_polar_field(lat, lon, data, pole, difference_on, title, p_values, cscale, field, colorbar_on=False, return_data_map=True) else: file_type = 'ocean_month_z' datamap=plot_vertical_section(lon,lat,data,difference_on,title,p_values,cscale,field,layer_interface,axes_direction,lat_lon_bounds,file_type,\ colorbar_on=False,return_data_map=True) if row_num == 1: #ax.set_title(title_list[k], fontsize=18, y=1.13) ax.set_title(title_list[variable_list[k]], fontsize=18, y=1.13) #if k==0: # plt.ylabel(y_title_list[row_num-1], fontsize=18, labelpad=25) if k > 0: ax.set_yticks([]) #if k==0 and row_num<2: #ax.annotate(y_title_list[row_num-1], xy=(-0.6, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') #ax.annotate('Salinity', xy=(-0.45, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') # plt.ylabel(y_title_list[i], fontsize=18, labelpad=25) #if k==0 and row_num>1: #plt.ylabel('depth (m)', fontsize=14) #ax.annotate(y_title_list[row_num-1], xy=(-0.5, 0.5), xycoords='axes fraction', fontsize=21,rotation=90,verticalalignment='center') #if row_num!=nrows: # ax.set_xticks([]) #else: # plt.xlabel('latitude (deg)', fontsize=14) # ax.set_xticks([-40 ,-60, -80]) #if row_num==nrows: #cbar=fig.colorbar(datamap,shrink=0.5) #cbar=fig.colorbar(datamap) #Creating colorbar #fig.subplots_adjust(bottom=0.15) text(1, 1, letter_labels[(row_num - 1) * ncols + (k + 1) - 1], ha='right', va='bottom', transform=ax.transAxes, fontsize=15) #cbar_ax = fig.add_axes([0.13+(k*0.28),0.07, 0.20, 0.03]) #cbar=fig.colorbar(datamap, cax=cbar_ax, orientation="horizontal") cbar = fig.colorbar(datamap, orientation="horizontal") cbar.set_label(colorbar_unit_list[k]) tick_locator = ticker.MaxNLocator(nbins=5) cbar.locator = tick_locator cbar.update_ticks()
def main(): parser = argparse.ArgumentParser() args = parser.parse_args() #Flags save_figure=True significant_only=True plot_traj_fields=False plot_melt_fields=False plot_sea_ice_conc_fields=True plot_sea_ice_thickness_fields=True plot_traj_AB_fields=False plot_all_panels_without_data=False #False makes the real figure #Parameters; pole='south' #pole='north' title=None cscale=None Delta_list=np.array(['Delta1', 'Delta3', 'Delta9']) #Title_list=np.array(['Delta1 (Area=0.0026km^2)', 'Delta6 (Area=0.029km^2)', 'Delta9 (Area=1.8km^2)']) #Title_list=np.array(['Area=0.0026km^2', 'Area=0.35km^2', 'Area=1.8km^2']) #title_list = {'Delta1': 'Area=0.0026km^2', 'Delta3':'Area=0.029km^2', 'Delta4':'Area=0.12km^2' , 'Delta6': 'Area=0.35km^2' , 'Delta9': 'Area=1.8km^2'} #title_list = {'Delta1': 'Length=60m', 'Delta3':'Length=200m', 'Delta4':'Length=350m$' , 'Delta6': 'Length=700m$' , 'Delta9': 'Length=1600m'} title_list = {'Delta1': 'Length=62m', 'Delta3':'Length=209m', 'Delta9': 'Length=1659m'} color_vec=np.array(['blue', 'red', 'green', 'grey','purple', 'cyan', 'magenta', 'black', 'orange', 'coral', 'yellow', 'orchid', 'black', 'orange', 'coral', 'yellow', 'orchid' ]) y_title_list=np.array(['Sea-Ice Concentration\nAnomaly', 'Sea-Ice Thickenssn\nAnomaly']) #y_title_list=np.array(['Sea Ice Concentration', 'Sea Ice Thickenss']) y_title_list2=np.array(['Anomaly', 'Anomaly']) #colorbar_unit_list=np.array(['', 'melt (kg/m^2/s)', 'Conc (fraction)', 'Thickness (m)','']) colorbar_unit_list=np.array(['Concentration (fraction)', 'Thickness (m)']) nrows=2 ncols=len(Delta_list)#3 datapath='/home/Alon.Stern/Iceberg_Project/iceberg_scripts/python_scripts/size_matters_paper/processed_data/' #Setting up the figure fig, axes = plt.subplots(nrows=nrows, ncols=ncols) #This is used to plot the figure without the data for playing this anotations. if plot_all_panels_without_data==True: save_figure=False else: #Plotting Trajectory Fields if plot_traj_fields==True: boundinglat=-45 projection = 'splaea' row_num=1 for k in range(ncols): print 'Plotting Traj Fields for ' + Delta_list[k] ax=subplot(nrows,ncols,(row_num-1)*ncols+(k+1)) filename=datapath + Delta_list[k] + '_traj_1994_to_1995_all_south.mat' (lat ,lon,Total_berg_lon,Total_berg_lat)=load_traj_data_from_mat_file(filename) m = Basemap(projection=projection, boundinglat=boundinglat, lon_0=180) plot_polar_field(lat,lon,None,pole,difference_on=0.,title=None) m.scatter(Total_berg_lon,Total_berg_lat,1,marker='o',color=color_vec[k]) ax.set_title(title_list[Delta_list[k]], fontsize=20,y=1.13) if k==0: plt.ylabel(y_title_list[k], fontsize=20, labelpad=25) fig.subplots_adjust(right=0.8) #Plotting Sea Ice Conc Fields if plot_sea_ice_conc_fields==True: cscale=0.04 row_num=1 difference_on=1 field_name='Sea Ice Concentration' file_extension='_CN_1959_to_2019_all_south_xy_anomaly.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, file_extension,cscale, \ row_num,difference_on, pole,field_name,significant_only,y_title_list2) #Plotting Sea Ice Thickness Fields if plot_sea_ice_thickness_fields==True: cscale=0.1 row_num=2 difference_on=1 field_name='Sea Ice Thickness' file_extension='_HI_1959_to_2019_all_south_xy_anomaly.mat' produce_figure_row(fig,axes,nrows,ncols,Delta_list, title_list,colorbar_unit_list,y_title_list, datapath, file_extension,cscale, \ row_num,difference_on, pole,field_name,significant_only,y_title_list2) fig.subplots_adjust(right=0.8) subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) fig.set_size_inches(18.5, 10.5,forward=True) if save_figure==True: plt.savefig('paper_figures/Fig_CN_HI_D1_D3_D9.png',dpi=300,bbox_inches='tight') #plt.savefig('paper_figures/Fig_CN_HI_D1_D3_D9.eps',bbox_inches='tight') plt.show()