Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make axes in plots log scale #7

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
25ec232
Added log scale options to plots
tegonzalo Mar 4, 2021
0ec8353
Copied too much
tegonzalo Mar 4, 2021
32c69d1
Again
tegonzalo Mar 4, 2021
4a683f8
Added guard for empty field
tegonzalo Mar 4, 2021
a7dbd14
Added optimised tick settings
tegonzalo Mar 5, 2021
e891985
Added the custom tick stuff as optional
tegonzalo Mar 8, 2021
6af303d
Changed minor ticks in log scale
tegonzalo Mar 10, 2021
59f5e0b
Improved ticks for nticks > 10 in log scale
tegonzalo Mar 19, 2021
17349a9
Fixed typo
tegonzalo Mar 28, 2021
515dc5e
Another bug
tegonzalo Mar 28, 2021
b682fb3
Changed all print statements to python3
tegonzalo Apr 29, 2021
cfc6884
exceptions now
tegonzalo Apr 29, 2021
758ddf6
another one
tegonzalo Apr 29, 2021
b411b38
Missed one print
tegonzalo Apr 29, 2021
1f28d65
fixed filters
tegonzalo Apr 29, 2021
d2b5aec
Changes itermitems and added future
tegonzalo Apr 29, 2021
fd69df2
Fixed case with exactly 10 ticks
tegonzalo May 3, 2021
e56433d
Changed future import
tegonzalo May 3, 2021
30f8c6b
Fixed type
tegonzalo May 4, 2021
34b3e4b
Added background to plots
tegonzalo May 5, 2021
155972e
Added blame scale
tegonzalo May 25, 2021
5fad496
Fixed typos and changed examples
tegonzalo May 25, 2021
189ed20
Fixed 1/0 problem in ticks
tegonzalo May 25, 2021
1a77f44
Removed Lambda from profile likelihood ratio label
tegonzalo May 27, 2021
58711fb
Merge https://github.com/tegonzalo/pippi into tegonzalo_test
patscott Jun 30, 2021
0066a1e
Syntax updates for python3
patscott Jun 30, 2021
fa4a559
Update axis labels in example to match new log plotting
patscott Jun 30, 2021
68cfd3e
Merge branch 'master' into tegonzalo_test
patscott Jun 30, 2021
27f8cfd
Fixed future print import to work properly in python 2.7
patscott Jun 30, 2021
0592cac
Added new colours
tegonzalo May 20, 2022
33fa271
Merge branch 'master' of https://github.com/tegonzalo/pippi
tegonzalo May 20, 2022
87fcac0
Fixed colours and bug
tegonzalo Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions example/example.pip
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ assign_to_pippi_datastream = 'np.log10($2)-np.log10($3)':64 \
;Assign a python function or named hdf5 data stream to a particular pippi datastream index (use pippi probe to test; EFN)
quantity_labels = 0:'multiplicity' \
1:'-lnlike' \
2:'$\log_{10}\left(m_0/\mathrm{TeV}\right)$' \
3:'$\log_{10}\left(m_\frac12/\mathrm{TeV}\right)$' \
2:'$m_0$ (TeV)' \
3:'$m_\frac12$ (TeV)' \
4:'$A_0$ (TeV)' \
5:'$\tan\beta$' \
64:'$\log_{10}\left(m_0/m_\frac12\right)$' \
Expand All @@ -67,7 +67,8 @@ plot_colourbar_2D = {3,2} {5,4} ;2D plots that should include colour

plot_comparison = T ;Overplot distributions from comparisonFilename in 1D plots and contours in 2D plots
extra_legend_lines = 'Flat priors' 'CMSSM $\mu>0$';Additional text lines to be included in any legends (EFN)
blame = 'pippi v2.2' ;Credit line to be placed in top corner of all plots
blame_text = 'pippi v2.2' ;Credit line to be placed in top corner of all plots
blame_scale = 0.5 ;Scale of credit line, default is 0.5
yaxis_number_angle = -90 ;Angle relative to vertical for y-axis numerical labels

plot_posterior_mean_on_posterior_pdf = T ;Indicate the posterior mean in all posterior pdf plots
Expand All @@ -77,6 +78,8 @@ plot_best_fit_on_profile_like = T ;Indicate the best fit in all profil

axis_ranges = 2:{2.0,3.5} 3:{2.05,3.6} 4:{-4,4} ;Axis ranges over which to plot parameters/observables (defaults to data_ranges if absent)

custom_ticks = ;Parameters/observables that use custom ticks

reference_point = 2:3.3 3:2.5 ;Coordinates of reference point (only plotted where one of the listed axes is present)
reference_text = 'True value' ;Key string to be printed for reference point

Expand Down
5 changes: 4 additions & 1 deletion example/example_diver.pip
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ plot_colourbar_2D = ;2D plots that should include colour

plot_comparison = F ;Overplot distributions from comparisonFilename in 1D plots and contours in 2D plots
extra_legend_lines = ;Additional text lines to be included in any legends (EFN)
blame = 'pippi v2.2' ;Credit line to be placed in top corner of all plots
blame_text = 'pippi v2.2' ;Credit line to be placed in top corner of all plots
blame_scale = 0.5 ;Scale of credit line, default is 0.5
yaxis_number_angle = -90 ;Angle relative to vertical for y-axis numerical labels

plot_posterior_mean_on_posterior_pdf = F ;Indicate the posterior mean in all posterior pdf plots
Expand All @@ -69,6 +70,8 @@ plot_best_fit_on_profile_like = T ;Indicate the best fit in all profil

axis_ranges = ;Axis ranges over which to plot parameters/observables (defaults to data_ranges if absent)

custom_ticks = ;Parameters/observables that use custom ticks

reference_point = ;Coordinates of reference point (only plotted where one of the listed axes is present)
reference_text = ;Key string to be printed for reference point

Expand Down
41 changes: 21 additions & 20 deletions pippi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Originally developed: March 2012
#############################################################

from __future__ import print_function
from pippi_probe import *
from pippi_merge import *
from pippi_pare import *
Expand All @@ -37,41 +38,41 @@ def main(arguments):
#Check if pippi has been invoked with one of the five known specific commands
command = commandLineOptions[arguments[1]]
if not command in [merge, pare]:
print
print 'Beginning pippi '+arguments[1]+' operation...'
print()
print('Beginning pippi '+arguments[1]+' operation...')
try:
command(arguments[2:])
except BaseException as err:
print
print 'Running pippi failed in '+command.__name__+' operation, due to error:'
print err
print
print()
print('Running pippi failed in '+command.__name__+' operation, due to error:')
print(err)
print()
sys.exit()
if not command in [merge, pare]:
print
print 'Completed sucessfully.'
print
print()
print('Completed sucessfully.')
print()
except KeyError:
#Otherise check if it has been invoked with just a filename
if os.path.isfile(arguments[1]):
print
print 'Beginning pippi parse-to-plot operation...'
print()
print('Beginning pippi parse-to-plot operation...')
for command in [parse, script, plot]:
try:
command(arguments[1:])
except BaseException as err:
print
print 'Running pippi failed in '+command.__name__+' operation.'
print err
print
print()
print('Running pippi failed in '+command.__name__+' operation.')
print(err)
print()
sys.exit()
print
print 'Completed sucessfully.'
print
print()
print('Completed sucessfully.')
print()
else:
#Otherwise crack it and tell the user to get their shit in order
print
print 'Can\'t find file '+arguments[1]
print()
print('Can\'t find file '+arguments[1])
usage()

sys.exit()
Expand Down
11 changes: 11 additions & 0 deletions pippi_colours.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
# Originally developed: March 2012
#############################################################

from __future__ import print_function
import re
import copy

permittedSchemes = {}

def Blockshading(colour,line_code, fill_code):
scheme = colourScheme('Blockshading_'+colour)
scheme.backgroundColour = '#fff'
scheme.baseProfColourMap = '#fff--#fff(contour1)--#'+fill_code+'(contour1)--#'+fill_code
scheme.basePostColourMap = '#fff--#fff(contour1)--#'+fill_code+'(contour1)--#'+fill_code
scheme.mainPostContourColour2D = '\'#'+line_code+'\''
Expand Down Expand Up @@ -43,6 +45,7 @@ class colourScheme:
comparisonProfColour1D = 'Grey'
comparisonPostContourColour2D = 'Grey'
comparisonProfContourColour2D = 'Grey'
backgroundColour = '#fff'
baseProfColourMap = '#fff--#fff(contour2)--#f45(contour1)--#612'
basePostColourMap = '#fff--#fff(contour2)--#88f(contour1)--#229'

Expand Down Expand Up @@ -122,6 +125,7 @@ def colourMap(self,contours,kind):

# iceCube colour scheme
iceCube = colourScheme('iceCube')
iceCube.backgroundColour = '#fff'
iceCube.baseProfColourMap = '#fff--#fff(contour2)--#292(contour1)--#f55(contour1)--#000'
iceCube.basePostColourMap = '#fff--#fff(contour2)--#29d(contour1)--#f55(contour1)--#000'
iceCube.baseObsColourMap = 'hls:White(contour1)--Red(contour2)--Green(contour3)'
Expand All @@ -132,6 +136,7 @@ def colourMap(self,contours,kind):

# iceCube79 colour scheme
iceCube79 = colourScheme('iceCube79')
iceCube79.backgroundColour = '#fff'
iceCube79.baseProfColourMap = '#fff--#fff(contour2)--#fab(contour1)--#f45'
iceCube79.basePostColourMap = '#fff--#fff(contour2)--#ddf(contour1)--#88f'
iceCube79.baseObsColourMap = 'hls:White(contour1)--Red(contour2)--Green(contour3)'
Expand All @@ -145,6 +150,7 @@ def colourMap(self,contours,kind):

# iceCube3sig colour scheme
iceCube3sig = colourScheme('iceCube3sig')
iceCube3sig.backgroundColour = '#fff'
iceCube3sig.baseProfColourMap = '#fff--#fff(contour3)--#292(contour2)--#fff(contour2)--#929(contour1)--#f55(contour1)--#000'
iceCube3sig.basePostColourMap = '#fff--#fff(contour3)--#29d(contour2)--#fff(contour2)--#929(contour1)--#f55(contour1)--#000'
iceCube3sig.baseObsColourMap = 'hls:White(contour1)--Red(contour2)--Green(contour3)'
Expand All @@ -155,6 +161,7 @@ def colourMap(self,contours,kind):

# SBClassic colour scheme
SBClassic = colourScheme('SBClassic')
SBClassic.backgroundColour = '#fff'
SBClassic.baseProfColourMap = '#fff--#fff(contour2)--#2f2(contour1)--#f33(0.5)--#000'
SBClassic.basePostColourMap = '#fff--#fff(contour2)--#95d(contour1)--#f33(0.5)--#000'
SBClassic.baseObsColourMap = 'hls:White(contour1)--Red(contour2)--Green(contour3)'
Expand All @@ -165,6 +172,7 @@ def colourMap(self,contours,kind):

# BlueGold colour scheme
BlueGold = colourScheme('BlueGold')
BlueGold.backgroundColour = '#fff'
BlueGold.baseProfColourMap = '#fff--#fff(contour2)--#f44(contour2)--#f44(contour1)--#ece(contour1)--#ece'
BlueGold.basePostColourMap = '#fff--#fff(contour2)--#44f(contour2)--#44f(contour1)--#fc0(contour1)--#fc0'
BlueGold.baseObsColourMap = 'hls:White(contour1)--Red(contour2)--Green(contour3)'
Expand All @@ -178,6 +186,7 @@ def colourMap(self,contours,kind):

# nightOfTheAllanachs colour scheme
nightOfTheAllanachs = colourScheme('nightOfTheAllanachs')
nightOfTheAllanachs.backgroundColour = '#000'
nightOfTheAllanachs.basePostColourMap = '#000--#000(contour2)--#808(contour1)--#f33(0.5)--#ff0'
nightOfTheAllanachs.baseProfColourMap = '#000--#000(contour2)--#33f(contour1)--#0ff(0.5)--#ff0'
nightOfTheAllanachs.baseObsColourMap = 'Black(contour1)--Red(contour2)--Green(contour3)'
Expand All @@ -195,6 +204,7 @@ def colourMap(self,contours,kind):

# nightOfTheAllanachs2 colour scheme
nightOfTheAllanachs2 = colourScheme('nightOfTheAllanachs2')
nightOfTheAllanachs2.backgroundColour = '#000'
nightOfTheAllanachs2.basePostColourMap = '#000--#000(contour2)--#808(contour1)--#f33(0.5)--#ff0'
nightOfTheAllanachs2.baseProfColourMap = '#000--#000(contour2)--#33f(contour1)--#0ff(0.5)--#ff0'
nightOfTheAllanachs2.baseObsColourMap = 'Black(contour1)--Red(contour2)--#00FFFF(contour3)'
Expand All @@ -214,6 +224,7 @@ def colourMap(self,contours,kind):

# nightOfTheAllanachs3 colour scheme
nightOfTheAllanachs3 = colourScheme('nightOfTheAllanachs3')
nightOfTheAllanachs3.backgroundcolour = '#000'
nightOfTheAllanachs3.basePostColourMap = '#000--#000(contour2)--#808(contour1)--#f33(0.5)--#ff0'
nightOfTheAllanachs3.baseProfColourMap = '#000--#000(contour2)--#33f(contour1)--#0ff(0.5)--#ff0'
nightOfTheAllanachs3.baseObsColourMap = 'Black(contour1)--Blue(contour2)--Orange(contour3)'
Expand Down
50 changes: 25 additions & 25 deletions pippi_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ def merge(filenames):
import h5py
f = h5py.File(filenames[0],'r')
h5merge = True
print
print "Files identified as hdf5. Interpreting final argument as output filename."
print
print "Concatenating common datasets and outputting to {0}...".format(filenames[-1])
print
print()
print("Files identified as hdf5. Interpreting final argument as output filename.")
print()
print("Concatenating common datasets and outputting to {0}...".format(filenames[-1]))
print()
except:
h5merge = False

Expand All @@ -49,19 +49,19 @@ def merge(filenames):
try:
fout = h5py.File(filenames[-1],'w-')
except:
print "Could not create output file {0}!".format(filenames[-1])
print "Please make sure it does not exist already."
print
print("Could not create output file {0}!".format(filenames[-1]))
print("Please make sure it does not exist already.")
print()
return

print " Determining common datasets..."
print(" Determining common datasets...")
for fname in filenames[0:-1]:
print " Opening: {0}".format(fname)
print(" Opening: {0}".format(fname))
try:
f = h5py.File(fname,'r')
except:
print "Could not open file {0}!".format(fname)
print
print("Could not open file {0}!".format(fname))
print()
return
files[fname] = f
datasets = {}
Expand All @@ -77,35 +77,35 @@ def merge(filenames):
datashape = dataset_collection[0][x].shape
if all(f[x].dtype == datatype and f[x].shape[1:] == datashape[1:] for f in dataset_collection):
common_datasets.add(x)
print
print " Common datasets: "
for x in common_datasets: print " {0}".format(x)
print
print()
print(" Common datasets: ")
for x in common_datasets: print(" {0}".format(x))
print()

#Find the length of each dataset and create it (empty) in the new file
print " Creating empty datasets of required lengths in {0}...".format(filenames[-1])
print(" Creating empty datasets of required lengths in {0}...".format(filenames[-1]))
out_dsets = {}
for ds in common_datasets:
length = 0
for f in dataset_collection: length += f[ds].len()
datatype = dataset_collection[0][ds].dtype
datashape = (length,) + dataset_collection[0][ds].shape[1:]
out_dsets[ds] = fout.create_dataset(ds, datashape, dtype=datatype)
print
print()

#Copy the data over to the new file
print " Adding data to empty datasets in {0}...".format(filenames[-1])
print(" Adding data to empty datasets in {0}...".format(filenames[-1]))
for ds in common_datasets:
print " Populating {0}".format(ds)
print(" Populating {0}".format(ds))
index_low = 0
for f in dataset_collection:
index_high = index_low + f[ds].len()
out_dsets[ds][index_low:index_high,...] = f[ds][...]
index_low = index_high

print
print "Done."
print
print()
print("Done.")
print()


else: # We are doing an ASCII merge
Expand Down Expand Up @@ -137,7 +137,7 @@ def merge(filenames):
#Crash if a later chain or line has a different number of columns to the first one
sys.exit('Error: chains do not match (number of columns differ). Quitting...')
#Output the current line to stdout and get the next one
print line.rstrip('\n')
print(line.rstrip('\n'))
#Read the next line
line = infile.readline()
#Work out the number of columns in the next line
Expand All @@ -150,6 +150,6 @@ def merge(filenames):

def get_datasets(g,datasets):
import h5py
for name, item in g.iteritems():
for name, item in g.items():
if isinstance(item,h5py.Group): get_datasets(item,datasets)
if isinstance(item,h5py.Dataset): datasets[item.name] = item
2 changes: 1 addition & 1 deletion pippi_pare.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ def pare(argstring):

# Pump it through the user-supplied function, printing each new point to stdout
for i in range(chainArray.shape[0]):
print '\t'.join([str(x) for x in pareFunc(chainArray[i,:])])
print('\t'.join([str(x) for x in pareFunc(chainArray[i,:])]))


Loading