def save(self, filename): """Save the interpolation data to a file. This data may not be the same from one version of scipy to another, and may break with new versions, so is important to test that this works with new versions of scipy. For now, the only important values for the spline interpolation are stored in the spline's _data member, but could change, as could the structure of _eval_args. To be safe, do not depend on this to load old interpolations. It is probably safest to create a new interpolation for a new scipy version. The saved files are not compatible between Python 2 and Python 3. """ data = {'_data': self._data} if self.ext is not None: data['ext'] = self.ext else: # We are on an older version of SciPy, just use ext=0 # meaning to extrapolate. SciPy versions before 0.15 always # did this. data['ext'] = 0 util.pickle(data, filename) self.filename = filename
def save(self, filename): """Save the interpolation data to a file. This data may not be the same from one version of scipy to another, and may break with new versions, so is important to test that this works with new versions of scipy. For now, the only important values for the spline interpolation are stored in the spline's _data member, but could change, as could the structure of _eval_args. To be safe, do not depend on this to load old interpolations. It is probably safest to create a new interpolation for a new scipy version. The saved files are not compatible between Python 2 and Python 3. """ util.pickle(self._data, filename)
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'], con['nuclide'], p, con['n_gl'], postgl_shielding=con['postgl_shielding']) con['sigma'] = con['nuclide'].measurement_error(C_true) C_meas = np.random.normal(loc=C_true, scale=con['sigma']) C_meas_err = con['nuclide'].measurement_error(C_meas) con['C_meas'] = C_meas con['C_meas_err'] = C_meas_err meas_fig = Figure(figsize=(fig_width, fig_height)) meas_canvas = FigureCanvas(meas_fig) ax = meas_fig.add_subplot(111) ax.set_title('Synthetic Concentration Measurements', y=1.03, fontsize=12) ax.errorbar(C_meas, con['sample_depths_m'], xerr=C_meas_err, fmt='k.') ax.invert_yaxis() ax.set_xlabel('[$^{10}$Be] (atoms/g)', fontsize=10) ax.set_ylabel('Depth (m)', fontsize=10) ax.set_xscale('log') meas_fig.subplots_adjust(left=0.15) #, top=0.95 meas_canvas.print_figure('meas_conc.png', dpi=500) util.pickle(con, 'con.dat') # save that input data! util.pickle(p, 'production_rate.dat')
"n_initial": 500, "lo_lim": np.array([-50, 0, -100, 0], dtype=float), "hi_lim": np.array([50, 200, 100, 200], dtype=float), "d": 4, "ne": 1000, "m_true": np.array([20.0, 100.0, 0.0, 100.0], dtype=float), # for benchmarking 'seed': 10453, 'plot': False, } conf['ts'] = np.linspace(2, 20, 1000) conf['dof'] = conf['ts'].size - conf['d'] sigma_obs = 1.0 # meters pos_true = positions(conf['m_true'], conf['ts']) def chi2v(pre, obs, sigma_obs, nu): return (((obs - pre) / sigma_obs)**2).sum() / nu def fn(m): pos = positions(m, conf['ts']) misfit = chi2v(pos, pos_true, sigma_obs, conf['dof']) return misfit if __name__ == "__main__": util.pickle(conf, 'conf.pkl') na.search(fn, conf)
C_true = sim.multiglaciate(con['dz'], con['t_gl'], con['t_int'], con['t_postgl'], con['sample_depths'], con['nuclide'], p, con['n_gl'], postgl_shielding=con['postgl_shielding']) con['sigma'] = con['nuclide'].measurement_error(C_true) C_meas = np.random.normal(loc=C_true, scale=con['sigma']) C_meas_err = con['nuclide'].measurement_error(C_meas) con['C_meas'] = C_meas con['C_meas_err'] = C_meas_err meas_fig = Figure(figsize=(fig_width, fig_height)) meas_canvas = FigureCanvas(meas_fig) ax = meas_fig.add_subplot(111) ax.set_title('Synthetic Concentration Measurements', y=1.03, fontsize=12) ax.errorbar(C_meas, con['sample_depths_m'], xerr=C_meas_err, fmt='k.') ax.invert_yaxis() ax.set_xlabel('[$^{10}$Be] (atoms/g)', fontsize=10) ax.set_ylabel('Depth (m)', fontsize=10) ax.set_xscale('log') meas_fig.subplots_adjust(left=0.15) #, top=0.95 meas_canvas.print_figure('meas_conc.png', dpi=500) util.pickle(con, 'con.dat') # save that input data! util.pickle(p, 'production_rate.dat')
"nr": 2, "n_initial": 500, "lo_lim": np.array([-50, 0, -100, 0], dtype=float), "hi_lim": np.array([50, 200, 100, 200], dtype=float), "d": 4, "ne": 1000, "m_true": np.array([20.0, 100.0, 0.0, 100.0], dtype=float), # for benchmarking 'seed': 10453, 'plot': False, } conf['ts'] = np.linspace(2, 20, 1000) conf['dof'] = conf['ts'].size - conf['d'] sigma_obs = 1.0 # meters pos_true = positions(conf['m_true'], conf['ts']) def chi2v(pre, obs, sigma_obs, nu): return (((obs - pre) / sigma_obs) ** 2).sum() / nu def fn(m): pos = positions(m, conf['ts']) misfit = chi2v(pos, pos_true, sigma_obs, conf['dof']) return misfit if __name__ == "__main__": util.pickle(conf, 'conf.pkl') na.search(fn, conf)