def fit_pix_values(t_ccd, esec, id=1): logger = logging.getLogger("sherpa") logger.setLevel(logging.WARN) data_id = id ui.clean() ui.set_method('simplex') ui.load_user_model(dark_scale_model, 'model') ui.add_user_pars('model', ['scale', 'dark_t_ref']) ui.set_model(data_id, 'model') ui.load_arrays( data_id, np.array(t_ccd), np.array(esec), ) ui.set_staterror(data_id, 30 * np.ones(len(t_ccd))) model.scale.val = 0.588 model.scale.min = 0.3 model.scale.max = 1.0 model.dark_t_ref.val = 500 ui.freeze(model.scale) # If more than 5 degrees in the temperature range, # thaw and fit for model.scale. Else just use/return # the fit of dark_t_ref if np.max(t_ccd) - np.min(t_ccd) > 2: # Fit first for dark_t_ref ui.fit(data_id) ui.thaw(model.scale) ui.fit(data_id) return ui.get_fit_results(), ui.get_model(data_id)
def _fit_poly(fit_data, evt_times, degree, data_id=0): """ Given event data transformed into Y or Z angle positions, and a degree of the desired fit polynomial, fit a polynomial to the data. :param fit_data: event y or z angle position data :param evt_times: times of event/fit_data :param degree: degree of polynomial to use for the fit model :param data_id: sherpa dataset id to use for the fit :returns: (sherpa model plot, sherpa model) """ # Set initial value for fit data position error init_error = 1 ui.clean() ui.load_arrays(data_id, evt_times - evt_times[0], fit_data, np.zeros_like(fit_data) + init_error) v2("Fitting a line to the data to get reduced stat errors") # First just fit a line to get reduced errors on this set ui.polynom1d.line ui.set_model(data_id, 'line') ui.thaw('line.c1') ui.fit(data_id) fit = ui.get_fit_results() calc_error = init_error * np.sqrt(fit.rstat) ui.set_staterror(data_id, calc_error) # Then fit the specified model v2("Fitting a polynomial of degree {} to the data".format(degree)) ui.polynom1d.fitpoly ui.freeze('fitpoly') # Thaw the coefficients requested by the degree of the desired polynomial ui.thaw('fitpoly.c0') fitpoly.c0.val = 0 for deg in range(1, 1 + degree): ui.thaw("fitpoly.c{}".format(deg)) ui.set_model(data_id, 'fitpoly') ui.fit(data_id) # Let's screw up Y on purpose if data_id == 0: fitpoly.c0.val = 0 fitpoly.c1.val = 7.5e-05 fitpoly.c2.val = -1.0e-09 fitpoly.c3.val = 0 fitpoly.c4.val = 0 mp = ui.get_model_plot(data_id) model = ui.get_model(data_id) return mp, model
def fit_pix_values(t_ccd, esec, id=1): logger = logging.getLogger("sherpa") logger.setLevel(logging.WARN) data_id = id ui.clean() ui.set_method("simplex") ui.load_user_model(dark_scale_model, "model") ui.add_user_pars("model", ["scale", "dark_t_ref"]) ui.set_model(data_id, "model") ui.load_arrays(data_id, np.array(t_ccd), np.array(esec), 0.1 * np.ones(len(t_ccd))) model.scale.val = 0.70 model.dark_t_ref.val = 500 ui.freeze(model.scale) # If more than 5 degrees in the temperature range, # thaw and fit for model.scale. Else just use/return # the fit of dark_t_ref ui.fit(data_id) ui.thaw(model.scale) ui.fit(data_id) return ui.get_fit_results(), ui.get_model(data_id)
def _fit_poly(fit_data, evt_times, degree, data_id=0): """ Given event data transformed into Y or Z angle positions, and a degree of the desired fit polynomial, fit a polynomial to the data. :param fit_data: event y or z angle position data :param evt_times: times of event/fit_data :param degree: degree of polynomial to use for the fit model :param data_id: sherpa dataset id to use for the fit :returns: (sherpa model plot, sherpa model) """ # Set initial value for fit data position error init_error = 1 ui.clean() ui.load_arrays(data_id, evt_times - evt_times[0], fit_data, np.zeros_like(fit_data) + init_error) v2("Fitting a line to the data to get reduced stat errors") # First just fit a line to get reduced errors on this set ui.polynom1d.line ui.set_model(data_id, 'line') ui.thaw('line.c1') ui.fit(data_id) fit = ui.get_fit_results() calc_error = init_error * np.sqrt(fit.rstat) ui.set_staterror(data_id, calc_error) # Then fit the specified model v2("Fitting a polynomial of degree {} to the data".format(degree)) ui.polynom1d.fitpoly ui.freeze('fitpoly') # Thaw the coefficients requested by the degree of the desired polynomial ui.thaw('fitpoly.c0') fitpoly.c0.val = 0 for deg in range(1, 1 + degree): ui.thaw("fitpoly.c{}".format(deg)) ui.set_model(data_id, 'fitpoly') ui.fit(data_id) mp = ui.get_model_plot(data_id) model = ui.get_model(data_id) return mp, model
def test_ui_set_full_model_2d_mismatch_1d(clean_ui, setup_ui_2d): ui.load_psf('psf1', 'gauss1d.g1') ui.set_full_model('psf1(gauss1d.g2 ) +const1d.c1') # Ideally this would fail but it currently does not ui.get_model()
def test_ui_set_full_model_2d(clean_ui, setup_ui_2d): ui.load_psf('psf1', 'gauss2d.g1') ui.set_full_model('psf1(gauss2d.g2 ) +const2d.c1') ui.get_model()
def test_set_full_model(self): ui.load_psf("psf1", "gauss2d.g1") ui.set_full_model("psf1(gauss2d.g2)+const2d.c1") ui.get_model() ui.get_source()
def test_set_full_model(self): ui.load_psf('psf1', 'gauss2d.g1') ui.set_full_model('psf1(gauss2d.g2)+const2d.c1') ui.get_model()