In [1]:
%matplotlib notebook
In [2]:
import os
import sys
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter, AutoMinorLocator)
import pandas as pd
from scipy.optimize import curve_fit
In [3]:
os.chdir('..')
os.getcwd()
Out[3]:
In [4]:
sys.path.append('../scripts/')
import bicorr_sim as bicorr_sim
import bicorr_plot as bicorr_plot
import bicorr_math as bicorr_math
In [5]:
%load_ext autoreload
%autoreload 2
What are the variables I need to plot?
In [6]:
os.listdir('cgmf/datap')
Out[6]:
In [7]:
meas_data = np.load('Cf072115_to_Cf072215b//datap/slices_analysis.npz')
cgmf_data = np.load('cgmf/datap/slices_analysis.npz')
freya_data= np.load('freya/datap/slices_analysis.npz')
ipol_data = np.load('ipol/datap/slices_analysis.npz')
ipol_noct_data = np.load('ipol_noct/datap/slices_analysis.npz')
datasets = [meas_data, cgmf_data, freya_data, ipol_data, ipol_noct_data]
legends =['Experiment', 'CGMF', 'FREYA', 'PoliMi', 'PoliMi-No CT']
fmts = ['x', 's', 'D', 'o', '^']
colors = ['#5d269b', '#dd673b', '#80bc31', '#3cbfe0', '#4242f4']
to_plot = [0,1, 2, 3]
In [8]:
cgmf_data.files
Out[8]:
In [9]:
line_thickness = 1
ebar_width = 3
In [10]:
angle_bin_centers = cgmf_data['angle_bin_centers']
angle_bin_edges = cgmf_data['angle_bin_edges']
angle_indices = np.arange(len(angle_bin_centers))
In [11]:
filenames_Eave = []
for a in angle_indices:
fig = plt.figure(figsize=(4,4))
ax = plt.gca()
for i in to_plot:
data = datasets[i]
angle_mid = angle_bin_centers[a]
angle_min = angle_bin_edges[a]
angle_max = angle_bin_edges[a+1]
title = '{} to {} degrees'.format(angle_min, angle_max)
x = data['e_slices']
y = data['Eave'][a,:]
yerr = data['Eave_err'][a,:]
ax.errorbar(x[1:],y[1:],yerr=yerr[1:],
fmt=fmts[i],
markeredgewidth=1,
markerfacecolor='none',
elinewidth = line_thickness,
capthick = line_thickness,
capsize=ebar_width,
c = colors[i])
ax.set_xlabel('$E_i$ (MeV)')
ax.set_ylabel('$\overline{E_j}$ (MeV)')
ax.set_xlim([0,6])
ax.set_ylim([2.15,2.7])
ax.text(3.5,2.65,'Pairs at {}$^\circ$'.format(int(angle_mid)), size=13)
# Set up ticks
ax.tick_params(axis='both',
which='major',
direction='inout',
length=6,
color='k',
bottom=True, right=True, top=True, left=True)
ax.tick_params(axis='both',
which='minor',
direction='in',
length=3,
bottom=True, right=True, top=True, left=True)
# Major
ax.xaxis.set_major_locator(MultipleLocator(1))
ax.yaxis.set_major_locator(MultipleLocator(0.2))
# Minor
ax.xaxis.set_minor_locator(MultipleLocator(.25))
ax.yaxis.set_minor_locator(MultipleLocator(0.05))
plt.legend([legends[i] for i in to_plot], loc=2)
plt.tight_layout()
filename_Eave = 'Eave_{}_degrees'.format(int(angle_mid)); filenames_Eave.append(filename_Eave);
bicorr_plot.save_fig_to_folder(filename_Eave,r'compare\fig\animate')
Redo 85 and 175 degrees
In [12]:
filenames_Eave
Out[12]:
In [13]:
import imageio
images_Eave = []
for filename in filenames_Eave:
images_Eave.append(imageio.imread(os.path.join('compare/fig/animate/',filename + '.png')))
imageio.mimsave('compare/fig/animate_Eave.gif',images_Eave, fps=1)
In [14]:
angle_bin_centers[[7,12,16]]
Out[14]:
In [15]:
indices = [7,12,16];
letters = ['(a)','(b)','(c)']
In [16]:
for i in np.arange(3):
print(letters[i])
In [17]:
filenames_Eave = []
for j in np.arange(3):
a = indices[j]
fig = plt.figure(figsize=(4,4))
ax = plt.gca()
for i in to_plot:
data = datasets[i]
angle_mid = angle_bin_centers[a]
angle_min = angle_bin_edges[a]
angle_max = angle_bin_edges[a+1]
title = '{} to {} degrees'.format(angle_min, angle_max)
x = data['e_slices']
y = data['Eave'][a,:]
yerr = data['Eave_err'][a,:]
ax.errorbar(x[1:],y[1:],yerr=yerr[1:],
fmt=fmts[i],
markeredgewidth=1,
markerfacecolor='none',
elinewidth = line_thickness,
capthick = line_thickness,
capsize=ebar_width,
c = colors[i])
ax.set_xlabel('$E_i$ (MeV)')
ax.set_ylabel('$\overline{E_j}$ (MeV)')
ax.set_xlim([0,6])
ax.set_ylim([2.2,2.7])
ax.text(3.7,2.61,'Pairs at {}$^\circ$'.format(int(angle_mid)), size=13)
ax.text(5.2,2.655,letters[j], size=15, backgroundcolor='white')
# Set up ticks
ax.tick_params(axis='both',
which='major',
direction='inout',
length=6,
color='k',
bottom=True, right=True, top=True, left=True)
ax.tick_params(axis='both',
which='minor',
direction='in',
length=3,
bottom=True, right=True, top=True, left=True)
# Major
ax.xaxis.set_major_locator(MultipleLocator(1))
ax.yaxis.set_major_locator(MultipleLocator(0.2))
# Minor
ax.xaxis.set_minor_locator(MultipleLocator(.25))
ax.yaxis.set_minor_locator(MultipleLocator(0.05))
leg = plt.legend([legends[i] for i in to_plot], loc=2)
leg.get_frame().set_edgecolor('w')
plt.tight_layout()
filename_Eave = 'Eave_{}_degrees1'.format(int(angle_mid)); filenames_Eave.append(filename_Eave);
bicorr_plot.save_fig_to_folder(filename_Eave,r'compare\fig\animate')
In [18]:
e_slices = ipol_data['e_slices']
In [19]:
cgmf_data['angle_bin_centers']
Out[19]:
In [20]:
e_slices[5]
Out[20]:
In [21]:
letters = ['(a)','(a)','(a)','(a)','(b)','(b)']
In [22]:
filenames_Ej = []
for e in [3,5]: # np.arange(1,len(e_slices)):
fig = plt.figure(figsize=(4,4))
ax = plt.gca()
for i in to_plot:
data = datasets[i]
e_slice = e_slices[e]
title = '$E_j$ = {} MeV'.format(e_slice)
x = data['angle_bin_centers']
y = data['Eave'][:,e]
yerr = data['Eave_err'][:,e]
ax.errorbar(x,y,yerr=yerr,
fmt=fmts[i],
markeredgewidth=1,
markerfacecolor='none',
elinewidth = line_thickness,
capthick = line_thickness,
capsize=ebar_width,
c = colors[i])
leg = plt.legend([legends[i] for i in to_plot], loc=1,framealpha=0)
leg.get_frame().set_edgecolor('w')
ax.text(30,2.57,'$E_i$ = {0:.1f} MeV'.format(e_slice), size=13)
ax.text(35,2.61,letters[e], size=15, backgroundcolor='white')
ax.set_xlabel(r'$\theta$ (degrees)')
ax.set_ylabel('$\overline{E_j}$ (MeV)')
ax.set_xlim([0,180])
ax.set_ylim([2.2,2.65])
# Set up ticks
ax.tick_params(axis='both',
which='major',
direction='inout',
length=6,
color='k',
bottom=True, right=True, top=True, left=True)
ax.tick_params(axis='both',
which='minor',
direction='in',
length=3,
bottom=True, right=True, top=True, left=True)
# Major
ax.xaxis.set_major_locator(MultipleLocator(45))
ax.yaxis.set_major_locator(MultipleLocator(0.2))
# Minor
ax.xaxis.set_minor_locator(MultipleLocator(15))
ax.yaxis.set_minor_locator(MultipleLocator(0.05))
plt.axvspan(0,30,facecolor='gray', alpha=0.2)
plt.tight_layout()
filename_Ej = 'Eave_at_{}_MeV'.format(e_slice).replace('.','_'); filenames_Ej.append(filename_Ej);
bicorr_plot.save_fig_to_folder(filename_Ej,r'compare\fig\animate')
In [ ]:
filenames_Ej
In [23]:
import imageio
images_Ej = []
for filename in filenames_Ej:
print(filename)
images_Ej.append(imageio.imread(os.path.join('compare/fig/animate/',filename + '.png')))
imageio.mimsave('compare/fig/animate_Eave_vs_angle.gif',images_Ej, fps=1)
Load E_sum dat
In [23]:
Esum_df_meas = pd.read_csv(r'Cf072115_to_Cf072215b/datap/Esum_df.csv',index_col=0)
Esum_df_cgmf = pd.read_csv(r'cgmf/datap/Esum_df.csv',index_col=0)
Esum_df_freya= pd.read_csv(r'freya/datap/Esum_df.csv',index_col=0)
Esum_df_ipol = pd.read_csv(r'ipol/datap/Esum_df.csv',index_col=0)
Esum_df_ipol_noct = pd.read_csv(r'ipol_noct/datap/Esum_df.csv',index_col=0)
Esum_dfs = [Esum_df_meas, Esum_df_cgmf, Esum_df_freya, Esum_df_ipol, Esum_df_ipol_noct]
In [24]:
filenames_Ej = []
e_indices = [1,3,5,7]
for i in to_plot:
Esum_df = Esum_dfs[i]
data = datasets[i]
fig = plt.figure(figsize=(4,4))
ax = plt.gca()
title = legends[i]
ax.errorbar(Esum_df['th_bin_center'],
Esum_df['Eave'],
yerr=Esum_df['Eave_err'],
fmt=fmts[i],
markeredgewidth=1,
markerfacecolor='none',
elinewidth=line_thickness,
capthick = line_thickness,
capsize = ebar_width)
for e in e_indices:
e_slice = e_slices[e]
x = data['angle_bin_centers']
y = data['Eave'][:,e]
yerr = data['Eave_err'][:,e]
ax.errorbar(x,y,yerr=yerr,
fmt = fmts[i],
markeredgewidth=1,
markerfacecolor='none',
elinewidth=line_thickness,
capthick=line_thickness,
capsize=ebar_width)
plt.legend(['all']+[str(e_slices[i]) for i in e_indices])
plt.title(title)
ax.set_xlabel(r'$\theta$ (degrees)')
ax.set_ylabel('$\overline{E_j}$ (MeV)')
ax.set_xlim([0,180])
ax.set_ylim([2.2,2.65])
# Set up ticks
ax.tick_params(axis='both',
which='major',
direction='inout',
length=6,
color='k',
bottom=True, right=True, top=True, left=True)
ax.tick_params(axis='both',
which='minor',
direction='in',
length=3,
bottom=True, right=True, top=True, left=True)
# Major
ax.xaxis.set_major_locator(MultipleLocator(45))
ax.yaxis.set_major_locator(MultipleLocator(0.2))
# Minor
ax.xaxis.set_minor_locator(MultipleLocator(15))
ax.yaxis.set_minor_locator(MultipleLocator(0.05))
plt.axvspan(0,30,facecolor='gray', alpha=0.2)
plt.tight_layout()
bicorr_plot.save_fig_to_folder('Ejave_vs_theta_'+title,r'compare\fig')
In [35]:
filenames_Eave = []
fig = plt.figure(figsize=(4,4))
ax = plt.gca()
angle_indices = np.arange(7,17)
for a in angle_indices:
angle_mid = angle_bin_centers[a]
angle_min = angle_bin_edges[a]
angle_max = angle_bin_edges[a+1]
for i in to_plot:
data = datasets[i]
title = '{} to {} degrees'.format(angle_min, angle_max)
x = data['e_slices']
y = data['Eave'][a,:]
yerr = data['Eave_err'][a,:]
m, m_err = bicorr_math.fit_f_line(x, y, y_err=yerr)[0:2]
print(m, m_err)
ax.errorbar(angle_mid,m,yerr=m_err,
fmt=fmts[i],
markeredgewidth=1,
markerfacecolor='none',
elinewidth = line_thickness,
capthick = line_thickness,
capsize=ebar_width,
c = colors[i])
leg = plt.legend([legends[i] for i in to_plot], loc=2)
leg.get_frame().set_edgecolor('w')
plt.axhline(0,color='gray', linewidth=1,linestyle='--')
ax.set_xlabel(r'$\theta$ (degrees)')
ax.set_ylabel(r'Slope $m$')
ax.set_xlim([80,180])
# Set up ticks
ax.tick_params(axis='both',
which='major',
direction='inout',
length=6,
color='k',
bottom=True, right=True, top=True, left=True)
ax.tick_params(axis='both',
which='minor',
direction='in',
length=3,
bottom=True, right=True, top=True, left=True)
# Major
ax.xaxis.set_major_locator(MultipleLocator(45))
ax.yaxis.set_major_locator(MultipleLocator(0.02))
# Minor
ax.xaxis.set_minor_locator(MultipleLocator(15))
ax.yaxis.set_minor_locator(MultipleLocator(0.005))
ax.text(165,0.04,'(d)', size=15, backgroundcolor='white')
plt.tight_layout()
bicorr_plot.save_fig_to_folder(r'e_slices_slope',r'compare\fig')
In [ ]: