From dd181da42af26b84ac5af76ac086fea03153dbfb Mon Sep 17 00:00:00 2001 From: "Paul M. Sutter" Date: Thu, 6 Jun 2024 00:49:53 +0200 Subject: [PATCH] bug fixed related to different boundary handling procedure. no guarantee that it's correct (yet) but it runs --- c_source/prep/prepObservation.cpp | 2 +- python_source/backend/classes.py | 8 ++++-- python_source/backend/cosmologyTools.py | 2 +- python_source/backend/launchers.py | 12 ++++---- python_source/backend/surveyTools.py | 38 ++++++++++++++----------- python_source/vide_pipeline/__main__.py | 14 ++++----- 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/c_source/prep/prepObservation.cpp b/c_source/prep/prepObservation.cpp index 073898f..bf74b60 100644 --- a/c_source/prep/prepObservation.cpp +++ b/c_source/prep/prepObservation.cpp @@ -290,7 +290,7 @@ void generateSurfaceMask(prepObservation_info& args , volume *= Rmax*Rmax*Rmax/3/1e6; numToInsert = (int)floor(volume*args.density_fake_arg); // TEST NOT USING MOCK PARTICLES - numToIntsert = 0 + numToInsert = 0; // END TEST cout << format("3d volume to fill: %g (Mpc/h)^3") % volume << endl; diff --git a/python_source/backend/classes.py b/python_source/backend/classes.py index ebb2b3b..2321c94 100644 --- a/python_source/backend/classes.py +++ b/python_source/backend/classes.py @@ -67,8 +67,9 @@ class Sample: dataUnit = 1 fullName = "lss.dr72dim.dat" nickName = "dim" - zobovDir = "" + outputDir = "" maskFile = "rast_window_512.fits" + nsideForMask = 128 selFunFile = "czselfunc.all.dr72dim.dat" zBoundary = (0.0, 0.1) zBoundaryMpc = (0., 300) @@ -98,7 +99,7 @@ class Sample: stacks = [] def __init__(self, dataFile="", fullName="", dataUnit=1, - nickName="", maskFile="", selFunFile="", + nickName="", maskFile="", nsideForMask=128, selFunFile="", zBoundary=(), zRange=(), zBoundaryMpc=(), shiftSimZ=False, minVoidRadius=-1, fakeDensity=0.01, volumeLimited=True, numAPSlices=1, @@ -114,6 +115,7 @@ class Sample: self.fullName = fullName self.nickName = nickName self.maskFile = maskFile + self.nsideForMask = nsideForMask self.selFunFile = selFunFile self.zBoundary = zBoundary self.zBoundaryMpc = zBoundaryMpc @@ -127,7 +129,7 @@ class Sample: self.isCombo = isCombo self.comboList = comboList self.numAPSlices = numAPSlices - self.zobovDir = None + self.outputDir = None self.profileBinSize = profileBinSize self.dataType = dataType self.boxLen = boxLen diff --git a/python_source/backend/cosmologyTools.py b/python_source/backend/cosmologyTools.py index 2443e18..595e278 100644 --- a/python_source/backend/cosmologyTools.py +++ b/python_source/backend/cosmologyTools.py @@ -23,7 +23,7 @@ import numpy as np import scipy.integrate as integrate import os -from backend import * +#from backend import * __all__=['expansion', 'comovingDistance', 'aveExpansion'] diff --git a/python_source/backend/launchers.py b/python_source/backend/launchers.py index a171c4b..5465878 100644 --- a/python_source/backend/launchers.py +++ b/python_source/backend/launchers.py @@ -54,7 +54,7 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None, sampleName = sample.fullName if regenerate: - inputParameterFlag = "inputParameter " + outputDir + + inputParameterFlag = "inputParameter " + outputDir + \ "/zobov_slice_"+sampleName+".par" outputFile = outputDir + "/regenerated_zobov_slice_" + sampleName else: @@ -67,14 +67,12 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None, datafile = inputDataDir+"/"+sample.dataFile if sample.maskFile == "": - maskFile = outputDir + "/constructed_mask.fits" - figureOutMask(dataFile, sample.nsideForMask, maskFile) - else: - maskFile = sample.maskFile + sample.maskFile = outputDir + "/constructed_mask.fits" + figureOutMask(datafile, sample.nsideForMask, sample.maskFile) edgeGalFile = outputDir + "/galaxy_edge_flags.txt" edgeMaskFile = outputDir + "/mask_edge_map.fits" - findEdgeGalaxies(dataFile, maskFile, edgeGalFile, edgeMaskFile, + findEdgeGalaxies(datafile, sample.maskFile, edgeGalFile, edgeMaskFile, sample.zBoundary[0], sample.zBoundary[1], sample.omegaM, useComoving) @@ -94,7 +92,7 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None, %s %s omegaM %g - """ % (datafile, maskFile, outputFile, + """ % (datafile, sample.maskFile, outputFile, outputDir+"/zobov_slice_"+sampleName+".par", sample.zBoundary[0], sample.zBoundary[1], sample.fakeDensity, useComovingFlag, inputParameterFlag, sample.omegaM) diff --git a/python_source/backend/surveyTools.py b/python_source/backend/surveyTools.py index d169f06..b1e32e5 100644 --- a/python_source/backend/surveyTools.py +++ b/python_source/backend/surveyTools.py @@ -24,6 +24,7 @@ import numpy as np import healpy as healpy import os from backend import * +from backend.cosmologyTools import * __all__=['getSurveyProps', 'getNside', 'figureOutMask', 'findEdgeGalaxies'] @@ -44,6 +45,8 @@ def getSurveyProps(maskFile, zmin, zmax, selFunMin, selFunMax, portion, zmin = zmin * LIGHT_SPEED/100. zmax = zmax * LIGHT_SPEED/100. + volume = area * (zmax**3 - zmin**3) / 3 + if selectionFuncFile == None: nbar = 1.0 @@ -119,7 +122,7 @@ def figureOutMask(galFile, nside, outMaskFile): pix = healpy.ang2pix(nside, theta, phi) mask[pix] = 1. - healpy.write_map(outMaskFile, mask, overwrite=True) + healpy.write_map(outMaskFile, mask, overwrite=True, dtype=np.dtype('float64')) return mask @@ -129,12 +132,12 @@ def figureOutMask(galFile, nside, outMaskFile): def findEdgeGalaxies(galFile, maskFile, edgeGalFile, edgeMaskFile, zmin, zmax, omegaM, useComoving=False): - if useComoving: - zmin = LIGHT_SPEED/100.*comovingDistance(zmin, Om=omegaM) - zmax = LIGHT_SPEED/100.*comovingDistance(zmax, Om=omegaM) - else: - zmin *= LIGHT_SPEED/100. - zmax *= LIGHT_SPEED/100. + #if useComoving: + # zmin = LIGHT_SPEED/100.*comovingDistance(zmin, Om=omegaM) + # zmax = LIGHT_SPEED/100.*comovingDistance(zmax, Om=omegaM) + #else: + # zmin *= LIGHT_SPEED/100. + # zmax *= LIGHT_SPEED/100. mask = healpy.read_map(maskFile) @@ -151,32 +154,33 @@ def findEdgeGalaxies(galFile, maskFile, edgeGalFile, edgeMaskFile, z = float(line[5]) if useComoving: - z = LIGHT_SPEED/100.*comovingDistance(z, Om=omegaM) + z = comovingDistance(z/LIGHT_SPEED, Om=omegaM) else: z *= LIGHT_SPEED/100. phi, theta = convertAngle(RA, Dec) # check the mask edges - neighbors = healpy.get_all_neighbors(nside, theta, phi) + neighbors = healpy.get_all_neighbours(nside, theta, phi) isOnMaskEdge = any(p == 0 for p in neighbors) # check the redshift boundaries tol = 0.01 # TODO: made this user-adjustable - zBuffer = (zmax-zmin)*tol - isOnHighZEdge = (z >= zmax-buffer) - isOnLowZEdge = (z <= zmin+buffer) + zbuffer = (zmax-zmin)*tol + isOnHighZEdge = (z >= zmax-zbuffer) + isOnLowZEdge = (z <= zmin+zbuffer) + print("DOING %f %f %f %f\n" % (zbuffer, z, zmax, zmin) ) if isOnMaskEdge: - edgeFile.write("1") + edgeFile.write("1\n") elif isOnHighZEdge: - edgeFile.write("2") + edgeFile.write("2\n") elif isOnLowZEdge: - edgeFile.write("3") + edgeFile.write("3\n") else: - edgeFile.write("0") + edgeFile.write("0\n") edgeFile.close() - healpy.write_map(edgeMaskFile, edgeMask, overwrite=True) + healpy.write_map(edgeMaskFile, edgeMask, overwrite=True, dtype=np.dtype('float64')) return diff --git a/python_source/vide_pipeline/__main__.py b/python_source/vide_pipeline/__main__.py index 1b88f7c..b624712 100644 --- a/python_source/vide_pipeline/__main__.py +++ b/python_source/vide_pipeline/__main__.py @@ -75,11 +75,11 @@ for sample in dataSampleList: sampleName = sample.fullName print(" Working with data set", sampleName, "...") - zobovDir = workDir+"/sample_"+sampleName+"/" - sample.zobovDir = zobovDir + outputDir = workDir+"/sample_"+sampleName+"/" + sample.outputDir = outputDir - if not os.access(zobovDir, os.F_OK): - os.makedirs(zobovDir) + if not os.access(outputDir, os.F_OK): + os.makedirs(outputDir) # --------------------------------------------------------------------------- if (startCatalogStage <= 1) and (endCatalogStage >= 1) and not sample.isCombo: @@ -94,7 +94,7 @@ for sample in dataSampleList: GENERATE_PATH = CTOOLS_PATH+"/prepSimulation" launchPrep(sample, GENERATE_PATH, workDir=workDir, - inputDataDir=inputDataDir, zobovDir=zobovDir, + inputDataDir=inputDataDir, outputDir=outputDir, figDir=figDir, logFile=logFile, useComoving=sample.useComoving, continueRun=continueRun, regenerate=regenerateFlag) @@ -103,7 +103,7 @@ for sample in dataSampleList: print(" Extracting voids with ZOBOV...", end=' ') sys.stdout.flush() - launchZobov(sample, ZOBOV_PATH, zobovDir=zobovDir, logDir=logDir, + launchZobov(sample, ZOBOV_PATH, outputDir=outputDir, logDir=logDir, continueRun=continueRun, numZobovDivisions=numZobovDivisions, numZobovThreads=numZobovThreads, mergingThreshold=mergingThreshold) @@ -119,7 +119,7 @@ for sample in dataSampleList: PRUNE_PATH = CTOOLS_PATH+"/pruneVoids" launchPrune(sample, PRUNE_PATH, - logFile=logFile, zobovDir=zobovDir, + logFile=logFile, outputDir=outputDir, useComoving=sample.useComoving, continueRun=continueRun, mergingThreshold=mergingThreshold, boundaryTolerance=boundaryTolerance)