def linear_model(model_0, a, wl): p_0 = np.array(model_0.getParams(), dtype=model_0.dtype) wl_0 = p_0['wl'] p = np.zeros(len(wl), dtype=p_0.dtype) p['wl'] = wl for n in p_0.dtype.names: p[n] = line(wl_0, p_0[n], a[n], wl) return [BDModel.fromParamVector(k) for k in p]
def loadModel(self, model_file): if not path.exists(model_file): logger.warn('Initial model file not found (%s), guessing one. ' % model_file) x0 = (self.flux.shape[1] / 2.0) + 1.0 y0 = (self.flux.shape[0] / 2.0) + 1.0 pa, ell = ellipse_params(self.flux, x0, y0) r = distance(self.flux.shape, x0, y0, pa, ell) r = np.ma.array(r, mask=self.flux.mask) hlr = r50(self.flux, r) I_e = self.flux.max() * 0.1 r_e = 0.5 * hlr n = 2.0 I_0 = self.flux.max() * 0.1 h = 1.0 * hlr model = BDModel() model.wl = 5635.0 model.x0.setValue(x0) model.x0.setLimitsRel(10, 10) model.y0.setValue(y0) model.y0.setLimitsRel(10, 10) model.disk.I_0.setValue(I_0) model.disk.I_0.setLimits(0.0, 10.0 * I_0) model.disk.h.setValue(h) model.disk.h.setLimits(0.0, 5.0 * hlr) model.disk.PA.setValue(pa) model.disk.PA.setLimits(0.0, 180.0) model.disk.ell.setValue(ell) model.disk.ell.setLimits(0.0, 1.0) model.bulge.I_e.setValue(I_e) model.bulge.I_e.setLimits(1e-33, 3.0 * I_e) model.bulge.r_e.setValue(r_e) model.bulge.r_e.setLimits(1e-33, 2.5 * r_e) model.bulge.n.setValue(n, vmin=1.0, vmax=5.0) model.bulge.PA.setValue(pa) model.bulge.PA.setLimits(0.0, 180.0) model.bulge.ell.setValue(ell) model.bulge.ell.setLimits(0.0, 1.0) return model else: return BDModel.load(model_file)
def get_model(model_file=None, with_default=False): if model_file is not None: try: logger.info('Loading model from %s.' % model_file) model = BDModel.load(model_file) model.wl = 5635.0 return model except: raise Exception('Could not read model file %s.' % model_file) elif not with_default: logger.info('Using default model.') return default_model() else: raise Exception('No model_file and with_default=False, what do you want?')
t_1p = c.firstPassParams l_obs_1p = t_1p['wl'][:] flag_bad_1p = (t_1p['flag'] > 0.0) | (t_1p['chi2'] > 20.0) box_radius = c.attrs['box_radius'] target_vd = c.attrs['target_vd'] PSF_FWHM = c.attrs['PSF_FWHM'] galaxyName = c.attrs['object_name'] flux_unit = c.attrs['flux_unit'] flag_bad = (t['flag'] > 0.0) | (t['chi2'] > 20.0) flag_ok = ~flag_bad fit_l_obs = t['wl'] masked_wl = load_line_mask('data/starlight/Mask.mE', fit_l_obs) initial_params = np.array(c.initialParams, dtype=t.dtype) initial_model = BDModel.fromParamVector(initial_params) psf = moffat_psf(PSF_FWHM, c.attrs['PSF_beta'], size=c.attrs['PSF_size']) bulge_model_im, disk_model_im = create_model_images(initial_model, c.total.f_obs.shape[1:], psf) bulge_model_im *= flux_unit disk_model_im *= flux_unit l1 = find_nearest_index(fit_l_obs, 5635.0) x0 = t['x0'][0] y0 = t['y0'][0] total_im = c.total.f_obs[l1] * flux_unit model_im = disk_model_im + bulge_model_im residual_im = (total_im - model_im) / total_im colnames = [ 'I_e',
disk_ifs = g.disk_ifs[...] disk_ifs_nopsf = g.disk_ifs_nopsf[...] full_ifs = np.ma.array(g.full_ifs[...], mask=masked) full_ifs_noise = np.ma.array(g.full_ifs_noise[...], mask=masked) wl = g.wl[...] true_psf = np.ma.array(g.psf[...]) tau_image = g.tau_image[...] age_base = g.age_base[...] flux_unit = g.full_ifs.attrs.fluxUnit true_psf_FWHM = g.full_ifs.attrs.psfFWHM norm_params = g.full_ifs.attrs.model norm_model = BDModel.fromParamVector(norm_params) norm_x0 = norm_params['x0'] norm_y0 = norm_params['y0'] db.close() logger.debug('Plotting original model.') #index_norm = find_nearest_index(l_ssp, 5635.0) vmin = np.log10(full_image.min()) vmax = np.log10(full_image.max()) fig = plt.figure(figsize=(8, 6)) gs = plt.GridSpec(2, 3, height_ratios=[2.0, 3.0]) ax = plt.subplot(gs[0,0]) ax.imshow(np.log10(full_image), vmin=vmin, vmax=vmax) ax.set_xticks([]) ax.set_yticks([])