setting the stage for on-the-fly mask and edge calculation

This commit is contained in:
Paul M. Sutter 2024-06-05 01:06:36 +02:00
parent 99a441013d
commit aded7a7c2c
6 changed files with 143 additions and 67 deletions

View file

@ -22,11 +22,10 @@
import numpy as np
import scipy.integrate as integrate
import healpy as healpy
import os
from backend import *
__all__=['expansion', 'angularDiameter', 'aveExpansion', 'getSurveyProps']
__all__=['expansion', 'angularDiameter', 'aveExpansion']
# returns 1/E(z) for the given cosmology
def expansion(z, Om = 0.27, Ot = 1.0, w0 = -1.0, wa = 0.0):
@ -51,62 +50,3 @@ def aveExpansion(zStart, zEnd, Om = 0.27, Ot = 1.0, w0 = -1.0, wa = 0.0):
ave = integrate.quad(expansion, zStart, zEnd, args=(Om, Ot, w0, wa))[0]
ave = (zEnd-zStart)/ave
return ave
# -----------------------------------------------------------------------------
# returns the volume and galaxy density for a given redshit slice
def getSurveyProps(maskFile, zmin, zmax, selFunMin, selFunMax, portion, selectionFuncFile=None, useComoving=False):
LIGHT_SPEED = 299792.458
mask = healpy.read_map(maskFile)
area = (1.*np.size(np.where(mask > 0)) / np.size(mask)) * 4.*np.pi
if useComoving:
zmin = LIGHT_SPEED/100.*angularDiameter(zmin, Om=0.27)
zmax = LIGHT_SPEED/100.*angularDiameter(zmax, Om=0.27)
selFunMin = LIGHT_SPEED/100.*angularDiameter(selFunMin, Om=0.27)
selFunMax = LIGHT_SPEED/100.*angularDiameter(selFunMax, Om=0.27)
else:
zmin = zmin * 3000
zmax = zmax * 3000
selFunMin *= 3000
selFunMax *= 3000
volume = area * (zmax**3 - zmin**3) / 3
if selectionFuncFile == None:
nbar = 1.0
elif not os.access(selectionFuncFile, os.F_OK):
print(" Warning, selection function file %s not found, using default of uniform selection." % selectionFuncFile)
nbar = 1.0
else:
selfunc = np.genfromtxt(selectionFuncFile)
selfunc = np.array(selfunc)
selfunc[:,0] = selfunc[:,0]/100.
selfuncUnity = selfunc
selfuncUnity[:,1] = 1.0
selfuncMin = selfunc[0,0]
selfuncMax = selfunc[-1,0]
selfuncDx = selfunc[1,0] - selfunc[0,0]
selfuncN = np.size(selfunc[:,0])
selFunMin = max(selFunMin, selfuncMin)
selFunMax = min(selFunMax, selfuncMax)
def f(z): return selfunc[np.ceil((z-selfuncMin)/selfuncDx), 1]*z**2
def fTotal(z): return selfuncUnity[np.ceil((z-selfuncMin)/selfuncDx), 1]*z**2
zrange = np.linspace(selFunMin, selFunMax)
nbar = scipy.integrate.quad(f, selFunMin, selFunMax)
nbar = nbar[0]
ntotal = scipy.integrate.quad(fTotal, 0.0, max(selfuncUnity[:,0]))
ntotal = ntotal[0]
nbar = ntotal / area / nbar
return (volume, nbar)