mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-04 15:21:11 +00:00
Implemented (yet another) new boundary handling scheme, whereby we scan radially along survey edge while flagging nearest galaxies. The prepObservation routine was significantly cleaned up to accommodate this, but it was ultimately implemented in python (surveyTools.py) for ease of prototyping, with the intent to move it back into C later.
Some general housekeeping, making sure some new parameters are passed around correctly, and removing the storage of some unused files. This update is considered HIGHLY UNSTABLE. It will almost certainly break somewhere for simulations. Still under active development.
This commit is contained in:
parent
62dd66be79
commit
3dce2593d9
9 changed files with 348 additions and 454 deletions
|
@ -39,17 +39,20 @@ from backend.cosmologyTools import *
|
|||
from backend.surveyTools import *
|
||||
import pickle
|
||||
import scipy.interpolate as interpolate
|
||||
import time
|
||||
|
||||
NetCDFFile = Dataset
|
||||
ncFloat = 'f8' # Double precision
|
||||
|
||||
LIGHT_SPEED = 299792.458
|
||||
#LIGHT_SPEED = 299792.458
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
||||
outputDir=None, figDir=None, logFile=None, useComoving=False,
|
||||
continueRun=None, regenerate=False):
|
||||
|
||||
startTime = time.time()
|
||||
|
||||
if sample.dataType == "observation":
|
||||
sampleName = sample.fullName
|
||||
|
||||
|
@ -67,14 +70,29 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
|||
datafile = inputDataDir+"/"+sample.dataFile
|
||||
|
||||
if sample.maskFile == "":
|
||||
sample.maskFile = outputDir + "/constructed_mask.fits"
|
||||
figureOutMask(datafile, sample.nsideForMask, sample.maskFile)
|
||||
if sample.nsideForContour == -1:
|
||||
sample.nsideForContour = 128
|
||||
|
||||
sample.maskFile = outputDir + "/constructed_mask.fits"
|
||||
figureOutMask(datafile, sample.nsideForContour, sample.maskFile)
|
||||
|
||||
# compute mean particle separation
|
||||
(boxVol, nbar) = getSurveyProps(sample.maskFile, sample.zRange[0],
|
||||
sample.zRange[1], sample.zRange[0], sample.zRange[1], "all",
|
||||
sample.omegaM, useComoving=useComoving)
|
||||
|
||||
numTracers = int(open(outputDir+"/mask_index.txt", "r").read())
|
||||
sample.meanPartSep = (1.*numTracers/boxVol/nbar)**(-1/3.)
|
||||
|
||||
|
||||
# flag edge galaxies
|
||||
galFile = outputDir + "galaxies.txt"
|
||||
edgeGalFile = outputDir + "/galaxy_edge_flags.txt"
|
||||
edgeMaskFile = outputDir + "/mask_edge_map.fits"
|
||||
findEdgeGalaxies(datafile, sample.maskFile, edgeGalFile, edgeMaskFile,
|
||||
#edgeMaskFile = outputDir + "/mask_edge_map.fits"
|
||||
contourFile = outputDir + "/contour_map.fits"
|
||||
findEdgeGalaxies(galFile, sample.maskFile, edgeGalFile, contourFile,
|
||||
sample.zBoundary[0], sample.zBoundary[1], sample.omegaM,
|
||||
useComoving, sample.boundaryWidth)
|
||||
useComoving, sample.boundaryWidth, sample.meanPartSep)
|
||||
|
||||
if useComoving:
|
||||
useComovingFlag = "useComoving"
|
||||
|
@ -92,12 +110,15 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
|||
%s
|
||||
%s
|
||||
omegaM %g
|
||||
nsideForContour %g
|
||||
meanPartSep %g
|
||||
""" % (datafile, sample.maskFile, outputFile,
|
||||
outputDir+"/zobov_slice_"+sampleName+".par",
|
||||
sample.zBoundary[0], sample.zBoundary[1], sample.fakeDensity,
|
||||
useComovingFlag, inputParameterFlag, sample.omegaM)
|
||||
useComovingFlag, inputParameterFlag, sample.omegaM,
|
||||
sample.nsideForContour, sample.meanPartSep)
|
||||
|
||||
parmFile = os.getcwd()+"/generate_"+sample.fullName+".par"
|
||||
parmFile = os.getcwd()+"/prep_"+sample.fullName+".par"
|
||||
|
||||
if regenerate or not (continueRun and jobSuccessful(logFile, "Done!\n")):
|
||||
with open(parmFile, mode="wt") as f:
|
||||
|
@ -106,9 +127,11 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
|||
with open(logFile, 'wt') as log:
|
||||
subprocess.call([binPath, arg1], stdout=log, stderr=log)
|
||||
if jobSuccessful(logFile, "Done!\n"):
|
||||
print("done")
|
||||
endTime = time.time()
|
||||
walltime = endTime - startTime
|
||||
print("done (%.2fs elapsed)" % walltime)
|
||||
else:
|
||||
print("FAILED!")
|
||||
print("FAILED! See log file for details.")
|
||||
exit(-1)
|
||||
|
||||
else:
|
||||
|
@ -118,7 +141,6 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
|||
|
||||
if os.access("contour_map.fits", os.F_OK):
|
||||
os.system("mv %s %s" % ("contour_map.fits", outputDir))
|
||||
os.system("mv %s %s" % ("mask_map.fits", outputDir))
|
||||
|
||||
if os.access("comoving_distance.txt", os.F_OK):
|
||||
os.system("mv %s %s" % ("comoving_distance.txt", outputDir))
|
||||
|
@ -129,15 +151,26 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
|||
|
||||
if os.access("galaxies.txt", os.F_OK):
|
||||
os.system("mv %s %s" % ("galaxies.txt", outputDir))
|
||||
os.system("mv %s %s" % ("mock_galaxies.txt", outputDir))
|
||||
os.system("mv %s %s" % ("mock_boundary.txt", outputDir))
|
||||
os.system("mv %s %s" % ("mock_sphere.txt", outputDir))
|
||||
#os.system("mv %s %s" % ("galaxy_edge_flags.txt", outputDir))
|
||||
|
||||
else: # simulation
|
||||
sampleName = sample.fullName
|
||||
|
||||
datafile = inputDataDir+"/"+sample.dataFile
|
||||
|
||||
# compute mean particle separation
|
||||
iX = float(sample.mySubvolume[0])
|
||||
iY = float(sample.mySubvolume[1])
|
||||
xMin = iX/sample.numSubvolumes * sample.boxLen
|
||||
yMin = iY/sample.numSubvolumes * sample.boxLen
|
||||
xMax = (iX+1)/sample.numSubvolumes * sample.boxLen
|
||||
yMax = (iY+1)/sample.numSubvolumes * sample.boxLen
|
||||
zMin = sample.zBoundaryMpc[0]
|
||||
zMax = sample.zBoundaryMpc[1]
|
||||
|
||||
boxVol = (xMax-xMin)*(yMax-yMin)*(zMax-zMin)
|
||||
sample.meanPartSep = (1.*numTracers/boxVol)**(-1/3.)
|
||||
|
||||
# check if the final subsampling is done
|
||||
lastSample = sample.subsample.split(', ')[-1]
|
||||
doneLine = "Done! %5.2e\n" % float(lastSample)
|
||||
|
@ -245,7 +278,7 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
|||
cmd = "%s --configFile=%s" % (binPath,parmFile)
|
||||
log = open(logFile, 'a')
|
||||
arg1 = "--configFile=%s" % parmFile
|
||||
|
||||
|
||||
|
||||
subprocess.call(cmd, stdout=log, stderr=log, shell=True)
|
||||
log.close()
|
||||
|
@ -257,7 +290,7 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
|||
|
||||
doneLine = "Done! %5.2e\n" % keepFraction
|
||||
if not jobSuccessful(logFile, doneLine):
|
||||
print("FAILED!") ### dies here for now
|
||||
print("FAILED! See log file for details.") ### dies here for now
|
||||
exit(-1)
|
||||
|
||||
prevSubSample = thisSubSample
|
||||
|
@ -281,29 +314,6 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
|||
os.system("mv %s %s" % ("total_particles.txt", outputDir))
|
||||
#os.system("mv %s %s" % ("sample_info.txt", outputDir))
|
||||
|
||||
# add to sample info file
|
||||
if sample.dataType == "observation":
|
||||
(boxVol, nbar) = getSurveyProps(sample.maskFile, sample.zRange[0],
|
||||
sample.zRange[1], sample.zRange[0], sample.zRange[1], "all",
|
||||
sample.omegaM, useComoving=useComoving)
|
||||
else:
|
||||
iX = float(sample.mySubvolume[0])
|
||||
iY = float(sample.mySubvolume[1])
|
||||
xMin = iX/sample.numSubvolumes * sample.boxLen
|
||||
yMin = iY/sample.numSubvolumes * sample.boxLen
|
||||
xMax = (iX+1)/sample.numSubvolumes * sample.boxLen
|
||||
yMax = (iY+1)/sample.numSubvolumes * sample.boxLen
|
||||
zMin = sample.zBoundaryMpc[0]
|
||||
zMax = sample.zBoundaryMpc[1]
|
||||
|
||||
boxVol = (xMax-xMin)*(yMax-yMin)*(zMax-zMin)
|
||||
nbar = 1.0
|
||||
|
||||
numTracers = int(open(outputDir+"/mask_index.txt", "r").read())
|
||||
numTotal = int(open(outputDir+"/total_particles.txt", "r").read())
|
||||
|
||||
meanSep = (1.*numTracers/boxVol/nbar)**(-1/3.)
|
||||
|
||||
# save this sample's information
|
||||
with open(outputDir+"/sample_info.dat", mode='wb') as output:
|
||||
pickle.dump(sample, output, pickle.HIGHEST_PROTOCOL)
|
||||
|
@ -325,9 +335,8 @@ def launchPrep(sample, binPath, workDir=None, inputDataDir=None,
|
|||
fp.write("Number of simulation subvolumes: %s\n" % sample.numSubvolumes)
|
||||
fp.write("My subvolume index: %s\n" % sample.mySubvolume)
|
||||
fp.write("Estimated volume (cubic Mpc/h): %g\n" % boxVol)
|
||||
fp.write("Number of real (non-boundary) tracers: %d\n" % numTracers)
|
||||
fp.write("Total number of tracers: %d\n" % numTotal)
|
||||
fp.write("Estimated mean tracer separation (Mpc/h): %g\n" % meanSep)
|
||||
fp.write("Total number of tracers: %d\n" % numTracers)
|
||||
fp.write("Estimated mean tracer separation (Mpc/h): %g\n" % sample.meanPartSep)
|
||||
fp.write("Minimum void size actually used (Mpc/h): %g\n" % sample.minVoidRadius)
|
||||
fp.close()
|
||||
|
||||
|
@ -336,6 +345,8 @@ def launchZobov(sample, binPath, outputDir=None, logDir=None, continueRun=None,
|
|||
numZobovDivisions=None, numZobovThreads=None,
|
||||
mergingThreshold=0.2):
|
||||
|
||||
startTime = time.time()
|
||||
|
||||
sampleName = sample.fullName
|
||||
|
||||
datafile = outputDir+"zobov_slice_"+sampleName
|
||||
|
@ -490,9 +501,11 @@ def launchZobov(sample, binPath, outputDir=None, logDir=None, continueRun=None,
|
|||
os.unlink(fileName)
|
||||
|
||||
if jobSuccessful(logFile, "Done!\n"):
|
||||
print("done")
|
||||
endTime = time.time()
|
||||
walltime = endTime - startTime
|
||||
print("done (%.2fs elapsed)" % walltime)
|
||||
else:
|
||||
print("FAILED!")
|
||||
print("FAILED! See log file for details.")
|
||||
exit(-1)
|
||||
|
||||
else:
|
||||
|
@ -507,6 +520,8 @@ def launchPrune(sample, binPath,
|
|||
continueRun=None, useComoving=False, mergingThreshold=0.2,
|
||||
boundaryTolerance=1.0):
|
||||
|
||||
startTime = time.time()
|
||||
|
||||
sampleName = sample.fullName
|
||||
|
||||
numVoids = sum(1 for line in \
|
||||
|
@ -580,9 +595,11 @@ def launchPrune(sample, binPath,
|
|||
|
||||
if jobSuccessful(logFile, "NetCDF: Not a valid ID\n") or \
|
||||
jobSuccessful(logFile, "Done!\n"):
|
||||
print("done")
|
||||
endTime = time.time()
|
||||
walltime = endTime - startTime
|
||||
print("done (%.2fs elapsed)" % walltime)
|
||||
else:
|
||||
print("FAILED!")
|
||||
print("FAILED! See log file for details.")
|
||||
#exit(-1)
|
||||
|
||||
else:
|
||||
|
@ -597,6 +614,8 @@ def launchVoidOverlap(sample1, sample2, sample1Dir, sample2Dir,
|
|||
overlapFrac=0.25,
|
||||
matchMethod=None, strictMatch=False):
|
||||
|
||||
startTime = time.time()
|
||||
|
||||
sampleName1 = sample1.fullName
|
||||
sampleName2 = sample2.fullName
|
||||
|
||||
|
@ -663,7 +682,9 @@ def launchVoidOverlap(sample1, sample2, sample1Dir, sample2Dir,
|
|||
log.close()
|
||||
|
||||
#if jobSuccessful(logFile, "Done!\n"):
|
||||
print("done")
|
||||
endTime = time.time()
|
||||
walltime = endTime - startTime
|
||||
print("done (%.2fs elapsed)" % walltime)
|
||||
#else:
|
||||
# print "FAILED!"
|
||||
# exit(-1)
|
||||
|
@ -707,7 +728,7 @@ def launchVelocityStack(sample, stack, binPath,
|
|||
if jobSuccessful(logFile, "Done!\n"):
|
||||
print("done")
|
||||
else:
|
||||
print("FAILED!")
|
||||
print("FAILED! See log file for details.")
|
||||
exit(-1)
|
||||
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue