Commit d1ac5cd8 authored by Plaszczynski Stephane's avatar Plaszczynski Stephane
Browse files

Merge branch '11-add-python-packaging' into 'dev'

Resolve "camel.py"

See merge request cosmotools/CAMEL!7
parents 1a9f4c6b baefbd21
...@@ -73,7 +73,7 @@ def mergeMC( filename, burnin=0.9, num=None, ext="txt", par=None, nelts=None): ...@@ -73,7 +73,7 @@ def mergeMC( filename, burnin=0.9, num=None, ext="txt", par=None, nelts=None):
if nelts < len(chain): if nelts < len(chain):
chain = chain[np.array(np.random.random(nelts)*len(chain),int),:] chain = chain[np.array(np.random.random(nelts)*len(chain),int),:]
dchain = dict( zip(par,np.transpose(chain))) dchain = dict( list(zip(par,np.transpose(chain))))
return(dchain) return(dchain)
...@@ -222,7 +222,7 @@ def GelmanRubin( chains, gap=10000, length_min=1000, length_max=None, new=False) ...@@ -222,7 +222,7 @@ def GelmanRubin( chains, gap=10000, length_min=1000, length_max=None, new=False)
print( "Not enough samples...") print( "Not enough samples...")
exit() exit()
it = range(length_min,length_max,gap)[1:-1] it = list(range(length_min,length_max,gap))[1:-1]
R = [] R = []
for isamp in it: for isamp in it:
print( "%d%%" % int(it.index(isamp)*100./len(it))) print( "%d%%" % int(it.index(isamp)*100./len(it)))
...@@ -262,7 +262,7 @@ def Geweke( chains, gap=10000, length_max=None): ...@@ -262,7 +262,7 @@ def Geweke( chains, gap=10000, length_max=None):
print( "Not enough samples...") print( "Not enough samples...")
exit() exit()
it = range(length_min,length_max,gap)[1:] it = list(range(length_min,length_max,gap))[1:]
T = [] T = []
for isamp in it: for isamp in it:
print( "%d%%" % int(it.index(isamp)*100./len(it))) print( "%d%%" % int(it.index(isamp)*100./len(it)))
...@@ -402,7 +402,7 @@ to_cosmomcName = { ...@@ -402,7 +402,7 @@ to_cosmomcName = {
'Aps143x217' : 'Aps143x217', 'Aps143x217' : 'Aps143x217',
} }
from_cosmomcName = dict(zip(to_cosmomcName.values(),to_cosmomcName.keys())) from_cosmomcName = dict(list(zip(list(to_cosmomcName.values()),list(to_cosmomcName.keys()))))
...@@ -442,7 +442,7 @@ def posterior1d( chains, params, nbin=50, smooth=1, ...@@ -442,7 +442,7 @@ def posterior1d( chains, params, nbin=50, smooth=1,
for c in range(nchain): for c in range(nchain):
chain = chains[c] chain = chains[c]
if chain.has_key(par): if par in chain:
hist1d( chain[par], smooth=smooth, color=colors[c], linestyle=linestyles[c], lw=lw[c], bins=nbin) hist1d( chain[par], smooth=smooth, color=colors[c], linestyle=linestyles[c], lw=lw[c], bins=nbin)
ax.tick_params(axis='both', which='major', labelsize=16) ax.tick_params(axis='both', which='major', labelsize=16)
...@@ -810,8 +810,8 @@ def plot_correlation( matC, par, **kwargs): ...@@ -810,8 +810,8 @@ def plot_correlation( matC, par, **kwargs):
covmat = np.tril( matC, k=-1) covmat = np.tril( matC, k=-1)
covmat[covmat==0] = np.NaN covmat[covmat==0] = np.NaN
plt.imshow( covmat, vmin=vmin, vmax=vmax, **kwargs) plt.imshow( covmat, vmin=vmin, vmax=vmax, **kwargs)
plt.yticks( range(len(covmat)), [parname.get(p,p) for p in par]) plt.yticks( list(range(len(covmat))), [parname.get(p,p) for p in par])
plt.xticks( range(len(covmat)), '') plt.xticks( list(range(len(covmat))), '')
plt.colorbar() plt.colorbar()
for i in range( len(par[:-1])): for i in range( len(par[:-1])):
# text( i, i+0.25, parname.get(par[i+1],par[i+1]),rotation=-90) # text( i, i+0.25, parname.get(par[i+1],par[i+1]),rotation=-90)
...@@ -880,7 +880,7 @@ def read_bestfit( dirname): ...@@ -880,7 +880,7 @@ def read_bestfit( dirname):
newline = f.readline() newline = f.readline()
if not "nan" in newline and not "inf" in newline and not "Abort" in newline: if not "nan" in newline and not "inf" in newline and not "Abort" in newline:
value = np.array( newline.split(), dtype=np.double) value = np.array( newline.split(), dtype=np.double)
bestfit = dict(zip(param, value)) bestfit = dict(list(zip(param, value)))
else : else :
bestfit = {'chi2':np.inf} bestfit = {'chi2':np.inf}
...@@ -990,11 +990,11 @@ simple_lik_name = { ...@@ -990,11 +990,11 @@ simple_lik_name = {
def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""): def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""):
#Extract Bestfit from logfile #Extract Bestfit from logfile
path, dirs, files = os.walk("%s" % (dbdir)).next() path, dirs, files = next(os.walk("%s" % (dbdir)))
for idir in dirs: for idir in dirs:
p,d,f = os.walk("%s/%s" % (dbdir,idir)).next() p,d,f = next(os.walk("%s/%s" % (dbdir,idir)))
# this will find the last 'camelZZ.par' file in folder # this will find the last 'camelZZ.par' file in folder
camelparfile="" camelparfile=""
...@@ -1161,11 +1161,11 @@ def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""): ...@@ -1161,11 +1161,11 @@ def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""):
def writeDerivedBestFit( dbdir, bfwrite=False, outpath=""): def writeDerivedBestFit( dbdir, bfwrite=False, outpath=""):
#Extract Bestfit from logfile #Extract Bestfit from logfile
path, dirs, files = os.walk("%s" % (dbdir)).next() path, dirs, files = next(os.walk("%s" % (dbdir)))
for idir in dirs: for idir in dirs:
p,d,f = os.walk("%s/%s" % (dbdir,idir)).next() p,d,f = next(os.walk("%s/%s" % (dbdir,idir)))
# this will find the last 'camelZZ.par' file in folder # this will find the last 'camelZZ.par' file in folder
camelparfile="" camelparfile=""
...@@ -1308,7 +1308,7 @@ def writeDerivedBestFit( dbdir, bfwrite=False, outpath=""): ...@@ -1308,7 +1308,7 @@ def writeDerivedBestFit( dbdir, bfwrite=False, outpath=""):
values += (chval.replace("chi2=","")).replace("\n","") values += (chval.replace("chi2=","")).replace("\n","")
values += " " values += " "
if not gderived: if not gderived:
print("before os.system" ) print("before os.system")
os.system("$CAMELROOT/Linux-x86_64/writeSpectra %s 1000 toto.fits > tmp.out" %(camelparfile) ) os.system("$CAMELROOT/Linux-x86_64/writeSpectra %s 1000 toto.fits > tmp.out" %(camelparfile) )
addin = open("tmp.out","r") addin = open("tmp.out","r")
...@@ -1364,7 +1364,7 @@ def writeDerivedBestFit( dbdir, bfwrite=False, outpath=""): ...@@ -1364,7 +1364,7 @@ def writeDerivedBestFit( dbdir, bfwrite=False, outpath=""):
bestfitfile = "%s/%s/best_fit%d" %(outpath,idir,count) bestfitfile = "%s/%s/best_fit%d" %(outpath,idir,count)
print(bestfitfile) print(bestfitfile)
print(goodline ) print(goodline)
# print(values,bestfitfile) # print(values,bestfitfile)
# if (not os.path.isfile(bestfitfile)) : # if (not os.path.isfile(bestfitfile)) :
if goodline: if goodline:
...@@ -1418,7 +1418,7 @@ class prof: ...@@ -1418,7 +1418,7 @@ class prof:
self._offset = offset self._offset = offset
self._CL = 68 self._CL = 68
path, dirs, files = os.walk("%s" % (self.dbdir)).next() path, dirs, files = next(os.walk("%s" % (self.dbdir)))
if sum([self.parname+"_" in d for d in dirs])==0: if sum([self.parname+"_" in d for d in dirs])==0:
raise ValueError( "Wrong directory") raise ValueError( "Wrong directory")
...@@ -1428,7 +1428,7 @@ class prof: ...@@ -1428,7 +1428,7 @@ class prof:
if not self.parname in idir: if not self.parname in idir:
continue continue
p,d,f = os.walk("%s/%s" % (self.dbdir,idir)).next() p,d,f = next(os.walk("%s/%s" % (self.dbdir,idir)))
if writeBestfit: if writeBestfit:
self._writeBestFit(idir,f) self._writeBestFit(idir,f)
...@@ -1527,7 +1527,7 @@ class prof: ...@@ -1527,7 +1527,7 @@ class prof:
Get all fit chi2 at a given value from multi-Minimize runs Get all fit chi2 at a given value from multi-Minimize runs
""" """
import os import os
path, dirs, files = os.walk("%s/%s_%s" % (self.dbdir,self.parname,val)).next() path, dirs, files = next(os.walk("%s/%s_%s" % (self.dbdir,self.parname,val)))
files = [f for f in files if f.startswith("best")] files = [f for f in files if f.startswith("best")]
nmin = len(files) nmin = len(files)
...@@ -1546,7 +1546,7 @@ class prof: ...@@ -1546,7 +1546,7 @@ class prof:
Get minimum at a given value from multi-Minimize runs Get minimum at a given value from multi-Minimize runs
""" """
import os import os
path, dirs, files = os.walk("%s/%s_%s" % (self.dbdir,self.parname,val)).next() path, dirs, files = next(os.walk("%s/%s_%s" % (self.dbdir,self.parname,val)))
files = [f for f in files if f.startswith("best")] files = [f for f in files if f.startswith("best")]
nmin = len(files) nmin = len(files)
...@@ -1558,7 +1558,7 @@ class prof: ...@@ -1558,7 +1558,7 @@ class prof:
print(fname) print(fname)
print(os.stat(fname).st_size) print(os.stat(fname).st_size)
if os.stat(fname).st_size !=0: if os.stat(fname).st_size !=0:
bftmp = read_bestfit( "%s/%s_%s/%s" % (self.dbdir,self.parname,val,f)) bftmp = read_bestfit("%s/%s_%s/%s" % (self.dbdir, self.parname, val, f))
if verbose: if verbose:
prtval = 'chi2' if verbose == True else verbose prtval = 'chi2' if verbose == True else verbose
print( f, bftmp[prtval]) print( f, bftmp[prtval])
...@@ -1571,7 +1571,7 @@ class prof: ...@@ -1571,7 +1571,7 @@ class prof:
def _params( self, val): def _params( self, val):
#Returns list of parameters from the fit file for a given value of the parameter #Returns list of parameters from the fit file for a given value of the parameter
import os import os
path, dirs, files = os.walk("%s/%s_%s" % (self.dbdir,self.parname,val)).next() path, dirs, files = next(os.walk("%s/%s_%s" % (self.dbdir,self.parname,val)))
files = [f for f in files if f.startswith("best")] files = [f for f in files if f.startswith("best")]
#read all parameters #read all parameters
...@@ -1709,7 +1709,7 @@ class prof: ...@@ -1709,7 +1709,7 @@ class prof:
if CL: if CL:
CL2delta = {68:1,95:3.84,99:6.63} CL2delta = {68:1,95:3.84,99:6.63}
if CL in CL2delta.keys(): if CL in list(CL2delta.keys()):
delta = CL2delta[CL] delta = CL2delta[CL]
else: else:
raise ValueError('CL not in the list') raise ValueError('CL not in the list')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment