Esempio n. 1
0
    def zeroPaddData(self,desiredLength,paddmode='zero',where='end'):    
        #zero padds the time domain data, it is possible to padd at the beginning,
        #or at the end, and further gaussian or real zero padding is possible        
        #might not work for gaussian mode!

        desiredLength=int(desiredLength)
        #escape the function        
        if desiredLength<0:
            return 0

        #calculate the paddvectors        
        if paddmode=='gaussian':
            paddvec=py.normal(0,py.std(self.getPreceedingNoise())*0.05,desiredLength)
        else:
            paddvec=py.ones((desiredLength,self.tdData.shape[1]-1))
            paddvec*=py.mean(self.tdData[-20:,1:])
            
        timevec=self.getTimes()
        if where=='end':
            #timeaxis:
            newtimes=py.linspace(timevec[-1],timevec[-1]+desiredLength*self.dt,desiredLength)
            paddvec=py.column_stack((newtimes,paddvec))
            longvec=py.row_stack((self.tdData,paddvec))
        else:
            newtimes=py.linspace(timevec[0]-(desiredLength+1)*self.dt,timevec[0],desiredLength)
            paddvec=py.column_stack((newtimes,paddvec))
            longvec=py.row_stack((paddvec,self.tdData))
            
        self.setTDData(longvec)
Esempio n. 2
0
    def doCalculation(self,bool_findl=1,n_SVMAFS=5,bool_silent=0):
        #this function does the complete calculation
        #bandwidth
        bw=self.H.getBandwidth()
        #crop data
        self.H.manipulateFDData(-1,[bw[0]+50e9,bw[1]-200e9])
        #if l_opt shouldn't be calculated used bool_findl=False
        if bool_findl:
            self.l_opt=self.findLintelli()

        print('\033[92m\033[1m' + '  Use Sample Thickness: ' + str(self.l_opt*1e6) + ' micro m ' + '\033[0m')

        #calculate n for the given l_opt
        n=self.calculaten(self.H.fdData,self.l_opt)
        n_smoothed=n
        i=0
        
        #smooth it with SVMAF
        while i<n_SVMAFS:
            n_smoothed=self.SVMAF(self.H.getfreqs(),n_smoothed,self.l_opt)
            i+=1

        self.n=py.column_stack((self.H.getfreqs(),n,n_smoothed))   
        
        self.calculateinitsunc(self.H.fdData,self.l_opt)
        
        return self.n
Esempio n. 3
0
 def removePhaseOffset(self,freqs,ph,startfreq=200e9,endfreq=1e12):
     #cut phase to reasonable range:
     ph_c=self.getcroppedData(py.column_stack((freqs,ph)),startfreq,endfreq)
     #determine the slope and the offset      
     p=py.polyfit(ph_c[:,0],ph_c[:,1],1)
     #return full phase-offset(croppedPhase)
     return ph-p[1]
Esempio n. 4
0
    def calculateFDunc(self):
        #Calculates the uncertainty of the FFT according to:
        #   - J. M. Fornies-Marquina, J. Letosa, M. Garcia-Garcia, J. M. Artacho, "Error Propagation for the transformation of time domain into frequency domain", IEEE Trans. Magn, Vol. 33, No. 2, March 1997, pp. 1456-1459
        #return asarray _tdData
        #Assumes tha the amplitude of each time sample is statistically independent from the amplitude of the other time
        #samples

        # Calculates uncertainty of the real and imaginary part of the FFT and ther covariance
        unc_E_real = []
        unc_E_imag = []
        cov = []
        for f in self.getfreqs():
            unc_E_real.append(py.sum((py.cos(2*py.pi*f*self._tdData.getTimes())*self._tdData.getUncEX())**2))
            unc_E_imag.append(py.sum((py.sin(2*py.pi*f*self._tdData.getTimes())*self._tdData.getUncEX())**2))
            cov.append(-0.5*sum(py.sin(4*py.pi*f*self._tdData.getTimes())*self._tdData.getUncEX()**2))
        
        unc_E_real = py.sqrt(py.asarray(unc_E_real))
        unc_E_imag = py.sqrt(py.asarray(unc_E_imag))
        cov = py.asarray(cov)
        
        # Calculates the uncertainty of the modulus and phase of the FFT
        unc_E_abs = py.sqrt((self.getFReal()**2*unc_E_real**2+self.getFImag()**2*unc_E_imag**2+2*self.getFReal()*self.getFImag()*cov)/self.getFAbs()**2)
        unc_E_ph = py.sqrt((self.getFImag()**2*unc_E_real**2+self.getFReal()**2*unc_E_imag**2-2*self.getFReal()*self.getFImag()*cov)/self.getFAbs()**4)
        
        t=py.column_stack((self.getfreqs(),unc_E_real,unc_E_imag,unc_E_abs,unc_E_ph))
        return self.getcroppedData(t)  
Esempio n. 5
0
    def importfile(self,fname,params):
        # if even more sophisticated things are needed, just inherit THzTdData class
        #and override the importfile method
        #try to load the file with name fname
        #it should be possible to write this shorter
        try:
            #if no Y_col is specified            
            if params.has_key('Y_col'):
                #import it right away
                if params['dec_sep']=='.':
                    data=py.loadtxt(fname,
                                usecols=(params['time_col'],
                                         params['X_col'],
                                         params['Y_col']),
                                skiprows=params['skiprows'])
                                
                elif params['dec_sep']==',':
                    #if the decimal separator is , do a replacement
                    str2float=lambda val: float(val.replace(',','.'))
                    data=py.loadtxt(fname,
                                converters={params['time_col']:str2float,
                                            params['X_col']:str2float,
                                            params['Y_col']:str2float},
                                usecols=(params['time_col'],
                                         params['X_col'],
                                         params['Y_col']),
                                skiprows=params['skiprows'])                
            else:
                #import it right away
                if params['dec_sep']=='.':
                    data=py.loadtxt(fname,
                                usecols=(params['time_col'],
                                         params['X_col']),
                                skiprows=params['skiprows'])
                                
                elif params['dec_sep']==',':
                    #if the decimal separator is , do a replacement
                    str2float=lambda val: float(val.replace(',','.'))
                    data=py.loadtxt(fname,
                                converters={params['time_col']:str2float,
                                            params['X_col']:str2float},
                                usecols=(params['time_col'],
                                         params['X_col']),
                                skiprows=params['skiprows'])
                dummy_Y=py.zeros((data.shape[0],1))
                data=py.column_stack((data,dummy_Y))
        except IOError:
            print "File " + fname + " could not be loaded"
            sys.exit()

        #scale the timaaxis
        data[:,0]*=params['time_factor']
        
        #if the measurement was taken in negative time direction, flip the data
        if data[1,0]-data[0,0]<0:
            data=py.flipud(data)
     
        return data
Esempio n. 6
0
 def getInterpolatedFDData(self,newfbins,strmode='linear'):
     #not only for this function, also for others maybe useful: 
     #check if it is possible to give as an argument a slice, i.e.
     # '1:' for interpolating all data, '3' for only the absdata and so on 
     oldfreqs=self.getfreqs()
     newfreqs=py.arange(min(oldfreqs),max(oldfreqs),newfbins)
     
     interfdData=interp1d(oldfreqs,self.fdData[:,1:],strmode,axis=0)
     
     return py.column_stack((newfreqs,interfdData(newfreqs)))
Esempio n. 7
0
 def _rotateToXChannel(self,tdData):
     #this function should remove all signal from Y-Channel
     
     #Calculate lock-in phase:
     unc_raw=self.getelnNoise(tdData)
     XC=unumpy.uarray(tdData[:,1],unc_raw[0])
     YC=unumpy.uarray(tdData[:,2],unc_raw[1])
     #go to pulse:
     phase=self._determineLockinPhase(tdData)
     
     #rotate to XChannel
     XC_new=XC*py.cos(phase)+YC*py.sin(phase)
     YC_new=-XC*py.sin(phase)+YC*py.cos(phase)
     tdData[:,1]=unumpy.nominal_values(XC_new)
     tdData[:,2]=unumpy.nominal_values(YC_new)
     
     unc_new=py.column_stack((unumpy.std_devs(XC_new),unumpy.std_devs(YC_new)))
     tdData=py.column_stack((tdData,unc_new))
     return tdData
Esempio n. 8
0
File: p2.py Progetto: boada/ICD
def plot_color_vs_mass_vs_icd():
    galaxies = mk_galaxy_struc()
    # Add the figures

    # Mass vs color plot I-H
    f1 = pyl.figure(1, figsize=(6, 4))
    f1s1 = f1.add_subplot(212)

    color1 = []
    mass1 = []
    icd1 = []

    for i in range(len(galaxies)):
        if galaxies[i].ston_I > 30.0:
            if -0.05 < galaxies[i].ICD_IH and galaxies[i].ICD_IH < 0.25:
                mass1.append(galaxies[i].Mass)
                color1.append(galaxies[i].Imag - galaxies[i].Hmag)
                icd1.append(galaxies[i].ICD_IH)
            else:
                mass1.append(galaxies[i].Mass)
                color1.append(galaxies[i].Imag - galaxies[i].Hmag)
                icd1.append(0.25)

    # Sort the arrays by ICD
    mass1 = pyl.asarray(mass1)
    color1 = pyl.asarray(color1)
    icd1 = pyl.asarray(icd1)

    IH_array = pyl.column_stack((mass1, color1, icd1))

    IH_array = colsort(IH_array, 3)

    sc1 = f1s1.scatter(IH_array[:, 0],
                       IH_array[:, 1],
                       c=IH_array[:, 2],
                       s=50,
                       cmap='spectral')

    ############
    # FIGURE 1 #
    ############

    bar = pyl.colorbar(sc1)
    bar.set_label(r"$\xi[I,H]$")

    f1s1.set_xscale('log')
    f1s1.set_xlim(3e7, 1e12)
    f1s1.set_ylim(0.0, 4.0)
    f1s1.set_xlabel(r"Mass $[M_{\odot}]$")
    f1s1.set_ylabel("$(I-H)_{Observed}$")

    #    pyl.subplots_adjust(left=0.15, bottom=0.15, right=.75)
    #    pyl.savefig('color_vs_mass_vs_icd_IH.eps',bbox='tight')
    return f1s1
Esempio n. 9
0
File: p2.py Progetto: boada/ICD
def plot_color_vs_mass_vs_icd():
    galaxies=mk_galaxy_struc()
    # Add the figures

    # Mass vs color plot I-H
    f1 = pyl.figure(1,figsize=(6,4))
    f1s1 = f1.add_subplot(212)


    color1 = []
    mass1 = []
    icd1 = []

    for i in range(len(galaxies)):
        if galaxies[i].ston_I >30.0:
            if -0.05 < galaxies[i].ICD_IH and galaxies[i].ICD_IH < 0.25:
                mass1.append(galaxies[i].Mass)
                color1.append(galaxies[i].Imag-galaxies[i].Hmag)
                icd1.append(galaxies[i].ICD_IH)
            else:
                mass1.append(galaxies[i].Mass)
                color1.append(galaxies[i].Imag-galaxies[i].Hmag)
                icd1.append(0.25)

    # Sort the arrays by ICD
    mass1 = pyl.asarray(mass1)
    color1 = pyl.asarray(color1)
    icd1 = pyl.asarray(icd1)

    IH_array = pyl.column_stack((mass1,color1,icd1))

    IH_array = colsort(IH_array,3)

    sc1 = f1s1.scatter(IH_array[:,0], IH_array[:,1], c=IH_array[:,2], s=50,
    cmap='spectral')


    ############
    # FIGURE 1 #
    ############

    bar = pyl.colorbar(sc1)
    bar.set_label(r"$\xi[I,H]$")

    f1s1.set_xscale('log')
    f1s1.set_xlim(3e7,1e12)
    f1s1.set_ylim(0.0,4.0)
    f1s1.set_xlabel(r"Mass $[M_{\odot}]$")
    f1s1.set_ylabel("$(I-H)_{Observed}$")

#    pyl.subplots_adjust(left=0.15, bottom=0.15, right=.75)
#    pyl.savefig('color_vs_mass_vs_icd_IH.eps',bbox='tight')
    return f1s1
Esempio n. 10
0
 def calcTDData(self,tdDatas):
     #tdDatas is a a 3d array of measurements, along with their uncertainties
     #meantdData is the weighted sum of the different measurements
     #meantdData,sumofweights=py.average(tdDatas[:,:,1:3],axis=0,weights=1.0/tdDatas[:,:,3:]**2,returned=True)
     meantdData=py.average(tdDatas[:,:,1:3],axis=0)
     #use error propagation formula
     noise=py.sqrt(py.mean(self.getAllPrecNoise()[0]**2))
     if tdDatas.shape[0]==1:
         rep = py.zeros((len(tdDatas[0,:,0]),2))
     else:
         rep = py.std(tdDatas[:,:,1:3],axis=0, ddof=1)/py.sqrt(self.numberOfDataSets)
     unc = py.sqrt(rep**2+noise**2)
     #unc=py.sqrt(1.0/sumofweights)
     #time axis are all equal
     return py.column_stack((tdDatas[0][:,0],meantdData,unc))       
Esempio n. 11
0
    def _calculatefdData(self,tdData):
        #no need to copy it before (access member variable is ugly but shorter)

        #calculate the fft of the X channel
        fd=py.fft(tdData.getEX())
        #calculate absolute and phase values
        fdabs=abs(fd)
        fdph=abs(py.unwrap(py.angle(fd)))
        #calculate frequency axis
        dfreq=py.fftfreq(tdData.num_points,tdData.dt)
        #extrapolate phase to 0 and 0 frequency
        fdph=self.removePhaseOffset(dfreq,fdph)
        #set up the fdData array
        t=py.column_stack((dfreq,fd.real,fd.imag,fdabs,fdph))
        
        #this is so not nice!
        self.fdData=t
        unc=self.calculateFDunc()
        t=self.getcroppedData(t,0,unc[-1,0])
        
        #interpolate uncertainty        
        intpunc=interp1d(unc[:,0],unc[:,1:],axis=0)        
        unc=intpunc(t[:,0])
        return py.column_stack((t,unc))
Esempio n. 12
0
 def getmovingAveragedData(self,window_size_GHz=-1):
     #so far unelegant way of convolving the columns one by one
     #even not nice, improvement possible?
     if window_size_GHz<0.5e9:
         window_size=int(self.getEtalonSpacing()/self.getfbins())
     else:
         window_size=int(window_size_GHz/self.getfbins())
           
     window_size+=window_size%2+1
     window=py.ones(int(window_size))/float(window_size)
     
     dataabs=py.convolve(self.getFAbs(), window, 'valid')
     dataph=py.convolve(self.getFPh(), window, 'valid')
     one=py.ones((window_size-1)/2,)
     dataabs=py.concatenate((dataabs[0]*one,dataabs,dataabs[-1]*one))
     dataph=py.concatenate((dataph[0]*one,dataph,dataph[-1]*one))
     return py.column_stack((self.fdData[:,:3],dataabs,dataph,self.fdData[:,5:]))
Esempio n. 13
0
 def getFilteredData(self,windowlen=100e9,maxorder=3):
     #windowlength should be smaller the etalon frequency, in order to emphasize them
     #for the length algorithm
     #it should be of the order of typical absorption line widthes for their analysis
     #remove etalon minima
     
     #what happens if the savgol filter is applied to real and imaginary part of the fft?!        
     #maybe nice to check?!
     fbins=self.getfbins()
     #100e9 should be replaced by the Etalon frequency 
     N_min=int(windowlen/fbins)
     order=min(N_min-1,maxorder)
     
     absdata=signal.savgol_filter(self.getFAbs(),N_min-N_min%2+1,order)
     phdata=signal.savgol_filter(self.getFAbs(),N_min-N_min%2+1,order)
    
     return py.column_stack((self.fdData[:,:3],absdata,phdata,self.fdData[:,5:]))
Esempio n. 14
0
    def saveResults(self,filename=None):
        #save the results to a file        
        H_theory=self.H_theory(self.H.getfreqs(),[self.n[:,1].real,self.n[:,1].imag],self.l_opt)        
        #built the variable that should be saved:        
        savetofile=py.column_stack((
        self.H.getfreqs(), #frequencies
        self.n[:,1].real,-self.n[:,1].imag, #the real and imaginary part of n
        self.n[:,2].real,-self.n[:,2].imag, #the real and imaginary part of the smoothed n
        self.H.getFReal(),self.H.getFImag(),#H_measured
        self.H.getFRealUnc(),self.H.getFImagUnc(),#uncertainties
        self.H.getFAbs(),self.H.getFPh(),#absH,ph H measured    
        H_theory.real,H_theory.imag, #theoretic H
        ))

        headerstr=('freq, ' 
        'ref_ind_real, ref_ind_imag, '
        'ref_ind_sreal, ref_ind_simag, '
        'H_measured_real, H_measured_imag, '
        'Hunc_real, Hunc_imag, '
        'abs(H_measured), angle(H_measured), '
        'H_theory_real, H_theory_imag')
        if filename==None:
            fname=self.getFilenameSuggestion()
        else:
            fname=filename+"_"
        fname+='analyzed_' + 'D=' + str(self.l_opt/1e-6) +'.txt'
        py.savetxt(fname,savetofile,delimiter=',',header=headerstr)
        
        # Save in a separate file the results of the simplified calculation of n, k, alpha end epsilon along with their unc
        headerstr=('freq, ' 
        'ref_ind_real, ref_ind_imag, '
        'u(ref_ind_real), u(ref_ind_imag), '
        'std(l)_n, std(Esam)_n, std(Eref)_n, f(Theta)_n, f(k<<<)_n, f(FP)_n, f(n0)_n, '
        'std(l)_k, std(Esam)_k, std(Eref)_k, f(Theta)_k, f(k<<<)_k, f(FP)_k, f(n0)_k, '
        'Epsilon_1, Epsilon_2, '
        'u(Epsilon_1), u(Epsilon_2), '
        'alpha, u(alpha), alpha_max, ')
        
        if filename==None:
            fname=self.getFilenameSuggestion()
        else:
            fname=filename+"_"
            
        fname+='SimplifiedAnalysis_' + 'D=' + str(self.l_opt/1e-6) +'.txt'
        py.savetxt(fname,self.n_with_unc,delimiter=',',header=headerstr)
Esempio n. 15
0
    def calculatefdData(self):
        #this function overrides the original fdData (that takes normally a tdData and does the fft)
        #here instead we use the fdref and fdsam objects to calculate H
        
        #check if it is possible to divide the Fdsam and Fdref objects
        prob_str=self._checkDataIntegrity()
        if not prob_str=='good':
            print("interpolation required")
            print(prob_str)
            self._commonFreqSamRef(prob_str)
        
        #calculate the uncertainty of H_real and H_imag
        H_unc=self.calculateFDunc()

        #phase
        H_ph=self.fdref.getFPh()-self.fdsam.getFPh()
        #H itself
        H=(self.fdsam.getFReal()+1j*self.fdsam.getFImag())/(self.fdref.getFReal()+1j*self.fdref.getFImag())
        H=py.column_stack((self.fdref.getfreqs(),H.real,H.imag,abs(H),H_ph,H_unc))
        return H    
Esempio n. 16
0
    def calculaten(self,H,l):
        #this calculates n for a given transferfunction H and a given thickness l
    
        #calculate the initial values
        inits=py.asarray(self.calculateinits(H,l))
        
        res=[] #the array of refractive index
        vals=[] # the array of error function values
        bnds=((1,None),(0,None)) #not used at the moment, with SLSQP bnds can be introduced
        nums=len(H[:,0])
        #minimize the deviation of H_theory to H_measured for each frequency
        for i in range(nums):
#            t=minimize(self.error_func,[inits[0,i],inits[1,i]],args=(H[i,:2],l), method='SLSQP',\
#            bounds=bnds, options={'ftol':1e-9,'maxiter':2000, 'disp': False})
            t=minimize(self.error_func,[inits[0,i],inits[1,i]],args=(H[i,:3],l), method='Nelder-Mead',
            options={'xtol': 1e-6,'disp':False})
            res.append(t.x[0]-1j*t.x[1])
            vals.append(t.fun)
        n=py.asarray(res)
        #self.n is a 5xlengthf array, frequency,n_real,n_imag,n_smoothed_real,n_smoothed_imag
        self.n=py.column_stack((H[:,0],n,n))
        return n
Esempio n. 17
0
 def calculateFDunc(self):  
     #Calculates the uncertainty of the FFT according to:
     #   - J. M. Fornies-Marquina, J. Letosa, M. Garcia-Garcia, J. M. Artacho, "Error Propagation for the transformation of time domain into frequency domain", IEEE Trans. Magn, Vol. 33, No. 2, March 1997, pp. 1456-1459
     
     # Calculate the uncertainty of the real and imaginary part of H
     #x=[a,b,c,d]
     dfda=lambda x: x[2]/(x[2]**2+x[3]**2)
     dfdb=lambda x: x[3]/(x[2]**2+x[3]**2)
     dfdc=lambda x: (x[0]*x[3]**2-x[0]*x[2]**2-2*x[1]*x[2]*x[3])/(x[2]**2+x[3]**2)**2
     dfdd=lambda x: (x[1]*x[2]**2-x[1]*x[3]**2-2*x[0]*x[2]*x[3])/(x[2]**2+x[3]**2)**2
     
     dgda=lambda x: -x[3]/(x[2]**2+x[3]**2)
     dgdb=lambda x: x[2]/(x[2]**2+x[3]**2)
     dgdc=lambda x: -(x[1]*x[2]**2-x[1]*x[3]**2+2*x[0]*x[2]*x[3])/(x[2]**2+x[3]**2)**2
     dgdd=lambda x: (x[0]*x[3]**2-x[0]*x[2]**2-2*x[1]*x[2]*x[3])/(x[2]**2+x[3]**2)**2
     
     ta=self.fdsam.getFReal()
     tb=self.fdsam.getFImag()
     tc=self.fdref.getFReal()
     td=self.fdref.getFImag()
     
     H_unc_real2=(self.fdsam.getFRealUnc()*dfda(py.asarray([ta,tb,tc,td])))**2
     H_unc_real2+=(self.fdsam.getFImagUnc()*dfdb(py.asarray([ta,tb,tc,td])))**2
     H_unc_real2+=(self.fdref.getFRealUnc()*dfdc(py.asarray([ta,tb,tc,td])))**2
     H_unc_real2+=(self.fdref.getFImagUnc()*dfdd(py.asarray([ta,tb,tc,td])))**2
     
     H_unc_imag2=(self.fdsam.getFRealUnc()*dgda(py.asarray([ta,tb,tc,td])))**2
     H_unc_imag2+=(self.fdsam.getFImagUnc()*dgdb(py.asarray([ta,tb,tc,td])))**2
     H_unc_imag2+=(self.fdref.getFRealUnc()*dgdc(py.asarray([ta,tb,tc,td])))**2
     H_unc_imag2+=(self.fdref.getFImagUnc()*dgdd(py.asarray([ta,tb,tc,td])))**2
     
     # Calculate the uncertainty of the modulus and phase of H
     H_uncabs = py.sqrt((self.fdsam.getFAbsUnc()/self.fdref.getFAbs())**2 + (self.fdsam.getFAbs()*self.fdref.getFAbsUnc())**2/self.fdref.getFAbs()**4)
     H_uncph = py.sqrt(self.fdsam.getFPhUnc()**2 + self.fdref.getFPhUnc()**2)
     
     return py.column_stack((py.sqrt(H_unc_real2),py.sqrt(H_unc_imag2),H_uncabs,H_uncph))
Esempio n. 18
0
def plot_uvj_vs_icd():
    #galaxies=mk_galaxy_struc()
    galaxies = pickle.load(open('galaxies.pickle', 'rb'))
    #Take out the UDF data
    #galaxies = filter(lambda galaxy: galaxy.field == 1, galaxies)
    #galaxies = filter(lambda galaxy: -0.05 < galaxy.ICD_IH < 0.25, galaxies)
    galaxies = filter(lambda galaxy: galaxy.ICD_IH != None, galaxies)

    #f,(ax1, ax2) = pyl.subplots(1,2,sharex=True, sharey=True,figsize=(6.25,4.5))

    F = pyl.figure(1, figsize=(8, 4))
    grid = AxesGrid(F,
                    111,
                    nrows_ncols=(1, 3),
                    axes_pad=0.1,
                    add_all=True,
                    label_mode='L',
                    share_all=True,
                    cbar_location='top',
                    cbar_mode='each')
    ax1 = grid[0]
    ax2 = grid[1]
    ax3 = grid[2]

    uv = []
    vj = []
    icd = []
    mass = []

    appenduv = uv.append
    appendvj = vj.append
    appendicd = icd.append
    appendmass = mass.append

    #Build Arrays
    for galaxy in galaxies:
        if galaxy.ston_I > 30.:
            appenduv(-2.5 * pyl.log10(galaxy.Uflux_rest / galaxy.Vflux_rest))
            appendvj(-2.5 * pyl.log10(galaxy.Vflux_rest / galaxy.Jflux_rest))
            if galaxy.ICD_IH > 0.5:
                appendicd(0.5)
            else:
                appendicd(galaxy.ICD_IH)
            appendmass(galaxy.Mass)

    x = [g for g in galaxies if g.ston_I > 30. and g.Mips != None]
    uv2 = []
    vj2 = []
    mips = []
    appenduv2 = uv2.append
    appendvj2 = vj2.append
    appendmips = mips.append

    for galaxy in x:
        appenduv2(-2.5 * pyl.log10(galaxy.Uflux_rest / galaxy.Vflux_rest))
        appendvj2(-2.5 * pyl.log10(galaxy.Vflux_rest / galaxy.Jflux_rest))
        if galaxy.Mips > 45:
            appendmips(45.)
        else:
            appendmips(galaxy.Mips)

    #Convert to Numpy Array
    uv = pyl.asarray(uv)
    vj = pyl.asarray(vj)
    uv2 = pyl.asarray(uv2)
    vj2 = pyl.asarray(vj2)
    icd = pyl.asarray(icd)
    mass = pyl.asarray(mass)
    mips = pyl.asarray(mips)

    #Build Plotting Matrices
    cut = pyl.column_stack((uv, vj, icd * 100., mass))
    cut3 = pyl.column_stack((uv2, vj2, mips))

    cut = colsort(cut, 3)
    cut2 = colsort(cut, 4)
    cut3 = colsort(cut3, 3)

    #plot!
    sc1 = ax1.scatter(cut[:, 1], cut[:, 0], c=cut[:, 2], s=50, cmap='Spectral')
    sc2 = ax2.scatter(cut2[:, 1],
                      cut2[:, 0],
                      c=cut2[:, 3],
                      s=50,
                      cmap='Spectral')
    sc3 = ax3.scatter(cut3[:, 1],
                      cut3[:, 0],
                      c=cut3[:, 2],
                      s=50,
                      cmap='Spectral')

    #Add Lines
    ax1.set_ylim(-0.5, 2.5)
    ax1.set_xlim(-1.5, 2.5)

    limits = ax1.axis()
    ax1.axis
    #x = [limits[0], 0.69, 1.4,1.4]
    #y = [1.2, 1.2, 1.82, limits[3]]
    x = [limits[0], 0.92, 1.6, 1.6]
    y = [1.3, 1.3, 1.89, limits[3]]

    ax1.plot(x, y, lw=2, c='k')
    ax2.plot(x, y, lw=2, c='k')
    ax3.plot(x, y, lw=2, c='k')

    #Add the color bar and labels and stuff
    grid.cbar_axes[0].colorbar(sc1)
    grid.cbar_axes[1].colorbar(sc2)
    grid.cbar_axes[2].colorbar(sc3)

    ax = grid.cbar_axes[0]
    ax.axis["top"].toggle(ticks=True, ticklabels=True, label=True)
    ax.set_xlabel(r'$\xi[i_{775},H_{160}]$ (%)', fontsize=16)
    ax = grid.cbar_axes[1]
    ax.set_xlabel(r'Log Mass $(M_\odot)$', fontsize=16)
    ax = grid.cbar_axes[2]
    ax.set_xlabel(r'24$\mu$m ($\mu$Jy)', fontsize=16)

    grid.axes_llc.set_xticks([-1, 0, 1, 2])
    grid.axes_llc.set_yticks([0, 1, 2])

    ax1.set_ylabel('$(U-V)_{Rest}$')
    ax1.set_xlabel('$(V-J)_{Rest}$')
    ax2.set_xlabel('$(V-J)_{Rest}$')
    ax3.set_xlabel('$(V-J)_{Rest}$')

    pyl.tight_layout()
    pyl.savefig('UVJ_vs_icd_mass.eps', bbox='tight')
    pyl.show()
Esempio n. 19
0
File: shuffle.py Progetto: boada/ICD
import pylab as pyl
import cPickle as pickle

galaxies = pickle.load(open('./galaxies.pickle','rb'))
galaxies = filter(lambda galaxy: galaxy.ston_I > 30., galaxies)

mergers = pyl.asarray([galaxy.Merger for galaxy in galaxies])
icd = pyl.asarray([galaxy.ICD_IH*100 for galaxy in galaxies])

stack = pyl.column_stack((mergers, icd))

result =[]
for i in range(10000):
    # shuffle the icd values
    pyl.shuffle(stack[:,1])

    #get the high ICD ones
    gt = pyl.where(stack[:,1] > 20)

    # are they mergers?
    y = stack[:,0][gt]

    #how many mergers?
    m = len(y.nonzero()[0])

    #what percentage?
    per = m/float(len(gt[0]))

    # save that percentage
    result.append(per)
Esempio n. 20
0
hdulist =\
pyf.open('/home/steven/Projects/image_fields/CANDELS/GOODS_S/catalogs/results_gsd_fit_zsol_chab_cb07.fits')
tbdata=hdulist[1].data

icd = pyl.loadtxt('gini_m20/icd_1.5_3.5_gsd_full_ston.txt')

f1 = pyl.figure(1,figsize=(6,4))
f1s1 = f1.add_subplot(111)

icd1 = []
sfr = []
appendicd1 = icd1.append
appendsfr = sfr.append

for i in range(len(icd)):
    if icd[i][11] > 30.0:
        for j in range(len(tbdata.field('ID'))):
            if icd[i][0] == tbdata.field('ID')[j]:
                print icd[i][0], tbdata.field('ID')[j]
                appendicd1(icd[i][9])
                appendsfr(tbdata.field('SFR')[j])

icd1 = pyl.asarray(icd1)
sfr = pyl.asarray(sfr)

plt_matrix=pyl.column_stack((sfr,icd1))

f1s1.scatter(pyl.log10(plt_matrix[:,0]),plt_matrix[:,1],s=50)

pyl.show()
Esempio n. 21
0
def plot_color_vs_mass_vs_icd():
    #galaxies=mk_galaxy_struc()
    galaxies = pickle.load(open('galaxies.pickle', 'rb'))

    F = pyl.figure(1, figsize=(6, 3.5))
    grid = AxesGrid(F,
                    111,
                    nrows_ncols=(1, 1),
                    add_all=True,
                    label_mode='L',
                    cbar_location='right',
                    cbar_mode='each',
                    aspect=False)

    color1 = []
    mass1 = []
    icd1 = []
    color2 = []
    mass2 = []
    icd2 = []

    for galaxy in galaxies:
        if galaxy.ston_I > 30. and galaxy.ICD_IH != None:
            mass1.append(galaxy.Mass)
            color1.append(galaxy.Imag - galaxy.Hmag)
            icd1.append(pyl.log10(galaxy.ICD_IH * 100))
            '''
            if galaxy.ICD_IH < -0.05:
                mass1.append(galaxy.Mass)
                color1.append(galaxy.Imag-galaxy.Hmag)
                icd1.append(-0.05*100)
            elif -0.05 < galaxy.ICD_IH < 0.25:
                mass1.append(galaxy.Mass)
                color1.append(galaxy.Imag-galaxy.Hmag)
                icd1.append(galaxy.ICD_IH*100.)
            else:
                mass1.append(galaxy.Mass)
                color1.append(galaxy.Imag-galaxy.Hmag)
                icd1.append(0.25*100.)
            '''
        elif galaxy.ICD_IH != None:
            mass2.append(galaxy.Mass)
            color2.append(galaxy.Imag - galaxy.Hmag)
            icd2.append(galaxy.ICD_IH * 100)

    # Sort the arrays by ICD
    mass1 = pyl.asarray(mass1)
    color1 = pyl.asarray(color1)
    icd1 = pyl.asarray(icd1)

    IH_array = pyl.column_stack((mass1, color1, icd1))
    IH_array = colsort(IH_array, 3)

    #sc2 = grid[0].scatter(mass2, icd2, c='0.8', s=20)
    sc1 = grid[0].scatter(IH_array[:, 0],
                          IH_array[:, 1],
                          c=IH_array[:, 2],
                          s=50,
                          cmap='spectral')

    grid.cbar_axes[0].colorbar(sc1)
    grid.cbar_axes[0].set_ylabel(r'Log $\xi[i_{775},H_{160}]$ (%)')

    #grid[0].set_xscale('log')
    #grid[0].set_xlim(3e7,1e12)
    #grid[0].set_ylim(0.0,3.5)
    grid[0].set_xlabel(r"Log Mass $(M_{\odot})$")
    grid[0].set_ylabel("$(i_{775}-H_{160})_{Observed}$")
    grid[0].set_yticks([0, 1, 2, 3])
    grid[0].set_xticks([8, 9, 10, 11, 12])

    #pyl.tight_layout()
    #pyl.savefig('color_vs_mass_vs_icd_IH.eps',bbox='tight')

    pyl.show()
Esempio n. 22
0
    def calculateinitsunc(self,H,l,sigma_L = 1e-6,sigma_Theta = 1,n_exact = 1,filename=None):
        # Calculates the uncertianty on n and k according to:
        # W. Withayachumnankul, B. M. Fisher, H. Lin, D. Abbott, "Uncertainty in terahertz time-domain spectroscopy measurement", J. Opt. Soc. Am. B., Vol. 25, No. 6, June 2008, pp. 1059-1072
        #
        # sigma_L = standard uncertainty on sample thickness in meter
        # sigma_Theta = interval of sample misallignment in degree
        # n_exact = exact value of the refractive index of air during the measurements
        
        n, k = self.calculateinits(H,l)
        n = py.asarray(n)
        k = py.asarray(k)      
        
        Asam = []
        Aref = []
        Bsam = []
        Bref = []
        for i in range(len(self.H.getfreqs())):
            Asam.append((py.sum(py.imag(self.H.fdsam.getFAbs().tolist()[i]*py.exp(1j*2*py.pi*self.H.getfreqs().tolist()[i]*self.H.fdsam._tdData.getTimes()))*self.H.fdsam._tdData.getUncEX())**2))
            Aref.append((py.sum(py.imag(self.H.fdref.getFAbs().tolist()[i]*py.exp(1j*2*py.pi*self.H.getfreqs().tolist()[i]*self.H.fdref._tdData.getTimes()))*self.H.fdref._tdData.getUncEX())**2))
            Bsam.append((py.sum(py.real(self.H.fdsam.getFAbs().tolist()[i]*py.exp(1j*2*py.pi*self.H.getfreqs().tolist()[i]*self.H.fdsam._tdData.getTimes()))*self.H.fdsam._tdData.getUncEX())**2))
            Bref.append((py.sum(py.real(self.H.fdref.getFAbs().tolist()[i]*py.exp(1j*2*py.pi*self.H.getfreqs().tolist()[i]*self.H.fdref._tdData.getTimes()))*self.H.fdref._tdData.getUncEX())**2))
        
        # Uncertainty on n
        sn_Esam_2 = ((c/(2*py.pi*self.H.getfreqs()*l))**2 * py.asarray(Asam)/self.H.fdsam.getFAbs()**4)/self.H.fdsam._tdData.numberOfDataSets
        sn_Eref_2 = ((c/(2*py.pi*self.H.getfreqs()*l))**2 * py.asarray(Aref)/self.H.fdref.getFAbs()**4)/self.H.fdref._tdData.numberOfDataSets
        sn_l_2 = ((n-self.n_0)*sigma_L/l)**2
        #sn_l_2_1 = (c*self.H.getFPh()/(2*py.pi*self.H.getfreqs()*l*l))**2 * sigma_L**2
        #sn_H_2 = (c/(2*py.pi*self.H.getfreqs()*l))**2 * self.H.getFPhUnc()**2
        fn_Theta = (n-self.n_0.real)*(1/py.cos(sigma_Theta*py.pi/180)-1)
        fn_H = (c/(2*py.pi*self.H.getfreqs()*l))*py.absolute(-py.angle(4*(n-1j*k)*self.n_0/(n-1j*k+self.n_0)**2))
        fn_FP = (c/(2*py.pi*self.H.getfreqs()*l))*py.absolute(-py.angle(1/(1-((n-1j*k-self.n_0)/(n-1j*k+self.n_0))**2*py.exp(-2*1j*(n-1j*k)*2*py.pi*self.H.getfreqs()*l/c))))
        fn_n0 = abs(self.n_0.real - n_exact)*py.ones(len(self.H.getFPh()))
        u_n = py.sqrt(sn_l_2+sn_Esam_2+sn_Eref_2)+fn_Theta+fn_H+fn_FP+fn_n0

        # Uncertianty on k
        sk_Esam_2 = ((c/(2*py.pi*self.H.getfreqs()*l))**2 *(Bsam/self.H.fdsam.getFAbs()**4 + ((n-self.n_0)/(n+self.n_0))**2 * sn_Esam_2/n**2))/self.H.fdsam._tdData.numberOfDataSets
        sk_Eref_2 = ((c/(2*py.pi*self.H.getfreqs()*l))**2 *(Bref/self.H.fdref.getFAbs()**4 + ((n-self.n_0)/(n+self.n_0))**2 * sn_Eref_2/n**2))/self.H.fdref._tdData.numberOfDataSets
        sk_l_2 = (k*sigma_L/l)**2 + (c*(n-self.n_0)/((n+self.n_0)*n*2*py.pi*self.H.getfreqs()*l))**2*sn_l_2
        #sk_l_2_1 = ((c/(2*py.pi*self.H.getfreqs()*l*l))*py.log(self.H.getFAbs()*(n+self.n_0.real)**2/(4*n*self.n_0.real)))**2 * sigma_L**2
        #sk_H_2 = (-c/(2*py.pi*self.H.getfreqs()*l*self.H.getFAbs()))**2 * self.H.getFAbsUnc()**2
        fk_Theta = k*(1/py.cos(sigma_Theta*py.pi/180)-1)+c*(n-self.n_0.real)*fn_Theta/(n*2*py.pi*self.H.getfreqs()*l*(n+self.n_0.real))
        fk_H = (c/(2*py.pi*self.H.getfreqs()*l))*(py.log(py.absolute(n/(n-1j*k)*((n-1j*k+self.n_0.real)/(n+self.n_0.real))**2))+py.absolute(fn_H)*(n-self.n_0.real)/(n*(n+self.n_0.real)))
        fk_FP = (c/(2*py.pi*self.H.getfreqs()*l))*(py.absolute(-py.log(py.absolute(1/(1-((n-1j*k-self.n_0)/(n-1j*k+self.n_0))**2*py.exp(-2*1j*(n-1j*k)*2*py.pi*self.H.getfreqs()*l/c)))))+py.absolute(fn_FP)*(n-self.n_0.real)/(n*(n+self.n_0.real)))
        fk_n0 = (c/(2*py.pi*self.H.getfreqs()*l))*(n-self.n_0.real)*(self.n_0.real - n_exact)/(n*self.n_0.real)
        u_k = py.sqrt(sk_l_2+sk_Esam_2+sk_Eref_2)+fk_Theta+fk_H+fk_FP+fk_n0
        
        # Convert n in epsilon Epsilon = Epsilon_1 + j Epsilon_2 = (n+jk)**2
        # Epsilon_1 = n**2 - k**2
        # Epsilon_2 = -2nk
        Epsilon_1 = n**2 - k **2
        Epsilon_2 = -2 * n * k
        u_Epsilon_1 = py.sqrt((2*n*u_n)**2 + (-2*k*u_k)**2)
        u_Epsilon_2 = py.sqrt((-2*k*u_n)**2 + (-2*n*u_k)**2)
        
        # Calculate absorption coefficient
        # alpha = 4 * pi * k * f / c1
        alpha = 4 * py.pi * k * self.H.getfreqs() / (100 * c)      # in cm^-1
        u_alpha = 4 * py.pi * u_k * self.H.getfreqs() / (100 * c)  # in cm^-1
        
        # Calculate maximum measurable absorption coefficient according to
        # P. U. Jepsen and B. M. Fisher: "Dynamic Range in terahertz time-domain transmission and reflection spectroscopy", Optics Letters, Vol. 30, n. 1, pp. 29-31, Jan 2005
        
        alpha_max = 2 * py.log((self.H.fdsam.getDR() * 4 * n)/(n + 1)**2) / (100 * l) # in cm^-1
        
        # Save results into a table accessible from outside
        self.n_with_unc=py.real(py.column_stack((
        self.H.getfreqs(),                            # frequencies
        n, k,                                         # real and imaginary part of n
        u_n, u_k,                                     # k=1 combined uncertainty on n and k
        py.sqrt(sn_l_2), py.sqrt(sn_Esam_2), py.sqrt(sn_Eref_2), fn_Theta, fn_H, fn_FP, fn_n0, # Uncertainty components of n due to thickness, H, sample misallignment, k<<<, Neglect FP, ref ind of air
        py.sqrt(sk_l_2), py.sqrt(sk_Esam_2), py.sqrt(sk_Eref_2), fk_Theta, fk_H, fk_FP, fk_n0, # Uncertainty components of k due to thickness, H, sample misallignment, k<<<, Neglect FP, ref ind of air
        Epsilon_1, Epsilon_2,                         # Real and imaginary part of Epsilon
        u_Epsilon_1, u_Epsilon_2,                     # k = 1 uncertainty on the real and imaginary part of Epsilon
        alpha, u_alpha,                               # Absorption coefficient and its k = 1 uncertainty
        alpha_max,                                     # Maximum measurable absorption coefficient
        )))
        return
Esempio n. 23
0
def plot_color_vs_mass_vs_icd():
    galaxies = mk_galaxy_struc()
    # Add the figures

    #    pyl.rcParams.update(mplparams.aps['params'])

    # Mass vs color plot I-H
    f1 = pyl.figure('CM_ICD_IH', figsize=(6, 4))
    f1s1 = f1.add_subplot(111)

    # Mass vs color plot J-H
    f2 = pyl.figure('CM_ICD_ZH', figsize=(8, 8))
    f2s1 = f2.add_subplot(111)

    # Mass vs color plot Z-H
    f3 = pyl.figure('CM_ICD_JH', figsize=(8, 8))
    f3s1 = f3.add_subplot(111)

    color1 = []
    mass1 = []
    icd1 = []
    color2 = []
    mass2 = []
    icd2 = []
    color3 = []
    mass3 = []
    icd3 = []

    for i in range(len(galaxies)):
        if galaxies[i].ston_I > 30.0:
            if -0.05 < galaxies[i].ICD_IH and galaxies[i].ICD_IH < 0.25:
                mass1.append(galaxies[i].Mass)
                color1.append(galaxies[i].Imag - galaxies[i].Hmag)
                icd1.append(galaxies[i].ICD_IH * 100.)
            else:
                mass1.append(galaxies[i].Mass)
                color1.append(galaxies[i].Imag - galaxies[i].Hmag)
                icd1.append(0.25 * 100.)

        if galaxies[i].ston_Z > 30.0:
            if -0.05 < galaxies[i].ICD_ZH and galaxies[i].ICD_ZH < 0.25:
                mass2.append(galaxies[i].Mass)
                color2.append(galaxies[i].Zmag - galaxies[i].Hmag)
                icd2.append(galaxies[i].ICD_ZH)
            else:
                mass2.append(galaxies[i].Mass)
                color2.append(galaxies[i].Zmag - galaxies[i].Hmag)
                icd2.append(0.3)

        if galaxies[i].ston_J > 30.0:
            if -0.05 < galaxies[i].ICD_JH and galaxies[i].ICD_JH < 0.25:
                mass3.append(galaxies[i].Mass)
                color3.append(galaxies[i].Jmag - galaxies[i].Hmag)
                icd3.append(galaxies[i].ICD_JH)
            else:
                mass3.append(galaxies[i].Mass)
                color3.append(galaxies[i].Jmag - galaxies[i].Hmag)
                icd3.append(0.3)

    # Sort the arrays by ICD
    mass1 = pyl.asarray(mass1)
    color1 = pyl.asarray(color1)
    icd1 = pyl.asarray(icd1)
    mass2 = pyl.asarray(mass2)
    color2 = pyl.asarray(color2)
    icd2 = pyl.asarray(icd2)
    mass3 = pyl.asarray(mass3)
    color3 = pyl.asarray(color3)
    icd3 = pyl.asarray(icd3)

    IH_array = pyl.column_stack((mass1, color1, icd1))
    ZH_array = pyl.column_stack((mass2, color2, icd2))
    JH_array = pyl.column_stack((mass3, color3, icd3))

    IH_array = colsort(IH_array, 3)
    ZH_array = colsort(ZH_array, 3)
    JH_array = colsort(JH_array, 3)

    sc1 = f1s1.scatter(IH_array[:, 0],
                       IH_array[:, 1],
                       c=IH_array[:, 2],
                       s=50,
                       cmap='spectral',
                       edgecolor='w')
    sc2 = f2s1.scatter(ZH_array[:, 0],
                       ZH_array[:, 1],
                       c=ZH_array[:, 2],
                       s=50,
                       cmap='spectral')
    sc3 = f3s1.scatter(JH_array[:, 0],
                       JH_array[:, 1],
                       c=JH_array[:, 2],
                       s=50,
                       cmap='spectral')

    ############
    # FIGURE 1 #
    ############
    pyl.figure('CM_ICD_IH')

    bar = pyl.colorbar(sc1)
    bar.set_label(r"$\xi[I,H]$ (%)")

    f1s1.set_xscale('log')
    f1s1.set_xlim(3e7, 1e12)
    f1s1.set_ylim(0.0, 3.5)
    f1s1.set_xlabel(r"Mass $[M_{\odot}]$")
    f1s1.set_ylabel("$(I-H)_{Observed}$")

    pyl.subplots_adjust(left=0.16, bottom=0.23, right=0.74)
    #pyl.tight_layout()
    pyl.savefig('color_vs_mass_vs_icd_IH.eps', bbox='tight')

    ############
    # FIGURE 2 #
    ############
    pyl.figure('CM_ICD_ZH')
    bar = pyl.colorbar(sc2)
    bar.set_label(r"$\xi[Z,H]$", fontsize=20)

    f2s1.set_xscale('log')
    f2s1.set_xlim(3e7, 1e12)
    f2s1.set_ylim(0.0, 3.5)
    f2s1.set_xlabel(r"$Log_{10}(M_{\odot})$", fontsize=20)
    f2s1.set_ylabel("$(Z-H)_{Observed}$", fontsize=20)
    f2s1.tick_params(axis='both', pad=7)
    pyl.savefig('color_vs_mass_vs_icd_ZH.eps')

    ############
    # FIGURE 3 #
    ############
    pyl.figure('CM_ICD_JH')
    bar = pyl.colorbar(sc3)
    bar.set_label(r"$\xi[J,H]$", fontsize=20)

    f3s1.set_xscale('log')
    f3s1.set_xlim(3e7, 1e12)
    f3s1.set_ylim(-0.5, 1.5)
    f3s1.set_xlabel(r"$Log_{10}(M_{\odot})$", fontsize=20)
    f3s1.set_ylabel("$(J-H)_{Observed}$", fontsize=20)
    f3s1.tick_params(axis='both', pad=7)
    pyl.savefig('color_vs_mass_vs_icd_JH.eps')

    pyl.show()
Esempio n. 24
0
def plot_uvj_vs_icd():
    #galaxies=mk_galaxy_struc()
    galaxies = pickle.load(open('galaxies.pickle','rb'))
    #Take out the UDF data
    #galaxies = filter(lambda galaxy: galaxy.field == 1, galaxies)
    #galaxies = filter(lambda galaxy: -0.05 < galaxy.ICD_IH < 0.25, galaxies)
    galaxies = filter(lambda galaxy: galaxy.ICD_IH != None, galaxies)

    #f,(ax1, ax2) = pyl.subplots(1,2,sharex=True, sharey=True,figsize=(6.25,4.5))

    F = pyl.figure(1,figsize=(8,4))
    grid = AxesGrid(F, 111,
                        nrows_ncols=(1,3),
                        axes_pad = 0.1,
                        add_all=True,
                        label_mode = 'L',
                        share_all=True,
                        cbar_location = 'top',
                        cbar_mode = 'each')
    ax1 = grid[0]
    ax2 = grid[1]
    ax3 = grid[2]

    uv =[]
    vj =[]
    icd = []
    mass= []

    appenduv = uv.append
    appendvj = vj.append
    appendicd = icd.append
    appendmass = mass.append

    #Build Arrays
    for galaxy in galaxies:
        if galaxy.ston_I > 30.:
            appenduv(-2.5*pyl.log10(galaxy.Uflux_rest/galaxy.Vflux_rest))
            appendvj(-2.5*pyl.log10(galaxy.Vflux_rest/galaxy.Jflux_rest))
            if galaxy.ICD_IH > 0.5:
                appendicd(0.5)
            else:
                appendicd(galaxy.ICD_IH)
            appendmass(galaxy.Mass)

    x = [g for g in galaxies if g.ston_I > 30. and g.Mips != None]
    uv2 =[]
    vj2 =[]
    mips =[]
    appenduv2 = uv2.append
    appendvj2 = vj2.append
    appendmips = mips.append

    for galaxy in x:
        appenduv2(-2.5*pyl.log10(galaxy.Uflux_rest/galaxy.Vflux_rest))
        appendvj2(-2.5*pyl.log10(galaxy.Vflux_rest/galaxy.Jflux_rest))
        if galaxy.Mips > 45:
            appendmips(45.)
        else:
            appendmips(galaxy.Mips)

    #Convert to Numpy Array
    uv = pyl.asarray(uv)
    vj = pyl.asarray(vj)
    uv2 = pyl.asarray(uv2)
    vj2 = pyl.asarray(vj2)
    icd = pyl.asarray(icd)
    mass = pyl.asarray(mass)
    mips = pyl.asarray(mips)

    #Build Plotting Matrices
    cut = pyl.column_stack((uv, vj, icd*100., mass))
    cut3 = pyl.column_stack((uv2, vj2, mips))

    cut = colsort(cut,3)
    cut2 = colsort(cut,4)
    cut3 = colsort(cut3,3) 

    #plot!
    sc1 = ax1.scatter(cut[:,1], cut[:,0], c=cut[:,2], s=50, cmap='Spectral')
    sc2 = ax2.scatter(cut2[:,1], cut2[:,0], c=cut2[:,3], s=50, cmap='Spectral')
    sc3 = ax3.scatter(cut3[:,1], cut3[:,0], c=cut3[:,2], s=50, cmap='Spectral')

    #Add Lines
    ax1.set_ylim(-0.5,2.5)
    ax1.set_xlim(-1.5,2.5)

    limits = ax1.axis()
    ax1.axis
    #x = [limits[0], 0.69, 1.4,1.4]
    #y = [1.2, 1.2, 1.82, limits[3]]
    x = [limits[0], 0.92, 1.6,1.6]
    y = [1.3, 1.3, 1.89, limits[3]]

    ax1.plot(x,y,lw=2,c='k')
    ax2.plot(x,y,lw=2,c='k')
    ax3.plot(x,y,lw=2,c='k')

    #Add the color bar and labels and stuff
    grid.cbar_axes[0].colorbar(sc1)
    grid.cbar_axes[1].colorbar(sc2)
    grid.cbar_axes[2].colorbar(sc3)

    ax = grid.cbar_axes[0]
    ax.axis["top"].toggle(ticks=True, ticklabels=True, label=True)
    ax.set_xlabel(r'$\xi[i_{775},H_{160}]$ (%)', fontsize=16)
    ax = grid.cbar_axes[1]
    ax.set_xlabel(r'Log Mass $(M_\odot)$', fontsize=16)
    ax = grid.cbar_axes[2]
    ax.set_xlabel(r'24$\mu$m ($\mu$Jy)', fontsize=16)

    grid.axes_llc.set_xticks([-1,0,1,2])
    grid.axes_llc.set_yticks([0,1,2])

    ax1.set_ylabel('$(U-V)_{Rest}$')
    ax1.set_xlabel('$(V-J)_{Rest}$')
    ax2.set_xlabel('$(V-J)_{Rest}$')
    ax3.set_xlabel('$(V-J)_{Rest}$')

    pyl.tight_layout()
    pyl.savefig('UVJ_vs_icd_mass.eps',bbox='tight')
    pyl.show()
Esempio n. 25
0
def plot_color_vs_mass_vs_icd():
    galaxies=mk_galaxy_struc()
    # Add the figures

#    pyl.rcParams.update(mplparams.aps['params'])

    # Mass vs color plot I-H
    f1 = pyl.figure('CM_ICD_IH',figsize=(6,4))
    f1s1 = f1.add_subplot(111)

    label =[]
    color = []
    mass = []
    sersic = []

    for galaxy in galaxies:
        if galaxy.ston_I >30. and galaxy.sersic <= 1.6 and galaxy.sersic >= 0.:
            if galaxy.sersic > 1.6:
                sersic.append(1.6)
            else:
                sersic.append(galaxy.sersic)
            #color.append(galaxy.Imag-galaxy.Hmag)
            color.append(galaxy.ICD_IH)
            mass.append(galaxy.Mass)
            label.append(galaxy.ID)

    # Sort the arrays by ICD
    mass = pyl.asarray(mass)
    color = pyl.asarray(color)
    sersic = pyl.asarray(sersic)

    IH_array = pyl.column_stack((mass,color,sersic,label))

    IH_array = colsort(IH_array,3)

    '''
    for label,x,y in zip(IH_array[:,3],IH_array[:,0], IH_array[:,1]):
        pyl.annotate(label,xy=(x,y),
            xytext=(x,y),textcoords='data',ha='right',va='bottom',
            bbox=dict(boxstyle='round,pad=0.5',fc='yellow',alpha=0.5),
            arrowprops=dict(arrowstyle='->'))
    '''

    sc1 = f1s1.scatter(IH_array[:,0], IH_array[:,1], c=IH_array[:,2], s=50,
    cmap='spectral')


    ############
    # FIGURE 1 #
    ############
    pyl.figure('CM_ICD_IH')

    bar = pyl.colorbar(sc1)
    bar.set_label("Sersic Index, n")

    f1s1.set_xscale('log')
    f1s1.set_xlim(3e7,1e12)
    #f1s1.set_ylim(-0.1,3.5)
    f1s1.set_ylim(-0.01,0.25)
    f1s1.set_xlabel(r"Mass $[M_{\odot}]$")
    f1s1.set_ylabel("$(I-H)_{Observed}$")

    pyl.subplots_adjust(left=0.15, bottom=0.15, right=.75)
   # pyl.savefig('color_vs_mass_vs_icd_IH.eps',bbox='tight')

    pyl.show()
import numpy as np
import pylab as py

dir='/mount/riachuelo1/hahn/data/manera_mock/dr11/'
nbar=np.loadtxt(dir+'nbar-cmass-dr11may22-N-Anderson.dat')

i=0
while (nbar[i,0]<0.35):
    i=i+1

print i

output = py.column_stack((nbar[i:201,0],nbar[i:201,3]/max(nbar[i:201,3])))
py.savetxt(dir+'cp-redshift-nbar-dr11may22-N-Anderson.dat',output)

py.figure(1)
py.plot(output[:,0], output[:,1])
py.xlabel('Redshift (z)')
py.ylabel('Normalized n(z)')
py.show()
Esempio n. 27
0
def plot_uvj_vs_icd():
    galaxies=mk_galaxy_struc()
    #Take out the UDF data
    galaxies = filter(lambda galaxy: galaxy.field == 1, galaxies)
    galaxies = filter(lambda galaxy: -0.05 < galaxy.ICD_IH < 0.25, galaxies)

    #f,(ax1, ax2) = pyl.subplots(1,2,sharex=True, sharey=True,figsize=(6.25,4.5))

    F = pyl.figure(1,figsize=(6,3.1))
    grid = AxesGrid(F, 111,
                        nrows_ncols=(1,2),
                        axes_pad = 0.1,
                        add_all=True,
                        label_mode = 'L',
                        share_all=True,
                        cbar_location = 'top',
                        cbar_mode = 'single')
    ax1 = grid[0]
    ax2 = grid[1]

    uv =[]
    vj =[]
    icd = []
    uv_all =[]
    vj_all =[]
    icd_all = []

    appenduv = uv.append
    appendvj = vj.append
    appendicd = icd.append
    appenduv_all = uv_all.append
    appendvj_all = vj_all.append
    appendicd_all = icd_all.append

    #Build Arrays
    for galaxy in galaxies:
        if galaxy.ston_I >30. and galaxy.ston_H > 30.:
            appenduv(-2.5*pyl.log10(galaxy.Uflux_rest/galaxy.Vflux_rest))
            appendvj(-2.5*pyl.log10(galaxy.Vflux_rest/galaxy.Jflux_rest))
            appendicd(pyl.log10(galaxy.Mass))
        appenduv_all(-2.5*pyl.log10(galaxy.Uflux_rest/galaxy.Vflux_rest))
        appendvj_all(-2.5*pyl.log10(galaxy.Vflux_rest/galaxy.Jflux_rest))
        appendicd_all(pyl.log10(galaxy.Mass))


    #Convert to Numpy Array
    uv = pyl.asarray(uv)
    vj = pyl.asarray(vj)
    icd = pyl.asarray(icd)
    uv_all = pyl.asarray(uv_all)
    vj_all = pyl.asarray(vj_all)
    icd_all = pyl.asarray(icd_all)

    #Build Plotting Matrices
    cut = pyl.column_stack((uv,vj,icd))
    total = pyl.column_stack((uv_all,vj_all,icd_all))

    cut = colsort(cut,3)
    total = colsort(total,3)

    #plot!
    sc1 = ax1.scatter(total[:,1], total[:,0], c=total[:,2], s=50,
            cmap='spectral')
    sc2 = ax2.scatter(cut[:,1], cut[:,0], c=cut[:,2], s=50,
            cmap='spectral')

    #Add Lines
    ax1.set_ylim(-0.5,2.5)
    ax1.set_xlim(-1.5,2.5)

    limits = ax1.axis()
    ax1.axis
    x = [limits[0], 0.69, 1.4,1.4]
    y = [1.2, 1.2, 1.82, limits[3]]

    ax1.plot(x,y,lw=2,c='k')
    ax2.plot(x,y,lw=2,c='k')

    #Add the color bar and labels and stuff
    grid.cbar_axes[0].colorbar(sc2)
    ax = grid.cbar_axes[0]
    ax.axis["top"].toggle(ticks=True, ticklabels=True, label=True)
    ax.set_xlabel('Log Mass $[M_{\odot}]$')

    grid.axes_llc.set_xticks([-1,0,1,2])
    grid.axes_llc.set_yticks([0,1,2])

    ax1.set_ylabel('$U-V_{Rest}$')
    ax1.set_xlabel('$V-J_{Rest}$')
    ax2.set_xlabel('$V-J_{Rest}$')

    #pyl.savefig('UVJ_vs_mass.eps',bbox='tight')
    pyl.show()
Esempio n. 28
0
def plot_uvj_vs_icd():
    galaxies=mk_galaxy_struc()
    #Take out the UDF data
    galaxies = filter(lambda galaxy: galaxy.field == 1, galaxies)
    galaxies = filter(lambda galaxy: -0.05 < galaxy.ICD_IH < 0.25, galaxies)

    #f,(ax1, ax2) = pyl.subplots(1,2,sharex=True, sharey=True,figsize=(6.25,4.5))

    #F = pyl.figure(1,figsize=(6,4))
    F = pyl.figure(1)
    grid = AxesGrid(F, 111,
                        nrows_ncols=(2,1),
                        axes_pad = 0.1,
                        add_all=True,
                        label_mode = 'L',
                        share_all=True,
                        cbar_location = 'right',
                        cbar_mode = 'each')
    ax1 = grid[0]
    ax2 = grid[1]

    uv =[]
    vj =[]
    icd = []
    mass= []
    uv_all =[]
    vj_all =[]
    icd_all = []

    appenduv = uv.append
    appendvj = vj.append
    appendicd = icd.append
    appendmass = mass.append
    appenduv_all = uv_all.append
    appendvj_all = vj_all.append
    appendicd_all = icd_all.append

    #Build Arrays
    for galaxy in galaxies:
        if galaxy.ston_I > 30.:
            appenduv(-2.5*pyl.log10(galaxy.Uflux_rest/galaxy.Vflux_rest))
            appendvj(-2.5*pyl.log10(galaxy.Vflux_rest/galaxy.Jflux_rest))
            appendicd(galaxy.ICD_IH)
            appendmass(galaxy.Mass)


    #Convert to Numpy Array
    uv = pyl.asarray(uv)
    vj = pyl.asarray(vj)
    icd = pyl.asarray(icd)
    mass = pyl.asarray(mass)

    #Build Plotting Matrices
    cut = pyl.column_stack((uv, vj, icd*100., pyl.log10(mass)))
    #total = pyl.column_stack((uv_all,vj_all,icd_all))

    cut = colsort(cut,3)
    cut2 = colsort(cut,4)
    #total = colsort(total,3)

    #plot!
    sc1 = ax1.scatter(cut[:,1], cut[:,0], c=cut[:,2], s=50,
            cmap='spectral')
    sc2 = ax2.scatter(cut2[:,1], cut2[:,0], c=cut2[:,3], s=50,
            cmap='spectral')

    #Add Lines
    ax1.set_ylim(-0.5,2.5)
    ax1.set_xlim(-1.5,2.5)

    limits = ax1.axis()
    ax1.axis
    x = [limits[0], 0.69, 1.4,1.4]
    y = [1.2, 1.2, 1.82, limits[3]]

    ax1.plot(x,y,lw=2,c='k')
    ax2.plot(x,y,lw=2,c='k')

    ax1.fill_between(x,y,limits[3], facecolor='w', edgecolor='k', hatch='/',
            zorder=0)
    ax2.fill_between(x,y,limits[3], facecolor='w', edgecolor='k', hatch='/',
            zorder=0)

    #Add the color bar and labels and stuff
    grid.cbar_axes[0].colorbar(sc1)
    grid.cbar_axes[1].colorbar(sc2)
    ax = grid.cbar_axes[0]
    ax.axis["right"].toggle(ticks=True, ticklabels=True, label=True)
    ax.set_ylabel('ICD[F775W, F160W] (%)', fontsize=16)
    ax = grid.cbar_axes[1]
    ax.set_ylabel(r'Log Mass $(M_\odot)$', fontsize=16)

    grid.axes_llc.set_xticks([-1,0,1,2])
    grid.axes_llc.set_yticks([0,1,2])

    ax1.text(0,2,'Passive',color='k', horizontalalignment='center',
        backgroundcolor='w')
    ax2.text(0,2,'Passive',color='k', horizontalalignment='center',
        backgroundcolor='w')
    ax1.set_ylabel('$U-V_{Rest}$')
    ax1.set_xlabel('$V-J_{Rest}$')
    ax2.set_xlabel('$V-J_{Rest}$')

    pyl.show()
Esempio n. 29
0
def plot_grad_vs_mass():
    grad = pyl.loadtxt('asymm_color_grads/colourGradients_U-V.txt')
    icd = pyl.loadtxt('gini_m20/icd_1.5_3.5_gsd_full_ston.txt')

    f1 = pyl.figure('Grad vs Mass', figsize=(6, 4))
    f1s1 = f1.add_subplot(111)
    f2 = pyl.figure(2)
    f2s1 = f2.add_subplot(111)  #,projection='3d')
    f2s1 = plotfix(f2s1)

    mass = []
    gradient = []
    icd1 = []
    id_num = []
    appendid_num = id_num.append
    appendmass = mass.append
    appendgradient = gradient.append
    appendicd1 = icd1.append
    for i in range(len(icd)):
        for j in range(len(grad)):
            if icd[i][0] == grad[j][0]:
                if icd[i][11] > 30.0:
                    appendmass(icd[i][8])
                    appendgradient(grad[j][2])
                    appendicd1(icd[i][9])
                    appendid_num(icd[i][0])

    mass = pyl.asarray(mass)
    gradient = pyl.asarray(gradient)
    icd1 = pyl.asarray(icd1)
    id_num = pyl.asarray(id_num)
    plt_matrix = pyl.column_stack((mass, gradient, icd1, id_num))

    pyl.figure(1)
    f1s1.scatter(plt_matrix[:, 0], plt_matrix[:, 1], s=50)
    f1s1.set_xscale('log')
    f1s1.hlines(0.0, 3e7, 1e12)
    f1s1.axvspan(3e7, 1e9, facecolor='#FFFDD0', ec='None', zorder=0)
    f1s1.axvspan(1e11, 1e12, facecolor='#FFFDD0', ec='None', zorder=0)
    f1s1.set_xlim(3e7, 1e12)
    f1s1.set_xlabel(r"$M/M_{\odot}$", fontsize=18)

    pyl.subplots_adjust(left=0.17, bottom=0.18)

    pyl.figure(2)

    for label, x, y in zip(plt_matrix[:, 3], plt_matrix[:, 1], plt_matrix[:,
                                                                          2]):
        pyl.annotate(label,
                     xy=(x, y),
                     xytext=(x, y),
                     textcoords='data',
                     ha='right',
                     va='bottom',
                     bbox=dict(boxstyle='round,pad=0.5',
                               fc='yellow',
                               alpha=0.5),
                     arrowprops=dict(arrowstyle='->'))

    f2s1.scatter(plt_matrix[:, 1], plt_matrix[:, 2], s=50)
    #f2s1.set_xscale('log')
    f2s1.set_ylim(-0.05, 0.25)

    #f2s1.set_xlabel(r"$M/M_{\odot}$",fontsize=18)
    f2s1.set_xlabel("Color Gradient", fontsize=18)
    f2s1.set_ylabel(r"$\xi[I,H]$", fontsize=18)

    pyl.show()
Esempio n. 30
0
def plot_color_vs_mass_vs_icd():
    galaxies=mk_galaxy_struc()
    # Add the figures

#    pyl.rcParams.update(mplparams.aps['params'])

    # Mass vs color plot I-H
    f1 = pyl.figure('CM_ICD_IH',figsize=(6,4))
    f1s1 = f1.add_subplot(111)

    # Mass vs color plot J-H
    f2 = pyl.figure('CM_ICD_ZH',figsize=(8,8))
    f2s1 = f2.add_subplot(111)

    # Mass vs color plot Z-H
    f3 = pyl.figure('CM_ICD_JH',figsize=(8,8))
    f3s1 = f3.add_subplot(111)

    color1 = []
    mass1 = []
    icd1 = []
    color2 = []
    mass2 = []
    icd2 = []
    color3 = []
    mass3 = []
    icd3 = []

    for i in range(len(galaxies)):
        if galaxies[i].ston_I >30.0:
            if -0.05 < galaxies[i].ICD_IH and galaxies[i].ICD_IH < 0.25:
                mass1.append(galaxies[i].Mass)
                color1.append(galaxies[i].Imag-galaxies[i].Hmag)
                icd1.append(galaxies[i].ICD_IH*100.)
            else:
                mass1.append(galaxies[i].Mass)
                color1.append(galaxies[i].Imag-galaxies[i].Hmag)
                icd1.append(0.25*100.)

        if galaxies[i].ston_Z >30.0:
            if -0.05 < galaxies[i].ICD_ZH and galaxies[i].ICD_ZH < 0.25:
                mass2.append(galaxies[i].Mass)
                color2.append(galaxies[i].Zmag-galaxies[i].Hmag)
                icd2.append(galaxies[i].ICD_ZH)
            else:
                mass2.append(galaxies[i].Mass)
                color2.append(galaxies[i].Zmag-galaxies[i].Hmag)
                icd2.append(0.3)

        if galaxies[i].ston_J >30.0:
            if -0.05 < galaxies[i].ICD_JH and galaxies[i].ICD_JH < 0.25:
                mass3.append(galaxies[i].Mass)
                color3.append(galaxies[i].Jmag-galaxies[i].Hmag)
                icd3.append(galaxies[i].ICD_JH)
            else:
                mass3.append(galaxies[i].Mass)
                color3.append(galaxies[i].Jmag-galaxies[i].Hmag)
                icd3.append(0.3)

    # Sort the arrays by ICD
    mass1 = pyl.asarray(mass1)
    color1 = pyl.asarray(color1)
    icd1 = pyl.asarray(icd1)
    mass2 = pyl.asarray(mass2)
    color2 = pyl.asarray(color2)
    icd2 = pyl.asarray(icd2)
    mass3 = pyl.asarray(mass3)
    color3 = pyl.asarray(color3)
    icd3 = pyl.asarray(icd3)

    IH_array = pyl.column_stack((mass1,color1,icd1))
    ZH_array = pyl.column_stack((mass2,color2,icd2))
    JH_array = pyl.column_stack((mass3,color3,icd3))

    IH_array = colsort(IH_array,3)
    ZH_array = colsort(ZH_array,3)
    JH_array = colsort(JH_array,3)

    sc1 = f1s1.scatter(IH_array[:,0], IH_array[:,1], c=IH_array[:,2], s=50,
    cmap='spectral',edgecolor='w')
    sc2 = f2s1.scatter(ZH_array[:,0], ZH_array[:,1], c=ZH_array[:,2], s=50,
    cmap='spectral')
    sc3 = f3s1.scatter(JH_array[:,0], JH_array[:,1], c=JH_array[:,2], s=50,
    cmap='spectral')


    ############
    # FIGURE 1 #
    ############
    pyl.figure('CM_ICD_IH')

    bar = pyl.colorbar(sc1)
    bar.set_label(r"$\xi[I,H]$ (%)")

    f1s1.set_xscale('log')
    f1s1.set_xlim(3e7,1e12)
    f1s1.set_ylim(0.0,3.5)
    f1s1.set_xlabel(r"Mass $[M_{\odot}]$")
    f1s1.set_ylabel("$(I-H)_{Observed}$")

    pyl.subplots_adjust(left=0.16, bottom=0.23, right=0.74)
    #pyl.tight_layout()
    pyl.savefig('color_vs_mass_vs_icd_IH.eps',bbox='tight')

    ############
    # FIGURE 2 #
    ############
    pyl.figure('CM_ICD_ZH')
    bar = pyl.colorbar(sc2)
    bar.set_label(r"$\xi[Z,H]$",fontsize=20)

    f2s1.set_xscale('log')
    f2s1.set_xlim(3e7,1e12)
    f2s1.set_ylim(0.0,3.5)
    f2s1.set_xlabel(r"$Log_{10}(M_{\odot})$",fontsize=20)
    f2s1.set_ylabel("$(Z-H)_{Observed}$",fontsize=20)
    f2s1.tick_params(axis='both',pad=7)
    pyl.savefig('color_vs_mass_vs_icd_ZH.eps')

    ############
    # FIGURE 3 #
    ############
    pyl.figure('CM_ICD_JH')
    bar = pyl.colorbar(sc3)
    bar.set_label(r"$\xi[J,H]$",fontsize=20)

    f3s1.set_xscale('log')
    f3s1.set_xlim(3e7,1e12)
    f3s1.set_ylim(-0.5,1.5)
    f3s1.set_xlabel(r"$Log_{10}(M_{\odot})$",fontsize=20)
    f3s1.set_ylabel("$(J-H)_{Observed}$",fontsize=20)
    f3s1.tick_params(axis='both',pad=7)
    pyl.savefig('color_vs_mass_vs_icd_JH.eps')

    pyl.show()
Esempio n. 31
0
def plot_uvj_vs_icd():
    galaxies = mk_galaxy_struc()
    #Take out the UDF data
    galaxies = filter(lambda galaxy: galaxy.field == 1, galaxies)
    galaxies = filter(lambda galaxy: -0.05 < galaxy.ICD_IH < 0.25, galaxies)

    #f,(ax1, ax2) = pyl.subplots(1,2,sharex=True, sharey=True,figsize=(6.25,4.5))

    #F = pyl.figure(1,figsize=(6,4))
    F = pyl.figure(1)
    grid = AxesGrid(F,
                    111,
                    nrows_ncols=(2, 1),
                    axes_pad=0.1,
                    add_all=True,
                    label_mode='L',
                    share_all=True,
                    cbar_location='right',
                    cbar_mode='each')
    ax1 = grid[0]
    ax2 = grid[1]

    uv = []
    vj = []
    icd = []
    mass = []
    uv_all = []
    vj_all = []
    icd_all = []

    appenduv = uv.append
    appendvj = vj.append
    appendicd = icd.append
    appendmass = mass.append
    appenduv_all = uv_all.append
    appendvj_all = vj_all.append
    appendicd_all = icd_all.append

    #Build Arrays
    for galaxy in galaxies:
        if galaxy.ston_I > 30.:
            appenduv(-2.5 * pyl.log10(galaxy.Uflux_rest / galaxy.Vflux_rest))
            appendvj(-2.5 * pyl.log10(galaxy.Vflux_rest / galaxy.Jflux_rest))
            appendicd(galaxy.ICD_IH)
            appendmass(galaxy.Mass)

    #Convert to Numpy Array
    uv = pyl.asarray(uv)
    vj = pyl.asarray(vj)
    icd = pyl.asarray(icd)
    mass = pyl.asarray(mass)

    #Build Plotting Matrices
    cut = pyl.column_stack((uv, vj, icd * 100., pyl.log10(mass)))
    #total = pyl.column_stack((uv_all,vj_all,icd_all))

    cut = colsort(cut, 3)
    cut2 = colsort(cut, 4)
    #total = colsort(total,3)

    #plot!
    sc1 = ax1.scatter(cut[:, 1], cut[:, 0], c=cut[:, 2], s=50, cmap='spectral')
    sc2 = ax2.scatter(cut2[:, 1],
                      cut2[:, 0],
                      c=cut2[:, 3],
                      s=50,
                      cmap='spectral')

    #Add Lines
    ax1.set_ylim(-0.5, 2.5)
    ax1.set_xlim(-1.5, 2.5)

    limits = ax1.axis()
    ax1.axis
    x = [limits[0], 0.69, 1.4, 1.4]
    y = [1.2, 1.2, 1.82, limits[3]]

    ax1.plot(x, y, lw=2, c='k')
    ax2.plot(x, y, lw=2, c='k')

    ax1.fill_between(x,
                     y,
                     limits[3],
                     facecolor='w',
                     edgecolor='k',
                     hatch='/',
                     zorder=0)
    ax2.fill_between(x,
                     y,
                     limits[3],
                     facecolor='w',
                     edgecolor='k',
                     hatch='/',
                     zorder=0)

    #Add the color bar and labels and stuff
    grid.cbar_axes[0].colorbar(sc1)
    grid.cbar_axes[1].colorbar(sc2)
    ax = grid.cbar_axes[0]
    ax.axis["right"].toggle(ticks=True, ticklabels=True, label=True)
    ax.set_ylabel('ICD[F775W, F160W] (%)', fontsize=16)
    ax = grid.cbar_axes[1]
    ax.set_ylabel(r'Log Mass $(M_\odot)$', fontsize=16)

    grid.axes_llc.set_xticks([-1, 0, 1, 2])
    grid.axes_llc.set_yticks([0, 1, 2])

    ax1.text(0,
             2,
             'Passive',
             color='k',
             horizontalalignment='center',
             backgroundcolor='w')
    ax2.text(0,
             2,
             'Passive',
             color='k',
             horizontalalignment='center',
             backgroundcolor='w')
    ax1.set_ylabel('$U-V_{Rest}$')
    ax1.set_xlabel('$V-J_{Rest}$')
    ax2.set_xlabel('$V-J_{Rest}$')

    pyl.show()
Esempio n. 32
0
 def getInterData(self,tdData,desiredLength,mint,maxt,tkind='linear'):
     #use cubic interpolation only, if you know, that the data is not too no
     intpdata=interp1d(tdData[:,0],tdData[:,1:],axis=0,kind=tkind)
     timeaxis=py.linspace(mint,maxt,desiredLength)
     longerData=intpdata(timeaxis)
     return py.column_stack((timeaxis,longerData))
Esempio n. 33
0

### Targeted ###
################
with hdf.File('./../MLmethods/buzzard_targetedRealistic.hdf5', 'r') as f:
    dset  = f[f.keys()[0]]
    #data = dset['IDX', 'HALOID', 'ZSPEC', 'M200c', 'NGAL', 'LOSVD',
    #    'LOSVD_err', 'MASS', 'LOSVD_dist']
    data = dset['ZSPEC', 'M200c', 'LOSVD',]

mask = ((pyl.log10(data['LOSVD']) > 3.12 ) & (data['M200c'] < 10**14.5) |
    (data['LOSVD'] < 50))
data = data[~mask]
badData = data[mask]

X = pyl.column_stack([data['ZSPEC'], pyl.log10(data['M200c']),
    pyl.log10(data['LOSVD'])])
f = corner.corner(X, labels=['z', 'Log $M_{200c}$', 'Log $\sigma$'], bins=50,
        smooth=True, fill_contours=True)


# add the bars. The axes are row indexed

axes = f.axes

# histogram labels
axes[0].set_ylabel('P(z)')
axes[0].yaxis.set_label_position('right')
axes[4].set_ylabel('P(Log $M_{200c}$)')
axes[4].yaxis.set_label_position('right')
axes[8].set_ylabel('P(Log $\sigma$)')
axes[8].yaxis.set_label_position('right')
Esempio n. 34
0
hdulist =\
pyf.open('/home/steven/Projects/image_fields/CANDELS/GOODS_S/catalogs/results_gsd_fit_zsol_chab_cb07.fits')
tbdata = hdulist[1].data

icd = pyl.loadtxt('gini_m20/icd_1.5_3.5_gsd_full_ston.txt')

f1 = pyl.figure(1, figsize=(6, 4))
f1s1 = f1.add_subplot(111)

icd1 = []
sfr = []
appendicd1 = icd1.append
appendsfr = sfr.append

for i in range(len(icd)):
    if icd[i][11] > 30.0:
        for j in range(len(tbdata.field('ID'))):
            if icd[i][0] == tbdata.field('ID')[j]:
                print icd[i][0], tbdata.field('ID')[j]
                appendicd1(icd[i][9])
                appendsfr(tbdata.field('SFR')[j])

icd1 = pyl.asarray(icd1)
sfr = pyl.asarray(sfr)

plt_matrix = pyl.column_stack((sfr, icd1))

f1s1.scatter(pyl.log10(plt_matrix[:, 0]), plt_matrix[:, 1], s=50)

pyl.show()
Esempio n. 35
0
def plot_grad_vs_mass():
    grad = pyl.loadtxt('asymm_color_grads/colourGradients_U-V.txt')
    icd = pyl.loadtxt('gini_m20/icd_1.5_3.5_gsd_full_ston.txt')

    f1 = pyl.figure('Grad vs Mass',figsize=(6,4))
    f1s1 = f1.add_subplot(111)
    f2 = pyl.figure(2)
    f2s1 = f2.add_subplot(111)#,projection='3d')
    f2s1 = plotfix(f2s1)

    mass = []
    gradient = []
    icd1 = []
    id_num = []
    appendid_num = id_num.append
    appendmass = mass.append
    appendgradient = gradient.append
    appendicd1 = icd1.append
    for i in range(len(icd)):
        for j in range(len(grad)):
            if icd[i][0] == grad[j][0]:
                if icd[i][11] > 30.0:
                    appendmass(icd[i][8])
                    appendgradient(grad[j][2])
                    appendicd1(icd[i][9])
                    appendid_num(icd[i][0])

    mass = pyl.asarray(mass)
    gradient = pyl.asarray(gradient)
    icd1 = pyl.asarray(icd1)
    id_num = pyl.asarray(id_num)
    plt_matrix = pyl.column_stack((mass,gradient,icd1,id_num))

    pyl.figure(1)
    f1s1.scatter(plt_matrix[:,0],plt_matrix[:,1],s=50)
    f1s1.set_xscale('log')
    f1s1.hlines(0.0,3e7,1e12)
    f1s1.axvspan(3e7,1e9,facecolor='#FFFDD0',ec='None',zorder=0)
    f1s1.axvspan(1e11,1e12,facecolor='#FFFDD0',ec='None',zorder=0)
    f1s1.set_xlim(3e7,1e12)
    f1s1.set_xlabel(r"$M/M_{\odot}$",fontsize=18)

    pyl.subplots_adjust(left=0.17,bottom=0.18)

    pyl.figure(2)

    for label,x,y in zip(plt_matrix[:,3],plt_matrix[:,1], plt_matrix[:,2]):
        pyl.annotate(label,xy=(x,y),
                xytext=(x,y),textcoords='data',ha='right',va='bottom',
                bbox=dict(boxstyle='round,pad=0.5',fc='yellow',alpha=0.5),
                arrowprops=dict(arrowstyle='->'))

    f2s1.scatter(plt_matrix[:,1],plt_matrix[:,2],s=50)
    #f2s1.set_xscale('log')
    f2s1.set_ylim(-0.05,0.25)
    
    #f2s1.set_xlabel(r"$M/M_{\odot}$",fontsize=18)
    f2s1.set_xlabel("Color Gradient",fontsize=18)
    f2s1.set_ylabel(r"$\xi[I,H]$",fontsize=18)


    pyl.show()
Esempio n. 36
0
def plot_uvj_vs_icd():
    galaxies = mk_galaxy_struc()
    #Take out the UDF data
    galaxies = filter(lambda galaxy: galaxy.field == 1, galaxies)
    galaxies = filter(lambda galaxy: -0.05 < galaxy.ICD_IH < 0.25, galaxies)

    #f,(ax1, ax2) = pyl.subplots(1,2,sharex=True, sharey=True,figsize=(6.25,4.5))

    F = pyl.figure(1, figsize=(6, 3.1))
    grid = AxesGrid(F,
                    111,
                    nrows_ncols=(1, 2),
                    axes_pad=0.1,
                    add_all=True,
                    label_mode='L',
                    share_all=True,
                    cbar_location='top',
                    cbar_mode='single')
    ax1 = grid[0]
    ax2 = grid[1]

    uv = []
    vj = []
    icd = []
    uv_all = []
    vj_all = []
    icd_all = []

    appenduv = uv.append
    appendvj = vj.append
    appendicd = icd.append
    appenduv_all = uv_all.append
    appendvj_all = vj_all.append
    appendicd_all = icd_all.append

    #Build Arrays
    for galaxy in galaxies:
        if galaxy.ston_I > 30. and galaxy.ston_H > 30.:
            appenduv(-2.5 * pyl.log10(galaxy.Uflux_rest / galaxy.Vflux_rest))
            appendvj(-2.5 * pyl.log10(galaxy.Vflux_rest / galaxy.Jflux_rest))
            appendicd(pyl.log10(galaxy.Mass))
        appenduv_all(-2.5 * pyl.log10(galaxy.Uflux_rest / galaxy.Vflux_rest))
        appendvj_all(-2.5 * pyl.log10(galaxy.Vflux_rest / galaxy.Jflux_rest))
        appendicd_all(pyl.log10(galaxy.Mass))

    #Convert to Numpy Array
    uv = pyl.asarray(uv)
    vj = pyl.asarray(vj)
    icd = pyl.asarray(icd)
    uv_all = pyl.asarray(uv_all)
    vj_all = pyl.asarray(vj_all)
    icd_all = pyl.asarray(icd_all)

    #Build Plotting Matrices
    cut = pyl.column_stack((uv, vj, icd))
    total = pyl.column_stack((uv_all, vj_all, icd_all))

    cut = colsort(cut, 3)
    total = colsort(total, 3)

    #plot!
    sc1 = ax1.scatter(total[:, 1],
                      total[:, 0],
                      c=total[:, 2],
                      s=50,
                      cmap='spectral')
    sc2 = ax2.scatter(cut[:, 1], cut[:, 0], c=cut[:, 2], s=50, cmap='spectral')

    #Add Lines
    ax1.set_ylim(-0.5, 2.5)
    ax1.set_xlim(-1.5, 2.5)

    limits = ax1.axis()
    ax1.axis
    x = [limits[0], 0.69, 1.4, 1.4]
    y = [1.2, 1.2, 1.82, limits[3]]

    ax1.plot(x, y, lw=2, c='k')
    ax2.plot(x, y, lw=2, c='k')

    #Add the color bar and labels and stuff
    grid.cbar_axes[0].colorbar(sc2)
    ax = grid.cbar_axes[0]
    ax.axis["top"].toggle(ticks=True, ticklabels=True, label=True)
    ax.set_xlabel('Log Mass $[M_{\odot}]$')

    grid.axes_llc.set_xticks([-1, 0, 1, 2])
    grid.axes_llc.set_yticks([0, 1, 2])

    ax1.set_ylabel('$U-V_{Rest}$')
    ax1.set_xlabel('$V-J_{Rest}$')
    ax2.set_xlabel('$V-J_{Rest}$')

    #pyl.savefig('UVJ_vs_mass.eps',bbox='tight')
    pyl.show()
Esempio n. 37
0
            high_icd.append(33.5)
        else:
            high_icd.append(galaxy.ICD_IH*100)
    else:
        low_mass.append(galaxy.Mass)
        low_color.append(galaxy.Imag - galaxy.Hmag)
        low_icd.append(galaxy.ICD_IH*100)

low_mass = pyl.asarray(low_mass)
low_color = pyl.asarray(low_color)
low_icd = pyl.asarray(low_icd)
high_mass = pyl.asarray(high_mass)
high_color = pyl.asarray(high_color)
high_icd = pyl.asarray(high_icd)

low = pyl.column_stack((low_mass, low_color, low_icd))
high = pyl.column_stack((high_mass, high_color, high_icd))

#sort
high_sort = colsort(high, 3)

#plot
sc2 = f1s1.scatter(low[:,0], low[:,1], c='0.8', edgecolor='0.8', s=25)
#sc1 = f1s1.scatter(high_sort[:,0], high_sort[:,1], c=high_sort[:,2], s=50,
#        cmap='spectral')
sc1 = f1s1.scatter(high_sort[:,0], high_sort[:,1], c='#9370DB', s=50)

#bar = pyl.colorbar(sc1)
#bar.set_label(r'$\xi[i_{775}, H_{160}]$ (%)')

f1s1.set_xlabel(r'Log Mass $(M_\odot)$')