mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-04 15:21:11 +00:00
Merge branch 'master' of bitbucket.org:cosmicvoids/void_identification
This commit is contained in:
commit
e9194f5c55
3 changed files with 151 additions and 98 deletions
|
@ -62,7 +62,7 @@ def getSampleName(setName, redshift, useVel, iSlice=-1, iVol=-1):
|
|||
def writeScript(setName, dataFileNameBase, dataFormat,
|
||||
scriptDir, catalogDir, fileNums, redshifts, numSubvolumes,
|
||||
numSlices, useVel, lbox, minRadius, omegaM, subsample=1.0,
|
||||
suffix=".dat"):
|
||||
suffix=".dat", dataFileNameList=None):
|
||||
|
||||
|
||||
if useVel: setName += "_pv"
|
||||
|
@ -134,7 +134,7 @@ newSample = Sample(dataFile = "{dataFile}",
|
|||
numSubvolumes = {numSubvolumes},
|
||||
mySubvolume = "{mySubvolume}",
|
||||
useLightCone = {useLightCone},
|
||||
subsample = {subsample})
|
||||
subsample = "{subsample}")
|
||||
dataSampleList.append(newSample)
|
||||
newSample.addStack(0.0, 5.0, 20, 25, False, False)
|
||||
newSample.addStack(0.0, 5.0, 30, 35, False, False)
|
||||
|
@ -165,33 +165,32 @@ newSample.addStack(0.0, 5.0, 90, 95, False, False)
|
|||
for i in xrange(len(zVsDY)):
|
||||
zVsDX[i] = vp.angularDiameter(zVsDY[i], Om=Om)
|
||||
|
||||
if useLightCone:
|
||||
boxWidthZ = np.interp(vp.angularDiameter(zBox,Om=Om)+100. / \
|
||||
LIGHT_SPEED*lbox, zVsDX, zVsDY)-zBox
|
||||
dzSafe = 0.03
|
||||
else:
|
||||
boxWidthZ = np.interp(vp.angularDiameter(zBox,Om=Om)+100. / \
|
||||
LIGHT_SPEED*lbox, zVsDX, zVsDY)-zBox
|
||||
#boxWidthZ = lbox*100./LIGHT_SPEED
|
||||
dzSafe = 0.0
|
||||
boxWidthZ = np.interp(vp.angularDiameter(zBox,Om=Om)+100. / \
|
||||
LIGHT_SPEED*lbox, zVsDX, zVsDY)-zBox
|
||||
|
||||
for iSlice in xrange(numSlices):
|
||||
sliceMin = zBox + dzSafe + iSlice*(boxWidthZ-2.*dzSafe)/numSlices
|
||||
sliceMax = zBox + dzSafe + (iSlice+1)*(boxWidthZ-2.*dzSafe)/numSlices
|
||||
|
||||
if useLightCone:
|
||||
dzSafe = 0.03
|
||||
sliceMin = zBox + dzSafe + iSlice*(boxWidthZ-2.*dzSafe)/numSlices
|
||||
sliceMax = zBox + dzSafe + (iSlice+1)*(boxWidthZ-2.*dzSafe)/numSlices
|
||||
sliceMinMpc = sliceMin*LIGHT_SPEED/100.
|
||||
sliceMaxMpc = sliceMax*LIGHT_SPEED/100.
|
||||
else:
|
||||
sliceMinMpc = LIGHT_SPEED/100.*vp.angularDiameter(sliceMin, Om=Om)
|
||||
sliceMaxMpc = LIGHT_SPEED/100.*vp.angularDiameter(sliceMax, Om=Om)
|
||||
sliceMinMpc = zBoxMpc + iSlice*lbox/numSlices
|
||||
sliceMaxMpc = zBoxMpc + (iSlice+1)*lbox/numSlices
|
||||
sliceMin = np.interp(sliceMinMpc*100./LIGHT_SPEED, zVsDX, zVsDY)
|
||||
sliceMax = np.interp(sliceMaxMpc*100./LIGHT_SPEED, zVsDX, zVsDY)
|
||||
|
||||
sliceMin = "%0.2f" % sliceMin
|
||||
sliceMax = "%0.2f" % sliceMax
|
||||
sliceMinMpc = "%0.1f" % sliceMinMpc
|
||||
sliceMaxMpc = "%0.1f" % sliceMaxMpc
|
||||
|
||||
dataFileName = dataFileNameBase + fileNum + suffix
|
||||
if (dataFileNameList != None):
|
||||
dataFileName = dataFileNameList[iFile]
|
||||
else:
|
||||
dataFileName = dataFileNameBase + fileNum + suffix
|
||||
|
||||
for iX in xrange(numSubvolumes):
|
||||
for iY in xrange(numSubvolumes):
|
||||
|
@ -216,7 +215,7 @@ newSample.addStack(0.0, 5.0, 90, 95, False, False)
|
|||
numSubvolumes=numSubvolumes,
|
||||
mySubvolume=mySubvolume,
|
||||
useLightCone=useLightCone,
|
||||
subsample=subsample))
|
||||
subsample=str(subsample).strip('[]')))
|
||||
|
||||
scriptFile.close()
|
||||
return
|
||||
|
@ -233,44 +232,60 @@ if not os.access(catalogDir, os.F_OK): os.mkdir(catalogDir)
|
|||
# ss0.000175 ~ SDSS DR9 mid
|
||||
baseResolution = float(numPart)/lbox/lbox/lbox # particles/Mpc^3
|
||||
prevSubSample = -1
|
||||
for thisSubSample in sorted(subSamples, reverse=True):
|
||||
subSamples = sorted(subSamples, reverse=True)
|
||||
for iSubSample in xrange(len(subSamples)):
|
||||
|
||||
keepFraction = float(thisSubSample) / baseResolution
|
||||
maxKeep = keepFraction * numPart
|
||||
subSampleList = subSamples[0:iSubSample+1]
|
||||
|
||||
keepFractionList = []
|
||||
for subSample in subSampleList:
|
||||
keepFractionList.append(float(subSample) / baseResolution)
|
||||
thisSubSample = subSamples[iSubSample]
|
||||
maxKeep = keepFractionList[-1] * numPart
|
||||
minRadius = int(np.ceil(lbox/maxKeep**(1./3)))
|
||||
|
||||
partFileList = []
|
||||
for (iRedshift, redshift) in enumerate(redshifts):
|
||||
if particleFileDummy == '':
|
||||
partFileList.append(particleFileBase+fileNums[iRedshift])
|
||||
else:
|
||||
partFileList.append(particleFileBase.replace(particleFileDummy,
|
||||
fileNums[iRedshift]))
|
||||
|
||||
if args.script or args.all:
|
||||
print " Doing subsample", thisSubSample, "scripts"
|
||||
sys.stdout.flush()
|
||||
setName = prefix+"ss"+str(thisSubSample)
|
||||
if dataFormat == "multidark":
|
||||
subSampleToUse = 1.0
|
||||
fileToUse = prefix+"ss"+str(thisSubSample)+"_z"
|
||||
suffix = ".dat"
|
||||
elif dataFormat == "gadget":
|
||||
subSampleToUse = keepFraction
|
||||
#subSampleToUse = thisSubSample
|
||||
fileToUse = particleFileBase
|
||||
suffix = ""
|
||||
elif dataFormat == "lanl":
|
||||
subSampleToUse = keepFraction
|
||||
#subSampleToUse = thisSubSample
|
||||
fileToUse = particleFileBase
|
||||
suffix = ""
|
||||
elif dataFormat == "random":
|
||||
|
||||
if dataFormat == "random":
|
||||
subSampleToUse = 1.0
|
||||
fileToUse = "ran.ss"+str(thisSubSample)+"_z"
|
||||
suffix = ".dat"
|
||||
|
||||
writeScript(setName, fileToUse, dataFormat,
|
||||
writeScript(setName, fileToUse, dataFormat,
|
||||
scriptDir, catalogDir, fileNums, redshifts,
|
||||
numSubvolumes, numSlices, False, lbox, minRadius, omegaM,
|
||||
subsample=subSampleToUse, suffix=suffix)
|
||||
writeScript(setName, fileToUse, dataFormat,
|
||||
writeScript(setName, fileToUse, dataFormat,
|
||||
scriptDir, catalogDir, fileNums, redshifts,
|
||||
numSubvolumes, numSlices, True, lbox, minRadius, omegaM,
|
||||
subsample=subSampleToUse, suffix=suffix)
|
||||
|
||||
else:
|
||||
subSampleToUse = keepFractionList
|
||||
suffix = ""
|
||||
fileToUse = partFileList[0]
|
||||
writeScript(setName, fileToUse, dataFormat,
|
||||
scriptDir, catalogDir, fileNums, redshifts,
|
||||
numSubvolumes, numSlices, False, lbox, minRadius, omegaM,
|
||||
subsample=subSampleToUse, suffix=suffix,
|
||||
dataFileNameList=partFileList)
|
||||
writeScript(setName, fileToUse, dataFormat,
|
||||
scriptDir, catalogDir, fileNums, redshifts,
|
||||
numSubvolumes, numSlices, True, lbox, minRadius, omegaM,
|
||||
subsample=subSampleToUse, suffix=suffix,
|
||||
dataFileNameList=partFileList)
|
||||
|
||||
|
||||
if args.subsample or args.all:
|
||||
print " Doing subsample", thisSubSample
|
||||
sys.stdout.flush()
|
||||
|
@ -411,31 +426,37 @@ if (args.halos or args.all) and haloFileBase != "":
|
|||
|
||||
sampleName = prefix+"halos_min"+str(minHaloMass)+"_z"+fileNums[iRedshift]
|
||||
outFile = open(catalogDir+"/"+sampleName+".dat", 'w')
|
||||
|
||||
outFile.write("%f\n" %(lbox))
|
||||
outFile.write("%s\n" %(omegaM))
|
||||
outFile.write("%s\n" %(hubble))
|
||||
outFile.write("%s\n" %(redshift))
|
||||
outFile.write("%d\n" %(numPart))
|
||||
|
||||
inFile = open(dataFile, 'r')
|
||||
for (iHalo,line) in enumerate(inFile):
|
||||
if iHalo < haloFileNumComLines: continue
|
||||
line = line.split(haloFileColSep)
|
||||
if minHaloMass == "none" or float(line[haloFileMCol]) > minHaloMass:
|
||||
x = float(line[haloFileXCol])
|
||||
y = float(line[haloFileYCol])
|
||||
z = float(line[haloFileZCol])
|
||||
vz = float(line[haloFileVZCol])
|
||||
vy = float(line[haloFileVYCol])
|
||||
vx = float(line[haloFileVXCol])
|
||||
if dataFormat == "sdf":
|
||||
# TODO process halo file with SDFcvt
|
||||
outFile = open(catalogDir+"/"+sampleName+".dat", 'w')
|
||||
outFile.write("-99 -99 -99 -99 -99 -99 -99\n")
|
||||
outFile.close()
|
||||
else:
|
||||
outFile = open(catalogDir+"/"+sampleName+".dat", 'w')
|
||||
inFile = open(dataFile, 'r')
|
||||
for (iHalo,line) in enumerate(inFile):
|
||||
if iHalo < haloFileNumComLines: continue
|
||||
line = line.split(haloFileColSep)
|
||||
if minHaloMass == "none" or float(line[haloFileMCol]) > minHaloMass:
|
||||
x = float(line[haloFileXCol])
|
||||
y = float(line[haloFileYCol])
|
||||
z = float(line[haloFileZCol])
|
||||
vz = float(line[haloFileVZCol])
|
||||
vy = float(line[haloFileVYCol])
|
||||
vx = float(line[haloFileVXCol])
|
||||
|
||||
# write to output file
|
||||
outFile.write("%d %e %e %e %e %e %e\n" %(iHalo,x,y,z,vz,vy,vx))
|
||||
# write to output file
|
||||
outFile.write("%d %e %e %e %e %e %e\n" %(iHalo,x,y,z,vz,vy,vx))
|
||||
|
||||
outFile.write("-99 -99 -99 -99 -99 -99 -99\n")
|
||||
inFile.close()
|
||||
outFile.close()
|
||||
outFile.write("-99 -99 -99 -99 -99 -99 -99\n")
|
||||
outFile.close()
|
||||
inFile.close()
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# now the HOD
|
||||
|
@ -510,6 +531,14 @@ if (args.hod or args.all) and haloFileBase != "":
|
|||
else:
|
||||
haloFile = catalogDir+haloFileBase.replace(haloFileDummy,
|
||||
fileNums[iRedshift])
|
||||
|
||||
if dataFormat == "sdf":
|
||||
# TODO process halo file with SDFcvt
|
||||
inFile = haloFile
|
||||
outFile = haloFile+"_temp"
|
||||
|
||||
haloFile = outFile
|
||||
|
||||
parFile.write(parFileText.format(omegaM=omegaM,
|
||||
hubble=hubble,
|
||||
redshift=redshift,
|
||||
|
@ -535,4 +564,6 @@ if (args.hod or args.all) and haloFileBase != "":
|
|||
os.system("mv %s/hod.mock %s" % (catalogDir, outFileName))
|
||||
os.system("rm %s/hod.*" % catalogDir)
|
||||
|
||||
os.system("rm %s" % haloFile)
|
||||
|
||||
print " Done!"
|
||||
|
|
|
@ -105,37 +105,43 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None,
|
|||
|
||||
datafile = inputDataDir+"/"+sample.dataFile
|
||||
|
||||
if regenerate:
|
||||
inputParameterFlag = "inputParameter " + zobovDir+"/zobov_slice_"+sampleName+".par"
|
||||
outputFile = zobovDir+"/regenerated_zobov_slice_" + sampleName
|
||||
else:
|
||||
inputParameterFlag = ""
|
||||
outputFile = zobovDir+"/zobov_slice_" + sampleName
|
||||
prevSubSample = -1
|
||||
for thisSubSample in sample.subsample.split(', '):
|
||||
|
||||
if prevSubSample == -1:
|
||||
inputParameterFlag = ""
|
||||
outputFile = zobovDir+"/zobov_slice_" + sampleName + "_ss" + thisSubSample
|
||||
keepFraction = float(thisSubSample)
|
||||
subSampleLine = "subsample %g" % keepFraction
|
||||
else:
|
||||
inputParameterFlag = "inputParameter " + zobovDir+"/zobov_slice_"+\
|
||||
sampleName+"_ss"+prevSubSample+".par"
|
||||
outputFile = zobovDir+"/_zobov_slice_" + sampleName + "_ss" + thisSubSample
|
||||
keepFraction = float(thisSubSample)/float(prevSubSample)
|
||||
subSampleLine = "resubsample %g" % keepFraction
|
||||
|
||||
if sample.usePecVel:
|
||||
includePecVelString = "peculiarVelocities"
|
||||
else:
|
||||
includePecVelString = ""
|
||||
if sample.usePecVel: includePecVelString = "peculiarVelocities"
|
||||
|
||||
if sample.useLightCone:
|
||||
useLightConeString = "cosmo"
|
||||
else:
|
||||
useLightConeString = ""
|
||||
if sample.useLightCone: useLightConeString = "cosmo"
|
||||
|
||||
if sample.dataFormat == "multidark" or sample.dataFormat == "random":
|
||||
dataFileLine = "multidark " + datafile
|
||||
elif sample.dataFormat == "gadget":
|
||||
dataFileLine = "gadget " + datafile
|
||||
if sample.dataFormat == "multidark" or sample.dataFormat == "random":
|
||||
dataFileLine = "multidark " + datafile
|
||||
elif sample.dataFormat == "gadget":
|
||||
dataFileLine = "gadget " + datafile
|
||||
elif sample.dataFormat == "sdf":
|
||||
dataFileLine = "sdf " + datafile
|
||||
|
||||
iX = float(sample.mySubvolume[0])
|
||||
iY = float(sample.mySubvolume[1])
|
||||
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
|
||||
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
|
||||
|
||||
conf="""
|
||||
conf="""
|
||||
%s
|
||||
output %s
|
||||
outputParameter %s
|
||||
|
@ -148,36 +154,52 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None,
|
|||
rangeY_max %g
|
||||
rangeZ_min %g
|
||||
rangeZ_max %g
|
||||
subsample %g
|
||||
%s
|
||||
%s
|
||||
""" % (dataFileLine, outputFile,
|
||||
zobovDir+"/zobov_slice_"+sampleName+".par",
|
||||
outputFile+".par",
|
||||
includePecVelString,
|
||||
useLightConeString,
|
||||
sample.dataUnit,
|
||||
xMin, xMax, yMin, yMax,
|
||||
sample.zBoundaryMpc[0], sample.zBoundaryMpc[1],
|
||||
sample.subsample,inputParameterFlag)
|
||||
subSampleLine,inputParameterFlag)
|
||||
|
||||
parmFile = os.getcwd()+"/generate_"+sample.fullName+".par"
|
||||
parmFile = os.getcwd()+"/generate_"+sample.fullName+".par"
|
||||
|
||||
file(parmFile, mode="w").write(conf)
|
||||
file(parmFile, mode="w").write(conf)
|
||||
|
||||
if regenerate or not (continueRun and jobSuccessful(logFile, "Done!\n")):
|
||||
cmd = "%s --configFile=%s &> %s" % (binPath,parmFile,logFile)
|
||||
os.system(cmd)
|
||||
if jobSuccessful(logFile, "Done!\n"):
|
||||
print "done"
|
||||
else:
|
||||
print "FAILED!"
|
||||
exit(-1)
|
||||
doneLine = "Done! %5.2e\n" % keepFraction
|
||||
print "TEST", doneLine
|
||||
if not (continueRun and jobSuccessful(logFile, doneLine)):
|
||||
if (prevSubSample == -1):
|
||||
cmd = "%s --configFile=%s &> %s" % (binPath,parmFile,logFile)
|
||||
else:
|
||||
cmd = "%s --configFile=%s &>> %s" % (binPath,parmFile,logFile)
|
||||
os.system(cmd)
|
||||
|
||||
if not jobSuccessful(logFile, doneLine):
|
||||
print "FAILED!"
|
||||
exit(-1)
|
||||
|
||||
else:
|
||||
print "already done!"
|
||||
# remove intermediate files
|
||||
if (prevSubSample != -1):
|
||||
os.unlink(zobovDir+"/zobov_slice_"+sampleName+"_ss"+prevSubSample+".par")
|
||||
os.unlink(zobovDir+"/zobov_slice_"+sampleName+"_ss"+prevSubSample)
|
||||
|
||||
prevSubSample = thisSubSample
|
||||
|
||||
if (continueRun and jobSuccessful(logFile, doneLine)): print "already done!"
|
||||
if jobSuccessful(logFile, doneLine): print "done"
|
||||
|
||||
# place the final subsample
|
||||
os.system("mv %s %s" % (zobovDir+"/zobov_slice_"+sampleName+"_ss"+\
|
||||
prevSubSample, zobovDir+"/zobov_slice_"+sampleName))
|
||||
os.system("mv %s %s" % (zobovDir+"/zobov_slice_"+sampleName+"_ss"+\
|
||||
prevSubSample+".par", zobovDir+"/zobov_slice_"+sampleName+".par"))
|
||||
|
||||
if os.access("comoving_distance.txt", os.F_OK):
|
||||
os.system("mv %s %s" % ("comoving_distance.txt", zobovDir))
|
||||
#os.system("mv %s %s" % ("sample_info.txt", zobovDir))
|
||||
|
||||
if os.access(parmFile, os.F_OK):
|
||||
os.unlink(parmFile)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue