Beispiel #1
0
 def ProcessEAZYOutput(self,ASCII=False):
     ''' Rewrite the standard EAZY output to a more useable format.
         Must have the EAZY binary output. Set in EAZY .param file.
         Writes a .pkl files with the obj P(z).
         pz = {ID:np.array(P(z)),z:np.array(z)}
         Saved in binary or ASCII
     '''
     if ASCII == False: ending='.pklb'
     elif ASCII == True: ending='.pkl'
     if os.path.exists('EAZY/%s/%s.pz'%(self.clusterName,self.clusterName)) == False:
         print bcolors.FAIL+'Can not Process EAZY'+bcolors.ENDC
         print bcolors.FAIL+'Do not have standard EAZY binary output'+bcolors.ENDC
         raise RuntimeError('Must create binary ouput from EAZY, set in .param file, and run cl.RunEAZY()')
     if os.path.exists('CATALOGS/%s.cat'%self.clusterName) == False:
         raise RuntimeError('Must write catalog, try running cl.WriteCatalog()')
     fi = np.genfromtxt('CATALOGS/%s.cat'%self.clusterName,names=True)
     pz = {}
     for idx,obj in enumerate(fi):
         zrange, data = eazy.getEazyPz(idx,
                                       MAIN_OUTPUT_FILE='EAZY/%s/%s'%(self.clusterName,self.clusterName),
                                       OUTPUT_DIRECTORY='./')
         if pz.has_key('z') == False:
             pz['z'] = zrange
         elif np.all(pz['z']==zrange) == False:
             print bcolors.FAIL+'EAZY objects have different z ranges!'+bcolors.ENDC
         id = str(int(obj['ID']))
         pz[id] = data
     WritePickle(pz,'EAZY/pzpickles/'+self.clusterName+ending,ASCII=ASCII)
     print 'Saved EAZY Pickle as '+'EAZY/pzpickles/'+self.clusterName+ending
Beispiel #2
0
def plotResult(idnum,catalog,save=False):

    id=str(idnum)

    obsData=Table.read(catalog).to_pandas()
    rmag=-2.5*np.log10(obsData['fRauto'][idnum])+23.9
    
    axes = eazy.plotExampleSED(idx=idnum, writePNG=False, MAIN_OUTPUT_FILE='photz',
                            OUTPUT_DIRECTORY='OUTPUT', CACHE_FILE='Same', lrange=[3800, 3.e4],
                            axes=None, individual_templates=False, fnu=False)
			   
    sed = eazy.getEazySED(idnum, MAIN_OUTPUT_FILE='photz', OUTPUT_DIRECTORY='./OUTPUT',
                        CACHE_FILE='Same', scale_flambda=True, verbose=False,
                        individual_templates=False)

    lambdaz, temp_sed, lci, obs_sed, fobs, efobs = sed

    zgrid, pzi, prior = eazy.getEazyPz(idnum, MAIN_OUTPUT_FILE='photz', OUTPUT_DIRECTORY='./OUTPUT',
                                    CACHE_FILE='Same', binaries=None, get_prior=True)
    
    axes[1].plot(zgrid, pzi, color='black')
    axes[1].plot(zgrid, prior/prior.max()*pzi.max(), color='purple')

    axes[1].set_xlim([0.,1.])
    axes[0].text(5500.,axes[0].get_ylim()[1]*0.1,r'$m_{R}$ = '+str(rmag)[:5]+' mag')

    if save == True:
        plt.savefig('OUTPUT/'+id+'.pdf',format='pdf',dpi=6000)
        plt.clf()
    else:
        plt.show()
    plt.close()
Beispiel #3
0
def _sample_eazy_redshifts(gal_ID: int,
                           eazy_outdir: str,
                           ndraws: int = 1000) -> np.ndarray:
    """
    Returns a sample of redshifts drawn from the
    EAZY photo-z PDF of galaxy <gal_iD>.
    Args:
        gal_ID(int): ID number of the galaxy in the EAZY table.
        eazy_outdir(str): Path to the EAZY results folder
        ndraws(int, optional): Number of redshift samples desired.
    Returns:
        sample_z (np.ndarray): Redshift sample array of length ndraws.
    """
    # Get posterior
    zgrid, pz = ez.getEazyPz(gal_ID - 1, OUTPUT_DIRECTORY=eazy_outdir)
    # Force a value of 0 at z = 0
    zgrid = np.hstack([[0], zgrid])
    pz = np.hstack([[0], pz])
    if np.all(np.diff(zgrid) == 0):
        return -99

    # make a CDF
    cdf_z = np.cumsum(pz)
    cdf_z /= np.max(cdf_z)
    cdf_interp = interp1d(cdf_z,
                          zgrid,
                          kind="linear",
                          fill_value=0,
                          bounds_error=False)

    # Use uniform distribution to produce random draws from the CDF
    sample_u = np.random.rand(ndraws)
    sample_z = cdf_interp(sample_u)
    return sample_z
Beispiel #4
0
	sp_sed.set_xlim(2*10**-1, 1.7*10**1)
	sp_sed.set_ylim(fmin/5, fmax*5)
	sp_sed = restore_logaxes_labels(sp_sed)

	sp_sed.set_xlabel('wavelength [$\mu m$]')
	sp_sed.set_ylabel('F lambda')




	###  P(z) subplot
	sp_pz.set_xlabel('z', size=13)
	sp_pz.set_ylabel('P(z)', rotation=90, size=13)
	
	pz = eazyPy.getEazyPz(i, MAIN_OUTPUT_FILE=version, OUTPUT_DIRECTORY='./EAZY')

	sp_pz.fill_between(pz[0], 0, pz[1], color='#00b300')
	sp_pz.set_xlim(0, 5)




	pylab.savefig('/Users/atomczak/mugshot%i_%s.pdf' % (cat.id[i], version))



	sp_info.clear()
	sp_sed.clear()
	sp_pz.clear()
Beispiel #5
0
################################################
#### Pull out data from the BINARY_OUTPUTS files
################################################

## SED, data & fit
sed = eazy.getEazySED(17, MAIN_OUTPUT_FILE='photz', OUTPUT_DIRECTORY='./OUTPUT',
                      CACHE_FILE='Same', scale_flambda=True, verbose=False,
                      individual_templates=False)

lambdaz, temp_sed, lci, obs_sed, fobs, efobs = sed
axes[0].scatter(lci, obs_sed, color='orange', zorder=2)
axes[0].scatter(lci, fobs, color='green', marker='s', s=150, zorder=2)

## p(z)
zgrid, pzi, prior = eazy.getEazyPz(17, MAIN_OUTPUT_FILE='photz', OUTPUT_DIRECTORY='./OUTPUT',
                                   CACHE_FILE='Same', binaries=None, get_prior=True)
                                   
axes[1].plot(zgrid, pzi, color='black')
axes[1].plot(zgrid, prior/prior.max()*pzi.max(), color='purple')
plt.savefig('eazy_fit_2.png')

################################################
#### Investigate template fit residuals for zeropoints
################################################
eazy.show_fit_residuals(root='photz', PATH='./OUTPUT/', savefig='fit_residuals.png', adjust_zeropoints='zphot.zeropoint', fix_filter=None, ref_filter=28, get_resid=False, wclip=[1200, 30000.0])

## Run again using the zphot.zeropoint file you just made, this can be done iteratively
params = eazy.EazyParam('zphot.param.default')
params['GET_ZP_OFFSETS'] = 'y'
params.write('zphot.param')
os.system('../src/eazy -p zphot.param -z zphot.zeropoint')
Beispiel #6
0
sed = eazy.getEazySED(17,
                      MAIN_OUTPUT_FILE='photz',
                      OUTPUT_DIRECTORY='./OUTPUT',
                      CACHE_FILE='Same',
                      scale_flambda=True,
                      verbose=False,
                      individual_templates=False)

lambdaz, temp_sed, lci, obs_sed, fobs, efobs = sed
axes[0].scatter(lci, obs_sed, color='orange', zorder=2)
axes[0].scatter(lci, fobs, color='green', marker='s', s=150, zorder=2)

## p(z)
zgrid, pzi, prior = eazy.getEazyPz(17,
                                   MAIN_OUTPUT_FILE='photz',
                                   OUTPUT_DIRECTORY='./OUTPUT',
                                   CACHE_FILE='Same',
                                   binaries=None,
                                   get_prior=True)

axes[1].plot(zgrid, pzi, color='black')
axes[1].plot(zgrid, prior / prior.max() * pzi.max(), color='purple')
plt.savefig('eazy_fit_2.png')

################################################
#### Investigate template fit residuals for zeropoints
################################################
eazy.show_fit_residuals(root='photz',
                        PATH='./OUTPUT/',
                        savefig='fit_residuals.png',
                        adjust_zeropoints='zphot.zeropoint',
                        fix_filter=None,