def make_plot(in_filename, out_filename, time, title): ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() age = abs(particles.least_create_times / 3600. - time) dry_diameters = particles.dry_diameters() s_crit = (particles.critical_rel_humids(env_state) - 1) * 100 x_axis = partmc.log_grid(min=1e-8, max=1e-6, n_bin=140) y_axis = partmc.linear_grid(min=0, max=48, n_bin=96) vals2d = partmc.multival_2d(dry_diameters, age, s_crit, x_axis, y_axis) plt.clf() plt.pcolor(x_axis.edges(), y_axis.edges(), vals2d.transpose(), norm=matplotlib.colors.LogNorm(), linewidths=0.1) a = plt.gca() a.set_xscale("log") a.set_yscale("linear") plt.axis([x_axis.min, x_axis.max, y_axis.min, y_axis.max]) plt.xlabel("dry diameter (m)") plt.ylabel("age (h)") cbar = plt.colorbar() cbar.set_label("S_crit (%)") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def process_data(in_filename_list, out_filename): total_value = None for in_filename in in_filename_list: ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() dry_diameters = particles.dry_diameters() * 1e6 # m to um masses = particles.masses() * 1e9 # kg to ug value = partmc.histogram_1d(dry_diameters, x_axis, weights=masses / particles.comp_vols) value /= 1e6 # m^{-3} to cm^{-3} if total_value is None: total_value = value else: total_value += value total_value /= len(in_filename_list) np.savetxt(out_filename, total_value) mask = np.ma.make_mask(total_value <= 0.0) masked_total_value = np.ma.array(total_value, mask=mask) return (masked_total_value.min(), masked_total_value.max())
def check_num(in_dir, in_filename, in_file_pattern, out_filename, counter): time_filename_list = partmc.get_time_filename_list(in_dir, in_file_pattern) id_p_array = np.array([16388, 10, 33311, 9212, 451, 11769]) d = np.zeros((len(id_p_array),len(time_filename_list))) seconds = np.zeros(len(time_filename_list)) i_count = 0 for [time, filename, key] in time_filename_list: print time, filename, key ncf = scipy.io.netcdf.netcdf_file(filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() wet_diameters = particles.diameters() id_list = list(particles.ids) for i in range(0,6): i_index = id_list.index(id_p_array[i]) d[i,i_count] = wet_diameters[i_index] seconds[i_count] = i_count i_count = i_count + 1 plt.figure() plt.semilogy(seconds, d[0,:], 'b-', label = 'act1_2') plt.semilogy(seconds, d[1,:], 'g-', label = 'not_1_2') plt.semilogy(seconds, d[2,:], 'r-', label = 'act2_not_act1') plt.semilogy(seconds, d[3,:], 'b-', label = 'act1_2') plt.semilogy(seconds, d[4,:], 'g-', label = 'not_1_2') plt.semilogy(seconds, d[5,:], 'r-', label = 'act2_not_act1') plt.xlabel("time (s)") plt.ylabel("diameter (m)") plt.legend(loc = 'upper left') fig = plt.gcf() fig.savefig(out_filename)
def make_plot(in_filename,out_filename,title): ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() bc = particles.masses(include = ["BC"]) dry_mass = particles.masses(exclude = ["H2O"]) bc_frac = bc / dry_mass dry_diameters = particles.dry_diameters() x_axis = partmc.log_grid(min=1e-8,max=1e-6,n_bin=70) y_axis = partmc.linear_grid(min=0,max=0.8,n_bin=40) hist2d = partmc.histogram_2d(dry_diameters, bc_frac, x_axis, y_axis, weights = 1/particles.comp_vols) plt.clf() plt.pcolor(x_axis.edges(), y_axis.edges(), hist2d.transpose(),norm = matplotlib.colors.LogNorm(), linewidths = 0.1) a = plt.gca() a.set_xscale("log") a.set_yscale("linear") plt.axis([x_axis.min, x_axis.max, y_axis.min, y_axis.max]) plt.xlabel("dry diameter (m)") plt.ylabel("BC mass fraction") cbar = plt.colorbar() cbar.set_label("number density (m^{-3})") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def get_plot_data_bc(filename, value_min=None, value_max=None): ncf = scipy.io.netcdf.netcdf_file(filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() diameters = particles.dry_diameters() * 1e6 comp_frac = particles.masses(include = ["BC"]) \ / particles.masses(exclude = ["H2O"]) * 100 # hack to avoid landing just around the integer boundaries comp_frac *= (1.0 + 1e-12) h2o = particles.masses(include=["H2O"]) x_axis = partmc.log_grid(min=diameter_axis_min, max=diameter_axis_max, n_bin=num_diameter_bins * 2) y_axis = partmc.linear_grid(min=bc_axis_min, max=bc_axis_max, n_bin=num_bc_bins * 2) value = partmc.multival_2d(diameters, comp_frac, h2o, x_axis, y_axis) if value_max == None: value_max = value.max() if value_min == None: maxed_value = np.where(value > 0.0, value, value_max) value_min = maxed_value.min() #if value_max > 0.0: # value = (log(value) - log(value_min)) \ # / (log(value_max) - log(value_min)) #value = value.clip(0.0, 1.0) return (value, x_axis.edges(), y_axis.edges(), env_state, value_min, value_max)
def make_plot(in_filename,out_filename,time,title): ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() age = abs(particles.least_create_times / 3600. - time) dry_diameters = particles.dry_diameters() x_axis = partmc.log_grid(min=1e-8,max=1e-6,n_bin=70) y_axis = partmc.linear_grid(min=0, max = 48, n_bin=49) hist2d = partmc.histogram_2d(dry_diameters, age, x_axis, y_axis, weights = 1/particles.comp_vols) plt.clf() plt.pcolor(x_axis.edges(), y_axis.edges(), hist2d.transpose(),norm = matplotlib.colors.LogNorm(), linewidths = 0.1) a = plt.gca() a.set_xscale("log") a.set_yscale("linear") plt.axis([x_axis.min, x_axis.max, y_axis.min, y_axis.max]) plt.xlabel("dry diameter (m)") plt.ylabel("age (h)") cbar = plt.colorbar() cbar.set_label("number density (m^{-3})") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def make_plot(netcdf_dir, netcdf_pattern, out_filename): time_filename_list = partmc.get_time_filename_list(netcdf_dir, netcdf_pattern) ccn_array = np.zeros([len(time_filename_list), 4]) i_counter = 0 for [time, filename, key] in time_filename_list: print time, filename, key ncf = scipy.io.netcdf.netcdf_file(filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() s_crit = (particles.critical_rel_humids(env_state) - 1) * 100 activated_1 = (s_crit < config.s_crit_1) number_act_1 = sum(1 / particles.comp_vols[activated_1]) activated_2 = (s_crit < config.s_crit_2) number_act_2 = sum(1 / particles.comp_vols[activated_2]) activated_3 = (s_crit < config.s_crit_3) number_act_3 = sum(1 / particles.comp_vols[activated_3]) ccn_array[i_counter, 0] = time ccn_array[i_counter, 1] = number_act_1 ccn_array[i_counter, 2] = number_act_2 ccn_array[i_counter, 3] = number_act_3 i_counter += 1 print ccn_array np.savetxt(out_filename, ccn_array)
def make_plot(in_filename,out_filename,title): print in_filename ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() dry_diameters = particles.dry_diameters() s_crit = (particles.critical_rel_humids(env_state) - 1)*100 x_axis = partmc.log_grid(min=1e-8,max=1e-6,n_bin=70) y_axis = partmc.log_grid(min=1e-3,max=1e2,n_bin=50) hist2d = partmc.histogram_2d(dry_diameters, s_crit, x_axis, y_axis, weights = 1/particles.comp_vols) plt.clf() plt.pcolor(x_axis.edges(), y_axis.edges(), hist2d.transpose(),norm = matplotlib.colors.LogNorm(), linewidths = 0.1) a = plt.gca() a.set_xscale("log") a.set_yscale("log") plt.axis([x_axis.min, x_axis.max, y_axis.min, y_axis.max]) plt.xlabel("dry diameter (m)") plt.ylabel("critical supersaturation (%)") cbar = plt.colorbar() cbar.set_label("number density (m^{-3})") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def process_data(in_filename_list, out_filename): total_value = None for in_filename in in_filename_list: ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() dry_diameters = particles.dry_diameters() * 1e6 # m to um scrit = (particles.critical_rel_humids(env_state) - 1) * 100 # in % value = partmc.histogram_2d(dry_diameters, scrit, x_axis, y_axis, weights = 1 / particles.comp_vols, only_positive=False) # do not account for y_axis in % as it is a log-scale value /= 1e6 # m^{-3} to cm^{-3} if total_value is None: total_value = value else: total_value += value total_value /= len(in_filename_list) np.savetxt(out_filename, total_value) mask = np.ma.make_mask(total_value <= 0.0) masked_total_value = np.ma.array(total_value, mask=mask) return(masked_total_value.min(), masked_total_value.max())
def process_data(in_filename_list, out_filename): total_value = None for in_filename in in_filename_list: ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() dry_diameters = particles.dry_diameters() * 1e6 # m to um comp_frac = particles.masses(include = ["BC"]) \ / particles.masses(exclude = ["H2O"]) * 100 # in % # hack to avoid landing just around the integer boundaries comp_frac *= (1.0 + 1e-12) value = partmc.histogram_2d(dry_diameters, comp_frac, x_axis, y_axis, weights=1 / particles.comp_vols, only_positive=False) value *= 100 # account for y_axis scaling in % value /= 1e6 # m^{-3} to cm^{-3} if total_value is None: total_value = value else: total_value += value total_value /= len(in_filename_list) np.savetxt(out_filename, total_value) mask = np.ma.make_mask(total_value <= 0.0) masked_total_value = np.ma.array(total_value, mask=mask) return (masked_total_value.min(), masked_total_value.max())
def make_plot(in_filename,out_filename,title): ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() oin = particles.masses(include = ["BC"]) dry_mass = particles.masses(exclude = ["H2O"]) oin_frac = oin / dry_mass dry_diameters = particles.dry_diameters() print oin.max() x_axis = partmc.log_grid(min=1e-8,max=1e-4,n_bin=100) y_axis = partmc.log_grid(min=1e-19,max=6e-15,n_bin=30) hist2d = partmc.histogram_2d(dry_diameters, oin, x_axis, y_axis, weights = 1/particles.comp_vols) plt.clf() plt.pcolor(x_axis.edges(), y_axis.edges(), hist2d.transpose(),norm = matplotlib.colors.LogNorm(), linewidths = 0.1) a = plt.gca() a.set_xscale("log") a.set_yscale("log") plt.axis([1e-8, 1e-4, 1e-19, 6e-15]) plt.xlabel("dry diameter (m)") plt.ylabel("BC mass") plt.grid(True) # plt.clim(1e6, 1e12) cbar = plt.colorbar() cbar.set_label(r"number density ($\rm m^{-3}$)") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def make_plot(in_dir, in_files, title, out_filename, error): x_axis = partmc.log_grid(min=1e-8, max=1e-5, n_bin=3) x_centers = x_axis.centers() counter = 0 hist_array = np.zeros([len(x_centers), config.i_loop_max]) error = np.zeros([3]) for file in in_files: ncf = scipy.io.netcdf.netcdf_file(in_dir + file, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() dry_diameters = particles.dry_diameters() hist = partmc.histogram_1d(dry_diameters, x_axis, weights=1 / particles.comp_vols) hist_array[:, counter] = hist counter = counter + 1 plt.clf() for i_loop in range(0, config.i_loop_max): plt.loglog(x_axis.centers(), hist_array[:, i_loop], 'k') plt.errorbar(x_axis.centers(), np.average(hist_array, axis=1), np.std(hist_array, axis=1)) avg = np.average(hist_array, axis=1) std = np.std(hist_array, axis=1) error = std / avg print 'avg and std ', avg, std, error plt.axis([1e-8, 1e-5, 1e4, 1e11]) plt.xlabel("dry diameter (m)") plt.ylabel("number density (m^{-3})") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def make_plot(in_dir, in_filename1, in_filename2, in_filename3, out_filename, title, ccn_cn_i, ccn_cn_j): print in_filename1, in_filename2, in_filename3 ncf = scipy.io.netcdf.netcdf_file(in_dir + in_filename1, 'r') particles1 = partmc.aero_particle_array_t(ncf) ncf.close() ncf = scipy.io.netcdf.netcdf_file(in_dir + in_filename2, 'r') particles2 = partmc.aero_particle_array_t(ncf) ncf.close() ncf = scipy.io.netcdf.netcdf_file(in_dir + in_filename3, 'r') particles3 = partmc.aero_particle_array_t(ncf) ncf.close() x_axis = partmc.log_grid(min=1e-10, max=1e-4, n_bin=30) x_centers = x_axis.centers() wet_diameters1 = particles1.diameters() wet_diameters2 = particles2.diameters() wet_diameters3 = particles3.diameters() hist1 = partmc.histogram_1d(wet_diameters1, x_axis, weights=1 / particles1.comp_vols) hist2 = partmc.histogram_1d(wet_diameters2, x_axis, weights=1 / particles2.comp_vols) hist3 = partmc.histogram_1d(wet_diameters3, x_axis, weights=1 / particles3.comp_vols) is_activated = (wet_diameters3 > 2e-6) sum_tot = sum(1 / particles3.comp_vols) * 1e-6 num_act = sum(1 / particles3.comp_vols[is_activated]) * 1e-6 print title, num_act, sum_tot, num_act / sum_tot * 100 ccn_cn_ratio[ccn_cn_i, ccn_cn_j] = num_act / sum_tot plt.clf() plt.semilogx(x_axis.centers(), hist1, label='0 min') plt.semilogx(x_axis.centers(), hist2, label='2 mins') plt.semilogx(x_axis.centers(), hist3, label='10 mins') plt.legend(loc='upper left') plt.xlabel("wet diameter (m)") plt.ylabel("number density (m^{-3})") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def make_plot(dir_name, in_filename, out_filename): ncf = scipy.io.netcdf.netcdf_file(dir_name + in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() bc = particles.masses(include=["BC"]) dry_mass = particles.masses(exclude=["H2O"]) bc_frac = bc / dry_mass dry_diameters = particles.dry_diameters() * 1e6 x_axis = partmc.log_grid(min=1e-3, max=1e1, n_bin=100) y_axis = partmc.linear_grid(min=0, max=0.8, n_bin=40) hist2d = partmc.histogram_2d(dry_diameters, bc_frac, x_axis, y_axis, weights=1 / particles.comp_vols) hist2d = hist2d * 1e-6 print hist2d[36, :] (figure, axes_array, cbar_axes_array) = mpl_helper.make_fig_array(1, 1, figure_width=5, top_margin=0.5, bottom_margin=0.45, left_margin=0.65, right_margin=1, vert_sep=0.3, horiz_sep=0.3, colorbar="shared", colorbar_location="right") axes = axes_array[0][0] cbar_axes = cbar_axes_array[0] p = axes.pcolor(x_axis.edges(), y_axis.edges(), hist2d.transpose(), norm=matplotlib.colors.LogNorm(vmin=1e3, vmax=1e5), linewidths=0.1) axes.set_xscale("log") axes.set_yscale("linear") axes.set_ylabel(r"BC mass fraction $w_{\rm BC}$") axes.set_xlabel(r"dry diameter $D$/ $\rm \mu m$") axes.set_ylim(0, 0.8) axes.set_xlim(5e-3, 1e0) axes.grid(True) cbar = figure.colorbar(p, cax=cbar_axes, format=matplotlib.ticker.LogFormatterMathtext(), orientation='vertical') cbar_axes.xaxis.set_label_position('top') cbar.set_label(r"number conc. $n(D,w_{\rm BC})$ / $\rm cm^{-3}$") mpl_helper.remove_fig_array_axes(axes_array) figure.savefig(out_filename)
def make_plot(in_dir, in_filename_wc, in_filename_nc, title, out_filename_wc, out_filename_nc): print 'file ', in_dir + in_filename_wc ncf = scipy.io.netcdf.netcdf_file(in_dir + in_filename_wc, 'r') particles_wc = partmc.aero_particle_array_t(ncf) ncf.close() ncf = scipy.io.netcdf.netcdf_file(in_dir + in_filename_nc, 'r') particles_nc = partmc.aero_particle_array_t(ncf) ncf.close() # so4_wc = particles_wc.masses(include = ["SO4"])/particles_wc.aero_data.molec_weights[0] # nh4_wc = particles_wc.masses(include = ["NH4"])/particles_wc.aero_data.molec_weights[3] # no3_wc = particles_wc.masses(include = ["NO3"])/particles_wc.aero_data.molec_weights[1] so4_nc = particles_nc.masses( include=["SO4"]) / particles_nc.aero_data.molec_weights[0] nh4_nc = particles_nc.masses( include=["NH4"]) / particles_nc.aero_data.molec_weights[3] no3_nc = particles_nc.masses( include=["NO3"]) / particles_nc.aero_data.molec_weights[1] # plt.scatter(nh4_wc, 2*so4_wc+no3_wc) # a = plt.gca() # gets the axis # a.set_xscale("log") # x axis log # a.set_yscale("log") # y axis log # plt.axis([1e-25, 1e-15, 1e-25, 1e-15]) # axis limit # plt.title(title) # fig = plt.gcf() # fig.savefig(out_filename_wc) plt.scatter(nh4_nc, 2 * so4_nc + no3_nc) a = plt.gca() # gets the axis a.set_xscale("log") # x axis log a.set_yscale("log") # y axis log plt.axis([1e-25, 1e-15, 1e-25, 1e-15]) # axis limit plt.title(title) fig = plt.gcf() fig.savefig(out_filename_nc)
def make_plot(in_dir, in_filename1, in_filename2, in_filename3, out_filename): print in_filename1, in_filename2, in_filename3 ncf = scipy.io.netcdf.netcdf_file(in_dir + in_filename1, 'r') particles1 = partmc.aero_particle_array_t(ncf) ncf.close() ncf = scipy.io.netcdf.netcdf_file(in_dir + in_filename2, 'r') particles2 = partmc.aero_particle_array_t(ncf) ncf.close() ncf = scipy.io.netcdf.netcdf_file(in_dir + in_filename3, 'r') particles3 = partmc.aero_particle_array_t(ncf) ncf.close() x_axis = partmc.log_grid(min=1e-10, max=1e-4, n_bin=50) x_centers = x_axis.centers() dry_diameters1 = particles1.dry_diameters() dry_diameters2 = particles2.dry_diameters() dry_diameters3 = particles3.dry_diameters() hist1 = partmc.histogram_1d(dry_diameters1, x_axis, weights=particles1.masses(exclude=["H2O"]) / particles1.comp_vols) hist2 = partmc.histogram_1d(dry_diameters2, x_axis, weights=particles2.masses(exclude=["H2O"]) / particles2.comp_vols) hist3 = partmc.histogram_1d(dry_diameters3, x_axis, weights=particles3.masses(exclude=["H2O"]) / particles3.comp_vols) plt.clf() plt.loglog(x_axis.centers(), hist1, label='initial') plt.loglog(x_axis.centers(), hist2, label='6 hours') plt.loglog(x_axis.centers(), hist3, label='12 hours') plt.legend(loc='center right') plt.axis([5e-9, 1e-4, 1e-14, 1e-7]) plt.grid(True) plt.xlabel("dry diameter (m)") plt.ylabel(r"mass concentration ($\rm kg \, m^{-3}$)") fig = plt.gcf() fig.savefig(out_filename)
def make_plot(in_filename, out_filename, title): ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() so4 = particles.masses( include=["SO4"]) / particles.aero_data.molec_weights[0] nh4 = particles.masses( include=["NH4"]) / particles.aero_data.molec_weights[3] no3 = particles.masses( include=["NO3"]) / particles.aero_data.molec_weights[1] dry_mass = particles.masses(exclude=["H2O"]) so4_frac = so4 / dry_mass ion_ratio = (2 * so4 + no3) / nh4 is_neutral = (ion_ratio < 2) print 'neutral ', sum(is_neutral), ion_ratio[is_neutral] dry_diameters = particles.dry_diameters() x_axis = partmc.log_grid(min=1e-8, max=1e-6, n_bin=70) y_axis = partmc.linear_grid(min=0, max=1.0, n_bin=50) hist2d = partmc.histogram_2d(dry_diameters, so4_frac, x_axis, y_axis, weights=1 / particles.comp_vols) plt.clf() plt.semilogx(dry_diameters, ion_ratio, 'rx') fig = plt.gcf() fig.savefig('figs/t.pdf') plt.clf() plt.pcolor(x_axis.edges(), y_axis.edges(), hist2d.transpose(), norm=matplotlib.colors.LogNorm(), linewidths=0.1) a = plt.gca() a.set_xscale("log") a.set_yscale("linear") plt.axis([x_axis.min, x_axis.max, y_axis.min, y_axis.max]) plt.xlabel("dry diameter (m)") plt.ylabel("SO4 mass fraction") cbar = plt.colorbar() cbar.set_label("number density (m^{-3})") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def make_plot(in_files, f1, f2, f3, f4, f5, f6): x_axis = partmc.log_grid(min=1e-10,max=1e-4,n_bin=100) y_axis = partmc.linear_grid(min=0,max=1.,n_bin=50) x_centers = x_axis.centers() y_centers = y_axis.centers() counter = 0 hist_array_num = np.zeros([len(x_centers),len(y_centers),config.i_loop_max]) hist_average_num = np.zeros([len(x_centers), len(y_centers)]) hist_std_num = np.zeros([len(x_centers), len(y_centers)]) hist_std_norm_num = np.zeros([len(x_centers), len(y_centers)]) hist_array_mass = np.zeros([len(x_centers),len(y_centers),config.i_loop_max]) hist_average_num = np.zeros([len(x_centers), len(y_centers)]) hist_std_num = np.zeros([len(x_centers), len(y_centers)]) hist_std_norm_num = np.zeros([len(x_centers), len(y_centers)]) for file in in_files: ncf = scipy.io.netcdf.netcdf_file(config.netcdf_dir+'/'+file, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() bc = particles.masses(include = ["BC"]) dry_mass = particles.masses(exclude = ["H2O"]) bc_frac = bc / dry_mass dry_diameters = particles.dry_diameters() hist2d = partmc.histogram_2d(dry_diameters, bc_frac, x_axis, y_axis, weights = 1 / particles.comp_vols) hist_array_num[:,:,counter] = hist2d hist2d = partmc.histogram_2d(dry_diameters, bc_frac, x_axis, y_axis, weights = particles.masses(include=["BC"]) / particles.comp_vols) hist_array_mass[:,:,counter] = hist2d counter = counter+1 hist_average_num = np.average(hist_array_num, axis = 2) hist_std_num = np.std(hist_array_num, axis = 2) hist_std_norm_num = hist_std_num / hist_average_num hist_std_norm_num = np.ma.masked_invalid(hist_std_norm_num) hist_average_mass = np.average(hist_array_mass, axis = 2) hist_std_mass = np.std(hist_array_mass, axis = 2) hist_std_norm_mass = hist_std_mass / hist_average_mass hist_std_norm_mass = np.ma.masked_invalid(hist_std_norm_mass) np.savetxt(f1, x_axis.edges()) np.savetxt(f2, y_axis.edges()) np.savetxt(f3, hist_average_num) np.savetxt(f4, hist_std_norm_num) np.savetxt(f5, hist_average_mass) np.savetxt(f6, hist_std_norm_mass)
def make_plot(in_filename,out_filename): ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() bc = particles.masses(include = ["BC"]) dry_mass = particles.masses(exclude = ["H2O"]) bc_frac = bc / dry_mass so4 = particles.masses(include = ["SO4"]) inorg = particles.masses(include = ["SO4", "NO3", "NH4"]) inorg_frac = inorg / dry_mass kappas = particles.kappas() wet_diameters = particles.diameters() dry_diameters = particles.dry_diameters() * 1e6 x_axis = partmc.log_grid(min=1e-2,max=1e0,n_bin=90) y_axis = partmc.linear_grid(min=0,max=0.8,n_bin=40) vals = partmc.multival_2d(dry_diameters, bc_frac, kappas, x_axis, y_axis, rand_arrange=False) vals_pos = np.ma.masked_less_equal(vals, 0) vals_zero = np.ma.masked_not_equal(vals, 0) plt.clf() if vals_zero.count() > 0: plt.pcolor(x_axis.edges(), y_axis.edges(), vals_zero.transpose(), cmap=matplotlib.cm.gray, linewidths = 0.1) if vals_pos.count() > 0: plt.pcolor(x_axis.edges(), y_axis.edges(), vals_pos.transpose(), linewidths = 0.1) title = partmc.time_of_day_string(env_state) a = plt.gca() a.set_xscale("log") a.set_yscale("linear") plt.axis([x_axis.min, x_axis.max, y_axis.min, y_axis.max]) plt.xlabel("dry diameter (\mu m)") plt.ylabel("BC dry mass fraction") cbar = plt.colorbar() plt.clim(0, 0.6) cbar.set_label("kappa") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def get_plot_data_bc(filename, value_min=None, value_max=None): ncf = scipy.io.netcdf.netcdf_file(filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() diameters = particles.dry_diameters() * 1e6 x_axis = partmc.log_grid(min=diameter_axis_min, max=diameter_axis_max, n_bin=num_diameter_bins) value = partmc.histogram_1d(diameters, x_axis, weights=1 / particles.comp_vols) value /= 1e6 return (value, x_axis.centers())
def make_plot(dir_name,in_filename,out_filename): ncf = scipy.io.netcdf.netcdf_file(dir_name+in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() dry_diameters = particles.dry_diameters() * 1e6 s_crit = (particles.critical_rel_humids(env_state) - 1)*100 x_axis = partmc.log_grid(min=1e-3,max=1e1,n_bin=100) y_axis = partmc.log_grid(min=1e-3,max=1e2,n_bin=50) hist2d = partmc.histogram_2d(dry_diameters, s_crit, x_axis, y_axis, weights = particles.num_concs) hist2d = hist2d * 1e-6 (figure, axes_array, cbar_axes_array) = mpl_helper.make_fig_array(1,1, figure_width=5, top_margin=0.5, bottom_margin=0.45, left_margin=0.65, right_margin=1, vert_sep=0.3, horiz_sep=0.3, colorbar="shared", colorbar_location="right") axes = axes_array[0][0] cbar_axes = cbar_axes_array[0] p = axes.pcolor(x_axis.edges(), y_axis.edges(), hist2d.transpose(), norm = matplotlib.colors.LogNorm(vmin=1e3, vmax=1e5), linewidths = 0.1) axes.set_xscale("log") axes.set_yscale("log") axes.set_ylabel(r"crit. supersat. $S_{\rm c}$") axes.set_xlabel(r"dry diameter $D$/ $\rm \mu m$") axes.set_ylim(1e-3,10) axes.set_xlim(5e-3, 1e0) axes.grid(True) cbar = figure.colorbar(p, cax=cbar_axes, format=matplotlib.ticker.LogFormatterMathtext(), orientation='vertical') cbar_axes.xaxis.set_label_position('top') cbar.set_label(r"number conc. $n(D,S_{\rm c})$ / $\rm cm^{-3}$") mpl_helper.remove_fig_array_axes(axes_array) figure.savefig(out_filename) plt.close()
def make_plot(in_files, f1, f2, f3, f4, f5): x_axis = partmc.log_grid(min=1e-10, max=1e-4, n_bin=100) x_centers = x_axis.centers() counter = 0 hist_array_num = np.zeros([len(x_centers), config.i_loop_max]) hist_array_mass = np.zeros([len(x_centers), config.i_loop_max]) for file in in_files: ncf = scipy.io.netcdf.netcdf_file(config.netcdf_dir + '/' + file, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() dry_diameters = particles.dry_diameters() hist = partmc.histogram_1d(dry_diameters, x_axis, weights=1 / particles.comp_vols) hist_array_num[:, counter] = hist hist = partmc.histogram_1d(dry_diameters, x_axis, weights=particles.masses(exclude=["H2O"]) / particles.comp_vols) hist_array_mass[:, counter] = hist counter = counter + 1 hist_array_gav_num = np.exp(np.average(np.log(hist_array_num), axis=1)) hist_array_gstd_num = np.exp(np.std(np.log(hist_array_num), axis=1)) e_bar_top_num = hist_array_gav_num * hist_array_gstd_num e_bar_bottom_num = hist_array_gav_num / hist_array_gstd_num e_bars_num = np.vstack((hist_array_gav_num - e_bar_bottom_num, e_bar_top_num - hist_array_gav_num)) hist_array_gav_mass = np.exp(np.average(np.log(hist_array_mass), axis=1)) hist_array_gstd_mass = np.exp(np.std(np.log(hist_array_mass), axis=1)) e_bar_top_mass = hist_array_gav_mass * hist_array_gstd_mass e_bar_bottom_mass = hist_array_gav_mass / hist_array_gstd_mass e_bars_mass = np.vstack((hist_array_gav_mass - e_bar_bottom_mass, e_bar_top_mass - hist_array_gav_mass)) np.savetxt(f1, x_axis.centers()) np.savetxt(f2, hist_array_gav_num) np.savetxt(f3, e_bars_num) np.savetxt(f4, hist_array_gav_mass) np.savetxt(f5, e_bars_mass)
def process_data(in_filename_list): total_value = None for in_filename in in_filename_list: ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() time_since_midnight = env_state.start_time_of_day \ + env_state.elapsed_time value = (1 / particles.comp_vols).sum() value /= 1e6 # m^{-3} to cm^{-3} if total_value is None: total_value = value else: total_value += value total_value /= len(in_filename_list) return [time_since_midnight, total_value]
def process_data(in_filename_list): total_value = None for in_filename in in_filename_list: ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() time_since_midnight = env_state.start_time_of_day \ + env_state.elapsed_time value = (particles.raw_masses / particles.comp_vols).sum(1) value *= 1e3 # kg m^{-3} to mg cm^{-3} if total_value is None: total_value = value else: total_value += value total_value /= len(in_filename_list) return np.concatenate((np.array([time_since_midnight]), total_value))
def make_plot(in_dir, in_filename, title, out_filename): print 'file ', in_dir+in_filename ncf = scipy.io.netcdf.netcdf_file(in_dir+in_filename, 'r') particles= partmc.aero_particle_array_t(ncf) ncf.close() bc = particles.masses(include = ["BC"])/particles.aero_data.molec_weights[0] oc = particles.masses(include = ["OC"])/particles.aero_data.molec_weights[3] no3 = particles.masses(include = ["NO3"])/particles.aero_data.molec_weights[1] plt.scatter(bc,oc) a = plt.gca() # gets the axis a.set_xscale("log") # x axis log a.set_yscale("log") # y axis log plt.axis([1e-20, 1e-15, 1e-20, 1e-15]) # axis limit plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def make_plot(in_dir, in_files, title, out_filename): x_axis = partmc.log_grid(min=1e-10,max=1e-4,n_bin=100) x_centers = x_axis.centers() counter = 0 hist_array = np.zeros([len(x_centers),config.i_loop_max]) for file in in_files: ncf = scipy.io.netcdf.netcdf_file(in_dir+file, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() dry_diameters = particles.dry_diameters() hist = partmc.histogram_1d(dry_diameters, x_axis, weights = 1 / particles.comp_vols) hist_array[:,counter] = hist counter = counter+1 # hist_array_av = np.average(hist_array,axis = 1) # hist_array_std = np.std(hist_array, axis = 1) # hist_array_std_clipped = np.minimum(hist_array_std, hist_array_av - 1) # e_bars = np.vstack((hist_array_std_clipped, hist_array_std)) hist_array_gav = np.exp(np.average(np.log(hist_array),axis = 1)) hist_array_gstd = np.exp(np.std(np.log(hist_array), axis = 1)) e_bar_top = hist_array_gav * hist_array_gstd e_bar_bottom = hist_array_gav / hist_array_gstd e_bars = np.vstack((hist_array_gav - e_bar_bottom, e_bar_top - hist_array_gav)) plt.clf() # for i_loop in range(0,config.i_loop_max): # plt.loglog(x_axis.centers(), hist_array[:,i_loop], 'k') a = plt.gca() # gets the axis a.set_xscale("log") # x axis log a.set_yscale("log") # y axis log plt.errorbar(x_axis.centers(), hist_array_gav, e_bars) plt.axis([5e-9, 5e-6, 1e4, 1e11]) plt.xlabel("dry diameter (m)") plt.ylabel("number density (m^{-3})") # plt.title(title) plt.grid(True) fig = plt.gcf() fig.savefig(out_filename)
def make_plot(in_dir, in_filename, out_filename, out_data_name): print in_filename ncf = scipy.io.netcdf.netcdf_file(in_dir+in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() x_axis = partmc.log_grid(min=1e-9,max=1e-5,n_bin=100) x_centers = x_axis.centers() diameters = particles.diameters() pure_bc = ((particles.masses(include = ["BC"]) > 0) & (particles.masses(include = ["SO4"]) == 0)) pure_so4 = ((particles.masses(include = ["SO4"]) > 0) & (particles.masses(include = ["BC"]) == 0)) with_bc = (particles.masses(include = ["BC"]) > 0) with_so4 = (particles.masses(include = ["SO4"]) > 0) mixed_bc_so4 = ((particles.masses(include = ["SO4"]) > 0) & (particles.masses(include = ["BC"]) > 0)) hist = partmc.histogram_1d(diameters, x_axis, weights = 1 / particles.comp_vols) / 1e6 hist_bc = partmc.histogram_1d(diameters[pure_bc], x_axis, weights = 1 / particles.comp_vols[pure_bc]) /1e6 hist_so4 = partmc.histogram_1d(diameters[pure_so4], x_axis, weights = 1 / particles.comp_vols[pure_so4]) /1e6 hist_mixed = partmc.histogram_1d(diameters[mixed_bc_so4], x_axis, weights = 1 / particles.comp_vols[mixed_bc_so4]) / 1e6 plt.clf() plt.loglog(x_centers*1e6, hist, 'r-', label = 'total') plt.loglog(x_centers*1e6, hist_bc, 'k-', label = 'pure bc') plt.loglog(x_centers*1e6, hist_so4, 'b-', label = 'pure so4') plt.loglog(x_centers*1e6, hist_mixed, 'g-', label = 'mixed so4 and bc') plt.axis([1e-3, 2e-0, 1e-1, 1e4]) plt.xlabel("dry diameter / micrometer") plt.ylabel("number density / cm^{-3}") plt.legend(loc = "upper left") plt.grid(True) fig = plt.gcf() fig.savefig(out_filename) np.savetxt("diameter_values.txt", x_centers*1e6) np.savetxt(out_data_name+"_total_acc_bc1.txt", hist) np.savetxt(out_data_name+"_bc_acc_bc1.txt", hist_bc) np.savetxt(out_data_name+"_so4_acc_bc1.txt", hist_so4) np.savetxt(out_data_name+"_mixed_acc_bc1.txt", hist_mixed)
def make_plot(in_dir, in_filename, out_filename): print in_filename ncf = scipy.io.netcdf.netcdf_file(in_dir + in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() x_axis = partmc.log_grid(min=1e-10, max=1e-4, n_bin=100) x_centers = x_axis.centers() dry_diameters = particles.dry_diameters() hist = partmc.histogram_1d(dry_diameters, x_axis, weights=1 / particles.comp_vols) plt.clf() plt.loglog(x_axis.centers(), hist) plt.axis([1e-10, 1e-4, 1e7, 1e15]) plt.xlabel("dry diameter (m)") plt.ylabel("number density (m^{-3})") fig = plt.gcf() fig.savefig(out_filename)
def make_plot(in_filename, out_filename, title): ncf = scipy.io.netcdf.netcdf_file(in_filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() bc_volume = particles.volumes(include=["BC"]) bc = particles.masses(include=["BC"]) dry_mass = particles.masses(exclude=["H2O"]) bc_frac = bc / dry_mass coat_frac = 1 - bc / dry_mass is_bc = (bc_frac > 0.05) dry_diameters = particles.dry_diameters() core_diameters = (6 / math.pi * bc_volume)**(1. / 3.) coating_thickness = (dry_diameters - core_diameters) / 2. ratio = coating_thickness / dry_diameters print ratio.max() x_axis = partmc.linear_grid(min=0, max=ratio.max(), n_bin=50) hist1d = partmc.histogram_1d(coating_thickness[is_bc] / dry_diameters[is_bc], x_axis, weights=1 / particles.comp_vols[is_bc]) print hist1d plt.clf() a = plt.gca() a.set_xscale("linear") a.set_yscale("log") plt.plot(x_axis.centers(), hist1d) plt.axis([x_axis.min, x_axis.max, 1e8, 1e12]) plt.grid(True) plt.xlabel("coating thickness / dry diameter") plt.ylabel("number concentration (m^{-3})") plt.title(title) fig = plt.gcf() fig.savefig(out_filename)
def get_plot_data(filename, value_min=None, value_max=None): ncf = scipy.io.netcdf.netcdf_file(filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() diameters = particles.dry_diameters() * 1e6 comp_frac = particles.masses(include = ["BC"]) \ / particles.masses(exclude = ["H2O"]) * 100 # hack to avoid landing just around the integer boundaries comp_frac *= (1.0 + 1e-12) h2o = particles.masses(include=["H2O"]) * 1e18 # kg to fg x_axis = partmc.log_grid(min=diameter_axis_min, max=diameter_axis_max, n_bin=num_diameter_bins * 2) y_axis = partmc.linear_grid(min=bc_axis_min, max=bc_axis_max, n_bin=num_bc_bins * 2) value = partmc.multival_2d(diameters, comp_frac, h2o, x_axis, y_axis) return (value, x_axis.edges(), y_axis.edges(), env_state)
def make_plot(netcdf_pattern, aging_ss, output_pkl): particle_set = {} netcdf_dir = "/Users/nriemer/subversion/partmc/trunk/scenarios/1_urban_plume/out" time_filename_list = partmc.get_time_filename_list(netcdf_dir, netcdf_pattern) for [time, filename, key] in time_filename_list: print time, filename, key ncf = scipy.io.netcdf.netcdf_file(filename, 'r') particles = partmc.aero_particle_array_t(ncf) removed_info = partmc.aero_removed_info_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() dry_diameters = particles.dry_diameters() s_crit = (particles.critical_rel_humids(env_state) - 1) * 100 bc = particles.masses(include=["BC"]) no3 = particles.masses(include=["NO3"]) so4 = particles.masses(include=["SO4"]) nh4 = particles.masses(include=["NH4"]) dry_mass = particles.masses(exclude=["H2O"]) bc_frac = bc / dry_mass no3_frac = no3 / dry_mass so4_frac = so4 / dry_mass nh4_frac = nh4 / dry_mass solute_frac = (no3 + so4 + nh4) / dry_mass kappas = particles.kappas() comp_vols = particles.comp_vols h2o = particles.masses(include=["H2O"]) for id in particle_set.keys(): while particle_set[id].current_id in removed_info.ids: i = np.nonzero( removed_info.ids == particle_set[id].current_id)[0][0] if removed_info.actions[i] != removed_info.AERO_INFO_COAG: particle_set[id].remove_time = time particle_set[id].current_id = 0 else: particle_set[id].current_id = removed_info.other_ids[i] for i in range(len(particles.ids)): id = particles.ids[i] if id not in particle_set: particle_set[id] = Struct() particle_set[id].current_id = id particle_set[id].emit_time = time particle_set[id].emit_diam = dry_diameters[i] particle_set[id].emit_s_crit = s_crit[i] particle_set[id].emit_kappa = kappas[i] particle_set[id].remove_time = -1 particle_set[id].aged_flag = False particle_set[id].aging_time = -1 particle_set[id].min_s_crit = s_crit[i] particle_set[id].emit_bc_fraction = bc_frac[i] particle_set[id].emit_comp_vols = comp_vols[i] particle_set[id].aging_kappa = -1 particle_set[id].aging_h2o = -1 particle_set[id].aging_no3_fraction = -1 particle_set[id].aging_so4_fraction = -1 particle_set[id].aging_nh4_fraction = -1 particle_set[id].aging_solute_fraction = -1 particle_set[id].aging_diameter = -1 for id in particle_set.keys(): if particle_set[id].current_id in particles.ids: i = np.nonzero( particles.ids == particle_set[id].current_id)[0][0] if s_crit[i] <= particle_set[id].min_s_crit: particle_set[id].min_s_crit = s_crit[i] if (s_crit[i] <= aging_ss) and (particle_set[id].aged_flag == False): particle_set[id].aging_time = time particle_set[id].aged_flag = True particle_set[id].aging_kappa = kappas[i] particle_set[id].aging_diameter = dry_diameters[i] particle_set[id].aging_h2o = h2o[i] particle_set[id].aging_no3_fraction = no3_frac[i] particle_set[id].aging_so4_fraction = so4_frac[i] particle_set[id].aging_nh4_fraction = nh4_frac[i] particle_set[id].aging_solute_fraction = solute_frac[i] output = open(output_pkl, 'wb') pickle.dump(particle_set, output) output.close()
i_loop_max = config.i_loop_max i_ens_max = config.i_ens_max netcdf_dir = "/home/nriemer/subversion/partmc/branches/nriemer/local_scenarios/brownian_test_paper2/out/" array_num_init = np.zeros([i_loop_max*i_ens_max]) array_mass_init = np.zeros([i_loop_max*i_ens_max]) array_num_end = np.zeros([i_loop_max*i_ens_max]) array_mass_end = np.zeros([i_loop_max*i_ens_max]) for i_loop in range (0, i_ens_max*i_loop_max): filename = "brownian_part_%05d_00000001.nc" % (i_loop+1) print filename ncf = scipy.io.netcdf.netcdf_file(netcdf_dir+filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close() total_number = sum(1/particles.comp_vols) total_dry_mass = sum(particles.masses()/particles.comp_vols) array_num_init[i_loop] = total_number array_mass_init[i_loop]= total_dry_mass filename = "brownian_part_%05d_00000002.nc" % (i_loop+1) print filename ncf = scipy.io.netcdf.netcdf_file(netcdf_dir+filename, 'r') particles = partmc.aero_particle_array_t(ncf) env_state = partmc.env_state_t(ncf) ncf.close()
def grid_box_histogram(time): # filename prefix dir = config.data_dir prefix = config.file_prefix filename = '%s_%08i.nc' %(prefix,time) # make grids diam_axis = partmc.log_grid(min=1e-9,max=1e-6,n_bin=60) bc_axis = partmc.linear_grid(min=0,max=1.,n_bin=50) # load the file ncf = scipy.io.netcdf.netcdf_file(config.data_dir+'/'+filename, 'r') particles = partmc.aero_particle_array_t(ncf) ncf.close() # compute the values bc = particles.masses(include = ["BC"]) dry_mass = particles.masses(exclude = ["H2O"]) bc_frac = bc / dry_mass dry_diameters = particles.dry_diameters() # 2D histogram hist_2d_bc = partmc.histogram_2d(dry_diameters, bc_frac, diam_axis, bc_axis, weights = 1 / particles.comp_vols) # convert hist_2d_bc /= 1e6 # create the figure width_in = 4.0 (figure, axes, cbar_axes) = mpl_helper.make_fig(figure_width=width_in, colorbar=True,left_margin=.7,right_margin=1.1, top_margin=0.3, bottom_margin=.65, colorbar_height_fraction=0.8) # Data min and max # we want this to be fixed for all time data_min = 10**2 #min(data_mins) data_max = 10**6 #max(data_maxes) norm = matplotlib.colors.LogNorm(vmin=data_min, vmax=data_max) p = axes.pcolormesh(diam_axis.edges()/1e-6, bc_axis.edges()*100, hist_2d_bc.transpose(),norm = norm, linewidths = 0.1, edgecolors='None') # make the plot pretty axes.set_xscale('log') axes.set_yscale('linear') xlabel = r'diameter $(\mu \rm m)$' ylabel = r'BC mass fraction' axes.set_xlabel(xlabel) axes.set_ylabel(ylabel) axes.set_xlim(.005,1) axes.set_ylim(0,80) axes.set_yticks([0,20,40,60,80]) axes.grid(True) # colorbar cbar = figure.colorbar(p, cax=cbar_axes, format=matplotlib.ticker.LogFormatterMathtext(), orientation='vertical') kwargs = {} kwargs["format"] = matplotlib.ticker.LogFormatterMathtext() cmappable = matplotlib.cm.ScalarMappable(norm=norm) cmappable.set_array(numpy.array([hist_2d_bc.min(), hist_2d_bc.max()])) cbar_label = r"num. conc. $(\rm cm^{-3})$" cbar.set_label(cbar_label) cbar.solids.set_edgecolor("face") # Save figure and print name fig_name = '%s/bc_plot_%08i.pdf' % \ (config.fig_dir, time) figure.savefig(fig_name) # print name in case we need it print fig_name return