def VeffLF(self): ''' Use V_Eff method to calculate properly weighted measured luminosity function ''' self.phifunc = np.zeros(len(self.lum)) for i in range(len(self.lum)): self.phifunc[i] = V.lumfunc(self.flux[i], self.dVdzf, self.Omega_0, self.zmin, self.zmax, self.Flim, self.alpha) self.Lavg, self.lfbinorig, self.var = V.getBootErrLog( self.lum, self.phifunc, self.zmin, self.zmax, self.nboot, self.nbins, self.root)
def setDLdVdz(self): ''' Create 1-D interpolated functions for luminosity distance (cm) and comoving volume differential (Mpc^3); also get function for minimum luminosity considered ''' self.DL = np.zeros(len(self.z)) zint = np.linspace(0.95*self.zmin,1.05*self.zmax,len(self.z)) dVdzarr, DLarr, minlum = np.zeros(len(zint)), np.zeros(len(zint)), np.zeros(len(zint)) for i,zi in enumerate(self.z): self.DL[i] = V.dLz(zi) # In Mpc DLarr[i] = V.dLz(zint[i]) dVdzarr[i] = V.dVdz(zint[i]) minlum[i] = np.log10(4.0*np.pi*(DLarr[i]*3.086e24)**2 * self.root) self.DLf = interp1d(zint,DLarr) self.dVdzf = interp1d(zint,dVdzarr) self.minlumf = interp1d(zint,minlum)
def Omega(logL, z, dLzfunc, Omega_0, Flim, alpha): ''' Calculate fractional area of the sky in which galaxies have fluxes large enough so that they can be detected Input ----- logL : float or numpy 1-D array Value or array of log luminosities in erg/s z : float or numpy 1-D array Value or array of redshifts; logL and z cannot be different-sized arrays dLzfunc : interp1d function 1-D interpolation function for luminosity distance in Mpc Omega_0: float Effective survey area in square arcseconds Flim: float 50% completeness flux value alpha: float Completeness-related slope Returns ------- Omega(logL,z) : Float or 1-D array (same size as logL and/or z) ''' L = 10**logL return Omega_0 / V.sqarcsec * V.p( L / (4.0 * np.pi * (3.086e24 * dLzfunc(z))**2), Flim, alpha)
def read_input_file(args): """ Function to read in input ascii file with properly named columns. Columns should include redshifts (header 'z') and a (linear) flux (header 'LineorBandName_flux') in 1.0e-17 erg/cm^2/s or log luminosity (header 'LineorBandName_lum') in log erg/s. Errors can be included with headers 'LineorBandName_flux_e' or 'LineorBandName_lum_e', with the same units. Input ----- args : class The args class is carried from function to function with information from command line input and config.py Return ------ z: Numpy 1-D Array Source redshifts flux: Numpy 1-D Array Source fluxes (1.0e-17 erg/cm^2/s or None if not in input file) flux_e: Numpy 1-D Array Source flux errors (1.0e-17 erg/cm^2/s or None if not in input file) lum: Numpy 1-D Array Source log luminosities (log erg/s or None if not in input file) lum_e: Numpy 1-D Array Source log luminosity errors (log erg/s or oNone if not in input file) root: Float Minimum flux cutoff based on the completeness curve parameters and desired minimum completeness """ datfile = Table.read(args.filename, format='ascii') z = datfile['z'] if abs(args.min_comp_frac - 0.0) < 1.0e-6: root = 0.0 else: root = fsolve( lambda x: V.p(x, args.Flim, args.alpha) - args.min_comp_frac, [args.Flim])[0] try: flux = datfile['%s_flux' % (args.line_name)] if max(flux) > 1.0e-5: cond = flux > 1.0e17 * root else: cond = flux > root flux_e = datfile['%s_flux_e' % (args.line_name)] flux, flux_e = flux[cond], flux_e[cond] except: flux, flux_e = None, None if '%s_lum' % (args.line_name) in datfile.columns: lum = datfile['%s_lum' % (args.line_name)] DL = np.zeros(len(z)) for i, zi in enumerate(z): DL[i] = V.dLz(zi) lumflux = 10**lum / (4.0 * np.pi * (DL * 3.086e24)**2) cond = lumflux > root lum = lum[cond] if '%s_lum_e' % (args.line_name) in datfile.columns: lum_e = datfile['%s_lum' % (args.line_name)][cond] else: lum_e = None else: lum, lum_e = None, None z = z[cond] return z, flux, flux_e, lum, lum_e, root