Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit 6b166d29 authored by Matthieu Tristram's avatar Matthieu Tristram
Browse files

Merge branch 'master' of https://gitlab.in2p3.fr/cosmotools/CAMEL

parents 2f387dfd 60eba629
......@@ -7,7 +7,7 @@ import matplotlib.pyplot as plt
import scipy.ndimage as nd
import sys
import re
import os
import glob,os
import gzip
import mmap
import pdb
......@@ -321,6 +321,7 @@ parname = {
'AdustTT' : '$A_\mathrm{dust}^\mathrm{TT}$',
'AdustTP' : '$A_\mathrm{dust}^\mathrm{TE}$',
'AdustPP' : '$A_\mathrm{dust}^\mathrm{EE}$',
'SPT_ADust' : '$A^\mathrm{dust}_\mathrm{SPT}$',
'SPT_high_95_cal' : '$c^\mathrm{SPT\ high}_{95}$',
'SPT_high_150_cal' : '$c^\mathrm{SPT\ high}_{150}$',
'SPT_high_220_cal' : '$c^\mathrm{SPT\ high}_{220}$',
......@@ -539,9 +540,10 @@ def hist2d( chain, par1, par2, *args, **kwargs):
H = nd.gaussian_filter( H, nsmooth)
npts = 5.
plt.imshow( H.T, origin='bottom', **kwargs)
plt.xticks(np.arange(npts+1)/npts*bins,["%4.2f" % i for i in np.linspace(extent[0][0],extent[0][1],npts+1)])
plt.yticks(np.arange(npts+1)/npts*bins,["%4.2f" % i for i in np.linspace(extent[1][0],extent[1][1],npts+1)])
# plt.imshow( H.T, origin='bottom', **kwargs)
# plt.xticks(np.arange(npts+1)/npts*bins,["%4.2f" % i for i in np.linspace(extent[0][0],extent[0][1],npts+1)])
# plt.yticks(np.arange(npts+1)/npts*bins,["%4.2f" % i for i in np.linspace(extent[1][0],extent[1][1],npts+1)])
plt.pcolormesh( X, Y, H.T, **kwargs)
plt.xlabel(parname.get(par1,par1))
plt.ylabel(parname.get(par2,par2))
......@@ -861,14 +863,18 @@ def gauss_prior(x,m,s):
simple_lik_name = {
'lowl_SMW_70_dx11d_2014_10_03_v5c_Ap' : 'bflike',
'HiLLiPOP:DX11dHM_superExt_CO_TT' : 'hlpTT',
'Hillipop:DX11dHM_superExt_CO_TT' : 'hlpPS',
'SPT_low' : 'SPT_low',
'SPT_high' : 'SPT_high',
'ACT_equat' : 'ACT_equat',
'ACT_south' : 'ACT_south',
'commander_rc2_v1.1_l2_29_B' : 'cmder',
'Lollipop' : 'lollipop',
'lollipop' : 'lollipop',
'lollipopn' : 'lollipop'
'lollipopn' : 'lollipop',
'BAO1D_dr12' : 'BAO(1D)',
'boss_dr12' : 'BAO(3D)',
'JLA' : 'SNIa(JLA)'
}
def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""):
......@@ -888,17 +894,23 @@ def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""):
# on cherche si on a lance le code avec Profile ou Minimize (camelrun)
CheckProfile=False
name =""
for file in glob.glob("%s/%s/camelrun*" % (dbdir,idir)):
name = file
print(file)
try:
name="%s/%s/%s" % (dbdir,idir,"camelrun")
#name="%s/%s/%s" % (dbdir,idir,"camelrun")
cr=open(name)
all_lines=cr.readlines()
for c in all_lines:
if "Profile" in c:
if "Profile" in c and not "#" in c:
CheckProfile=True
cr.close()
except ValueError:
return()
print CheckProfile
#build a line with all param names avoiding double counts
try:
parlist = Parnames( camelparfile)
......@@ -910,6 +922,7 @@ def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""):
if CheckProfile:
param_line += " profiled "
param_line+=" chi2 valid edm maxlim "
#print param_line
read=True
line_satisfied=False
for s in [f1 for f1 in f if ".o" in f1]:
......@@ -924,11 +937,21 @@ def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""):
# gets all lines in file
for c in all_lines:
if "=====" in c :
#print c
chnam = c.split(" ")[1]
#print chnam
if ".lik" in c :
param_line += simple_lik_name[chnam.replace(".lik:","")]
param_line += " "
line_satisfied=True
#print chnam
#print "|"+param_line+"|"
if "ollipop" in c :
param_line += simple_lik_name[chnam.replace(":","")]
param_line += " "
line_satisfied=True
#print chnam
#print "|"+param_line+"|"
if ".clik" in c :
......@@ -956,8 +979,6 @@ def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""):
#print param_line
sf.close()
for s in [f1 for f1 in f if ".o" in f1]:
......@@ -975,7 +996,7 @@ def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""):
if goodline:
values += " "
if (".lik" in c or ".clik" in c or ".lal" in c or ".par" in c ) and "=====" in c :
if (".lik" in c or ".clik" in c or ".lal" in c or ".par" in c or "llipop" in c) and "=====" in c :
chval = c.split(" ")[2]
values += (chval.replace("chi2=","")).replace("\n","")
values += " "
......@@ -997,8 +1018,21 @@ def writeExtendedBestFit( dbdir, bfwrite=False, outpath=""):
if bfwrite :
bestfitfile = "%s/%s/best_fit%d" % (dbdir,idir,count)
if outpath != "" :
print "outpath gene -> %s/" %(outpath)
#print os.path.isdir( "%s/" %(outpath))
if os.path.isdir( "%s/" %(outpath))==False :
#print 'mkdir ?'
#return();
os.mkdir( "%s" %(outpath) )
print "outpath -> %s/%s/" %(outpath,idir)
#print os.path.isdir( "%s/%s/" %(outpath,idir))
if os.path.isdir( "%s/%s/" %(outpath,idir))==False :
os.mkdir( "%s/%s/" %(outpath,idir) )
#print 'mkdir ?'
#return();
os.mkdir( "%s/%s" %(outpath,idir) )
bestfitfile = "%s/%s/best_fit%d" %(outpath,idir,count)
......@@ -1279,27 +1313,29 @@ class prof:
for idir in dirs:
if not self.parname in idir:
continue
p,d,f = os.walk("%s/%s" % (self.dbdir,idir)).next()
if writeBestfit:
self._writeBestFit(idir,f)
# for f2 in [f1 for f1 in f if ".o" in f1]:
# for f2 in [f1 for f1 in f if ".o" in f1]:
#check there are more than nestimate bestfit in directory idir
if sum([s.startswith("best_fit") for s in f]) >= nestimate:
# gets the value indicated in the subfolder's name
keep=True
for ii in remove:
if ii == idir.replace(self.parname+'_',''):
keep=False
if keep:
self._s.append( idir.replace(self.parname+'_',''))
# same thing but casts in double
self._v.append( np.double(idir.replace(self.parname+'_',''))+self._offset)
if len(self._s) <= 2:
raise ValueError( "not enough profiled-value available (need at least two)")
sortidx = np.argsort(self._v)
......@@ -1310,6 +1346,23 @@ class prof:
v,p = self.get()
self._p = p
self.ymin = min(p)
def write( self, filename):
params = [self.parname]+list(np.extract( self._params(self._s[0])!=self.parname, self._params(self._s[0])))
param_line = " ".join( params)+"\n"
f=open( filename,'w')
f.write(param_line)
# print(param_line)
for val in self._s:
data = self._point_minimum( val)
# print( " ".join([str(data[p]) for p in params]))
f.write( " ".join([str(data[p]) for p in params])+"\n")
f.close()
def _writeBestFit(self, dir, f):
#Extract Bestfit from logfile
......@@ -1352,7 +1405,26 @@ class prof:
newf.close()
def point_minimum( self, val, verbose=False):
def point_allfits( self, val, par='chi2'):
"""
Get all fit chi2 at a given value from multi-Minimize runs
"""
import os
path, dirs, files = os.walk("%s/%s_%s" % (self.dbdir,self.parname,val)).next()
files = [f for f in files if f.startswith("best")]
nmin = len(files)
allfits = []
for f in np.sort(files):
#read all parameters
fname= "%s/%s_%s/%s" % (self.dbdir,self.parname,val,f)
if os.stat(fname).st_size !=0:
bftmp = read_bestfit( "%s/%s_%s/%s" % (self.dbdir,self.parname,val,f))
allfits.append( bftmp[par])
return( allfits)
def _point_minimum( self, val, verbose=False):
"""
Get minimum at a given value from multi-Minimize runs
"""
......@@ -1365,16 +1437,36 @@ class prof:
for f in np.sort(files):
#read all parameters
fname= "%s/%s_%s/%s" % (self.dbdir,self.parname,val,f)
if verbose:
print fname
print os.stat(fname).st_size
if os.stat(fname).st_size !=0:
bftmp = read_bestfit( "%s/%s_%s/%s" % (self.dbdir,self.parname,val,f))
if verbose:
prtval = 'chi2' if verbose == True else verbose
print( f, bftmp[prtval])
if bftmp['chi2'] < bf['chi2']:
bf = bftmp
if verbose:
prtval = 'chi2' if verbose == True else verbose
print( f, bftmp[prtval])
if bftmp['chi2'] < bf['chi2']:
bf = bftmp
return( bf)
def _params( self, val):
"""
Returns list of parameters in the fit
"""
import os
path, dirs, files = os.walk("%s/%s_%s" % (self.dbdir,self.parname,val)).next()
files = [f for f in files if f.startswith("best")]
#read all parameters
fname= "%s/%s_%s/%s" % (self.dbdir,self.parname,val,files[0])
f = open( fname, 'r')
params = np.array( f.readline().split(), dtype=str)
return( params)
def get( self, par='chi2'):
"""
Return profile likelihood
......@@ -1391,9 +1483,10 @@ class prof:
"""
p = []
for val in self._s:
p.append( self.point_minimum( val)[par])
p.append( self._point_minimum( val)[par])
return( self._v, p)
def fit( self, method='cubic', order=3, deltaMax=np.inf, upper=False, CL=None, bounds=None):
"""
Fit the profile with different models
......@@ -1537,6 +1630,7 @@ class prof:
all plot arguments
"""
ax = plt.gca()
color = kwargs.pop( "color", next(ax._get_lines.color_cycle))
linestyle = kwargs.pop( "linestyle", '-')
label = kwargs.pop( "label", None)
......@@ -1544,7 +1638,7 @@ class prof:
if extent==None:
extent = (self._v[0],self._v[-1])
ax.plot(self._v,self._p-self.ymin,'ok', color=color,marker=marker)
ax.plot(self._v,self._p-self.ymin,color=color,marker=marker,linestyle='')
ax.set_xlabel(parname.get(self._nameforclass,self._nameforclass),fontsize=fontsize)
ax.set_ylabel("$\chi^2-\chi^2_{min}$",fontsize=fontsize)
......
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