From 39e16d41ff08ef953851b7aff2c8381a6b067b15 Mon Sep 17 00:00:00 2001 From: "P.M. Sutter" Date: Fri, 9 May 2014 12:01:59 -0500 Subject: [PATCH] bug fixes --- python_tools/setup.py | 2 +- .../void_python_tools/voidUtil/catalogUtil.py | 2 +- .../void_python_tools/voidUtil/matchUtil.py | 69 +++++----- .../void_python_tools/voidUtil/plotUtil.py | 128 +++++++++--------- .../void_python_tools/voidUtil/profileUtil.py | 2 +- .../void_python_tools/voidUtil/xcorUtil.py | 2 +- 6 files changed, 103 insertions(+), 102 deletions(-) diff --git a/python_tools/setup.py b/python_tools/setup.py index 2a21fc6..23f5e79 100644 --- a/python_tools/setup.py +++ b/python_tools/setup.py @@ -31,7 +31,7 @@ setup( cmdclass = {'build_ext': build_ext}, include_dirs = [np.get_include()], packages= - ['void_python_tools','void_python_tools.backend','void_python_tools.apTools', 'void_python_tools.xcor', 'void_python_tools.voidUtil', + ['void_python_tools','void_python_tools.backend','void_python_tools.apTools', 'void_python_tools.voidUtil', 'void_python_tools.apTools.profiles','void_python_tools.apTools.chi2',], #ext_modules = [Extension("void_python_tools.chi2.velocityProfileFitNative", ["void_python_tools/chi2/velocityProfileFitNative.pyx"], libraries=["gsl", "gslcblas"]), Extension("void_python_tools.chi2.likelihoo", ["void_python_tools/chi2/likelihood.pyx"], libraries=["gsl", "gslcblas"])] #ext_modules = [ diff --git a/python_tools/void_python_tools/voidUtil/catalogUtil.py b/python_tools/void_python_tools/voidUtil/catalogUtil.py index 3374105..107e4f9 100644 --- a/python_tools/void_python_tools/voidUtil/catalogUtil.py +++ b/python_tools/void_python_tools/voidUtil/catalogUtil.py @@ -269,7 +269,7 @@ def loadVoidCatalog(sampleDir, dataPortion="central", loadPart=True): densCon = line[9], voidProb = line[10], radius = pow(line[7]/volNorm*3./4./np.pi, 1./3.), - barycenter = np.zeros((3)) + barycenter = np.zeros((3)), parentID = 0, treeLevel = 0, numChildren = 0, diff --git a/python_tools/void_python_tools/voidUtil/matchUtil.py b/python_tools/void_python_tools/voidUtil/matchUtil.py index ef39dae..6b342ed 100755 --- a/python_tools/void_python_tools/voidUtil/matchUtil.py +++ b/python_tools/void_python_tools/voidUtil/matchUtil.py @@ -32,7 +32,7 @@ def compareCatalogs(baseCatalogDir, compareCatalogDir, outputDir="./", logDir="./", matchMethod="useID", dataPortion="central", strictMatch=True, - pathToCTools="../../../c_tools") + pathToCTools="../../../c_tools"): # reports the overlap between two void catalogs # baseCatalogDir: directory of catalog 1 @@ -44,36 +44,37 @@ def compareCatalogs(baseCatalogDir, compareCatalogDir, # strictMatch: if True, only attempt to match to trimmed catalog # pathToCTools: path to location of VIDE c_tools directory -if not os.access(outputDir, os.F_OK): - os.makedirs(outputDir) - -if not os.access(logDir, os.F_OK): - os.makedirs(logDir) - -outFileName = outputDir + "/" + "voidOverlap" #+ ".dat" - -with open(baseCatalogDir+"/sample_info.dat", 'rb') as input: - baseSample = pickle.load(input) - -with open(compareCatalogDir+"/sample_info.dat", 'rb') as input: - sample = pickle.load(input) - -print " Comparing", baseSample.fullName, "to", sample.fullName, "...", -sys.stdout.flush() - -sampleName = sample.fullName - -binPath = pathToCTools+"/analysis/voidOverlap" -logFile = logDir+"/compare_"+baseSample.fullName+"_"+sampleName+".out" -stepOutputFileName = outFileName + "_" + baseSample.fullName + "_" + \ - sampleName + "_" - -launchVoidOverlap(baseSample, sample, baseCatalogDir, - compareCatalogDir, binPath, - thisDataPortion=dataPortion, logFile=logFile, - continueRun=False, workDir=workDir, - outputFile=stepOutputFileName, - matchMethod=matchMethod, - strictMatch=strictMatch) - -print " Done!" + if not os.access(outputDir, os.F_OK): + os.makedirs(outputDir) + + if not os.access(logDir, os.F_OK): + os.makedirs(logDir) + + outFileName = outputDir + "/" + "voidOverlap" #+ ".dat" + + with open(baseCatalogDir+"/sample_info.dat", 'rb') as input: + baseSample = pickle.load(input) + + with open(compareCatalogDir+"/sample_info.dat", 'rb') as input: + sample = pickle.load(input) + + print " Comparing", baseSample.fullName, "to", sample.fullName, "...", + sys.stdout.flush() + + sampleName = sample.fullName + + binPath = pathToCTools+"/analysis/voidOverlap" + logFile = logDir+"/compare_"+baseSample.fullName+"_"+sampleName+".out" + stepOutputFileName = outFileName + "_" + baseSample.fullName + "_" + \ + sampleName + "_" + + launchVoidOverlap(baseSample, sample, baseCatalogDir, + compareCatalogDir, binPath, + thisDataPortion=dataPortion, logFile=logFile, + continueRun=False, workDir=workDir, + outputFile=stepOutputFileName, + matchMethod=matchMethod, + strictMatch=strictMatch) + + print " Done!" + return diff --git a/python_tools/void_python_tools/voidUtil/plotUtil.py b/python_tools/void_python_tools/voidUtil/plotUtil.py index d0d4e0b..701ff46 100644 --- a/python_tools/void_python_tools/voidUtil/plotUtil.py +++ b/python_tools/void_python_tools/voidUtil/plotUtil.py @@ -43,68 +43,68 @@ def plotNumberFunction(catalogList, figDir="./", plotName="numberfunc", dataPortion="central"): -print "Plotting number function" - -plt.clf() -plt.xlabel("$R_{eff}$ [$h^{-1}Mpc$]", fontsize=14) -plt.ylabel(r"log ($n$ (> R) [$h^3$ Gpc$^{-3}$])", fontsize=14) - -for (iSample,catalog) in enumerate(catalogList): - sample = catalog.sampleInfo - data = catalog.voids[:].radius - - if sample.dataType == "observation": - maskFile = sample.maskFile - - boxVol = vp.getSurveyProps(maskFile, - sample.zBoundary[0], sample.zBoundary[1], - sample.zRange[0], sample.zRange[1], "all", - selectionFuncFile=None)[0] - #selectionFuncFile=sample.selFunFile)[0] - boxVol *= obsFudgeFactor - else: - boxVol = sample.boxLen*sample.boxLen*(sample.zBoundaryMpc[1] - - sample.zBoundaryMpc[0]) - - boxVol *= 1.e-9 # Mpc->Gpc - - bins = args.xmax/5. - hist, binEdges = np.histogram(data, bins=bins, range=(0., 100.)) - binCenters = 0.5*(binEdges[1:] + binEdges[:-1]) - - nvoids = len(data) - var = hist * (1. - hist/nvoids) - sig = np.sqrt(var) - - lowerbound = hist - sig - upperbound = hist + sig - - mean = np.log10(hist/boxVol) - lowerbound = np.log10(lowerbound/boxVol) - upperbound = np.log10(upperbound/boxVol) - - lineColor = colorList[iSample] - lineTitle = sample.fullName + print "Plotting number function" - trim = (bounds[0] > .01) - mean = mean[trim] - binCentersToUse = binCenters[trim] - lower = lowerbound[trim] - upper = upperbound[trim] - - alpha = 0.55 - fill_between(binCentersToUse, lower, upper, - label=lineTitle, color=lineColor, - alpha=alpha, - ) - - lineStyle = '-' - plt.plot(binCentersToUse, mean, lineStyle, - color=lineColor, - linewidth=3) - - plt.legend(loc = "upper right", fancybox=True, prop={'size':14}) - - 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") + plt.clf() + plt.xlabel("$R_{eff}$ [$h^{-1}Mpc$]", fontsize=14) + plt.ylabel(r"log ($n$ (> R) [$h^3$ Gpc$^{-3}$])", fontsize=14) + + for (iSample,catalog) in enumerate(catalogList): + sample = catalog.sampleInfo + data = catalog.voids[:].radius + + if sample.dataType == "observation": + maskFile = sample.maskFile + + boxVol = vp.getSurveyProps(maskFile, + sample.zBoundary[0], sample.zBoundary[1], + sample.zRange[0], sample.zRange[1], "all", + selectionFuncFile=None)[0] + #selectionFuncFile=sample.selFunFile)[0] + boxVol *= obsFudgeFactor + else: + boxVol = sample.boxLen*sample.boxLen*(sample.zBoundaryMpc[1] - + sample.zBoundaryMpc[0]) + + boxVol *= 1.e-9 # Mpc->Gpc + + bins = args.xmax/5. + hist, binEdges = np.histogram(data, bins=bins, range=(0., 100.)) + binCenters = 0.5*(binEdges[1:] + binEdges[:-1]) + + nvoids = len(data) + var = hist * (1. - hist/nvoids) + sig = np.sqrt(var) + + lowerbound = hist - sig + upperbound = hist + sig + + mean = np.log10(hist/boxVol) + lowerbound = np.log10(lowerbound/boxVol) + upperbound = np.log10(upperbound/boxVol) + + lineColor = colorList[iSample] + lineTitle = sample.fullName + + trim = (bounds[0] > .01) + mean = mean[trim] + binCentersToUse = binCenters[trim] + lower = lowerbound[trim] + upper = upperbound[trim] + + alpha = 0.55 + fill_between(binCentersToUse, lower, upper, + label=lineTitle, color=lineColor, + alpha=alpha, + ) + + lineStyle = '-' + plt.plot(binCentersToUse, mean, lineStyle, + color=lineColor, + linewidth=3) + + plt.legend(loc = "upper right", fancybox=True, prop={'size':14}) + + 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") diff --git a/python_tools/void_python_tools/voidUtil/profileUtil.py b/python_tools/void_python_tools/voidUtil/profileUtil.py index 348ba89..61c2199 100644 --- a/python_tools/void_python_tools/voidUtil/profileUtil.py +++ b/python_tools/void_python_tools/voidUtil/profileUtil.py @@ -94,7 +94,7 @@ def fitHSWProfile(radii, densities, sigmas): # pcov: covariance matrix popt, pcov = curve_fit(HamausProfile, radii, densities, - sigma=sigmas) + sigma=sigmas, maxfev=10000, xtol=5.e-3, p0=[1.0,-1.0]) diff --git a/python_tools/void_python_tools/voidUtil/xcorUtil.py b/python_tools/void_python_tools/voidUtil/xcorUtil.py index bad91fe..43f677f 100644 --- a/python_tools/void_python_tools/voidUtil/xcorUtil.py +++ b/python_tools/void_python_tools/voidUtil/xcorUtil.py @@ -61,7 +61,7 @@ def computeCrossCor(catalogDir, outputDir="./", logDir="./", matchMethod="useID", dataPortion="central", strictMatch=True, - pathToCTools="../../../c_tools") + pathToCTools="../../../c_tools"): # Computes void-void and void-matter(galaxy) correlations # baseCatalogDir: directory of catalog