-
Notifications
You must be signed in to change notification settings - Fork 6
/
pippi_script.py
1356 lines (1282 loc) · 84.3 KB
/
pippi_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#############################################################
# pippi: parse it, plot it
# ------------------------
# Program for creating plotting scripts for pippi.
#
# Author: Pat Scott (patscott@physics.mcgill.ca)
# Originally developed: March 2012
#############################################################
from __future__ import print_function
left_margin = 0.16
right_margin = 0.03
top_margin = 0.05
bottom_margin = 0.16
plot_scale = 1.1
import subprocess
import os
from pippi_utils import *
from pippi_read import *
#Define pip file entries required from parsing
parsedir = dataObject('parse_dir',safe_string)
# Define script-specific pip file entries
scriptdir = dataObject('script_dir',safe_string)
doComparison = dataObject('plot_comparison',boolean)
postMeanOnPost = dataObject('plot_posterior_mean_on_posterior_pdf',boolean)
postMeanOnProf = dataObject('plot_posterior_mean_on_profile_like',boolean)
bestFitOnPost = dataObject('plot_best_fit_on_posterior_pdf',boolean)
bestFitOnProf = dataObject('plot_best_fit_on_profile_like',boolean)
doLegend1D = dataObject('legend_on_1D',int_list)
doLegend2D = dataObject('legend_on_2D',intuple_list)
legendLoc1D = dataObject('legend_locations_1D',string_dictionary)
legendLoc2D = dataObject('legend_locations_2D',int_pair_string_dictionary)
doKey1D = dataObject('key_on_1D',int_list)
doKey2D = dataObject('key_on_2D',intuple_list)
keyLoc1D = dataObject('key_locations_1D',string_dictionary)
keyLoc2D = dataObject('key_locations_2D',int_pair_string_dictionary)
doColourbar = dataObject('plot_colourbar_2D',intuple_list)
doHistograms = dataObject('plot_as_histograms_1D',boolean)
legendLines = dataObject('extra_legend_lines',string_list)
plotSize = dataObject('plot_size',string)
blame = dataObject('blame',string)
logoFile = dataObject('logo_file',string)
logoLoc = dataObject('logo_loc',floatuple_list)
logoWidth = dataObject('logo_width',floater)
colours = dataObject('colour_scheme',internal)
axisRanges = dataObject('axis_ranges',floatuple_dictionary)
yAxisAngle = dataObject('yaxis_number_angle',floater)
refPoint = dataObject('reference_point',float_dictionary)
refKey = dataObject('reference_text',string)
keys = keys+[scriptdir,doComparison,postMeanOnPost,postMeanOnProf,bestFitOnPost,
bestFitOnProf,doColourbar,doLegend1D,doLegend2D,legendLoc1D,legendLoc2D,
doHistograms,legendLines,blame,colours,axisRanges,yAxisAngle,refPoint,
refKey,doKey1D,doKey2D,keyLoc1D,keyLoc2D,parsedir,logoFile,logoLoc,logoWidth]
# Define pip file entries to be read from savedkeys file
labels = dataObject('quantity_labels',string_dictionary)
dataRanges = dataObject('data_ranges',floatuple_dictionary)
lookupKeys = dataObject('lookup_keys',int_dictionary)
# Constants
blameFractionalVerticalOffset = 1.2e-2
PosteriorIsMainInComboPlot = True
likeColourbarString = 'Profile likelihood ratio $\Lambda=\mathcal{L}/\mathcal{L}_\mathrm{max}$'
postColourbarString = 'Relative probability $P/P_\mathrm{max}$'
defaultLegendLocation = 'bl'
defaultKeyLocation = 'tr'
defaultRefKey = 'Ref.\ point'
keyYSep = 0.055
keyXSep = 0.04
keyYVals = {'t':[0.94 - x*keyYSep for x in range(3)], 'c':[0.44 + x*keyYSep for x in range(3)], 'b':[0.065 + x*keyYSep for x in range(3)]}
keyXVals = {'r':[0.74 + x*keyXSep for x in range(2)], 'c':[0.45 + x*keyXSep for x in range(2)], 'l':[0.06 + x*keyXSep for x in range(2)]}
def script(filename):
# input: filename = the name of the pip file
print()
# Parse pip file
getIniData(filename,keys)
# Make sure that comparison is turned off if comparison filename is missing
if doComparison.value and secChain.value is None:
print(' Warning: comparison curves requested but no comparison file specified.\n Skipping comparison...\n')
doComparison.value = False
# Work out where the parse output is located
if parsedir.value is None:
# No parse_dir; default to searching the directory containing chain(s)
parseFiledir = re.sub(r'/.*?$', '/', mainChain.value)
else:
# Search in parse_dir
parseFiledir = parsedir.value+'/'
# Work out where the script output is to be located
if scriptdir.value is None:
# No script_dir; default to parse directory
baseFiledir = parseFiledir
else:
# Save in script_dir
baseFiledir = scriptdir.value+'/'
# Make sure script_dir exists, make it if not
safe_dir(scriptdir.value)
# Work out how to reference the parse dir from the script dir
if parseFiledir[0] == '/' or parseFiledir[0] == '~':
# The parse output path is absolute; easy-peasy
parseFiledirFromScriptFiledir = parseFiledir
else:
# The parse output path is a relative one
if baseFiledir[0] == '/' or baseFiledir[0] == '~':
# The script output is to be placed in an absolute path; need to convert the parse path to absolute too
parseFiledirFromScriptFiledir = os.getcwd() + '/' + parseFiledir
else:
# The script output is also to be placed in a relative path
parseFiledirFromScriptFiledir = re.sub(r'.+?/', '../', baseFiledir+'/') + parseFiledir
# Locate and scale logo (if any)
if logoFile.value is not None:
if logoFile.value == 'pippi': logoFile.value = sys.path[0]+'/pippi'
# Work out how to reference the logo file from the script dir
if logoFile.value[0] != '/':
if baseFiledir[0] == '/':
# The script output is to be placed in an absolute path; need to convert the logo path to absolute too
logoFile.value = os.getcwd() + '/' + logoFile.value
else:
# The script output is also to be placed in a relative path
logoFile.value = re.sub(r'.+?/', '../', baseFiledir+'/') + logoFile.value
# Strip extensions off chain filenames
baseFilename = baseFiledir + re.sub(r'.*/|\..?.?.?$', '', mainChain.value)
parseFilename = parseFiledir + re.sub(r'.*/|\..?.?.?$', '', mainChain.value)
parseFilenameFromScriptFiledir = parseFiledirFromScriptFiledir + re.sub(r'.*/|\..?.?.?$', '', mainChain.value)
if doComparison.value:
secParseFilename = parseFiledir + re.sub(r'.*/|\..?.?.?$', '', secChain.value) + '_comparison'
secParseFilenameFromScriptFiledir = parseFiledirFromScriptFiledir + re.sub(r'.*/|\..?.?.?$', '', secChain.value) + '_comparison'
# Retrieve labels and data ranges saved in earlier parsing run
getIniData([parseFilename+'_savedkeys.pip'],[labels,dataRanges,lookupKeys])
#Work out whether to do posteriors and check that flags match up
if doPosterior.value and not any(x in labels.value for x in permittedMults):
print(' Warning: do_posterior_pdf = T but no multiplicity in chain labels.\n Skipping posterior PDF...')
doPosterior.value = False
# set colour scheme if it is undefined
if colours.value is None: colours.value = basic
# Create 1D plotting scripts
if oneDplots.value is not None:
# Determine whether histograms are required or not
histString = '' if doHistograms.value is None or not doHistograms.value else 'hist'
# Loop over requested plots
for plot in oneDplots.value:
print(' Writing scripts for 1D plots of quantity ',plot)
# Set up filenames
currentBase = baseFilename+'_'+str(plot)
currentParse = parseFilenameFromScriptFiledir+'_'+str(plot)
currentBaseMinimal = re.sub(r'.*/', '', currentBase)
if doComparison.value: currentSecParse = secParseFilenameFromScriptFiledir+'_'+str(plot)
# Get plot limits
xtrema = dictFallback(axisRanges,dataRanges,plot)
xRange = xtrema[1] - xtrema[0]
ytrema = [0.0,1.0]
yRange = 1.0
# Locate and scale logo (if any)
if logoFile.value is not None:
logoCoords = [xtrema[0]+logoLoc.value[0][0]*xRange,logoLoc.value[0][1]]
logoString = '\'\\includegraphics[width = '+str(logoWidth.value*8.8)+'cm]{'+logoFile.value+'}\''
# Determine reference point
if refPoint.value is not None and plot in refPoint.value:
plotRef = True
refString = ' --draw-marker '+str(refPoint.value[plot])+','+str(yRange*colours.value.referenceMarkerInnerScale/40.0)+' '+\
colours.value.referenceMarkerInner+' /color \''+colours.value.referenceMarkerInnerColour+\
'\' /scale '+str(colours.value.referenceMarkerInnerScale)+' \\\n'+\
' --draw-marker '+str(refPoint.value[plot])+','+str(yRange*colours.value.referenceMarkerOuterScale/40.0)+' '+\
colours.value.referenceMarkerOuter+' /color \''+colours.value.referenceMarkerOuterColour+\
'\' /scale '+str(colours.value.referenceMarkerOuterScale)+' \\\n'
else:
plotRef = False
# Determine plot size
if plotSize.value == None or plotSize.value == '':
plotSizeInternal = '11cm x 4in'
else:
plotSizeInternal = plotSize.value
# Make profile likelihood plotting scripts
if doProfile.value:
# Get contours
if contours1D.value is not None:
contourLevels = getContours(parseFilename,plot,'like')
# Determine keys
keyString = ''
if doKey1D.value is not None and plot in doKey1D.value:
# Get gross key location
try:
keyLoc = keyLoc1D.value[plot]
except (KeyError, TypeError):
keyLoc = defaultKeyLocation
# Get text to be used for reference point
refText = defaultRefKey if refKey.value is None else refKey.value
# Get x and y coordinates for 3 possible keys (for markers and text)
yVals = ytrema[0] + np.array(keyYVals[keyLoc[0]])*yRange
xVals = xtrema[0] + np.array(keyXVals[keyLoc[1]])*xRange
markers = []
# Get details of key for reference point
if plotRef: markers.append([colours.value.referenceMarkerOuter, colours.value.referenceMarkerOuterColour,
colours.value.referenceMarkerOuterScale, refText, colours.value.referenceMarkerInner,
colours.value.referenceMarkerInnerColour, colours.value.referenceMarkerInnerScale/
colours.value.referenceMarkerOuterScale])
# Get details of key for posterior mean
if postMeanOnProf.value: markers.append([colours.value.mainPostMeanMarker, colours.value.mainPostMeanColour1D,
colours.value.mainPostMeanMarkerScale, 'Mean'])
# Get details of key for best fit
if bestFitOnProf.value: markers.append([colours.value.mainBestFitMarker, colours.value.mainBestFitColour1D,
colours.value.mainBestFitMarkerScale, 'Best fit'])
# Reverse vertical ordering if keys are to be placed at the top of the page, so as to fill from the top down
if keyLoc[0] == 't': markers.reverse()
# Construct ctioga2 command for each key
for i,key in enumerate(markers):
if key[0] == 'Bullet' or key[0] == 'BulletOpen': key[2] /= 1.5
if key[2] > 1.0: key[2] = 1.0
# Write the extra marker overlay for the reference point
if len(key) == 7: keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[4]+' /color \''+\
key[5]+'\' /scale '+str(key[6]*key[2])+'\\\n'
# Write the main marker
keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[0]+' /color \''+key[1]+'\' /scale '+str(key[2])+'\\\n'
# Write the key text
keyString += ' --draw-text '+str(xVals[1])+','+str(yVals[i])+' \''+key[3]+'\' /color \''+colours.value.keyTextColour1D
keyString += '\' /justification left /scale 0.75 /alignment center \\\n'
# Open plotting shell script file for writing
outfile = smart_open(currentBase+'_like1D.bsh','w')
outfile.write('#!/usr/bin/env bash\n')
outfile.write('# This plot script created by pippi '+pippiVersion+' on '+datetime.datetime.now().strftime('%c')+'\n')
outfile.write('ctioga2\\\n')
outfile.write(' --name '+currentBaseMinimal+'_like1D')
outfile.write(' --plot-scale \''+str(plot_scale)+'\'\\\n')
outfile.write(' --page-size \''+plotSizeInternal+'\'\\\n')
outfile.write(' --frame-margins '+str(left_margin)+','
+str(right_margin)+','
+str(top_margin)+','
+str(bottom_margin)+'\\\n')
outfile.write(' --xrange '+str(xtrema[0])+':'+str(xtrema[1])+'\\\n')
outfile.write(' --yrange 0:1\\\n')
outfile.write(' --ylabel \'Profile likelihood ratio $\Lambda=\mathcal{L}/\mathcal{L}_\mathrm{max}$\' /shift 2.1\\\n')
outfile.write(' --xlabel \''+labels.value[plot]+'\'\\\n')
outfile.write(' --label-style x /scale 1.0 /shift 0.15 --label-style y /scale 1.0 /shift 0.15')
if yAxisAngle.value is not None: outfile.write(' /angle '+str(yAxisAngle.value))
outfile.write('\\\n')
if contours1D is not None:
for i, contour in enumerate(contourLevels):
outfile.write(' --draw-line '+str(xtrema[0])+','+contour+' '+str(xtrema[1])+','+contour+' /color \'Black\' '+
'/style Dashes /width '+str(float(colours.value.lineWidth1D)*0.5)+'\\\n')
outfile.write(' --draw-text '+str(xtrema[0]+0.045*(xtrema[1]-xtrema[0]))+','+str(float(contour)+0.005)+' \''+str(contours1D.value[i])+
'\%CL\' /color \'Black\' /scale 0.5 /justification left /alignment bottom\\\n')
if doComparison.value:
# Do everything for comparison chain
outfile.write(' --plot '+currentSecParse+'_like1D'+histString+'.ct2@1:2 /fill xaxis /fill-transparency '+colours.value.fillTransparency1D+
' /fill-color '+colours.value.comparisonProfColour1D+' /color '+colours.value.comparisonProfColour1D+
' /line-style '+colours.value.comparison1DLineStyle+' /line-width '+colours.value.lineWidth1D+'\\\n')
if bestFitOnProf.value and colours.value.comparisonBestFitMarker is not None:
# Get best-fit point and plot it
bestFit = getCentralVal(secParseFilename,plot,'like',lookupKeys)
outfile.write(' --draw-marker '+str(bestFit)+','+str(yRange*colours.value.comparisonBestFitMarkerScale/40.0)+' '+
colours.value.comparisonBestFitMarker+' /color \''+colours.value.comparisonBestFitColour+
'\' /scale '+str(colours.value.comparisonBestFitMarkerScale)+' \\\n')
if postMeanOnProf.value and colours.value.comparisonPostMeanMarker is not None:
# Get posterior mean and plot it
postMean = getCentralVal(secParseFilename,plot,'post',lookupKeys)
if not postMean: sys.exit('Error: plot_posterior_mean_on_profile_like = T but no multiplicity given!')
outfile.write(' --draw-marker '+str(postMean)+','+str(yRange*colours.value.comparisonPostMeanMarkerScale/40.0)+' '+
colours.value.comparisonPostMeanMarker+' /color \''+colours.value.comparisonPostMeanColour+
'\' /scale '+str(colours.value.comparisonPostMeanMarkerScale)+' \\\n')
outfile.write(' --plot '+currentParse+'_like1D'+histString+'.ct2@1:2 /fill xaxis /fill-transparency '+colours.value.fillTransparency1D+
' /fill-color '+colours.value.mainProfColour1D+' /color '+colours.value.mainProfColour1D+
' /line-style '+colours.value.main1DLineStyle+' /line-width '+colours.value.lineWidth1D+'\\\n')
if doLegend1D.value is not None and plot in doLegend1D.value:
# Write legend
try:
legendLocation = legendLoc1D.value[plot]
except (KeyError, TypeError):
legendLocation = defaultLegendLocation
outfile.write(' --legend-inside \''+legendLocation+'\' /scale 1.0 /vpadding 0.1\\\n')
if legendLines.value is not None:
for x in legendLines.value: outfile.write(' --legend-line \''+x+'\' /color \''+colours.value.legendTextColour1D+'\'\\\n')
outfile.write(' --legend-line \'Prof.~likelihood\' /color \''+colours.value.legendTextColour1D+'\'\\\n')
if bestFitOnProf.value:
# Get best-fit point and plot it
bestFit = getCentralVal(parseFilename,plot,'like',lookupKeys)
outfile.write(' --draw-marker '+str(bestFit)+','+str(yRange*colours.value.mainBestFitMarkerScale/40.0)+' '+
colours.value.mainBestFitMarker+' /color \''+colours.value.mainBestFitColour1D+
'\' /scale '+str(colours.value.mainBestFitMarkerScale)+' \\\n')
if postMeanOnProf.value:
# Get posterior mean and plot it
postMean = getCentralVal(parseFilename,plot,'post',lookupKeys)
if not postMean: sys.exit('Error: plot_posterior_mean_on_profile_like = T but no multiplicity given!')
outfile.write(' --draw-marker '+str(postMean)+','+str(yRange*colours.value.mainPostMeanMarkerScale/40.0)+' '+
colours.value.mainPostMeanMarker+' /color \''+colours.value.mainPostMeanColour1D+
'\' /scale '+str(colours.value.mainPostMeanMarkerScale)+' \\\n')
# Plot reference point
if plotRef: outfile.write(refString)
# Draw key
outfile.write(keyString)
# Write credits
if blame.value is not None:
blameYCoordinate = str(blameFractionalVerticalOffset * yRange + ytrema[1])
outfile.write(' --draw-text '+str(xtrema[1])+','+blameYCoordinate+' \''+blame.value+'\' /scale 0.5 /justification right\\\n')
# Add logo
if logoFile.value is not None:
outfile.write(' --draw-text '+str(logoCoords[0])+','+str(logoCoords[1])+' '+logoString+'\\\n')
# Set axis colours
for x in ['top', 'bottom', 'left', 'right']:
outfile.write(' --axis-style '+x+' /stroke_color \''+colours.value.axisColour1D+'\'\\\n')
outfile.close
subprocess.call('chmod +x '+currentBase+'_like1D.bsh', shell=True)
# Make posterior pdf plotting scripts
if doPosterior.value:
# Get contours
if contours1D.value is not None:
mainContourLevels = getContours(parseFilename,plot,'post')
if doComparison.value: secContourLevels = getContours(secParseFilename,plot,'post')
# Determine keys
keyString = ''
if doKey1D.value is not None and plot in doKey1D.value:
# Get gross key location
try:
keyLoc = keyLoc1D.value[plot]
except (KeyError, TypeError):
keyLoc = defaultKeyLocation
# Get text to be used for reference point
refText = defaultRefKey if refKey.value is None else refKey.value
# Get x and y coordinates for 3 possible keys (for markers and text)
yVals = ytrema[0] + np.array(keyYVals[keyLoc[0]])*yRange
xVals = xtrema[0] + np.array(keyXVals[keyLoc[1]])*xRange
markers = []
# Get details of key for reference point
if plotRef: markers.append([colours.value.referenceMarkerOuter, colours.value.referenceMarkerOuterColour,
colours.value.referenceMarkerOuterScale, refText, colours.value.referenceMarkerInner,
colours.value.referenceMarkerInnerColour, colours.value.referenceMarkerInnerScale/
colours.value.referenceMarkerOuterScale])
# Get details of key for posterior mean
if postMeanOnPost.value: markers.append([colours.value.mainPostMeanMarker, colours.value.mainPostMeanColour1D,
colours.value.mainPostMeanMarkerScale, 'Mean'])
# Get details of key for best fit
if bestFitOnPost.value: markers.append([colours.value.mainBestFitMarker, colours.value.mainBestFitColour1D,
colours.value.mainBestFitMarkerScale, 'Best fit'])
# Reverse vertical ordering if keys are to be placed at the top of the page, so as to fill from the top down
if keyLoc[0] == 't': markers.reverse()
# Construct ctioga2 command for each key
for i,key in enumerate(markers):
if key[0] == 'Bullet' or key[0] == 'BulletOpen': key[2] /= 1.5
if key[2] > 1.0: key[2] = 1.0
# Write the extra marker overlay for the reference point
if len(key) == 7: keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[4]+' /color \''+\
key[5]+'\' /scale '+str(key[6]*key[2])+'\\\n'
# Write the main marker
keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[0]+' /color \''+key[1]+'\' /scale '+str(key[2])+'\\\n'
# Write the key text
keyString += ' --draw-text '+str(xVals[1])+','+str(yVals[i])+' \''+key[3]+'\' /color \''+colours.value.keyTextColour1D
keyString += '\' /justification left /scale 0.75 /alignment center \\\n'
# Open plotting shell script file for writing
outfile = smart_open(currentBase+'_post1D.bsh','w')
outfile.write('#!/usr/bin/env bash\n')
outfile.write('# This plot script created by pippi '+pippiVersion+' on '+datetime.datetime.now().strftime('%c')+'\n')
outfile.write('ctioga2\\\n')
outfile.write(' --name '+currentBaseMinimal+'_post1D')
outfile.write(' --plot-scale \''+str(plot_scale)+'\'\\\n')
outfile.write(' --page-size \''+plotSizeInternal+'\'\\\n')
outfile.write(' --frame-margins '+str(left_margin)+','
+str(right_margin)+','
+str(top_margin)+','
+str(bottom_margin)+'\\\n')
outfile.write(' --xrange '+str(xtrema[0])+':'+str(xtrema[1])+'\\\n')
outfile.write(' --yrange 0:1\\\n')
outfile.write(' --ylabel \'Relative probability $P/P_\mathrm{max}$\' /shift 2.1\\\n')
outfile.write(' --xlabel \''+labels.value[plot]+'\'\\\n')
outfile.write(' --label-style x /scale 1.0 /shift 0.15 --label-style y /scale 1.0 /shift 0.15')
if yAxisAngle.value is not None: outfile.write(' /angle '+str(yAxisAngle.value))
outfile.write('\\\n')
if contours1D is not None:
for i, contour in enumerate(mainContourLevels):
outfile.write(' --draw-line '+str(xtrema[0])+','+contour+' '+str(xtrema[1])+','+contour+' /color \''+colours.value.mainPostColour1D+
'\' /style Dashes /width '+str(float(colours.value.lineWidth1D)*0.5)+'\\\n')
outfile.write(' --draw-text '+str(xtrema[0]+0.045*(xtrema[1]-xtrema[0]))+','+str(float(contour)+0.005)+' \''+str(contours1D.value[i])+
'\%CR\' /color \''+colours.value.mainPostColour1D+'\' /scale 0.5 /justification left /alignment bottom\\\n')
if doComparison.value:
# Do everything for comparison chain
if contours1D is not None:
for i, contour in enumerate(secContourLevels):
outfile.write(' --draw-line '+str(xtrema[0])+','+contour+' '+str(xtrema[1])+','+contour+' /color \''+colours.value.comparisonPostColour1D+
'\' /style Dashes /width '+str(float(colours.value.lineWidth1D)*0.5)+'\\\n')
outfile.write(' --draw-text '+str(xtrema[0]+0.045*(xtrema[1]-xtrema[0]))+','+str(float(contour)+0.005)+' \''+str(contours1D.value[i])+
'\%CR\' /color \''+colours.value.comparisonPostColour1D+'\' /scale 0.5 /justification left /alignment bottom\\\n')
outfile.write(' --plot '+currentSecParse+'_post1D'+histString+'.ct2@1:2 /fill xaxis /fill-transparency '+colours.value.fillTransparency1D+
' /fill-color '+colours.value.comparisonPostColour1D+' /color '+colours.value.comparisonPostColour1D+
' /line-style '+colours.value.comparison1DLineStyle+' /line-width '+colours.value.lineWidth1D+'\\\n')
if bestFitOnPost.value and colours.value.comparisonBestFitMarker is not None:
# Get best-fit point and plot it
bestFit = getCentralVal(secParseFilename,plot,'like',lookupKeys)
outfile.write(' --draw-marker '+str(bestFit)+','+str(yRange*colours.value.comparisonBestFitMarkerScale/40.0)+' '+
colours.value.comparisonBestFitMarker+' /color \''+colours.value.comparisonBestFitColour+
'\' /scale '+str(colours.value.comparisonBestFitMarkerScale)+' \\\n')
if postMeanOnPost.value and colours.value.comparisonPostMeanMarker is not None:
# Get posterior mean and plot it
postMean = getCentralVal(secParseFilename,plot,'post',lookupKeys)
if not postMean: sys.exit('Error: plot_posterior_mean_on_posterior_pdf = T but no multiplicity given!')
outfile.write(' --draw-marker '+str(postMean)+','+str(yRange*colours.value.comparisonPostMeanMarkerScale/40.0)+' '+
colours.value.comparisonPostMeanMarker+' /color \''+colours.value.comparisonPostMeanColour+
'\' /scale '+str(colours.value.comparisonPostMeanMarkerScale)+' \\\n')
outfile.write(' --plot '+currentParse+'_post1D'+histString+'.ct2@1:2 /fill xaxis /fill-transparency '+colours.value.fillTransparency1D+
' /fill-color '+colours.value.mainPostColour1D+' /color '+colours.value.mainPostColour1D+
' /line-style '+colours.value.main1DLineStyle+' /line-width '+colours.value.lineWidth1D+'\\\n')
if doLegend1D.value is not None and plot in doLegend1D.value:
# Write legend
try:
legendLocation = legendLoc1D.value[plot]
except (KeyError, TypeError):
legendLocation = defaultLegendLocation
outfile.write(' --legend-inside \''+legendLocation+'\' /scale 1.0 /vpadding 0.1\\\n')
if legendLines.value is not None:
for x in legendLines.value: outfile.write(' --legend-line \''+x+'\' /color \''+colours.value.legendTextColour1D+'\'\\\n')
outfile.write(' --legend-line \'Marg.~posterior\' /color \''+colours.value.legendTextColour1D+'\'\\\n')
if bestFitOnPost.value:
# Get best-fit point and plot it
bestFit = getCentralVal(parseFilename,plot,'like',lookupKeys)
outfile.write(' --draw-marker '+str(bestFit)+','+str(yRange*colours.value.mainBestFitMarkerScale/40.0)+' '+
colours.value.mainBestFitMarker+' /color \''+colours.value.mainBestFitColour1D+
'\' /scale '+str(colours.value.mainBestFitMarkerScale)+' \\\n')
if postMeanOnPost.value:
# Get posterior mean and plot it
postMean = getCentralVal(parseFilename,plot,'post',lookupKeys)
if not postMean: sys.exit('Error: plot_posterior_mean_on_posterior_pdf = T but no multiplicity given!')
outfile.write(' --draw-marker '+str(postMean)+','+str(yRange*colours.value.mainPostMeanMarkerScale/40.0)+' '+
colours.value.mainPostMeanMarker+' /color \''+colours.value.mainPostMeanColour1D+
'\' /scale '+str(colours.value.mainPostMeanMarkerScale)+' \\\n')
# Plot reference point
if plotRef: outfile.write(refString)
# Draw key
outfile.write(keyString)
# Write credits
if blame.value is not None:
blameYCoordinate = str(blameFractionalVerticalOffset * yRange + ytrema[1])
outfile.write(' --draw-text '+str(xtrema[1])+','+blameYCoordinate+' \''+blame.value+'\' /scale 0.5 /justification right\\\n')
# Add logo
if logoFile.value is not None:
outfile.write(' --draw-text '+str(logoCoords[0])+','+str(logoCoords[1])+' '+logoString+'\\\n')
# Set axis colours
for x in ['top', 'bottom', 'left', 'right']:
outfile.write(' --axis-style '+x+' /stroke_color \''+colours.value.axisColour1D+'\'\\\n')
outfile.close
subprocess.call('chmod +x '+currentBase+'_post1D.bsh', shell=True)
# Make profile-posterior comparison plotting scripts
if doProfile.value and doPosterior.value:
bestFitData = [colours.value.mainBestFitMarker, colours.value.mainBestFitColour1D, colours.value.mainBestFitMarkerScale, colours.value.mainProfColour1D]
postMeanData = [colours.value.mainPostMeanMarker, colours.value.mainPostMeanColour1D, colours.value.mainPostMeanMarkerScale, colours.value.mainPostColour1D]
# Work out which is the main and which is the comparison
if PosteriorIsMainInComboPlot:
[main, sec] = ['post', 'like']
[mainData, secData] = [postMeanData, bestFitData]
else:
[main, sec] = ['like', 'post']
[mainData, secData] = [bestFitData, postMeanData]
# Get contours
if contours1D.value is not None:
mainContourLevels = getContours(parseFilename,plot,main)
secContourLevels = getContours(parseFilename,plot,sec)
# Determine keys
keyString = ''
if doKey1D.value is not None and plot in doKey1D.value:
markers = []
# Get details of key for reference point
if plotRef: markers.append([colours.value.referenceMarkerOuter, colours.value.referenceMarkerOuterColour,
colours.value.referenceMarkerOuterScale, refText, colours.value.referenceMarkerInner,
colours.value.referenceMarkerInnerColour, colours.value.referenceMarkerInnerScale/
colours.value.referenceMarkerOuterScale])
# Get details of key for posterior mean
markers.append([postMeanData[0], postMeanData[1], postMeanData[2], 'Mean'])
# Get details of key for best fit
markers.append([bestFitData[0], bestFitData[1], bestFitData[2], 'Best fit'])
# Reverse vertical ordering if keys are to be placed at the top of the page, so as to fill from the top down
if keyLoc[0] == 't': markers.reverse()
# Construct ctioga2 command for each key
for i,key in enumerate(markers):
if key[0] == 'Bullet' or key[0] == 'BulletOpen': key[2] /= 1.5
if key[2] > 1.0: key[2] = 1.0
# Write the extra marker overlay for the reference point
if len(key) == 7: keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[4]+' /color \''+\
key[5]+'\' /scale '+str(key[6]*key[2])+'\\\n'
# Write the main marker
keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[0]+' /color \''+key[1]+'\' /scale '+str(key[2])+'\\\n'
# Write the key text
keyString += ' --draw-text '+str(xVals[1])+','+str(yVals[i])+' \''+key[3]+'\' /color \''+colours.value.keyTextColour1D
keyString += '\' /justification left /scale 0.75 /alignment center \\\n'
# Open plotting shell script file for writing
outfile = smart_open(currentBase+'_combo1D.bsh','w')
outfile.write('#!/usr/bin/env bash\n')
outfile.write('# This plot script created by pippi '+pippiVersion+' on '+datetime.datetime.now().strftime('%c')+'\n')
outfile.write('ctioga2\\\n')
outfile.write(' --name '+currentBaseMinimal+'_combo1D')
outfile.write(' --plot-scale \''+str(plot_scale)+'\'\\\n')
outfile.write(' --page-size \''+plotSizeInternal+'\'\\\n')
outfile.write(' --frame-margins '+str(left_margin)+','
+str(right_margin)+','
+str(top_margin)+','
+str(bottom_margin)+'\\\n')
outfile.write(' --xrange '+str(xtrema[0])+':'+str(xtrema[1])+'\\\n')
outfile.write(' --yrange 0:1\\\n')
outfile.write(' --ylabel \'Relative probability $P/P_\mathrm{max}$\' /shift 2.1\\\n')
outfile.write(' --xlabel \''+labels.value[plot]+'\'\\\n')
outfile.write(' --label-style x /scale 1.0 /shift 0.15 --label-style y /scale 1.0 /shift 0.15')
if yAxisAngle.value is not None: outfile.write(' /angle '+str(yAxisAngle.value))
outfile.write('\\\n')
if contours1D is not None:
if main == 'like':
main_colour = colours.value.mainProfColour1D
main_text = 'CL'
sec_colour = colours.value.mainPostColour1D
sec_text = 'CR'
else:
main_colour = colours.value.mainPostColour1D
main_text = 'CR'
sec_colour = colours.value.mainProfColour1D
sec_text = 'CL'
for i, contour in enumerate(mainContourLevels):
outfile.write(' --draw-line '+str(xtrema[0])+','+contour+' '+str(xtrema[1])+','+contour+' /color \''+main_colour+
'\' /style Dashes /width '+str(float(colours.value.lineWidth1D)*0.5)+'\\\n')
outfile.write(' --draw-text '+str(xtrema[0]+0.045*(xtrema[1]-xtrema[0]))+','+str(float(contour)+0.005)+' \''+str(contours1D.value[i])+
'\%'+main_text+'\' /color \''+main_colour+'\' /scale 0.5 /justification left /alignment bottom\\\n')
for i, contour in enumerate(secContourLevels):
outfile.write(' --draw-line '+str(xtrema[0])+','+contour+' '+str(xtrema[1])+','+contour+' /color \''+sec_colour+
'\' /style Dashes /width '+str(float(colours.value.lineWidth1D)*0.5)+'\\\n')
outfile.write(' --draw-text '+str(xtrema[0]+0.045*(xtrema[1]-xtrema[0]))+','+str(float(contour)+0.005)+' \''+str(contours1D.value[i])+
'\%'+sec_text+'\' /color \''+sec_colour+'\' /scale 0.5 /justification left /alignment bottom\\\n')
# Plot comparison distribution
outfile.write(' --plot '+currentParse+'_'+sec+'1D'+histString+'.ct2@1:2 /fill xaxis /fill-transparency '+colours.value.fillTransparency1D+
' /fill-color '+secData[3]+' /color '+secData[3]+
' /line-style '+colours.value.comparison1DLineStyle+' /line-width '+colours.value.lineWidth1D+'\\\n')
# Plot main distribution
outfile.write(' --plot '+currentParse+'_'+main+'1D'+histString+'.ct2@1:2 /fill xaxis /fill-transparency '+colours.value.fillTransparency1D+
' /fill-color '+mainData[3]+' /color '+mainData[3]+
' /line-style '+colours.value.main1DLineStyle+' /line-width '+colours.value.lineWidth1D+'\\\n')
if doLegend1D.value is not None and plot in doLegend1D.value:
# Write legend
try:
legendLocation = legendLoc1D.value[plot]
except (KeyError, TypeError):
legendLocation = defaultLegendLocation
outfile.write(' --legend-inside \''+legendLocation+'\' /scale 1.0 /vpadding 0.1\\\n')
if legendLines.value is not None:
for x in legendLines.value: outfile.write(' --legend-line \''+x+'\' /color \''+colours.value.legendTextColour1D+'\'\\\n')
outfile.write(' --legend-line \'Like vs. Posterior\' /color \''+colours.value.legendTextColour1D+'\'\\\n')
# Get best-fit point
bestFit = getCentralVal(parseFilename,plot,'like',lookupKeys)
# Get posterior mean
postMean = getCentralVal(parseFilename,plot,'post',lookupKeys)
# Always plot both best fit and posterior mean on comparison plot
outfile.write(' --draw-marker '+str(bestFit)+','+str(yRange*bestFitData[2]/40.0)+' '+bestFitData[0]+' /color \''+bestFitData[1]+
'\' /scale '+str(bestFitData[2])+' \\\n')
if postMean: outfile.write(' --draw-marker '+str(postMean)+','+str(yRange*postMeanData[2]/40.0)+' '+postMeanData[0]+' /color \''+postMeanData[1]+
'\' /scale '+str(postMeanData[2])+' \\\n')
# Plot reference point
if plotRef: outfile.write(refString)
# Draw key
outfile.write(keyString)
# Write credits
if blame.value is not None:
blameYCoordinate = str(blameFractionalVerticalOffset * yRange + ytrema[1])
outfile.write(' --draw-text '+str(xtrema[1])+','+blameYCoordinate+' \''+blame.value+'\' /scale 0.5 /justification right\\\n')
# Add logo
if logoFile.value is not None:
outfile.write(' --draw-text '+str(logoCoords[0])+','+str(logoCoords[1])+' '+logoString+'\\\n')
# Set axis colours
for x in ['top', 'bottom', 'left', 'right']:
outfile.write(' --axis-style '+x+' /stroke_color \''+colours.value.axisColour1D+'\'\\\n')
outfile.close
subprocess.call('chmod +x '+currentBase+'_combo1D.bsh', shell=True)
# Create 2D plotting scripts
if twoDplots.value is not None:
# Loop over requested plots
for plot in twoDplots.value:
print(' Writing scripts for 2D plots of quantities ',plot)
# Set up filenames
currentBase = baseFilename+'_'+'_'.join([str(x) for x in plot])
currentParse = parseFilenameFromScriptFiledir+'_'+'_'.join([str(x) for x in plot])
currentBaseMinimal = re.sub(r'.*/', '', currentBase)
if doComparison.value: currentSecParse = secParseFilenameFromScriptFiledir+'_'+'_'.join([str(x) for x in plot])
# Get plot limits
xtrema = dictFallback(axisRanges,dataRanges,plot[0])
ytrema = dictFallback(axisRanges,dataRanges,plot[1])
xRange = xtrema[1] - xtrema[0]
yRange = ytrema[1] - ytrema[0]
# Locate and scale logo (if any)
if logoFile.value is not None:
logoCoords = [xtrema[0]+logoLoc.value[0][0]*xRange,ytrema[0]+logoLoc.value[0][1]*yRange]
logoString = '\'\\includegraphics[width = '+str(logoWidth.value*8.8)+'cm]{'+logoFile.value+'}\''
# Determine reference point
if refPoint.value is not None and all([x in refPoint.value for x in plot]):
plotRef = True
refString = ' --draw-marker '+str(refPoint.value[plot[0]])+','+str(refPoint.value[plot[1]])+' '+\
colours.value.referenceMarkerInner+' /color \''+colours.value.referenceMarkerInnerColour+\
'\' /scale '+str(colours.value.referenceMarkerInnerScale)+' \\\n'+\
' --draw-marker '+str(refPoint.value[plot[0]])+','+str(refPoint.value[plot[1]])+' '+\
colours.value.referenceMarkerOuter+' /color \''+colours.value.referenceMarkerOuterColour+\
'\' /scale '+str(colours.value.referenceMarkerOuterScale)+' \\\n'
else:
plotRef = False
# Determine plot size
if plotSize.value == None or plotSize.value == '':
if doColourbar.value is not None and plot in doColourbar.value:
plotSizeInternal = '12.5cm x 4in'
else:
plotSizeInternal = '11cm x 4in'
else:
plotSizeInternal = plotSize.value
# Make profile likelihood plotting scripts
if doProfile.value:
# Get contours
if contours2D.value is not None:
contourLevels = getContours(parseFilename,plot,'like')
# Determine keys
keyString = ''
if doKey2D.value is not None and plot in doKey2D.value:
# Get gross key location
try:
keyLoc = keyLoc2D.value[plot[0]][plot[1]]
except (KeyError, TypeError):
keyLoc = defaultKeyLocation
# Get text to be used for reference point
refText = defaultRefKey if refKey.value is None else refKey.value
# Get x and y coordinates for 3 possible keys (for markers and text)
yVals = ytrema[0] + np.array(keyYVals[keyLoc[0]])*yRange
xVals = xtrema[0] + np.array(keyXVals[keyLoc[1]])*xRange
markers = []
# Get details of key for reference point
if plotRef: markers.append([colours.value.referenceMarkerOuter,
colours.value.referenceMarkerOuterColour,
colours.value.referenceMarkerOuterColour,
colours.value.referenceMarkerOuterScale,
refText,
colours.value.referenceMarkerInner,
colours.value.referenceMarkerInnerColour,
colours.value.referenceMarkerInnerScale/colours.value.referenceMarkerOuterScale])
# Get details of key for posterior mean
if postMeanOnProf.value: markers.append([colours.value.mainPostMeanMarker,
colours.value.mainPostMeanColour2D,
colours.value.mainPostMeanColourOutline2D,
colours.value.mainPostMeanMarkerScale,
'Mean'])
# Get details of key for best fit
if bestFitOnProf.value: markers.append([colours.value.mainBestFitMarker,
colours.value.mainBestFitColour2D,
colours.value.mainBestFitColourOutline2D,
colours.value.mainBestFitMarkerScale,
'Best fit'])
# Reverse vertical ordering if keys are to be placed at the top of the page, so as to fill from the top down
if keyLoc[0] == 't': markers.reverse()
# Construct ctioga2 command for each key
for i,key in enumerate(markers):
if key[0] == 'Bullet' or key[0] == 'BulletOpen': key[3] /= 1.5
if key[3] > 1.0: key[3] = 1.0
# Write the extra marker overlay for the reference point
if len(key) == 8: keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[5]+' /color \''+\
key[6]+'\' /scale '+str(key[7]*key[3])+'\\\n'
# Write the main marker
keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[0]+' /fill-color \''+str(key[1])+'\' /stroke-color \''+str(key[2])+'\' /scale '+str(key[3])+'\\\n'
# Write the key text
keyString += ' --draw-text '+str(xVals[1])+','+str(yVals[i])+' \''+key[4]+'\' /color \''+colours.value.keyTextColour2D
keyString += '\' /justification left /scale 0.75 /alignment center \\\n'
# Open plotting shell script file for writing
outfile = smart_open(currentBase+'_like2D.bsh','w')
outfile.write('#!/usr/bin/env bash\n')
outfile.write('# This plot script created by pippi '+pippiVersion+' on '+datetime.datetime.now().strftime('%c')+'\n')
outfile.write('ctioga2\\\n')
outfile.write(' --name '+currentBaseMinimal+'_like2D')
outfile.write(' --plot-scale \''+str(plot_scale)+'\'\\\n')
outfile.write(' --page-size \''+plotSizeInternal+'\'\\\n')
if doColourbar.value is not None and plot in doColourbar.value:
outfile.write(' --frame-margins '+str(left_margin+0.03)+','
+str(right_margin+0.15)+','
+str(top_margin)+','
+str(bottom_margin)+'\\\n')
else:
outfile.write(' --frame-margins '+str(left_margin+0.05)+','
+str(right_margin+0.02)+','
+str(top_margin)+','
+str(bottom_margin)+'\\\n')
outfile.write(' --xrange '+str(xtrema[0])+':'+str(xtrema[1])+'\\\n')
outfile.write(' --yrange '+str(ytrema[0])+':'+str(ytrema[1])+'\\\n')
outfile.write(' --ylabel \''+labels.value[plot[1]]+'\' /shift 2.9\\\n')
outfile.write(' --xlabel \''+labels.value[plot[0]]+'\'\\\n')
outfile.write(' --label-style x /scale 1.0 /shift 0.15 --label-style y /scale 1.0 /shift 0.75')
if yAxisAngle.value is not None: outfile.write(' /angle '+str(yAxisAngle.value))
outfile.write(" /valign 'midheight'")
outfile.write('\\\n --xyz-map\\\n')
if doColourbar.value is not None and plot in doColourbar.value:
outfile.write(' --new-zaxis zvalues /location right /bar_size \'0.5cm\'\\\n')
outfile.write(" --label-style zvalues /angle 270 /shift 0.4 /valign 'midheight'\\\n")
outfile.write(' --plot '+currentParse+'_like2D.ct2@1:2:3 ')
if doColourbar.value is not None and plot in doColourbar.value: outfile.write('/zaxis zvalues ')
outfile.write('/color-map \''+colours.value.colourMap(contourLevels,'like')+'\'\\\n')
if doComparison.value:
# Do everything for comparison chain
if contours2D.value is not None:
# Plot contours
outfile.write(' --plot '+currentSecParse+'_like2D.ct2@1:2:3 /fill-transparency 1\\\n')
for contour in contourLevels:
outfile.write(' --draw-contour '+contour+' /color '+colours.value.comparisonProfContourColour2D+
' /style '+colours.value.comparisonContourStyle+' /width '+colours.value.lineWidth2D+'\\\n')
if bestFitOnProf.value and colours.value.comparisonBestFitMarker is not None:
# Get best-fit point and plot it
bestFit = getCentralVal(secParseFilename,plot,'like',lookupKeys)
outfile.write(' --draw-marker '+str(bestFit[0])+','+str(bestFit[1])+' '+
colours.value.comparisonBestFitMarker+' /color \''+colours.value.comparisonBestFitColour+
'\' /scale '+str(colours.value.comparisonBestFitMarkerScale)+' \\\n')
if postMeanOnProf.value and colours.value.comparisonPostMeanMarker is not None:
# Get posterior mean and plot it
postMean = getCentralVal(secParseFilename,plot,'post',lookupKeys)
if not postMean: sys.exit('Error: plot_posterior_mean_on_profile_like = T but no multiplicity given!')
outfile.write(' --draw-marker '+str(postMean[0])+','+str(postMean[1])+' '+
colours.value.comparisonPostMeanMarker+' /color \''+colours.value.comparisonPostMeanColour+
'\' /scale '+str(colours.value.comparisonPostMeanMarkerScale)+' \\\n')
outfile.write(' --plot '+currentParse+'_like2D.ct2@1:2:3 /fill-transparency 1\\\n')
if contours2D.value is not None:
# Plot contours
for contour in contourLevels:
outfile.write(' --draw-contour '+contour+' /color '+colours.value.mainProfContourColour2D+
' /style '+colours.value.mainContourStyle+' /width '+colours.value.lineWidth2D+'\\\n')
if doLegend2D.value is not None and plot in doLegend2D.value:
# Write legend
try:
legendLocation = legendLoc2D.value[plot[0]][plot[1]]
except (KeyError, TypeError):
legendLocation = defaultLegendLocation
outfile.write(' --legend-inside \''+legendLocation+'\' /scale 1.0 /vpadding 0.1\\\n')
if legendLines.value is not None:
for x in legendLines.value: outfile.write(' --legend-line \''+x+'\' /color \''+colours.value.legendTextColour2D+'\'\\\n')
outfile.write(' --legend-line \'Prof.~likelihood\' /color \''+colours.value.legendTextColour2D+'\'\\\n')
if bestFitOnProf.value:
# Get best-fit point and plot it
bestFit = getCentralVal(parseFilename,plot,'like',lookupKeys)
outfile.write(' --draw-marker '+str(bestFit[0])+','+str(bestFit[1])+' '+
colours.value.mainBestFitMarker+' /fill-color \''+str(colours.value.mainBestFitColour2D)+'\' /stroke-color \''+str(colours.value.mainBestFitColourOutline2D)+
'\' /scale '+str(colours.value.mainBestFitMarkerScale)+' \\\n')
if postMeanOnProf.value:
# Get posterior mean and plot it
postMean = getCentralVal(parseFilename,plot,'post',lookupKeys)
if not postMean: sys.exit('Error: plot_posterior_mean_on_profile_like = T but no multiplicity given!')
outfile.write(' --draw-marker '+str(postMean[0])+','+str(postMean[1])+' '+
colours.value.mainPostMeanMarker+' /fill-color \''+str(colours.value.mainPostMeanColour2D)+'\' /stroke-color \''+str(colours.value.mainPostMeanColourOutline2D)+
'\' /scale '+str(colours.value.mainPostMeanMarkerScale)+' \\\n')
# Plot reference point
if plotRef: outfile.write(refString)
# Draw key
outfile.write(keyString)
# Write credits
if blame.value is not None:
blameYCoordinate = str(blameFractionalVerticalOffset * yRange + ytrema[1])
outfile.write(' --draw-text '+str(xtrema[1])+','+blameYCoordinate+' \''+blame.value+'\' /scale 0.5 /justification right\\\n')
# Add logo
if logoFile.value is not None:
outfile.write(' --draw-text '+str(logoCoords[0])+','+str(logoCoords[1])+' '+logoString+'\\\n')
# Set axis colours
for x in ['top', 'bottom', 'left', 'right']:
outfile.write(' --axis-style '+x+' /stroke_color \''+colours.value.axisColour2D+'\'\\\n')
if doColourbar.value is not None and plot in doColourbar.value:
# Do labelling for colourbar
outfile.write(' --y2 --plot '+currentParse+'_like2D.ct2@1:2:3 /fill-transparency 1\\\n')
outfile.write(' --axis-style y /decoration ticks --yrange '+str(ytrema[0])+':'+str(ytrema[1])+'\\\n')
outfile.write(' --ylabel \''+likeColourbarString+'\' /shift 3.5 /angle 180 /scale 0.8\\\n')
outfile.close
subprocess.call('chmod +x '+currentBase+'_like2D.bsh', shell=True)
# Make posterior pdf plotting scripts
if doPosterior.value:
# Get contours
if contours2D.value is not None:
mainContourLevels = getContours(parseFilename,plot,'post')
if doComparison.value: secContourLevels = getContours(secParseFilename,plot,'post')
# Determine keys
keyString = ''
if doKey2D.value is not None and plot in doKey2D.value:
# Get gross key location
try:
keyLoc = keyLoc2D.value[plot[0]][plot[1]]
except (KeyError, TypeError):
keyLoc = defaultKeyLocation
# Get text to be used for reference point
refText = defaultRefKey if refKey.value is None else refKey.value
# Get x and y coordinates for 3 possible keys (for markers and text)
yVals = ytrema[0] + np.array(keyYVals[keyLoc[0]])*yRange
xVals = xtrema[0] + np.array(keyXVals[keyLoc[1]])*xRange
markers = []
# Get details of key for reference point
if plotRef: markers.append([colours.value.referenceMarkerOuter,
colours.value.referenceMarkerOuterColour,
colours.value.referenceMarkerOuterColour,
colours.value.referenceMarkerOuterScale,
refText,
colours.value.referenceMarkerInner,
colours.value.referenceMarkerInnerColour,
colours.value.referenceMarkerInnerScale/colours.value.referenceMarkerOuterScale])
# Get details of key for posterior mean
if postMeanOnPost.value: markers.append([colours.value.mainPostMeanMarker,
colours.value.mainPostMeanColour2D,
colours.value.mainPostMeanColourOutline2D,
colours.value.mainPostMeanMarkerScale,
'Mean'])
# Get details of key for best fit
if bestFitOnPost.value: markers.append([colours.value.mainBestFitMarker,
colours.value.mainBestFitColour2D,
colours.value.mainBestFitColourOutline2D,
colours.value.mainBestFitMarkerScale,
'Best fit'])
# Reverse vertical ordering if keys are to be placed at the top of the page, so as to fill from the top down
if keyLoc[0] == 't': markers.reverse()
# Construct ctioga2 command for each key
for i,key in enumerate(markers):
if key[0] == 'Bullet' or key[0] == 'BulletOpen': key[3] /= 1.5
if key[3] > 1.0: key[3] = 1.0
# Write the extra marker overlay for the reference point
if len(key) == 8: keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[5]+' /color \''+\
key[6]+'\' /scale '+str(key[7]*key[3])+'\\\n'
# Write the main marker
keyString += ' --draw-marker '+str(xVals[0])+','+str(yVals[i])+' '+key[0]+' /fill-color \''+str(key[1])+'\' /stroke-color \''+str(key[2])+'\' /scale '+str(key[3])+'\\\n'
# Write the key text
keyString += ' --draw-text '+str(xVals[1])+','+str(yVals[i])+' \''+key[4]+'\' /color \''+colours.value.keyTextColour2D
keyString += '\' /justification left /scale 0.75 /alignment center \\\n'
# Open plotting shell script file for writing
outfile = smart_open(currentBase+'_post2D.bsh','w')
outfile.write('#!/usr/bin/env bash\n')
outfile.write('# This plot script created by pippi '+pippiVersion+' on '+datetime.datetime.now().strftime('%c')+'\n')
outfile.write('ctioga2\\\n')
outfile.write(' --name '+currentBaseMinimal+'_post2D')
outfile.write(' --plot-scale \''+str(plot_scale)+'\'\\\n')
outfile.write(' --page-size \''+plotSizeInternal+'\'\\\n')
if doColourbar.value is not None and plot in doColourbar.value:
outfile.write(' --frame-margins '+str(left_margin+0.03)+','
+str(right_margin+0.15)+','
+str(top_margin)+','
+str(bottom_margin)+'\\\n')
else:
outfile.write(' --frame-margins '+str(left_margin+0.05)+','
+str(right_margin+0.02)+','
+str(top_margin)+','
+str(bottom_margin)+'\\\n')
outfile.write(' --xrange '+str(xtrema[0])+':'+str(xtrema[1])+'\\\n')
outfile.write(' --yrange '+str(ytrema[0])+':'+str(ytrema[1])+'\\\n')
outfile.write(' --ylabel \''+labels.value[plot[1]]+'\' /shift 2.9\\\n')
outfile.write(' --xlabel \''+labels.value[plot[0]]+'\'\\\n')
outfile.write(' --label-style x /scale 1.0 /shift 0.15 --label-style y /scale 1.0 /shift 0.75')
if yAxisAngle.value is not None: outfile.write(' /angle '+str(yAxisAngle.value))
outfile.write(" /valign 'midheight'")
outfile.write('\\\n --xyz-map\\\n')
if doColourbar.value is not None and plot in doColourbar.value:
outfile.write(' --new-zaxis zvalues /location right /bar_size \'0.5cm\'\\\n')
outfile.write(" --label-style zvalues /angle 270 /shift 0.4 /valign 'midheight'\\\n")
outfile.write(' --plot '+currentParse+'_post2D.ct2@1:2:3 ')
if doColourbar.value is not None and plot in doColourbar.value: outfile.write('/zaxis zvalues ')
outfile.write('/color-map \''+colours.value.colourMap(mainContourLevels,'post')+'\'\\\n')
if doComparison.value:
# Do everything for comparison chain
if contours2D.value is not None:
# Plot contours
outfile.write(' --plot '+currentSecParse+'_post2D.ct2@1:2:3 /fill-transparency 1\\\n')
for contour in secContourLevels:
outfile.write(' --draw-contour '+contour+' /color '+colours.value.comparisonPostContourColour2D+
' /style '+colours.value.comparisonContourStyle+' /width '+colours.value.lineWidth2D+'\\\n')
if bestFitOnPost.value and colours.value.comparisonBestFitMarker is not None:
# Get best-fit point and plot it
bestFit = getCentralVal(secParseFilename,plot,'like',lookupKeys)
outfile.write(' --draw-marker '+str(bestFit[0])+','+str(bestFit[1])+' '+
colours.value.comparisonBestFitMarker+' /color \''+colours.value.comparisonBestFitColour+
'\' /scale '+str(colours.value.comparisonBestFitMarkerScale)+' \\\n')
if postMeanOnPost.value and colours.value.comparisonPostMeanMarker is not None:
# Get posterior mean and plot it
postMean = getCentralVal(secParseFilename,plot,'post',lookupKeys)
outfile.write(' --draw-marker '+str(postMean[0])+','+str(postMean[1])+' '+
colours.value.comparisonPostMeanMarker+' /color \''+colours.value.comparisonPostMeanColour+
'\' /scale '+str(colours.value.comparisonPostMeanMarkerScale)+' \\\n')
outfile.write(' --plot '+currentParse+'_post2D.ct2@1:2:3 /fill-transparency 1\\\n')
if contours2D.value is not None:
# Plot contours
for contour in mainContourLevels:
outfile.write(' --draw-contour '+contour+' /color '+colours.value.mainPostContourColour2D+
' /style '+colours.value.mainContourStyle+' /width '+colours.value.lineWidth2D+'\\\n')
if doLegend2D.value is not None and plot in doLegend2D.value:
# Write legend
try:
legendLocation = legendLoc2D.value[plot[0]][plot[1]]
except (KeyError, TypeError):
legendLocation = defaultLegendLocation
outfile.write(' --legend-inside \''+legendLocation+'\' /scale 1.0 /vpadding 0.1\\\n')
if legendLines.value is not None:
for x in legendLines.value: outfile.write(' --legend-line \''+x+'\' /color \''+colours.value.legendTextColour2D+'\'\\\n')
outfile.write(' --legend-line \'Marg.~posterior\' /color \''+colours.value.legendTextColour2D+'\'\\\n')
if bestFitOnPost.value:
# Get best-fit point and plot it
bestFit = getCentralVal(parseFilename,plot,'like',lookupKeys)
outfile.write(' --draw-marker '+str(bestFit[0])+','+str(bestFit[1])+' '+
colours.value.mainBestFitMarker+' /fill-color \''+str(colours.value.mainBestFitColour2D)+'\' /stroke-color \''+str(colours.value.mainBestFitColourOutline2D)+
'\' /scale '+str(colours.value.mainBestFitMarkerScale)+' \\\n')
if postMeanOnPost.value:
# Get posterior mean and plot it
postMean = getCentralVal(parseFilename,plot,'post',lookupKeys)
outfile.write(' --draw-marker '+str(postMean[0])+','+str(postMean[1])+' '+
colours.value.mainPostMeanMarker+' /fill-color \''+str(colours.value.mainPostMeanColour2D)+'\' /stroke-color \''+str(colours.value.mainPostMeanColourOutline2D)+
'\' /scale '+str(colours.value.mainPostMeanMarkerScale)+' \\\n')
# Plot reference point
if plotRef: outfile.write(refString)
# Draw key
outfile.write(keyString)
# Write credits
if blame.value is not None:
blameYCoordinate = str(blameFractionalVerticalOffset * yRange + ytrema[1])
outfile.write(' --draw-text '+str(xtrema[1])+','+blameYCoordinate+' \''+blame.value+'\' /scale 0.5 /justification right\\\n')
# Add logo
if logoFile.value is not None:
outfile.write(' --draw-text '+str(logoCoords[0])+','+str(logoCoords[1])+' '+logoString+'\\\n')
# Set axis colours
for x in ['top', 'bottom', 'left', 'right']:
outfile.write(' --axis-style '+x+' /stroke_color \''+colours.value.axisColour2D+'\'\\\n')
if doColourbar.value is not None and plot in doColourbar.value:
# Do labelling for colourbar
outfile.write(' --y2 --plot '+currentParse+'_post2D.ct2@1:2:3 /fill-transparency 1\\\n')
outfile.write(' --axis-style y /decoration ticks --yrange '+str(ytrema[0])+':'+str(ytrema[1])+'\\\n')
outfile.write(' --ylabel \''+postColourbarString+'\' /shift 3.5 /angle 180 /scale 0.8\\\n')
outfile.close
subprocess.call('chmod +x '+currentBase+'_post2D.bsh', shell=True)
# Make observable plotting scripts
#if doObservable.value:
if obsPlots.value is not None:
for column in obsPlots.value:
# Get contours
if contours2D.value is not None:
contourLevelsLike = getContours(parseFilename,plot,'like')
contourLevelsObs = getContours_obs(parseFilename,plot,column)
# Determine keys
keyString = ''
if doKey2D.value is not None and plot in doKey2D.value:
# Get gross key location
try:
keyLoc = keyLoc2D.value[plot[0]][plot[1]]
except (KeyError, TypeError):
keyLoc = defaultKeyLocation
# Get text to be used for reference point
refText = defaultRefKey if refKey.value is None else refKey.value
# Get x and y coordinates for 3 possible keys (for markers and text)
yVals = ytrema[0] + np.array(keyYVals[keyLoc[0]])*yRange
xVals = xtrema[0] + np.array(keyXVals[keyLoc[1]])*xRange
markers = []
# Get details of key for reference point
if plotRef: markers.append([colours.value.referenceMarkerOuter,
colours.value.referenceMarkerOuterColour,
colours.value.referenceMarkerOuterColour,
colours.value.referenceMarkerOuterScale,
refText,
colours.value.referenceMarkerInner,
colours.value.referenceMarkerInnerColour,