Continuing development. Boundary handling seems to be stable and working. Now testing void finding.

This commit is contained in:
Paul M. Sutter 2025-01-08 15:13:29 +08:00
parent 3dce2593d9
commit cf97cfba5d
6 changed files with 92 additions and 41 deletions

View file

@ -131,7 +131,7 @@ def figureOutMask(galFile, nside, outMaskFile):
# figures out which galaxies live on a mask or redshift edge
def findEdgeGalaxies(galFile, maskFile, edgeGalFile, contourFile,
zmin, zmax, omegaM, useComoving, boundaryWidth,
meanPartSep):
meanPartSep, outputDir):
if useComoving:
zmin = comovingDistance(zmin, Om=omegaM)*LIGHT_SPEED
@ -145,15 +145,50 @@ def findEdgeGalaxies(galFile, maskFile, edgeGalFile, contourFile,
npix = healpy.nside2npix(nside)
# load in galaxies
galPos = np.genfromtxt(galFile)
#galPos = np.genfromtxt(galFile)
galPos = np.genfromtxt(outputDir+"/galaxies.txt")
with open(galFile, 'rb') as File:
chk = np.fromfile(File, dtype=np.int32,count=1)
Np = np.fromfile(File, dtype=np.int32,count=1)[0]
chk = np.fromfile(File, dtype=np.int32,count=1)
chk = np.fromfile(File, dtype=np.int32,count=1)
x = np.fromfile(File, dtype=np.float32,count=Np)
chk = np.fromfile(File, dtype=np.int32,count=1)
chk = np.fromfile(File, dtype=np.int32,count=1)
y = np.fromfile(File, dtype=np.float32,count=Np)
chk = np.fromfile(File, dtype=np.int32,count=1)
chk = np.fromfile(File, dtype=np.int32,count=1)
z = np.fromfile(File, dtype=np.float32,count=Np)
chk = np.fromfile(File, dtype=np.int32,count=1)
chk = np.fromfile(File, dtype=np.int32,count=1)
RA = np.fromfile(File, dtype=np.float32,count=Np)
chk = np.fromfile(File, dtype=np.int32,count=1)
chk = np.fromfile(File, dtype=np.int32,count=1)
Dec = np.fromfile(File, dtype=np.float32,count=Np)
chk = np.fromfile(File, dtype=np.int32,count=1)
chk = np.fromfile(File, dtype=np.int32,count=1)
redshift = np.fromfile(File, dtype=np.float32,count=Np)
chk = np.fromfile(File, dtype=np.int32,count=1)
#print(galPos.shape)
#galPos = np.column_stack((x,y,z))
#print(galPos.shape)
flagList = np.zeros(len(galPos[:,0]))
galTree = scipy.spatial.cKDTree(galPos)
# flag galaxies near mask edges
# using the "ray marching" algorithm: follow rays along lines of sight
# of all mask edges, flagging nearest neighbor galaxies as we go
raySteps = np.arange(zmin, zmax, meanPartSep)
#print(meanPartSep, len(raySteps))
contourPixels = np.nonzero(contourMap)[0]
#print(contourPixels)
@ -164,34 +199,42 @@ def findEdgeGalaxies(galFile, maskFile, edgeGalFile, contourFile,
y = raySteps * vec[1]
z = raySteps * vec[2]
ray = np.array((x,y,z)).T
#print(ray)
dist, nearest = galTree.query(ray)
flagList[nearest] = 1
#print(nearest)
# flag galaxies near redsfhit boundaries
# TODO - save time by only covering portion of sphere with data
ds = np.sqrt(healpy.nside2pixarea(nside)) / 1000.
phi = np.arange(0, 2*np.pi, ds*2)
theta = np.arange(0, np.pi, ds)
vec = healpy.ang2vec(theta, phi)
# TODO - save time by only covering portion of sphere that has data
sphereIndices = np.arange(len(contourMap))
vec = healpy.pix2vec(nside, sphereIndices)
vec = np.asarray(vec)
maxEdge = zmax * vec
maxEdge = maxEdge.T
dist, nearest = galTree.query(maxEdge)
#print(nearest)
#print(galPos[nearest])
flagList[nearest] = 2
minEdge = zmin * vec
minEdge = minEdge.T
dist, nearest = galTree.query(minEdge)
#print(nearest)
#print(galPos[nearest])
flagList[nearest] = 3
# output flag information
np.savetxt(edgeGalFile, flagList, fmt="%d")
# paint galaxy flags onto healpix map for diagnostics
# TODO - drop this when done testing
flagMap = np.zeros(len(contourMap))
justEdgeRA = RA[flagList == 1]
justEdgeDec = Dec[flagList == 1]
phi, theta = convertAngle(justEdgeRA, justEdgeDec)
ipix = healpy.ang2pix(nside, theta, phi)
np.put(flagMap, ipix, 1)
healpy.write_map("./flagged_galaxies.fits", flagMap, overwrite=True,
dtype=np.dtype('float64'))
# # output galaxy edge flags