<reponame>plivermore/AH-RJMCMC<gh_stars>1-10
# Script to make figures for manuscript
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import gridspec
import matplotlib.cm as cm
from matplotlib.colors import LogNorm
import os
import sys

if not os.path.exists('Outputs_Mixed_200M/input_file'):
    print('*'*50)
    print('Cannot find file: input_file')
    print('*'*50)
    sys.exit(0)


# Read some basic data from the input file
# This can be overwritten by either altering this file, or simply hardwiring the various parameters: e.g.
# age_min, age_max = 0, 100

for line in open('Outputs_Mixed_200M/input_file','r'):
    if not (line[0] == '#' or line == '\n'): #skip comments or blank lines...
        if line.split()[0].upper() == 'Intensity_prior'.upper():
            I_min, I_max =  float(line.split()[1]),float(line.split()[2])
        if line.split()[0].upper() == 'Age_bounds'.upper():
            age_min, age_max =  float(line.split()[1]),float(line.split()[2])
        if line.split()[0].upper() == 'Num_change_points'.upper():
            K_min, K_max =  int(line.split()[1]), int(line.split()[2])
        if line.split()[0].upper() == 'Credible'.upper():
            credible = float(line.split()[1])
        if line.split()[0].upper() == 'output_model'.upper():
            output_model_filename = line.split()[1]
        if line.split()[0].upper() == 'True_data'.upper():
            true_behaviour_file = line.split()[2]
            x_cts_true,y_cts_true=np.loadtxt(os.path.join(os.pardir,true_behaviour_file),unpack=True)
        if line.split()[0].upper() == 'Plotting_intensity_range'.upper():
            I_min,I_max =  float(line.split()[1]),float(line.split()[2])
        if line.split()[0].upper() == 'Burn_in'.upper():
            Burn_in = int(line.split()[1])
        if line.split()[0].upper() == 'Outputs_directory'.upper():
            outputs_directory = line.split()[1]
# read in the various data files that were output by the RJ-MCMC script
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, AutoMinorLocator,MaxNLocator)
print('Building supplement...')



# Each part figure is created separately and compiled in LaTex. The figures are generated by a function, defined below.

from draw_composite import draw_composite

base_dir = "./"
dirs = ['Outputs_Frag_200M/', 'Outputs_Frag_min_3_200M/', 'Outputs_Frag_min_4_200M/', 'Outputs_Frag_min_5_200M/', 'Outputs_Frag_min_6_200M/',
        'Outputs_Frag25_200M/', 'Outputs_Frag25_min_3_200M/', 'Outputs_Frag25_min_4_200M/', 'Outputs_Frag25_min_5_200M/', 'Outputs_Frag25_min_6_200M/',
        'Outputs_Frag50_200M/', 'Outputs_Frag50_min_3_200M/', 'Outputs_Frag50_min_4_200M/', 'Outputs_Frag50_min_5_200M/', 'Outputs_Frag50_min_6_200M/']
titles=[r"(a) Fragment level", r"(b) Minimum 3 $\mu$T",r"(c) Minimum 4 $\mu$T", r"(d) Minimum 5 $\mu$T", r"(e) Minimum 6 $\mu$T",
        r"(f) Fragment level, 25yr", r"(g) Minimum 3 $\mu$T, 25yr",r"(h) Minimum 4 $\mu$T, 25yr", r"(i) Minimum 5 $\mu$T, 25yr", r"(j) Minimum 6 $\mu$T, 25yr",
        r"(k) Fragment level, 50yr", r"(l) Minimum 3 $\mu$T, 50yr",r"(m) Minimum 4 $\mu$T, 50yr", r"(n) Minimum 5 $\mu$T, 50yr", r"(o) Minimum 6 $\mu$T, 50yr"]
        
Number_rows = 5
row_span_main_figure =3

for i in range(0,len(dirs)):
    print('Making figure part',i+1,' of ', len(dirs))
    fig2 = plt.subplots(figsize=(10,6))
    ax1 = plt.subplot2grid((Number_rows, 1), (0,0), colspan=1,rowspan=row_span_main_figure)
    ax2 = plt.subplot2grid((Number_rows, 1), (row_span_main_figure,0), colspan=1,rowspan=Number_rows-row_span_main_figure)
    plt.subplots_adjust(hspace=0.1, wspace=0)
    draw_composite( base_dir+dirs[i], "Fragment_Plot", titles[i], ax1, ax2,credible,16, plot_posterior_age_intensity=True, plot_spikes_times = True)
    ax2.set_xlabel('Age (BC)',fontsize=16)
        
    plt.savefig('Supplement_'+str(i)+'.pdf', bbox_inches='tight',pad_inches=0.0)
    plt.close()

dirs = ['Outputs_Frag_extended_errors_uniform_200M/', 'Outputs_Frag_extended_errors_normal_200M/']
titles=[r"Extended errors: uniform likelihood", r"Extended errors: normal likelihood"]
Number_rows = 5
row_span_main_figure =3

for i in range(len(dirs)):
    print('Making extra figure part',i+1)
    fig2 = plt.subplots(figsize=(10,6))
    ax1 = plt.subplot2grid((Number_rows, 1), (0,0), colspan=1,rowspan=row_span_main_figure)
    ax2 = plt.subplot2grid((Number_rows, 1), (row_span_main_figure,0), colspan=1,rowspan=Number_rows-row_span_main_figure)
    plt.subplots_adjust(hspace=0.1, wspace=0)
    draw_composite( dirs[i], "Fragment_Plot", titles[i], ax1, ax2,credible,16, plot_posterior_age_intensity=True, plot_spikes_times = True)
    ax2.set_xlabel('Age (BC)',fontsize=16)
    
    plt.savefig('Supplement_'+str(i+15)+'.pdf', bbox_inches='tight',pad_inches=0.0)
    plt.close()
