parser.add_argument('--measure-ba', dest='measureBa', action='store_true', help='Measure b/a instead of using the Master List.') args = parser.parse_args() return args ############################################################################# # Load the galaxy data. ############################################################################# args = parse_args() mc = load_morph_class(path.join(args.tablesDir, 'morph_eye_class.fits')) # Mark the available cubes as observed galaxies. #obs_cubes = glob(path.join(args.cubesDir, '*_synthesis_eBR_px1_q043.d14a512.ps03.k1.mE.CCM.Bgsd6e.fits')) obs_califa_str = np.array([califa_id_from_cube(f) for f in args.cubes]) obs_califa_id = np.array([califa_id_to_int(c_id) for c_id in obs_califa_str]) # Make the CALIFA IDs into indices. obs_keys = obs_califa_id - 1 mc.add_column('observed', np.zeros(len(mc), dtype='int')) mc.observed[obs_keys] = 1 mc.add_column('cube', np.zeros(len(mc), dtype='S128')) mc.cube[obs_keys] = args.cubes if args.measureBa: mc.add_column('ba', np.ones(len(mc), dtype='bool') * -1.0) mc.ba[obs_keys] = get_ba(args.cubes) ml = load_masterlist(path.join(args.tablesDir, 'califa_master_list_rgb.txt'))
def plotall(sample, args): sampleId = path.basename(args.sample) pdf = plot_setup('plots/%s_synthesis_all2.pdf' % (sampleId)) base = load_base(args.baseFile) at_flux_T = [] alogZ_mass_T = [] Mass_T = [] best_logt_T = [] best_logZ_T = [] at_flux_B = [] alogZ_mass_B = [] Mass_B = [] best_logt_B = [] best_logZ_B = [] at_flux_D = [] alogZ_mass_D = [] Mass_D = [] best_logt_D = [] best_logZ_D = [] name = {} name_best = {} htype = {} htype_best = {} for gal in sample: galaxyId = califa_id_from_cube(gal['cube']) if galaxyId not in args.galaxies: print '***** Skipped galaxy %s' % galaxyId continue Kt = getCube(args.cubeDir, galaxyId, sampleId, 'total') print gal print Kt.population.describe() Kb = getCube(args.cubeDir, galaxyId, sampleId, 'bulge') Kd = getCube(args.cubeDir, galaxyId, sampleId, 'disk') #try: #except: # print '***** Skipped galaxy %s' % galaxyId # continue best_logt, best_logZ = get_best_SSP_age_met(Kt, base) best_logt_T.append(best_logt) best_logZ_T.append(best_logZ) Mass_T.append(Kt.keywords['Mcor_tot']) best_logt, best_logZ = get_best_SSP_age_met(Kd, base) best_logt_D.append(best_logt) best_logZ_D.append(best_logZ) Mass_D.append(Kd.keywords['Mcor_tot']) best_logt, best_logZ = get_best_SSP_age_met(Kb, base) best_logt_B.append(best_logt) best_logZ_B.append(best_logZ) Mass_B.append(Kb.keywords['Mcor_tot']) name_best[(np.asscalar(best_logZ), np.asscalar(best_logt))] = galaxyId htype_best[(np.asscalar(best_logZ), np.asscalar(best_logt))] = gal['hubble_type'] at_flux, alogZ_mass = get_average_age_met(Kt) at_flux_T.append(at_flux) alogZ_mass_T.append(alogZ_mass) at_flux, alogZ_mass = get_average_age_met(Kd) at_flux_D.append(at_flux) alogZ_mass_D.append(alogZ_mass) at_flux, alogZ_mass = get_average_age_met(Kb) at_flux_B.append(at_flux) alogZ_mass_B.append(alogZ_mass) name[(np.asscalar(alogZ_mass), np.asscalar(at_flux))] = galaxyId htype[(np.asscalar(alogZ_mass), np.asscalar(at_flux))] = gal['hubble_type'] M_max = np.max(Mass_T) s = 100 width_pt = 448.07378 width_in = width_pt / 72.0 * 0.95 fig = plt.figure(figsize=(width_in, width_in * 0.7)) gs = plt.GridSpec(1, 1, height_ratios=[1.0]) ax = plt.subplot(gs[0]) #ax.set_title(u'Média dos vetores de população') for zB, tB, zD, tD, zT, tT in zip(alogZ_mass_B, at_flux_B, alogZ_mass_D, at_flux_D, alogZ_mass_T, at_flux_T): xy = np.array([[zB, tB], [zD, tD], [zT, tT]]) xc = xy[:,0].sum() / xy.shape[0] yc = xy[:,1].sum() / xy.shape[0] ax.text(xc, yc, '%s (%s)' % (name[(zB, tB)], htype[(zB, tB)]), color='k', ha='left', va='bottom') p = Polygon(xy, alpha=0.2, color='k') ax.add_patch(p) ax.scatter(alogZ_mass_B, at_flux_B, s=s * np.array(Mass_B) / M_max, color='r', label=r'bojo') ax.scatter(alogZ_mass_D, at_flux_D, s=s * np.array(Mass_D) / M_max, color='b', label=r'disco') ax.scatter(alogZ_mass_T, at_flux_T, s=s * np.array(Mass_T) / M_max, color='k', label=r'observado') ax.set_xlabel(r'$\langle \log (Z_\star/Z_\odot) \rangle_{\mathrm{Massa}}$') ax.set_ylabel(r'$\langle \log\ t_\star \rangle_{\mathrm{Fluxo}}$') ax.set_xlim(-0.4, 0.3) ax.set_ylim(9.4, 10.0) ax.legend(loc='lower left', frameon=False) # ax = plt.subplot(gs[1]) # ax.set_title(u'Ajuste de única SSP') # for zB, tB, zD, tD, zT, tT in zip(best_logZ_B, best_logt_B, best_logZ_D, best_logt_D, best_logZ_T, best_logt_T): # xy = np.array([[zB, tB], [zD, tD], [zT, tT]]) # xc = xy[:,0].sum() / xy.shape[0] # yc = xy[:,1].sum() / xy.shape[0] # ax.text(xc, yc, '%s (%s)' % (name_best[(zB, tB)], htype_best[(zB, tB)]), color='k', ha='left', va='bottom') # p = Polygon(xy, alpha=0.2, color='k') # ax.add_patch(p) # ax.scatter(best_logZ_B, best_logt_B, s=s * np.array(Mass_B) / M_max, color='r', label=r'bojo') # ax.scatter(best_logZ_D, best_logt_D, s=s * np.array(Mass_D) / M_max, color='b', label=r'disco') # ax.scatter(best_logZ_T, best_logt_T, s=s * np.array(Mass_T) / M_max, color='k', label=r'observado') # ax.set_xlabel(r'$\log (Z_\star/Z_\odot)$') # ax.set_ylabel(r'$\log\ t_\star$') # ax.set_xlim(-0.75, 0.3) # ax.set_ylim(9.2, 10.2) #ax.legend(loc='lower left') gs.tight_layout(fig, rect=[0, 0, 1, 0.97]) plt.show() pdf.savefig(fig) pdf.close()
def plotall(sample, args): sampleId = path.basename(args.sample) pdf = plot_setup('plots/%s_synthesis_all.pdf' % (sampleId)) base = load_base(args.baseFile) at_flux_Ts = [] alogZ_mass_Ts = [] at_flux_T = [] alogZ_mass_T = [] best_logt_T = [] best_logZ_T = [] at_flux_B = [] alogZ_mass_B = [] best_logt_B = [] best_logZ_B = [] at_flux_D = [] alogZ_mass_D = [] best_logt_D = [] best_logZ_D = [] name = {} name_best = {} for gal in sample: galaxyId = califa_id_from_cube(gal['cube']) try: Kt = getCube(args.cubeDir, galaxyId, sampleId, 'total') Kb = getCube(args.cubeDir, galaxyId, sampleId, 'bulge', Kt.HLR_pix) Kd = getCube(args.cubeDir, galaxyId, sampleId, 'disk', Kt.HLR_pix) except: print '***** Skipped galaxy %s' % galaxyId continue best_logt, best_logZ = get_best_SSP_age_met(Kt, base) best_logt_T.append(best_logt) best_logZ_T.append(best_logZ) best_logt, best_logZ = get_best_SSP_age_met(Kd, base) best_logt_D.append(best_logt) best_logZ_D.append(best_logZ) best_logt, best_logZ = get_best_SSP_age_met(Kb, base) best_logt_B.append(best_logt) best_logZ_B.append(best_logZ) name_best[(np.asscalar(best_logZ), np.asscalar(best_logt))] = galaxyId at_flux_Ts.append((Kt.at_flux__z * Kt.Lobn__z).sum() / Kt.Lobn__z.sum()) alogZ_mass_Ts.append((Kt.alogZ_mass__z * Kt.Mcor__z).sum() / Kt.Mcor__z.sum()) at_flux_T.append(np.asscalar(Kt.integrated_at_flux)) alogZ_mass_T.append(np.asscalar(Kt.integrated_alogZ_mass)) at_flux_B.append(np.asscalar(Kb.integrated_at_flux)) alogZ_mass_B.append(np.asscalar(Kb.integrated_alogZ_mass)) at_flux_D.append(np.asscalar(Kd.integrated_at_flux)) alogZ_mass_D.append(np.asscalar(Kd.integrated_alogZ_mass)) name[(np.asscalar(Kb.integrated_alogZ_mass), np.asscalar(Kb.integrated_at_flux))] = galaxyId fig = plt.figure(1, figsize=(5, 7)) gs = plt.GridSpec(2, 1, height_ratios=[1.0, 1.0]) ax = plt.subplot(gs[0]) ax.scatter(alogZ_mass_B, at_flux_B, color='r', label=r'Bulge') ax.scatter(alogZ_mass_D, at_flux_D, color='b', label=r'Disk') ax.set_title('Regular fit') for zB, tB, zD, tD in zip(alogZ_mass_B, at_flux_B, alogZ_mass_D, at_flux_D): ax.text(zB, tB, name[(zB, tB)], color='k', ha='right') try: x, y = line(zB, tB, zD, tD) ax.plot(x, y, 'k:') except: print 'Can\'t draw line:', zB, tB, zD, tD ax.set_xlabel(r'$\langle \log (Z_\star/Z_\odot) \rangle_{mass}$') ax.set_ylabel(r'$\langle \log\ t_\star \rangle_{flux}\ [yr]$') ax.set_xlim(-0.8, 0.4) ax.set_ylim(9.0, 10.5) ax.legend(loc='lower left') ax = plt.subplot(gs[1]) ax.scatter(best_logZ_B, best_logt_B, color='r', label=r'Bulge') ax.scatter(best_logZ_D, best_logt_D, color='b', label=r'Disk') ax.set_title('Best SSP fits') for zB, tB, zD, tD in zip(best_logZ_B, best_logt_B, best_logZ_D, best_logt_D): ax.text(zB, tB, name_best[(zB, tB)], color='k', ha='right') try: x, y = line(zB, tB, zD, tD) ax.plot(x, y, 'k:') except: print 'Can\'t draw line:', zB, tB, zD, tD ax.set_xlabel(r'$\log (Z_\star/Z_\odot)$') ax.set_ylabel(r'$\log\ t_\star\ [yr]$') ax.set_xlim(-0.8, 0.4) ax.set_ylim(9.0, 10.5) #ax.legend(loc='lower left') gs.tight_layout(fig, rect=[0, 0, 1, 0.97]) plt.show() pdf.savefig(fig) pdf.close()
def plotall(gal, sampleId, args, pdf): galaxyId = califa_id_from_cube(gal['cube']) try: Kt = getCube(args.cubeDir, galaxyId, sampleId, 'total') Kb = getCube(args.cubeDir, galaxyId, sampleId, 'bulge', Kt.HLR_pix) Kd = getCube(args.cubeDir, galaxyId, sampleId, 'disk', Kt.HLR_pix) except: print '***** Skipped galaxy %s' % galaxyId return ################################################################################ ########## ########## Spectra and residuals ########## ################################################################################ fig = plt.figure(1, figsize=(width_in, 0.8 * width_in)) gs = plt.GridSpec(2, 1, height_ratios=[3.0, 1.0]) ax = plt.subplot(gs[0]) fobs_T = np.ma.array(Kt.integrated_f_obs, mask=Kt.integrated_f_flag > 0.0) fobs_B = np.ma.array(Kb.integrated_f_obs, mask=Kb.integrated_f_flag > 0.0) fobs_D = np.ma.array(Kd.integrated_f_obs, mask=Kd.integrated_f_flag > 0.0) fsyn_T = Kt.integrated_f_syn fsyn_B = Kb.integrated_f_syn fsyn_D = Kd.integrated_f_syn fres_T = (fobs_T - fsyn_T) / fobs_T * 100.0 fres_B = (fobs_B - fsyn_B) / fobs_B * 100.0 fres_D = (fobs_D - fsyn_D) / fobs_D * 100.0 ax.plot(Kt.l_obs, fobs_T, 'k', label='observado') ax.plot(Kt.l_obs, fsyn_T, 'k', alpha=0.5) ax.plot(Kb.l_obs, fobs_B, 'r', label='bojo') ax.plot(Kt.l_obs, fsyn_B, 'r', alpha=0.5) ax.plot(Kd.l_obs, fobs_D, 'b', label='disco') ax.plot(Kt.l_obs, fsyn_D, 'b', alpha=0.5) ax.set_xlim(Kt.l_obs.min(), Kt.l_obs.max()) ax.xaxis.set_major_locator(MultipleLocator(500)) ax.set_xticklabels([]) ax.set_ylabel(r'$F_\lambda\ [\mathrm{erg} / \mathrm{s} / \mathrm{cm}^2 / \mathrm{\AA}]$') ax.set_title(u'Espectros integrados ajustados - síntese de populações estelares') ax.legend(loc='upper left', frameon=False) ax = plt.subplot(gs[1]) ax.plot(Kt.l_obs, fres_T, 'k', label='observado') ax.plot(Kb.l_obs, fres_B, 'r', label='bojo') ax.plot(Kd.l_obs, fres_D, 'b', label='disco') ax.plot(Kd.l_obs, np.zeros_like(Kd.l_obs), 'k:') ax.set_xlim(Kt.l_obs.min(), Kt.l_obs.max()) ax.set_ylim(-15.0, 15.0) ax.xaxis.set_major_locator(MultipleLocator(500)) ax.set_xlabel(r'Comprimento de onda $[\mathrm{\AA}]$') ax.set_ylabel(u'Resíduo [%]') #ax.grid(True) m_B = Kb.integrated_Mcor / Kt.integrated_Mcor * 100.0 m_D = Kd.integrated_Mcor / Kt.integrated_Mcor * 100.0 l_B = Kb.integrated_Lobn / Kt.integrated_Lobn * 100.0 l_D = Kd.integrated_Lobn / Kt.integrated_Lobn * 100.0 gs.tight_layout(fig, rect=[0, 0, 1, 1]) pdf.savefig(fig) ################################################################################ ########## ########## Radial profiles ########## ################################################################################ radius_HLR = 2.5 bins_T = np.arange(int(Kt.getHLR_pix() * radius_HLR)) #bins_T = np.arange(30) binc_T = bins_T[:-1] + 0.5 atf_T = Kt.radialProfile(Kt.at_flux__yx * Kt.LobnSD__yx, bins_T, rad_scale=1, mode='sum') / \ Kt.radialProfile(Kt.LobnSD__yx, bins_T, rad_scale=1, mode='sum') AV_T = Kt.radialProfile(Kt.A_V__yx, bins_T, rad_scale=1) azm_T = Kt.radialProfile(Kt.alogZ_mass__yx * Kt.McorSD__yx, bins_T, rad_scale=1, mode='sum') / \ Kt.radialProfile(Kt.McorSD__yx, bins_T, rad_scale=1, mode='sum') M_T = Kt.radialProfile(Kt.McorSD__yx, bins_T, rad_scale=1) atf_Ti = Kt.integrated_at_flux * np.ones_like(binc_T) AV_Ti = Kt.integrated_keywords['A_V'] * np.ones_like(binc_T) azm_Ti = Kt.integrated_alogZ_mass * np.ones_like(binc_T) M_Ti = Kt.integrated_Mcor / getArea(Kt, radius_HLR) * np.ones_like(binc_T) bins_B = np.arange(int(Kb.getHLR_pix() * radius_HLR)) binc_B = bins_B[:-1] + 0.5 atf_B = Kb.radialProfile(Kb.at_flux__yx * Kb.LobnSD__yx, bins_B, rad_scale=1, mode='sum') / \ Kb.radialProfile(Kb.LobnSD__yx, bins_B, rad_scale=1, mode='sum') AV_B = Kb.radialProfile(Kb.A_V__yx, bins_B, rad_scale=1) azm_B = Kb.radialProfile(Kb.alogZ_mass__yx * Kb.McorSD__yx, bins_B, rad_scale=1, mode='sum') / \ Kb.radialProfile(Kb.McorSD__yx, bins_B, rad_scale=1, mode='sum') M_B = Kb.radialProfile(Kb.McorSD__yx, bins_B, rad_scale=1) atf_Bi = Kb.integrated_at_flux * np.ones_like(binc_B) AV_Bi = Kb.integrated_keywords['A_V'] * np.ones_like(binc_B) azm_Bi = Kb.integrated_alogZ_mass * np.ones_like(binc_B) M_Bi = Kb.integrated_Mcor / getArea(Kb, radius_HLR) * np.ones_like(binc_B) bins_D = np.arange(int(Kd.getHLR_pix() * radius_HLR)) #bins_D = np.arange(30) binc_D = bins_D[:-1] + 0.5 atf_D = Kd.radialProfile(Kd.at_flux__yx * Kd.LobnSD__yx, bins_D, rad_scale=1, mode='sum') / \ Kd.radialProfile(Kd.LobnSD__yx, bins_D, rad_scale=1, mode='sum') AV_D = Kd.radialProfile(Kd.A_V__yx, bins_D, rad_scale=1) azm_D = Kd.radialProfile(Kd.alogZ_mass__yx * Kd.McorSD__yx, bins_D, rad_scale=1, mode='sum') / \ Kd.radialProfile(Kd.McorSD__yx, bins_D, rad_scale=1, mode='sum') M_D = Kd.radialProfile(Kd.McorSD__yx, bins_D, rad_scale=1) atf_Di = Kd.integrated_at_flux * np.ones_like(binc_D) AV_Di = Kd.integrated_keywords['A_V'] * np.ones_like(binc_D) azm_Di = Kd.integrated_alogZ_mass * np.ones_like(binc_D) M_Di = Kd.integrated_Mcor / getArea(Kd, radius_HLR) * np.ones_like(binc_D) fig = plt.figure(2, figsize=(width_in, 0.7 * width_in)) gs = plt.GridSpec(2, 2, height_ratios=[1.0, 1.0]) ax = plt.subplot(gs[0, 0]) ax.plot(binc_T, atf_T, 'k', label=r'observado') ax.plot(binc_B, atf_B, 'r', label='bojo') ax.plot(binc_D, atf_D, 'b', label=r'disco') ax.plot(binc_T, atf_Ti, 'k--') ax.plot(binc_B, atf_Bi, 'r--') ax.plot(binc_D, atf_Di, 'b--') #ax.set_xlabel(r'Raio $[\mathrm{arcsec}]$') ax.set_xticklabels([]) ax.set_ylabel(r'$\langle \log\ t_\star \rangle_{\mathrm{Fluxo}}$') ax.set_xlim(0, 25) # ax.legend(loc='lower right') ax = plt.subplot(gs[0, 1]) ax.plot(binc_T, AV_T, 'k', label=r'observado') ax.plot(binc_B, AV_B, 'r', label='bojo') ax.plot(binc_D, AV_D, 'b', label=r'disco') ax.plot(binc_T, AV_Ti, 'k--') ax.plot(binc_B, AV_Bi, 'r--') ax.plot(binc_D, AV_Di, 'b--') #ax.set_xlabel(r'Raio $[\mathrm{arcsec}]$') ax.set_xticklabels([]) ax.set_ylabel(r'$A_V$') ax.set_xlim(0, 25) ax.legend(loc='upper right', frameon=False) ax = plt.subplot(gs[1, 0]) ax.plot(binc_T, azm_T, 'k', label=r'observado') ax.plot(binc_B, azm_B, 'r', label='bojo') ax.plot(binc_D, azm_D, 'b', label=r'disco') ax.plot(binc_T, azm_Ti, 'k--') ax.plot(binc_B, azm_Bi, 'r--') ax.plot(binc_D, azm_Di, 'b--') ax.set_xlabel(r'Raio $[\mathrm{arcsec}]$') ax.set_ylabel(r'$\langle \log (Z_\star/Z_\odot) \rangle_{\mathrm{Massa}}$') ax.set_xlim(0, 25) # ax.legend(loc='upper right') ax = plt.subplot(gs[1, 1]) ax.plot(binc_T, np.log10(M_T), 'k', label=r'observado') ax.plot(binc_B, np.log10(M_B), 'r', label='bojo') ax.plot(binc_D, np.log10(M_D), 'b', label=r'disco') ax.plot(binc_T, np.log10(M_Ti), 'k--') ax.plot(binc_B, np.log10(M_Bi), 'r--') ax.plot(binc_D, np.log10(M_Di), 'b--') ax.set_xlabel(r'Raio $[\mathrm{arcsec}]$') ax.set_ylabel(r'$\log \mu_\star\ [\mathrm{M}_\odot / \mathrm{pc}^2]$') ax.set_xlim(0, 25) # ax.legend(loc='upper right') ax.text(0.95, 0.9, 'Bojo - massa: %.1f %%, lumin.: %.1f %%' % (m_B, l_B), color='r', ha='right', size=8, transform=ax.transAxes) ax.text(0.95, 0.8, 'Disco - massa: %.1f %%, lumin.: %.1f %%' % (m_D, l_D), color='b', ha='right', size=8, transform=ax.transAxes) plt.suptitle(u'Propriedades físicas - síntese de populações') gs.tight_layout(fig, rect=[0, 0, 1, 0.97]) pdf.savefig(fig) if args.debug: plt.show()