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 main():
	start_year=1947
        input_folder='/ptmp/Alon.Stern/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg_bergs_Delta2/'
	field='CN'
	months=range(0,11)
	file_type='ice_month'
	pole='south'
	(All_data, lat, lon) =generate_data_file(start_year, start_year, input_folder, field,months,file_type)
	data=np.squeeze(All_data)
	print data.shape
	#plt.show()

	#data(volcano)
	volcano=data
	m <- volcano
	dimx <- nrow(m)
	dimy <- ncol(m)

	d1 <- list(x = seq(0, 1, length = dimx), y = seq(0, 1, length = dimy), z = m)



	print 'Script complete'
Beispiel #3
0
def main():
	#Clear screen
	#os.system('clear')


	input_folder='/ptmp/Alon.Stern/model_output/ulm_mom6_2015.07.20_again_myIcebergTag/AM2_LM3_SIS2_MOM6i_1deg_bergs_Delta9/'
	field='CN'
	pole='north'
	pole=None
	save_traj_data=False

	input_folder='/home/Alon.Stern/Iceberg_Project/iceberg_scripts/python_scripts/size_matters_paper/Delta9_CN_1959_to_2019_all_south_xy_anomaly.mat'
	(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', 'Delta2','Delta3', 'Delta9']) ; naming_flag='Delta'

		datamap=m.scatter(Total_berg_lon,Total_berg_lat, c=Total_berg_mass0, marker='o',cmap='jet',norm=cNorm)
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=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=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'
Beispiel #7
0
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'