def replace_photo_uncert(catalog, columns): """ """ data = C.loaddata(catalog) # Loading the whole catalog content. head = C.loadheader(catalog) # Loading the original header. mm = A.get_magnitudes(catalog, columns) em = A.get_errmagnitudes(catalog, columns) filters = B.get_filter_list(columns) nl = len(mm[:, 0]) # nl is the number of detections inside every single band. nf = len(mm[0, :]) # nf is the number of bands inside the catalog. errmag = U.zeros((nl, nf), float) # Where the new photo errors will be saved. for jj in range(nf): maglim = B.get_limitingmagnitude(mm[:, jj], em[:, jj], 1., 0.25) print 'Limiting Magnitude for filter %s: %.3f' % (filters[jj], maglim) for ii in range(nl): if mm[ii, jj] == -99.: errmag[ii, jj] = 0.00 elif mm[ii, jj] == 99.: errmag[ii, jj] = maglim else: errmag[ii, jj] = em[ii, jj] # New values of mags error overwrites now the original data. vars, evars, posref, zpe, zpo = get_usefulcolumns(columns) data[:, evars] = errmag[:, U.arange(nf)] finalcatalog = catalog[:-3] + 'upp.cat' C.savedata(data, finalcatalog, dir="", header=head) # Saving & creating a new catalog.
def replace_kerttu_errmags(catalog, columns, finalcatalog): """ import alhambra_kerttu_fixerrmags as AFM catalog = '/Users/albertomolino/doctorado/articulos/ALHAMBRA/kerttu/test_photoz/kerttu.cat' columns = '/Users/albertomolino/doctorado/articulos/ALHAMBRA/kerttu/test_photoz/kerttu.columns' finalcatalog = '/Users/albertomolino/doctorado/articulos/ALHAMBRA/kerttu/test_photoz/kerttu3.cat' AFM.replace_kerttu_errmag(catalog,columns,finalcatalog) ------ """ data = C.loaddata(catalog) # Loading the whole catalog content. head = C.loadheader(catalog) # Loading the original header. mm = A.get_magnitudes(catalog, columns) em = A.get_errmagnitudes(catalog, columns) filters = B.get_filter_list(columns) nl = len(mm[:, 0]) # nl is the number of detections inside every single band. nf = len(mm[0, :]) # nf is the number of bands inside the catalog. errmag = U.zeros((nl, nf), float) # Where the new photo errors will be saved. for jj in range(nf): for ii in range(nl): if mm[ii, jj] == -99.: errmag[ii, jj] = 0.00 else: errmag[ii, jj] = em[ii, jj] # New values of mags error overwrites now the original data. vars, evars, posref, zpe, zpo = A.get_usefulcolumns(columns) data[:, evars] = errmag[:, U.arange(nf)] C.savedata(data, finalcatalog, dir="", header=head) # Saving & creating a new catalog.
import numpy as N import useful as U import bpz_tools as B import phz_plots as P import matplotlib.pyplot as plt sedlist = 'GOSMOSeB11.list' root = '/Users/albertomolino/doctorado/articulos/SPLUS/paper0/membership/' columns = root + 'splus_auto_cali.columns' fluxcomp = root + 'members_regular.flux_comparison' bpz = root + 'members_regular.bpz' zb, zs, chi2 = U.get_data(bpz, (1, 9, 8)) dz = (zb - zs) / (1. + zs) hdf5file = root + 'members_regular.hdf5' filters = B.get_filter_list(columns) ids = U.get_data(fluxcomp, 0) pos = N.where(ids == 4539)[0][0] z, x1, x2, x3 = P.getPDZ(hdf5file, pos) base_y = N.arange(0., 1., 0.1) #plt.figure(1, figsize = (6,6),dpi=75, facecolor='w', edgecolor='k') plt.clf() P.plotsedfittingbyID(ids[pos], columns, fluxcomp, sedlist, filters) plt.xlabel('Wavelength $[\AA]$', size=18, labelpad=-2) plt.ylabel('Magnitude', size=20, labelpad=2) plt.xticks(fontsize=15) plt.yticks(fontsize=15) #plt.ylim(23.,17) plt.xlim(3200, 9300) siete = plt.axes([0.5, .215, 0.375, 0.375]) y = x3 / x3.sum()
def check_variable_candidate(alhambraid): """ It replaces failed magnitudes in the ALHAMBRA catalogues (artificial absorptions, non-observed sources assigned as non-detected with upper limits) by m=-99,em=99 It might decrease the amount of low Odds at bright magnitudes. ---- import alhambra_photools as A A.replacing_fakeabsorptions(2,1,2) A.check_sample(image,catalog,posID,posX,posY,posMAG) A.alhambra_id_finder(ra1,dec1) idd = int(id[pos]) A.alhambra_colorstamp_byID(id) f,p,c,ids = A.alhambra_id_finder(37.4992,1.2482) """ field = int(str(alhambraid)[3]) pointing = int(str(alhambraid)[4]) ccd = int(str(alhambraid)[5]) numero = str(alhambraid)[-5:] print numero for ii in range(2): if numero[0] == '0': numero = numero[1:] print numero root2cats = '/Volumes/amb22/catalogos/reduction_v4f/f0%i/' % (field) catalog = root2cats + 'originals/f0%ip0%i_colorproext_%i_ISO.cat' % ( field, pointing, ccd) cols1 = root2cats + 'f0%ip0%i_%i_tot_ISO_eB10.columns' % (field, pointing, ccd) cols2 = root2cats + 'f0%ip0%i_colorproext_%i_ISO_phz_eB10.columns' % ( field, pointing, ccd) if os.path.exists(cols1): columns = cols1 else: columns = cols2 filters = B.get_filter_list(columns) print filters data = C.loaddata(catalog) # Loading the whole catalog content. head = C.loadheader(catalog) # Loading the original header. m = A.get_magnitudes(catalog, columns) # em = get_errmagnitudes(catalog,columns) root2 = '/Volumes/amb22/catalogos/reduction_v4e/' fluxc1 = root2 + 'f0%i/f0%ip0%i_colorproext_%i_ISO_phz_eB11.flux_comparison' % ( field, field, pointing, ccd) fluxc2 = root2 + 'f0%i/f0%ip0%i_colorproext_%i_ISO.flux_comparison' % ( field, field, pointing, ccd) if os.path.exists(fluxc1): fluxc = fluxc1 else: fluxc = fluxc2 ido, ftt, foo, efoo, zb, tb, mm = P.get_usefulfluxcomparison( columns, fluxc) pos = A.get_position(ido, int(numero)) print ido[pos], mm[pos] plt.figure(1, figsize=(10, 7), dpi=80, facecolor='w', edgecolor='k') plt.clf() # P.plot1sedfitting(foo[:,jj],efoo[:,jj],ftt[:,jj],zb[jj],tb[jj],root_bpz_sed+'eB11.list',filters) plt.plot(U.arange(20) + 1, foo[0:20, pos], 'k-', alpha=0.4, lw=6) plt.plot(U.arange(20) + 1, foo[0:20, pos], 'ko', alpha=0.4, ms=12) plt.errorbar(U.arange(20) + 1, foo[0:20, pos], (efoo[0:20, pos] / 1.), fmt="ko", alpha=0.4, ms=10) minf = (foo[0:20, pos].min()) * 1.1 maxf = (foo[0:20, pos].max()) * 1.1 maxef = (efoo[0:20, pos].max()) * 1.1 # plt.ylim(minf-maxef,maxf+maxef) plt.xlim(0, 21) plt.xlabel('Filter', size=25) plt.ylabel('Flux', size=25) plt.legend(['Magnitude: %.2f' % (m[pos][-1])], loc='upper right', numpoints=1, fontsize=20) plt.title(alhambraid, size=25) plt.grid() plt.show() namefig = '/Users/albertomolino/doctorado/photo/variability/analysis/vocheck.ID%s.png' % ( alhambraid) plt.savefig(namefig, dpi=125) outcat = '/Users/albertomolino/doctorado/photo/variability/analysis/vocheck.ID%s.cat' % ( alhambraid) A.select_rows_bylist_pro(catalog, ido[pos], outcat) print ' '
def SEDSEx_noise_comparison222(columns,fluxcomp,m_min,m_max,delta_m): """ fluxcomp = 'master.flux_comparison' columns = 'master.columns' SEDSEx_noise_comparison(columns,fluxcomp,14,21,0.3) """ basem = N.arange(m_min,m_max+delta_m,delta_m) ft,fob,efobs = A.get_fluxes(columns,fluxcomp) filters = B.get_filter_list(columns) nf = len(filters) for ss in range(nf): nband = ss mt = B.flux2mag(ft[:][nband]) mo = B.flux2mag(fob[:][nband]) emo = B.e_frac2mag(efobs[:][nband])/(fob[:][nband]) g = N.less(abs(mo),28) mor,mtr,emor = U.multicompress(g,(mo,mt,emo)) dm = mtr-mor g2 = N.less(abs(dm),1.) mor,mtr,emor = U.multicompress(g2,(mor,mtr,emor)) linea_sdm = U.bin_stats(mor,dm,basem,'std_mad') #SED linea_sem = U.bin_stats(mor,emor,basem,'std_mad') #SEx linea_sem = N.where(linea_sem<1.0e-4,0.0,linea_sem) linea_dm = U.bin_stats(mor,dm,basem,'mean_robust') #SED linea_em = U.bin_stats(mor,emor,basem,'mean_robust') #SEx linea2 = linea_dm+linea_sdm #SED linea1 = linea_sem+linea_em #SEx """ plt.figure(1, figsize = (11,9.5),dpi=80, facecolor='w', edgecolor='k') plt.clf() plt.subplot(211) plt.semilogy(basem,abs(linea_sdm),'r-',basem,linea_sem,'k-',lw=12) plt.legend(['SED','SEx'],loc='lower left',fontsize=30) plt.title('dispersions. Filter %s'%(filters[ss]),size=30) plt.grid() plt.xlim(m_min-delta_m,m_max+delta_m) plt.ylim(0.0001,1.) plt.xticks(fontsize=22) plt.yticks(fontsize=22) # plt.xlabel('magnitude',size=22) plt.ylabel('$\delta m$',size=22) plt.subplot(212) plt.semilogy(basem,abs(linea_dm),'r-',basem,linea_em,'k-',lw=12) #plt.legend(['SED','SEx'],loc='lower left',fontsize=30) plt.title('mean',size=30) plt.grid() plt.xlim(m_min-delta_m,m_max+delta_m) plt.ylim(0.001,1.) plt.xticks(fontsize=22) plt.yticks(fontsize=22) plt.xlabel('magnitude',size=22) plt.ylabel('$\delta m$',size=22) plt.savefig(final_root+'SEDdm1_Filter_%s.png'%(filters[ss])) """ plt.figure(1, figsize = (11,9.5),dpi=80, facecolor='w', edgecolor='k') plt.clf() plt.semilogy(basem,abs(linea_sdm),'r-',basem,linea_sem,'k-',lw=12) plt.semilogy(basem,abs(linea_dm),'r--',basem,linea_em,'k--',lw=12) plt.title('Filter %s'%(filters[ss]),size=30) plt.xlim(m_min-delta_m,m_max+delta_m) plt.ylim(0.0001,1.) plt.xticks(fontsize=22) plt.yticks(fontsize=22) plt.ylabel('$\delta m$',size=22) plt.legend(['$\sigma_{SED}$','$\sigma_{SEx}$','$\mu_{SED}$','$\mu_{SEx}$'],loc='lower left',fontsize=30) plt.grid() plt.xlabel('magnitude',size=22) plt.savefig(final_root+'SEDdm1_Filter_%s.png'%(filters[ss])) plt.figure(2, figsize = (11,9.5),dpi=80, facecolor='w', edgecolor='k') plt.clf() plt.semilogy(basem,abs(linea2),'r-',basem,linea1,'k-',lw=12) plt.legend(['SED','SEx'],loc='lower left',fontsize=30) plt.title('mean+disp. Filter %s'%(filters[ss]),size=30) plt.grid() plt.xlim(m_min-delta_m,m_max+delta_m) plt.ylim(0.01,1.) plt.xticks(fontsize=22) plt.yticks(fontsize=22) plt.xlabel('magnitude',size=22) plt.ylabel('$\delta m$',size=22) plt.savefig(final_root+'SEDdm2_Filter_%s.png'%(filters[ss]))