This commit is contained in:
Guilhem Lavaux 2012-11-18 21:57:36 -05:00
commit 9e79c784f3
29 changed files with 1679 additions and 2007 deletions

View file

@ -1,2 +1,3 @@
from classes import *
from launchers import *
from catalogPrep import *

File diff suppressed because it is too large Load diff

View file

@ -38,6 +38,7 @@ class Sample:
dataType = "observation"
dataFormat = "sdss"
dataFile = "lss.dr72dim.dat"
dataUNit = 1
fullName = "lss.dr72dim.dat"
nickName = "dim"
zobovDir = ""
@ -62,22 +63,21 @@ class Sample:
usePecVel = False
subsample = 1.0
useLightCone = True
numSubDivisions = 1
numSubvolumes = 1
mySubvolume = 1
stacks = []
def __init__(self, dataFile="", fullName="",
def __init__(self, dataFile="", fullName="", dataUnit=1,
nickName="", maskFile="", selFunFile="",
zBoundary=(), zRange=(), zBoundaryMpc=(),
minVoidRadius=0, fakeDensity=0.01, volumeLimited=True,
includeInHubble=True, partOfCombo=False, isCombo=False,
comboList=(), profileBinSize=2.0, skyFraction=0.19,
dataType="observation", numSubDivisions=2,
boxLen=1024, usePecVel=False, omegaM=0.27,
numSubvolumes=1, mySubvolume=1, dataFormat="sdss",
subsample="1.0", useLightCone=True):
dataType="observation",
subsample=1.0, useLightCone=True):
self.dataFile = dataFile
self.fullName = fullName
self.nickName = nickName
@ -97,7 +97,6 @@ class Sample:
self.profileBinSize = profileBinSize
self.skyFraction = skyFraction
self.dataType = dataType
self.numSubDivisions = numSubDivisions
self.boxLen = boxLen
self.usePecVel = usePecVel
self.omegaM = omegaM
@ -106,6 +105,7 @@ class Sample:
self.dataFormat = dataFormat
self.subsample = subsample
self.useLightCone = useLightCone
self.dataUnit = dataUnit
self.stacks = []

View file

@ -84,7 +84,7 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None,
if os.access("mask_index.txt", os.F_OK):
os.system("mv %s %s" % ("mask_index.txt", zobovDir))
os.system("mv %s %s" % ("total_particles.txt", zobovDir))
os.system("mv %s %s" % ("sample_info.txt", zobovDir))
#os.system("mv %s %s" % ("sample_info.txt", zobovDir))
if os.access("galaxies.txt", os.F_OK):
os.system("mv %s %s" % ("galaxies.txt", zobovDir))
@ -102,11 +102,16 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None,
else:
includePecVelString = ""
if sample.dataFormat == "multidark":
if sample.useLightCone:
useLightConeString = "cosmo"
else:
useLightConeString = ""
if sample.dataFormat == "multidark" or sample.dataFormat == "random":
dataFileLine = "multidark " + datafile
elif sample.dataFormat == "gadget":
dataFileLine = "gadget " + datafile
iX = float(sample.mySubvolume[0])
iY = float(sample.mySubvolume[1])
@ -120,16 +125,20 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None,
output %s
outputParameter %s
%s
%s
gadgetUnit %g
rangeX_min %g
rangeX_max %g
rangeY_min %g
rangeY_max %g
rangeZ_min %g
rangeZ_max %g
subsample %g
subsample %s
""" % (dataFileLine, zobovDir+"/zobov_slice_"+sampleName,
zobovDir+"/zobov_slice_"+sampleName+".par",
includePecVelString,
useLightConeString,
sample.dataUnit,
xMin, xMax, yMin, yMax,
sample.zBoundaryMpc[0], sample.zBoundaryMpc[1],
sample.subsample)
@ -150,11 +159,16 @@ def launchGenerate(sample, binPath, workDir=None, inputDataDir=None,
else:
print "already done!"
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)
# -----------------------------------------------------------------------------
def launchZobov(sample, binPath, zobovDir=None, logDir=None, continueRun=None):
def launchZobov(sample, binPath, zobovDir=None, logDir=None, continueRun=None,
numZobovDivisions=None, numZobovThreads=None):
sampleName = sample.fullName
@ -185,9 +199,9 @@ def launchZobov(sample, binPath, zobovDir=None, logDir=None, continueRun=None):
if os.access(zobovDir+"/voidDesc_"+sampleName+".out", os.F_OK):
os.unlink(zobovDir+"/voidDesc_"+sampleName+".out")
cmd = "%s/vozinit %s 0.1 1.0 2 %s %g %s %s %s >& %s" % \
(binPath, datafile, \
"_"+sampleName, sample.numSubDivisions, \
cmd = "%s/vozinit %s 0.1 1.0 %g %s %g %s %s %s >& %s" % \
(binPath, datafile, numZobovDivisions, \
"_"+sampleName, numZobovThreads, \
binPath, zobovDir, maskIndex, logFile)
os.system(cmd)
@ -232,11 +246,18 @@ def launchPrune(sample, binPath, thisDataPortion=None,
totalPart = open(zobovDir+"/total_particles.txt", "r").read()
maxDen = 0.2*float(mockIndex)/float(totalPart)
observationLine = " --isObservation"
periodicLine = " --periodic=''"
else:
mockIndex = -1
maxDen = 0.2
observationLine = ""
periodicLine = " --periodic='"
if sample.numSubvolumes == 1: periodicLine += "xy"
if sample.zBoundaryMpc[0] == 0 and \
sample.zBoundaryMpc[1] == sample.boxLen : periodicLine += "z"
periodicLine += "' "
if not (continueRun and jobSuccessful(logFile, "NetCDF: Not a valid ID\n")):
cmd = binPath
cmd += " --partFile=" + zobovDir+"/zobov_slice_"+str(sampleName)
@ -255,6 +276,7 @@ def launchPrune(sample, binPath, thisDataPortion=None,
cmd += " --rMin=" + str(sample.minVoidRadius)
cmd += " --numVoids=" + str(numVoids)
cmd += observationLine
cmd += periodicLine
cmd += " --output=" + zobovDir+"/voidDesc_"+\
str(thisDataPortion)+"_"+\
str(sampleName)+".out"
@ -276,7 +298,8 @@ def launchPrune(sample, binPath, thisDataPortion=None,
cmd += " >& " + logFile
os.system(cmd)
if jobSuccessful(logFile, "NetCDF: Not a valid ID\n"):
if jobSuccessful(logFile, "NetCDF: Not a valid ID\n") or \
jobSuccessful(logFile, "Done!\n"):
print "done"
else:
print "FAILED!"
@ -356,8 +379,8 @@ def launchStack(sample, stack, binPath, thisDataPortion=None, logDir=None,
%s
ranSeed %d
dataPortion %s
barycenters %s
boundaryDistances %s
#barycenters %s
#boundaryDistances %s
%s
""" % \
(zobovDir+"/voidDesc_"+thisDataPortion+"_"+sampleName+".out",
@ -460,34 +483,37 @@ def launchStack(sample, stack, binPath, thisDataPortion=None, logDir=None,
return
# figure out box volume and average density
maskFile = sample.maskFile
sulFunFile = sample.selFunFile
if sample.dataType == "observation":
maskFile = sample.maskFile
sulFunFile = sample.selFunFile
if not os.access(sample.selFunFile, os.F_OK) and not volumeLimited:
print " Cannot find", selFunFile, "!"
exit(-1)
if not os.access(sample.selFunFile, os.F_OK) and not sample.volumeLimited:
print " Cannot find", selFunFile, "!"
exit(-1)
sys.stdout = open(logFile, 'a')
sys.stderr = open(logFile, 'a')
zMin = sample.zRange[0]
zMax = sample.zRange[1]
if not sample.volumeLimited:
props = vp.getSurveyProps(maskFile, stack.zMin,
stack.zMax, zMin, zMax, "all",
selectionFuncFile=sample.selFunFile)
sys.stdout = open(logFile, 'a')
sys.stderr = open(logFile, 'a')
zMin = sample.zRange[0]
zMax = sample.zRange[1]
if not sample.volumeLimited:
props = vp.getSurveyProps(maskFile, stack.zMin,
stack.zMax, zMin, zMax, "all",
selectionFuncFile=sample.selFunFile)
else:
zMinForVol = sample.zBoundary[0]
zMaxForVol = sample.zBoundary[1]
props = vp.getSurveyProps(maskFile, zMinForVol,
zMaxForVol, zMin, zMax, "all")
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
boxVol = props[0]
nbar = props[1]
if sample.volumeLimited:
nbar = 1.0
else:
zMinForVol = sample.zBoundary[0]
zMaxForVol = sample.zBoundary[1]
props = vp.getSurveyProps(maskFile, zMinForVol,
zMaxForVol, zMin, zMax, "all")
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
boxVol = props[0]
nbar = props[1]
if sample.volumeLimited:
nbar = 1.0
boxVol = sample.boxLen**3
summaryLine = runSuffix + " " + \
thisDataPortion + " " + \
@ -809,7 +835,7 @@ def launchFit(sample, stack, logFile=None, voidDir=None, figDir=None,
maxtries = 5
while badChain:
Rexpect = (stack.rMin+stack.rMax)/2
Rtruncate = stack.rMax*3. + 1 # TEST
Rtruncate = stack.rMin*3. + 1 # TEST
ret,fits,args = vp.fit_ellipticity(voidDir,Rbase=Rexpect,
Niter=300000,
Nburn=100000,
@ -1173,7 +1199,11 @@ def launchHubble(dataPortions=None, dataSampleList=None, logDir=None,
voidDir = sample.zobovDir+"/stacks_" + runSuffix
centersFile = voidDir+"/centers.txt"
if os.access(centersFile, os.F_OK):
voidRedshifts = np.loadtxt(centersFile)[:,5]
voidRedshifts = np.loadtxt(centersFile)
if voidRedshifts.ndim > 1:
voidRedshifts = voidRedshifts[:,5]
else:
voidRedshifts = voidRedshifts[5]
#fp.write(str(len(voidRedshifts))+" ")
np.savetxt(fp, voidRedshifts[None])
else:

View file

@ -1,3 +1,5 @@
LIGHT_SPEED = 299792.458
colorList = ['r', 'b', 'g', 'y', 'c', 'm', 'y',
'brown', 'grey',
'darkred', 'orange', 'pink', 'darkblue',

View file

@ -1,17 +1,20 @@
__all__=['plotNumberCounts']
__all__=['plotRedshiftDistribution', 'plotSizeDistribution', 'plot1dProfiles',
'plotMarg1d', 'plotNumberDistribution']
from void_python_tools.backend.classes import *
from plotDefs import *
import numpy as np
import os
import pylab as plt
import void_python_tools.apTools as vp
# -----------------------------------------------------------------------------
def plotNumberCounts(workDir=None, sampleList=None, figDir=None, plotNameBase="numbercount",
def plotRedshiftDistribution(workDir=None, sampleList=None, figDir=None,
plotNameBase="zdist",
showPlot=False, dataPortion=None, setName=None):
plt.clf()
plt.xlabel("Comoving Distance (Mpc/h)")
plt.xlabel("Redshift")
plt.ylabel("Number of Voids")
plotTitle = setName
@ -41,7 +44,7 @@ def plotNumberCounts(workDir=None, sampleList=None, figDir=None, plotNameBase="n
zMax = sample.zRange[1]
range = (zMin, zMax)
nbins = np.ceil((zMax-zMin)/0.1)
nbins = np.ceil((zMax-zMin)/0.02)
thisMax = np.max(data[:,5])
thisMin = np.min(data[:,5])
@ -67,3 +70,210 @@ def plotNumberCounts(workDir=None, sampleList=None, figDir=None, plotNameBase="n
os.system("display %s" % figDir+"/fig_"+plotName+".png")
# -----------------------------------------------------------------------------
def plotSizeDistribution(workDir=None, sampleList=None, figDir=None,
plotNameBase="sizedist",
showPlot=False, dataPortion=None, setName=None):
plt.clf()
plt.xlabel("Void Radius (Mpc/h)")
plt.ylabel("Number of Voids")
plotTitle = setName
plotName = plotNameBase
xMin = 1.e00
xMax = 0
for (iSample,sample) in enumerate(sampleList):
sampleName = sample.fullName
lineTitle = sampleName
filename = workDir+"/sample_"+sampleName+"/centers_"+dataPortion+"_"+\
sampleName+".out"
if not os.access(filename, os.F_OK):
print "File not found: ", filename
continue
data = np.loadtxt(filename, comments="#")
if data.ndim == 1:
print " Too few!"
continue
xMin = 5
xMax = 140
range = (xMin, xMax)
nbins = np.ceil((xMax-xMin)/5)
#thisMax = np.max(data[:,5])
#thisMin = np.min(data[:,5])
#if thisMax > xMax: xMax = thisMax
#if thisMin < xMin: xMin = thisMin
plt.hist(data[:,4], bins=nbins,
label=lineTitle, color=colorList[iSample],
histtype = "step", range=range,
linewidth=linewidth)
plt.legend(title = "Samples", loc = "upper right")
plt.title(plotTitle)
plt.xlim(xMin, xMax)
#plt.xlim(xMin, xMax*1.4) # make room for legend
plt.savefig(figDir+"/fig_"+plotName+".pdf", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".eps", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".png", bbox_inches="tight")
if showPlot:
os.system("display %s" % figDir+"/fig_"+plotName+".png")
# -----------------------------------------------------------------------------
def plot1dProfiles(workDir=None, sampleList=None, figDir=None,
plotNameBase="1dprofile",
showPlot=False, dataPortion=None, setName=None):
plt.clf()
plt.xlabel(r"$R/R_{v,\mathrm{max}}$")
plt.ylabel(r"$n / \bar n$")
for (iSample,sample) in enumerate(sampleList):
sampleName = sample.fullName
for (iStack,stack) in enumerate(sample.stacks):
plotTitle = setName
plotName = plotNameBase
runSuffix = getStackSuffix(stack.zMin, stack.zMax, stack.rMin,
stack.rMax, dataPortion)
plotTitle = sampleName + ", z = "+str(stack.zMin)+"-"+str(stack.zMax)+", R = "+str(stack.rMin)+"-"+str(stack.rMax)+ r" $h^{-1}$ Mpc"
filename = workDir+"/sample_"+sampleName+"/stacks_"+runSuffix+\
"profile_1d.txt"
if not os.access(filename, os.F_OK):
print "File not found: ", filename
continue
data = np.loadtxt(filename, comments="#")
if data.ndim == 1:
print " Too few!"
continue
data[:,1] /= stack.rMax
plt.ylim(ymin=0.0, ymax=np.amax(data[:,2])+0.1)
plt.xlim(xmin=0.0, xmax=2.1)
plt.plot(data[:,1], data[:,2], label=lineTitle, color=colorList[0],
linewidth=linewidth)
plt.title(plotTitle)
plt.savefig(figDir+"/fig_"+plotName+".pdf", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".eps", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".png", bbox_inches="tight")
if showPlot:
os.system("display %s" % figDir+"/fig_"+plotName+".png")
# -----------------------------------------------------------------------------
def plotMarg1d(workDir=None, sampleList=None, figDir=None,
plotNameBase="marg1d",
showPlot=False, dataPortion=None, setName=None):
plotNames = ("Om", "w0", "wa")
plotTitles = ("$\Omega_M$", "$w_0$", "$w_a$")
files = ("Om", "w0", "wa")
for iPlot in range(len(plotNames)):
plt.clf()
plotName = plotNameBase+"_"+plotNames[iPlot]+"_"+dataPortion
plotTitle = plotTitles[iPlot]
dataFile = workDir + "/likelihoods_"+dataPortion+"_"+files[iPlot]+".dat"
plt.xlabel(plotTitle, fontsize="20")
plt.ylabel("Likelihood", fontsize="20")
plt.ylim(0.0, 1.0)
data = np.loadtxt(dataFile, comments="#")
plt.plot(data[:,0], data[:,1], color='k', linewidth=linewidth)
plt.savefig(figDir+"/fig_"+plotName+".pdf", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".eps", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".png", bbox_inches="tight")
if showPlot:
os.system("display %s" % figDir+"/fig_"+plotName+".png")
# -----------------------------------------------------------------------------
def plotNumberDistribution(workDir=None, sampleList=None, figDir=None,
plotNameBase="numberdist",
showPlot=False, dataPortion=None, setName=None):
plt.clf()
plt.xlabel("Void Radius (Mpc/h)")
plt.ylabel(r"N > R [$h^3$ Mpc$^{-3}$]")
plotTitle = setName
plotName = plotNameBase
plt.yscale('log')
for (iSample,sample) in enumerate(sampleList):
sampleName = sample.fullName
lineTitle = sampleName
if sample.dataType == "observation":
boxVol = vp.getSurveyProps(sample.maskFile,
sample.zBoundary[0], sample.zBoundary[1],
sample.zRange[0], sample.zRange[1], "all",
selectionFuncFile=sample.selFunFile)[0]
else:
boxVol = sample.boxLen*sample.boxLen*(sample.zBoundaryMpc[1] -
sample.zBoundaryMpc[0])
boxVol *= 1.e-9
filename = workDir+"/sample_"+sampleName+"/centers_"+dataPortion+"_"+\
sampleName+".out"
if not os.access(filename, os.F_OK):
print "File not found: ", filename
continue
data = np.loadtxt(filename, comments="#")
if data.ndim == 1:
print " Too few!"
continue
data = data[:,4]
indices = np.arange(0, len(data), 1)
sorted = np.sort(data)
plt.plot(sorted, indices[::-1]/boxVol, '-',
label=lineTitle, color=colorList[iSample],
linewidth=linewidth)
plt.legend(title = "Samples", loc = "upper right")
plt.title(plotTitle)
plt.savefig(figDir+"/fig_"+plotName+".pdf", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".eps", bbox_inches="tight")
plt.savefig(figDir+"/fig_"+plotName+".png", bbox_inches="tight")
if showPlot:
os.system("display %s" % figDir+"/fig_"+plotName+".png")