def updatePlots(self, model, reset=False): bulge_flux, disk_flux = create_model_images(model, self.flux.shape, self.psf) model_flux = bulge_flux + disk_flux x0 = model.x0.value - 1.0 y0 = model.y0.value - 1.0 pa, ell = ellipse_params(self.flux, x0, y0) pa = (90.0 + pa) * np.pi / 180.0 ba = 1.0 - ell bins = np.arange(30) r = bins[:-1] + 0.5 obs_r = radialProfile(self.flux, bins, x0, y0, pa, ba, rad_scale=1.0) obs_r = np.log10(obs_r) mod_r = radialProfile(model_flux, bins, x0, y0, pa, ba, rad_scale=1.0) mod_r = np.log10(mod_r) bulge_r = radialProfile(bulge_flux, bins, x0, y0, pa, ba, rad_scale=1.0) bulge_r = np.log10(bulge_r) disk_r = radialProfile(disk_flux, bins, x0, y0, pa, ba, rad_scale=1.0) disk_r = np.log10(disk_r) obs_im = np.log10(self.flux) mod_im = np.log10(model_flux) res_im = obs_im - mod_im if reset: self.plotPanel.reset(self.plotTitle, obs_im, mod_im, res_im, r, obs_r, mod_r, bulge_r, disk_r) else: self.plotPanel.update(obs_im, mod_im, res_im, r, obs_r, mod_r, bulge_r, disk_r)
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', 'I_0', 'r_e',
logger.info('Beginning decomposition.') decomp = IFSDecomposer() logger.info('Model using PSF FWHM = %.2f ", beta = %.2f.' % (args.modelPsfFWHM, args.modelPsfBeta)) decomp.setSynthPSF(FWHM=args.modelPsfFWHM, beta=args.modelPsfBeta, size=15) decomp.loadData(wl, full_ifs / flux_unit, full_ifs_noise / flux_unit, np.zeros_like(full_ifs, dtype='bool')) swll, swlu = 5590.0, 5680.0 sl1 = find_nearest_index(decomp.wl, swll) sl2 = find_nearest_index(decomp.wl, swlu) qSignal, qNoise, qWl = decomp.getSpectraSlice(sl1, sl2) logger.warn('Computing initial model (takes a LOT of time).') t1 = time.time() initial_model = bd_initial_model(qSignal, qNoise, decomp.PSF, quiet=False, cache_model_file=args.cacheModel) bulge_image, disk_image = create_model_images(initial_model, qSignal.shape, decomp.PSF) logger.warn('Initial model time: %.2f\n' % (time.time() - t1)) logger.debug('Plotting guessed initial model.') vmin = np.log10(qSignal.min()) vmax = np.log10(qSignal.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(qSignal), vmin=vmin, vmax=vmax) ax.set_xticks([]) ax.set_yticks([]) ax.set_title(r'Total') ax = plt.subplot(gs[0,1]) ax.imshow(np.log10(bulge_image), vmin=vmin, vmax=vmax)
imshape = (72,77) ifsshape = (len(l_ssp),) + imshape norm_y0 = norm_model.y0.value norm_x0 = norm_model.x0.value flagged = distance(imshape, norm_x0, norm_y0) > 32.0 noise = 0.05 flux_unit = 1e-16 logger.info('Creating original PSF (FWHM = %.2f ")' % args.truePsfFWHM) original_PSF = gaussian_psf(args.truePsfFWHM, size=15) logger.info('Creating model images.') bulge_image = np.ma.empty(ifsshape) disk_image = np.ma.empty(ifsshape) for i, model in enumerate(original_models): bulge_image[i], disk_image[i] = create_model_images(model, imshape, original_PSF) bulge_image[:,flagged] = np.ma.masked disk_image[:,flagged] = np.ma.masked model_image = bulge_image + disk_image #model_noise = model_image * noise logger.info('Creating IFS.') bulge_spectra = bulge_image * (flux_unit * bulge_flux[..., np.newaxis, np.newaxis]) disk_spectra = disk_image * (flux_unit * disk_flux[..., np.newaxis, np.newaxis]) full_spectra = bulge_spectra + disk_spectra full_noise = full_spectra * noise # FIXME: How to add gaussian noise to spectra? logger.info('Adding gaussian noise to IFS.') tmp_noise = np.zeros(full_spectra.shape) for i in xrange(ifsshape[0]):
logger.info('Creating PSF (FWHM = %.2f ", beta = %.2f)' % (args.psfFWHM, args.psfBeta)) PSF = moffat_psf(args.psfFWHM, args.psfBeta, size=max(args.Nx, args.Ny)) # Pad image to avoid artifacts at the borders when convolving. Ny_psf = PSF.shape[0] Nx_psf = PSF.shape[1] imshape_pad = (args.Ny + 2 * Ny_psf, args.Nx + 2 * Nx_psf) ifsshape_pad = (len(l_ssp),) + imshape_pad # Fix the model center for padded images. norm_y0 = norm_model.y0.value + Ny_psf norm_x0 = norm_model.x0.value + Nx_psf norm_model.y0.setValue(norm_y0) norm_model.x0.setValue(norm_x0) t1 = time.clock() logger.info("Creating bulge spectra (tau proportional to distance).") bulge_image_pad, disk_image_pad = create_model_images(norm_model, imshape_pad, PSF=None) bulge_r = get_bulge_distance(imshape_pad, norm_model) bulge_ifs_pad = np.empty(ifsshape_pad) tau_image_pad = np.empty(imshape_pad) for i in xrange(imshape_pad[0]): for j in xrange(imshape_pad[1]): r = bulge_r[i, j] tau = tau_r(args.tau0, args.dtau_dr, r) if tau <= 1e-20: tau = 1e-20 tau_image_pad[i, j] = tau bulge_sfh = SyntheticSFH(base.ageBase) bulge_sfh.addExp(base.ageBase.max(), tau, 1.0) bulge_spec = (f_ssp * bulge_sfh.massVector()[:, np.newaxis]).sum(axis=1).sum(axis=0) bulge_spec /= np.median(bulge_spec[wl_norm_window])
logger.info('Beginning decomposition.') decomp = IFSDecomposer() logger.info('Model using PSF FWHM = %.2f ", beta = %.2f.' % (args.modelPsfFWHM, args.modelPsfBeta)) decomp.setSynthPSF(FWHM=args.modelPsfFWHM, beta=args.modelPsfBeta, size=15) decomp.loadData(wl, full_ifs / flux_unit, full_ifs_noise / flux_unit, np.zeros_like(full_ifs, dtype='bool')) swll, swlu = 5590.0, 5680.0 sl1 = find_nearest_index(decomp.wl, swll) sl2 = find_nearest_index(decomp.wl, swlu) qSignal, qNoise, qWl = decomp.getSpectraSlice(sl1, sl2) logger.warn('Computing initial model (takes a LOT of time).') t1 = time.time() initial_model = bd_initial_model(qSignal, qNoise, decomp.PSF, quiet=False, cache_model_file=args.cacheModel) bulge_image, disk_image = create_model_images(initial_model, qSignal.shape, PSF=decomp.PSF) qSignal_model = bulge_image + disk_image qSignal_residual = (qSignal - qSignal_model) / qSignal bulge_image_nopsf, disk_image_nopsf = create_model_images(initial_model, qSignal.shape, PSF=None) logger.warn('Initial model time: %.2f\n' % (time.time() - t1)) ################################################################################ ########## ########## Plot fitted morph. model ########## ################################################################################ logger.debug('Plotting guessed initial model.') vmin = np.log10(qSignal.min()) vmax = np.log10(qSignal.max()) fig = plt.figure(figsize=(width_in, 0.8 * width_in))