def fn(m): """ Our objective function, takes an ndarray m that contains depths removed during each glaciation as a fraction of con['dz_max']. """ if SAVE_CONCENTRATION_DATA: global concs global indep_errs raw_dz = m * (con['max_dz'] - con['min_dz']) + con['min_dz'] dz = np.ones(con['n_gl']) * raw_dz[-1] dz[0:con['n_exact_depths']] = raw_dz[0:-1] conc = sim.multiglaciate(dz, con['t_gl'], con['t_int'], con['t_postgl'], con['sample_depths'], con['nuclide'], p, n_gl=con['n_gl'], postgl_shielding=con['postgl_shielding']) error = chi2(conc, con['C_meas'], con['C_meas_err']) print "Chi**2:", error if SAVE_CONCENTRATION_DATA: concs.append(conc) indep_errs.append(error) return error
def fn(m): """ Our objective function, takes an ndarray m that contains depths removed during each glaciation as a fraction of con['dz_max']. """ if SAVE_CONCENTRATION_DATA: global concs dz = m * (con['max_dz'] - con['min_dz']) + con['min_dz'] conc = sim.multiglaciate(dz, con['t_gl'], con['t_int'], con['t_postgl'], con['sample_depths'], con['nuclide'], p, n_gl=con['n_gl']) if SAVE_CONCENTRATION_DATA: concs.append(conc) error = chi2(conc, conc_meas, sigma) print "Chi**2:", error return error
def fn(m): """ Our objective function, takes an ndarray m that contains depths removed during each glaciation as a fraction of con['dz_max']. """ if SAVE_CONCENTRATION_DATA: global concs dz = m * (con['max_dz'] - con['min_dz']) + con['min_dz'] conc = sim.multiglaciate(dz, con['t_gl'], con['t_int'], con['t_postgl'], con['sample_depths'], con['nuclide'], p, n_gl=con['n_gl'], postgl_shielding=con['postgl_shielding']) if SAVE_CONCENTRATION_DATA: concs.append(conc) error = chi2(conc, con['C_meas'], con['sigma']) print "Chi**2:", error return error
plt.xlabel("$^{10}$Be Concentration (atoms / g)") plt.ylabel("Depth (m)") plt.title("Synthetic and Perturbed $^{10}$Be Concentration Profiles") plt.show() figname = "perturbed_conc" plt.savefig(figname + ".svg") plt.savefig(figname + ".png") # concentration profile with best fit best_conc_fig = plt.figure(5) best_conc_ax = best_conc_fig.add_subplot(111) plt.semilogx(conc_true, z_m, "*-", label="Target") plt.errorbar(conc_meas, z_m, xerr=conc_meas_err, fmt=".", ecolor="k", label="Target + Error") min_misfit = min(misfits) best_m = ms[misfits == min_misfit].T * 100.0 * con["rho"] best_conc = sim.multiglaciate( best_m, con["t_gl"], con["t_int"], con["t_postgl"], con["sample_depths"], con["nuclide"], p, n_gl=con["n_gl"] ) plt.semilogx(best_conc, z_m, "-", label="Best fit (chi2=%0.2f)" % min_misfit) best_conc_ax.invert_yaxis() plt.legend(loc="lower right") plt.xlabel("$^{10}$Be Concentration (atoms / g)") plt.ylabel("Depth (m)") plt.title("$^{10}$Be Depth Profiles") plt.show() figname = "best_conc" plt.savefig(figname + ".svg") plt.savefig(figname + ".png")
# concentration profile with best fit best_conc_fig = plt.figure(5) best_conc_ax = best_conc_fig.add_subplot(111) plt.semilogx(conc_true, z_m, '*-', label='Target') plt.errorbar(conc_meas, z_m, xerr=conc_meas_err, fmt='.', ecolor='k', label='Target + Error') min_misfit = min(misfits) best_m = ms[misfits == min_misfit].T * 100.0 * con['rho'] best_conc = sim.multiglaciate(best_m, con['t_gl'], con['t_int'], con['t_postgl'], con['sample_depths'], con['nuclide'], p, n_gl=con['n_gl']) plt.semilogx(best_conc, z_m, '-', label='Best fit (chi2=%0.2f)' % min_misfit) best_conc_ax.invert_yaxis() plt.legend(loc='lower right') plt.xlabel('$^{10}$Be Concentration (atoms / g)') plt.ylabel('Depth (m)') plt.title('$^{10}$Be Depth Profiles') plt.show() figname = 'best_conc' plt.savefig(figname + '.svg') plt.savefig(figname + '.png')
C_steady = sim.steady_erosion(z, p_sp, mu['P_fast'], mu['P_neg'], eros_rate, nuc, t, t_exp) t_gl = 15000 t_int = 85000 t_cycle = t_gl + t_int n_gl = int(np.floor(t_exp / t_cycle)) dz_scalar = eros_rate * t_cycle dz = np.ones(n_gl) * dz_scalar # interpolate a really awesome production rate function max_possible_depth = n_gl * dz_scalar + z_max npts = 500 # points to interpolate through p = production.interpolate_P_tot(max_possible_depth, npts, alt, lat, nuc) C_gl = sim.multiglaciate(dz, t_gl, t_int, 0, z, nuc, p, n_gl=n_gl) t_mid_postgl = 15000 # yr C_post15k = sim.simple_expose(z, t_mid_postgl, nuc, p) fig_height = 6 # in. fig_width = 5 # in. fig = Figure(figsize=(fig_width, fig_height)) fig_dpi = 500 canvas = FigureCanvas(fig) ax = fig.add_subplot(111) # ax.set_title('Steady v.s. glacial erosion', fontsize=14) ax.semilogx(C_steady, z_m, 'k--', label='Steady erosion') leg = ax.legend(loc='lower right', prop=leg_prop) ax.invert_yaxis() leg_prop = matplotlib.font_manager.FontProperties(size=10) ax.set_xlabel('[$^{10}$Be] (atoms/g)', fontsize=12)
plt.title('$^{10}$Be Depth Profile') plt.show() figname = 'measured_conc' plt.savefig(figname + '.svg') plt.savefig(figname + '.png') # concentration profile with best fit min_misfit = np.min(misfits) best_m = ms_denorm[misfits == min_misfit][0] many_depths = np.linspace(0, con['sample_depths'][-1], 200) best_conc_manypts = sim.multiglaciate(best_m, con['t_gl'], con['t_int'], con['t_postgl'], many_depths, con['nuclide'], p, n_gl=con['n_gl'], postgl_shielding=con['postgl_shielding']) many_depths_m = many_depths / 100 / con['rho'] plt.semilogx(best_conc_manypts, many_depths_m, '-b', label='Best Fit (ChiSquared = %0.2f)' % min_misfit) plt.legend(loc='lower right') plt.show() figname = 'best_conc' plt.savefig(figname + '.svg') plt.savefig(figname + '.png')
canvas.print_figure('const_hist.png', dpi=500) fig_height = 5 # in. fig_width = 3.5 # in. # interpolate a production function max_possible_depth = con['n_gl'] * con['max_dz'] + con['bottom_depth'] p = production.interpolate_P_tot(max_possible_depth, npts=con['n_prod_interp_pts'], alt=con['alt'], lat=con['lat'], n=con['nuclide']) # make target concentration graph z_target = np.linspace(0, con['bottom_depth']) C_target = sim.multiglaciate(con['dz'], con['t_gl'], con['t_int'], con['t_postgl'], z_target, con['nuclide'], p, con['n_gl'], postgl_shielding=con['postgl_shielding']) conc_fig = Figure(figsize=(fig_width, fig_height)) conc_canvas = FigureCanvas(conc_fig) ax = conc_fig.add_subplot(111) ax.set_title('Target Concentration Profile', fontsize=12) ax.semilogx(C_target, z_target / con['rho'] / 100) ax.invert_yaxis() ax.set_xlabel('[$^{10}$Be] (atoms/g)', fontsize=10) ax.set_ylabel('Depth (m)', fontsize=10) conc_fig.subplots_adjust(left=0.15, top=0.95) conc_canvas.print_figure('target_conc.png', dpi=500) C_true = sim.multiglaciate(con['dz'], con['t_gl'], con['t_int'], con['t_postgl'], con['sample_depths'],
max_possible_depth = con['n_gl'] * con['max_dz'] + con['bottom_depth'] # if production file exists already p = production.interpolate_P_tot(max_possible_depth, npts=con['interp_pts'], alt=con['alt'], lat=con['lat'], n=con['nuclide']) # calculate the true concentration profile (w/ many points, not sample depths) z_true_manypts = np.linspace(0, con['bottom_depth'], 200) C_true_manypts = sim.multiglaciate(con['dz'], con['t_gl'], con['t_int'], con['t_postgl'], z_true_manypts, con['nuclide'], p, con['n_gl'], postgl_shielding=con['postgl_shielding']) ## make the true concentration graph #true_conc_fig = plt.figure() #ax = true_conc_fig.add_subplot(111) #ax.title('True Concentration Profile') #plt.semilogx(C_true_manypts, z_true_manypts / con['rho'] / 100, lw=2) #ax.invert_yaxis() #plt.xlabel(r'[$^{10}$Be] (atoms/g)') #plt.ylabel('Depth (m)') ##ax.tick_params(labelsize=6) ##plt.setp(true_conc_ax.get_xticklabels(), rotation='horizontal')
max_possible_depth = con['n_gl'] * con['max_dz'] + con['bottom_depth'] npts = 500 # points to interpolate through zs = np.unique(np.logspace(0, np.log2(max_possible_depth + 1), npts, base=2)) - 1 prod_rates = production.P_tot(zs, con['alt'], con['lat'], con['nuclide']) #p = interp1d(zs, prod_rates, kind=3) # interp1d used as above gives crazy negative dives around z = 82000, do not # want that! UnivariateSpline seems to work much much better p = UnivariateSpline(zs, prod_rates, k=3, s=0) util.pickle(p, 'production_rate.dat') # get data for plotting a depth vs time curve, meters and years t_true, z_true = sim.glacial_depth_v_time(con['t_gl'], con['t_int'], con['t_postgl'], con['dz_true_m'], n_gl=con['n_gl']) conc_true = sim.multiglaciate(dz_true, con['t_gl'], con['t_int'], con['t_postgl'], con['sample_depths'], con['nuclide'], p, con['n_gl']) sigma_true = con['nuclide'].measurement_error(conc_true) conc_meas = np.random.normal(loc=conc_true, scale=sigma_true) # we need a way to measure error between models def chi2(a, b, sigma): """ Chi squared of two vectors """ return (((a - b) / sigma)**2).sum() # degrees of freedom in our problem dof = dz_true.size print 'Degrees of freedom =', dof sigma = con['nuclide'].measurement_error(conc_meas) perm_err = chi2(conc_meas, conc_true, sigma)
#plt.xlim(left=2) #plt.ylim(bottom=75) #plt.savefig('true_hist.png') # interpolate a production function max_possible_depth = con['n_gl'] * con['max_dz'] + con['bottom_depth'] # if production file exists already p = production.interpolate_P_tot(max_possible_depth, npts=con['interp_pts'], alt=con['alt'], lat=con['lat'], n=con['nuclide']) # calculate the true concentration profile (w/ many points, not sample depths) z_true_manypts = np.linspace(0, con['bottom_depth'], 200) C_true_manypts = sim.multiglaciate(con['dz'], con['t_gl'], con['t_int'], con['t_postgl'], z_true_manypts, con['nuclide'], p, con['n_gl'], postgl_shielding=con['postgl_shielding']) ## make the true concentration graph #true_conc_fig = plt.figure() #ax = true_conc_fig.add_subplot(111) #ax.title('True Concentration Profile') #plt.semilogx(C_true_manypts, z_true_manypts / con['rho'] / 100, lw=2) #ax.invert_yaxis() #plt.xlabel(r'[$^{10}$Be] (atoms/g)') #plt.ylabel('Depth (m)') ##ax.tick_params(labelsize=6) ##plt.setp(true_conc_ax.get_xticklabels(), rotation='horizontal') ##true_conc_fig.subplots_adjust(left=0.15, bottom=0.12, top=0.95) #plt.savefig('true_conc.png')
mu = muon.P_mu_total(z, alt, nuc, full_data=True) C_steady = sim.steady_erosion(z, p_sp, mu["P_fast"], mu["P_neg"], eros_rate, nuc, t, t_exp) t_gl = 15000 t_int = 85000 t_cycle = t_gl + t_int n_gl = int(np.floor(t_exp / t_cycle)) dz_scalar = eros_rate * t_cycle dz = np.ones(n_gl) * dz_scalar # interpolate a really awesome production rate function max_possible_depth = n_gl * dz_scalar + z_max npts = 500 # points to interpolate through p = production.interpolate_P_tot(max_possible_depth, npts, alt, lat, nuc) C_gl = sim.multiglaciate(dz, t_gl, t_int, 0, z, nuc, p, n_gl=n_gl) t_mid_postgl = 15000 # yr C_post15k = sim.simple_expose(z, t_mid_postgl, nuc, p) fig_height = 6 # in. fig_width = 5 # in. fig = Figure(figsize=(fig_width, fig_height)) fig_dpi = 500 canvas = FigureCanvas(fig) ax = fig.add_subplot(111) # ax.set_title('Steady v.s. glacial erosion', fontsize=14) ax.semilogx(C_steady, z_m, "k--", label="Steady erosion") leg = ax.legend(loc="lower right", prop=leg_prop) ax.invert_yaxis() leg_prop = matplotlib.font_manager.FontProperties(size=10) ax.set_xlabel("[$^{10}$Be] (atoms/g)", fontsize=12)
markersize=8, ecolor='k', label='Measured') conc_ax.invert_yaxis() plt.legend(loc='lower right') plt.xlabel('$^{10}$Be Concentration (atoms / g)') plt.ylabel('Depth (m)') plt.title('$^{10}$Be Depth Profile') plt.show() figname = 'measured_conc' plt.savefig(figname + '.svg') plt.savefig(figname + '.png') # concentration profile with best fit min_misfit = np.min(misfits) best_m = ms_denorm[misfits == min_misfit][0] many_depths = np.linspace(0, con['sample_depths'][-1], 200) best_conc_manypts = sim.multiglaciate(best_m, con['t_gl'], con['t_int'], con['t_postgl'], many_depths, con['nuclide'], p, n_gl=con['n_gl'], postgl_shielding=con['postgl_shielding']) many_depths_m = many_depths / 100 / con['rho'] plt.semilogx(best_conc_manypts, many_depths_m, '-b', label='Best Fit (ChiSquared = %0.2f)' % min_misfit) plt.legend(loc='lower right') plt.show() figname = 'best_conc' plt.savefig(figname + '.svg') plt.savefig(figname + '.png')
prod_rates = production.P_tot(zs, con['alt'], con['lat'], con['nuclide']) #p = interp1d(zs, prod_rates, kind=3) # interp1d used as above gives crazy negative dives around z = 82000, do not # want that! UnivariateSpline seems to work much much better p = UnivariateSpline(zs, prod_rates, k=3, s=0) util.pickle(p, 'production_rate.dat') # get data for plotting a depth vs time curve, meters and years t_true, z_true = sim.glacial_depth_v_time(con['t_gl'], con['t_int'], con['t_postgl'], con['dz_true_m'], n_gl=con['n_gl']) conc_true = sim.multiglaciate(dz_true, con['t_gl'], con['t_int'], con['t_postgl'], con['sample_depths'], con['nuclide'], p, con['n_gl']) sigma_true = con['nuclide'].measurement_error(conc_true) conc_meas = np.random.normal(loc=conc_true, scale=sigma_true) # we need a way to measure error between models def chi2(a, b, sigma): """ Chi squared of two vectors """ return (((a - b) / sigma)**2).sum() # degrees of freedom in our problem dof = dz_true.size print 'Degrees of freedom =', dof