def plot_lensedCls(self): """ Plots and saves all the lensed Cls in a unique image """ # protection from direct calls if lensing is not included if not self.lensing: return # number of Cls: num = self.lensedCls.shape[1] - 1 # l values: xvalues = self.lensedCls[:, 0] # set up the plots: plots = CMB_plots() plots.color = self.color index = 0 fig = plt.gcf() for ind in xrange(1, num + 1): yvalues = self.lensedCls[:, ind] index2 = int((ind - 1) / 2) temp = plt.subplot2grid((int(math.ceil(num / 2.0)), 2), (index2, index)) if ind == 1: plots.TT_plot(temp, xvalues, yvalues) temp.set_title('TT power spectrum') elif ind == 2: plots.EE_plot(temp, xvalues, yvalues) temp.set_title('EE power spectrum') elif ind == 3: plots.BB_plot(temp, xvalues, yvalues) temp.set_title('BB power spectrum') elif ind == 4: plots.TE_plot(temp, xvalues, yvalues) temp.set_title('TE power spectrum') else: temp.plot(xvalues, yvalues, color=self.color) if index == 0: index = 1 elif index == 1: index = 0 # global title of the plot plt.suptitle(self.name_h + ' lensed Cls', fontsize=16) # define the image size and layout fig.set_size_inches(self.x_size_inc, self.y_size_inc) fig.tight_layout() fig.subplots_adjust( top=0.90 ) # adjust for the fact that tight_layout does not consider suptitle # save the figure and close plt.savefig(self.outpath + self.name + '_lensCls.png') plt.clf()
def plot_scalCls(self): """ Plots and saves all the scalar Cls in a unique image """ # number of Cls: num = self.scalCls.shape[1] - 1 if self.transfer: num += 1 # l values: xvalues = self.scalCls[:, 0] # set up the plots: plots = CMB_plots() plots.color = self.color index = 0 fig = plt.gcf() for ind in xrange(1, num + 1): index2 = int((ind - 1) / 2) temp = plt.subplot2grid((int(math.ceil(num / 2.0)), 2), (index2, index)) if ind == 1: yvalues = self.scalCls[:, ind] plots.TT_plot(temp, xvalues, yvalues) temp.set_title('TT power spectrum') elif ind == 2: yvalues = self.scalCls[:, ind] plots.EE_plot(temp, xvalues, yvalues) temp.set_title('EE power spectrum') elif ind == 3: yvalues = self.scalCls[:, ind] plots.TE_plot(temp, xvalues, yvalues) temp.set_title('TE power spectrum') elif ind == 4 and self.lensing: yvalues = self.scalCls[:, ind] plots.Phi_plot(temp, xvalues, yvalues) temp.set_title('$\phi$ power spectrum') elif ind == 5 and self.lensing: yvalues = self.scalCls[:, ind] plots.PhiT_plot(temp, xvalues, yvalues) temp.set_title('$\phi$T power spectrum') elif ind == num and self.transfer: xvalues = self.matterpower[:, 0] yvalues = self.matterpower[:, 1] plots.Matter_plot(temp, xvalues, yvalues) temp.set_title('Matter power spectrum') else: yvalues = self.scalCls[:, ind] plots.Generic_Cl(temp, xvalues, yvalues) if index == 0: index = 1 elif index == 1: index = 0 # global title of the plot plt.suptitle(self.name_h + ' scalar Cls', fontsize=16) # define the image size and layout fig.set_size_inches(self.x_size_inc, self.y_size_inc) fig.tight_layout() fig.subplots_adjust( top=0.90 ) # adjust for the fact that tight_layout does not consider suptitle # save the figure and close plt.savefig(self.outpath + self.name + '_scalCls.png') plt.clf()
def plot_compare_scalCls(self): """ Plots and saves the comparison of all the scalar Cls in a unique image """ # number of Cls in the two files: num1 = self.scalCls_1.shape[1]-1 num2 = self.scalCls_2.shape[1]-1 # protection against different runs if num1!=num2: print 'wrong number of Cls' return # add the matter power spectrum if required: if self.transfer: num1 += 1 # values of l: xvalues_1 = self.scalCls_1[:,0] xvalues_2 = self.scalCls_2[:,0] # get minimuma and maximum l values: l_min = np.amax( [np.amin(xvalues_1), np.amin(xvalues_2)] ) l_max = np.amin( [np.amax(xvalues_1), np.amax(xvalues_2)] ) # get the l values: l_values = np.linspace(l_min, l_max, l_max-l_min) # set up the plots: plots_1 = CMB_plots() plots_2 = CMB_plots() plots_compa = CMB_plots() plots_1.color = self.color1 plots_2.color = self.color2 plots_compa.color = self.color_compa plots_compa.comparison = True plots_compa.axes_label_position = 'right' fig = plt.gcf() # do the plots: for ind in xrange(1,num1+1): # distribute the plots in the figure: temp = plt.subplot2grid((num1,2), (ind-1, 0)) temp_comp = plt.subplot2grid((num1,2), (ind-1, 1)) # do the l sampling and comparison: if not ( ind == num1 and self.transfer ): # get the y values: yvalues_1 = self.scalCls_1[:,ind] yvalues_2 = self.scalCls_2[:,ind] # interpolate the two spectra: spline_1 = UnivariateSpline( xvalues_1, yvalues_1, s=0) spline_2 = UnivariateSpline( xvalues_2, yvalues_2, s=0) # evaluate on the l grid: yvalues_1 = spline_1(l_values) yvalues_2 = spline_2(l_values) # protect against zeroes: yvalues_1_temp = np.abs( yvalues_1 ) yvalues_2_temp = np.abs( yvalues_2 ) try: min2val_1 = np.amin(yvalues_1_temp[np.nonzero(yvalues_1_temp)]) min2val_2 = np.amin(yvalues_2_temp[np.nonzero(yvalues_2_temp)]) except: min2val_1 = cutoff min2val_2 = cutoff np.place(yvalues_1, yvalues_1 == 0.0, min2val_1) np.place(yvalues_2, yvalues_2 == 0.0, min2val_2) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2)/abs(yvalues_1)*100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp)<cutoff, [cutoff]) else: # matter power spectrum case # get the k values: xvalues_1 = self.matterpower_1[:,0] xvalues_2 = self.matterpower_2[:,0] # get the y values: yvalues_1 = self.matterpower_1[:,1] yvalues_2 = self.matterpower_2[:,1] # get the k grid: k_min = np.amax( [np.amin(xvalues_1), np.amin(xvalues_2)] ) k_max = np.amin( [np.amax(xvalues_1), np.amax(xvalues_2)] ) k_values = np.logspace(np.log10(k_min), np.log10(k_max), 1000) # interpolate the two spectra: spline_1 = UnivariateSpline( xvalues_1, yvalues_1, s=0) spline_2 = UnivariateSpline( xvalues_2, yvalues_2, s=0) # evaluate on the l grid: yvalues_1 = spline_1(k_values) yvalues_2 = spline_2(k_values) # protect against zeroes: yvalues_1_temp = np.abs( yvalues_1 ) yvalues_2_temp = np.abs( yvalues_2 ) try: min2val_1 = np.amin(yvalues_1_temp[np.nonzero(yvalues_1_temp)]) min2val_2 = np.amin(yvalues_2_temp[np.nonzero(yvalues_2_temp)]) except: min2val_1 = cutoff min2val_2 = cutoff np.place(yvalues_1, yvalues_1 == 0.0, min2val_1) np.place(yvalues_2, yvalues_2 == 0.0, min2val_2) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2)/abs(yvalues_1)*100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp)<cutoff, [cutoff]) # make the plots: if ind == 1: # TT power spectrum: plots_1.TT_plot(temp, l_values, yvalues_1) plots_2.TT_plot(temp, l_values, yvalues_2) plots_compa.TT_plot(temp_comp, l_values, yvalues_comp) temp_comp.set_yscale('Log') temp.set_title('TT power spectrum') elif ind == 2: # EE power spectrum: plots_1.EE_plot(temp, l_values, yvalues_1) plots_2.EE_plot(temp, l_values, yvalues_2) plots_compa.EE_plot(temp_comp, l_values, yvalues_comp) temp.set_title('EE power spectrum') elif ind == 3: # TE power spectrum: plots_1.TE_plot(temp, l_values, yvalues_1) plots_2.TE_plot(temp, l_values, yvalues_2) plots_compa.TE_plot(temp_comp, l_values, yvalues_comp) temp.set_title('TE power spectrum') elif ind == 4 and self.lensing: # CMB lensing power spectrum: plots_1.Phi_plot(temp, l_values, yvalues_1) plots_2.Phi_plot(temp, l_values, yvalues_2) plots_compa.Phi_plot(temp_comp, l_values, yvalues_comp) temp.set_title('$\phi$ power spectrum') elif ind == 5 and self.lensing: # CMB lensing - Temperature power spectrum: plots_1.PhiT_plot(temp, l_values, yvalues_1) plots_2.PhiT_plot(temp, l_values, yvalues_2) plots_compa.PhiT_plot(temp_comp, l_values, yvalues_comp) temp.set_title('$\phi$T power spectrum') elif ind == num1 and self.transfer: # matter power spectrum: plots_1.Matter_plot(temp, k_values, yvalues_1) plots_2.Matter_plot(temp, k_values, yvalues_2) plots_compa.Matter_plot(temp_comp, k_values, yvalues_comp) temp.set_title('Matter power spectrum') else: # generic Cl comparison: plots_1.Generic_Cl(temp, l_values, yvalues_1) plots_2.Generic_Cl(temp, l_values, yvalues_2) plots_compa.Generic_Cl(temp_comp, l_values, yvalues_comp) # set the size of the image fig.set_size_inches( self.x_size_inc, self.y_size_inc) # set a tight layout fig.tight_layout(pad=0.3, h_pad=0.3, w_pad=0.3) # set the global title plt.suptitle(self.name_h1+' VS '+self.name_h2+ ' comparison of scalar Cls', fontsize=16) # set the global legend fig.legend( handles = [plots_1.TT_p, plots_2.TT_p, plots_compa.CV_p], labels = [self.name_h1, self.name_h2, 'Cosmic variance'], loc='lower center', ncol=3 ,fancybox=True) # adjust the size of the plot fig.subplots_adjust(top=0.92, bottom=0.08) # save the result and close plt.savefig(self.outpath+self.name1+'_'+self.name2+'_scalCls_comp.pdf') plt.clf() plt.close("all")
def plot_compare_totalCls(self): """ Plots and saves the comparison of all the total (scalar + tensor) Cls in a unique image If lensing is included lensed Cls are used. """ # protection from direct calls if tensors are not included if not self.tensor: return # decide what data to use: if self.lensing: data1 = self.lensedtotCls_1 data2 = self.lensedtotCls_2 else: data1 = self.totCls_1 data2 = self.totCls_2 # number of Cls: num1 = data1.shape[1]-1 num2 = data2.shape[1]-1 # protection against different runs if num1!=num2: print 'wrong number of Cls' return # get the x values: xvalues_1 = data1[:,0] xvalues_2 = data2[:,0] # get the l values: l_min = np.amax( [np.amin(xvalues_1), np.amin(xvalues_2)] ) l_max = np.amin( [np.amax(xvalues_1), np.amax(xvalues_2)] ) # get the l values: l_values = np.linspace(l_min, l_max, l_max-l_min) # set up the plots: plots_1 = CMB_plots() plots_2 = CMB_plots() plots_compa = CMB_plots() plots_1.color = self.color1 plots_2.color = self.color2 plots_compa.color = self.color_compa plots_compa.comparison = True plots_compa.axes_label_position = 'right' fig = plt.gcf() # do the plots: for ind in xrange(1,num1+1): temp = plt.subplot2grid((num1,2), (ind-1, 0)) temp_comp = plt.subplot2grid((num1,2), (ind-1, 1)) # get the y values: yvalues_1 = data1[:,ind] yvalues_2 = data2[:,ind] # interpolate the two spectra: spline_1 = UnivariateSpline( xvalues_1, yvalues_1, s=0) spline_2 = UnivariateSpline( xvalues_2, yvalues_2, s=0) # evaluate on the l grid: yvalues_1 = spline_1(l_values) yvalues_2 = spline_2(l_values) # protect against zeroes: yvalues_1_temp = np.abs( yvalues_1 ) yvalues_2_temp = np.abs( yvalues_2 ) try: min2val_1 = np.amin(yvalues_1_temp[np.nonzero(yvalues_1_temp)]) min2val_2 = np.amin(yvalues_2_temp[np.nonzero(yvalues_2_temp)]) except: min2val_1 = cutoff min2val_2 = cutoff np.place(yvalues_1, yvalues_1 == 0.0, min2val_1) np.place(yvalues_2, yvalues_2 == 0.0, min2val_2) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2)/abs(yvalues_1)*100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp)<cutoff, [cutoff]) if ind == 1: plots_1.TT_plot(temp, l_values, yvalues_1) plots_2.TT_plot(temp, l_values, yvalues_2) plots_compa.TT_plot(temp_comp, l_values, yvalues_comp) temp.set_yscale('Log') temp.set_title('TT power spectrum') elif ind == 2: plots_1.EE_plot(temp, l_values, yvalues_1) plots_2.EE_plot(temp, l_values, yvalues_2) plots_compa.EE_plot(temp_comp, l_values, yvalues_comp) temp.set_title('EE power spectrum') elif ind == 3: plots_1.BB_plot(temp, l_values, yvalues_1) plots_2.BB_plot(temp, l_values, yvalues_2) plots_compa.BB_plot(temp_comp, l_values, yvalues_comp) temp.set_title('BB power spectrum') elif ind == 4: plots_1.TE_plot(temp, l_values, yvalues_1) plots_2.TE_plot(temp, l_values, yvalues_2) plots_compa.TE_plot(temp_comp, l_values, yvalues_comp) temp.set_title('TE power spectrum') else: plots_1.TT_plot(temp, l_values, yvalues_1) plots_2.TT_plot(temp, l_values, yvalues_2) plots_compa.TT_plot(temp_comp, l_values, yvalues_comp) # set the size of the image fig.set_size_inches( self.x_size_inc, self.y_size_inc) # set a tight layout fig.tight_layout(pad=0.3, h_pad=0.3, w_pad=0.3) # set the global title if self.lensing: plt.suptitle(self.name_h1+' VS '+self.name_h2+' comparison of total lensed Cls', fontsize=16) else: plt.suptitle(self.name_h1+' VS '+self.name_h2+' comparison of total Cls', fontsize=16) # set the global legend fig.legend( handles = [plots_1.TT_p, plots_2.TT_p, plots_compa.CV_p], labels = [self.name_h1, self.name_h2, 'Cosmic variance'], loc='lower center', ncol=3 ,fancybox=True) # adjust the size of the plot fig.subplots_adjust(top=0.92, bottom=0.08) # save the result and close plt.savefig(self.outpath+self.name1+'_'+self.name2+'_totCls_comp.pdf') plt.clf() plt.close("all")
def plot_compare_scalCls(self): """ Plots and saves the comparison of all the scalar Cls in a unique image """ # number of Cls in the two files: num1 = self.scalCls_1.shape[1] - 1 num2 = self.scalCls_2.shape[1] - 1 # protection against different runs if num1 != num2: print 'wrong number of Cls' return if len(self.scalCls_1[:, 0]) != len(self.scalCls_2[:, 0]): print 'different lmax' return if len(self.matterpower_1[:, 0]) != len(self.matterpower_2[:, 0]): self.transfer = False # add the matter power spectrum if required: if self.transfer: num1 += 1 # values of l xvalues = self.scalCls_1[:, 0] # set up the plots: plots_1 = CMB_plots() plots_2 = CMB_plots() plots_compa = CMB_plots() plots_1.color = self.color1 plots_2.color = self.color2 plots_compa.color = self.color_compa plots_compa.comparison = True plots_compa.axes_label_position = 'right' fig = plt.gcf() # do the plots: for ind in xrange(1, num1 + 1): # distribute the plots in the figure: temp = plt.subplot2grid((num1, 2), (ind - 1, 0)) temp_comp = plt.subplot2grid((num1, 2), (ind - 1, 1)) if ind == 1: # TT power spectrum: yvalues_1 = self.scalCls_1[:, ind] yvalues_2 = self.scalCls_2[:, ind] # protection against values equal to zero: yvalues_temp = np.array(map(abs, yvalues_1)) min2val = np.min(yvalues_temp[np.nonzero(yvalues_temp)]) np.place(yvalues_1, yvalues_1 == 0.0, min2val) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2) / abs(yvalues_1) * 100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp) < 10.0**(-16), [10.0**(-16)]) # make the plots: plots_1.TT_plot(temp, xvalues, yvalues_1) plots_2.TT_plot(temp, xvalues, yvalues_2) plots_compa.TT_plot(temp_comp, xvalues, yvalues_comp) temp_comp.set_yscale('Log') temp.set_title('TT power spectrum') elif ind == 2: # EE power spectrum: yvalues_1 = self.scalCls_1[:, ind] yvalues_2 = self.scalCls_2[:, ind] # protection against values equal to zero: yvalues_temp = np.array(map(abs, yvalues_1)) min2val = np.min(yvalues_temp[np.nonzero(yvalues_temp)]) np.place(yvalues_1, yvalues_1 == 0.0, min2val) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2) / abs(yvalues_1) * 100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp) < 10.0**(-16), [10.0**(-16)]) # make the plots: plots_1.EE_plot(temp, xvalues, yvalues_1) plots_2.EE_plot(temp, xvalues, yvalues_2) plots_compa.EE_plot(temp_comp, xvalues, yvalues_comp) temp.set_title('EE power spectrum') elif ind == 3: # TE power spectrum: yvalues_1 = self.scalCls_1[:, ind] yvalues_2 = self.scalCls_2[:, ind] # protection against values equal to zero: yvalues_temp = np.array(map(abs, yvalues_1)) min2val = np.min(yvalues_temp[np.nonzero(yvalues_temp)]) np.place(yvalues_1, yvalues_1 == 0.0, min2val) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2) / abs(yvalues_1) * 100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp) < 10.0**(-16), [10.0**(-16)]) # make the plots: plots_1.TE_plot(temp, xvalues, yvalues_1) plots_2.TE_plot(temp, xvalues, yvalues_2) plots_compa.TE_plot(temp_comp, xvalues, yvalues_comp) temp.set_title('TE power spectrum') elif ind == 4 and self.lensing: # CMB lensing power spectrum: yvalues_1 = self.scalCls_1[:, ind] yvalues_2 = self.scalCls_2[:, ind] # protection against values equal to zero: yvalues_temp = np.array(map(abs, yvalues_1)) min2val = np.min(yvalues_temp[np.nonzero(yvalues_temp)]) np.place(yvalues_1, yvalues_1 == 0.0, min2val) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2) / abs(yvalues_1) * 100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp) < 10.0**(-16), [10.0**(-16)]) # make the plots: plots_1.Phi_plot(temp, xvalues, yvalues_1) plots_2.Phi_plot(temp, xvalues, yvalues_2) plots_compa.Phi_plot(temp_comp, xvalues, yvalues_comp) temp.set_title('$\phi$ power spectrum') elif ind == 5 and self.lensing: # CMB lensing - Temperature power spectrum: yvalues_1 = self.scalCls_1[:, ind] yvalues_2 = self.scalCls_2[:, ind] # protection against values equal to zero: yvalues_temp = np.array(map(abs, yvalues_1)) min2val = np.min(yvalues_temp[np.nonzero(yvalues_temp)]) np.place(yvalues_1, yvalues_1 == 0.0, min2val) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2) / abs(yvalues_1) * 100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp) < 10.0**(-16), [10.0**(-16)]) # make the plots: plots_1.PhiT_plot(temp, xvalues, yvalues_1) plots_2.PhiT_plot(temp, xvalues, yvalues_2) plots_compa.PhiT_plot(temp_comp, xvalues, yvalues_comp) temp.set_title('$\phi$T power spectrum') elif ind == num1 and self.transfer: # matter power spectrum: xvalues = self.matterpower_2[:, 0] yvalues_1 = self.matterpower_1[:, 1] yvalues_2 = self.matterpower_2[:, 1] # protection against values equal to zero: yvalues_temp = np.array(map(abs, yvalues_1)) min2val = np.min(yvalues_temp[np.nonzero(yvalues_temp)]) np.place(yvalues_1, yvalues_1 == 0.0, min2val) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2) / abs(yvalues_1) * 100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp) < 10.0**(-16), [10.0**(-16)]) # make the plots: plots_1.Matter_plot(temp, xvalues, yvalues_1) plots_2.Matter_plot(temp, xvalues, yvalues_2) plots_compa.Matter_plot(temp_comp, xvalues, yvalues_comp) temp.set_title('Matter power spectrum') else: # generic Cl comparison: yvalues_1 = self.scalCls_1[:, ind] yvalues_2 = self.scalCls_2[:, ind] # protection against values equal to zero: yvalues_temp = np.array(map(abs, yvalues_1)) min2val = np.min(yvalues_temp[np.nonzero(yvalues_temp)]) np.place(yvalues_1, yvalues_1 == 0.0, min2val) # computation of the percentual comparison: yvalues_comp = (yvalues_1 - yvalues_2) / abs(yvalues_1) * 100 # protection against values too small: np.place(yvalues_comp, abs(yvalues_comp) < 10.0**(-16), [10.0**(-16)]) # make the plots: plots_1.Generic_Cl(temp, xvalues, yvalues_1) plots_2.Generic_Cl(temp, xvalues, yvalues_2) plots_compa.Generic_Cl(temp_comp, xvalues, yvalues_comp) # set the size of the image fig.set_size_inches(self.x_size_inc, self.y_size_inc) # set a tight layout fig.tight_layout(pad=0.3, h_pad=0.3, w_pad=0.3) # set the global title plt.suptitle(self.name_h1 + ' VS ' + self.name_h2 + ' comparison of scalar Cls', fontsize=16) # set the global legend fig.legend(handles=[plots_1.TT_p, plots_2.TT_p, plots_compa.CV_p], labels=[self.name_h1, self.name_h2, 'Cosmic variance'], loc='lower center', ncol=3, fancybox=True) # adjust the size of the plot fig.subplots_adjust(top=0.92, bottom=0.08) # save the result and close plt.savefig(self.outpath + self.name1 + '_' + self.name2 + '_scalCls_comp.pdf') plt.clf() plt.close("all")
def plot_compare_totalCls(self): """ Plots and saves the comparison of all the total (scalar + tensor) Cls in a unique image If lensing is included lensed Cls are used. """ # protection from direct calls if tensors are not included if not self.tensor: return # decide what data to use: if self.lensing: data1 = self.lensedtotCls_1 data2 = self.lensedtotCls_2 else: data1 = self.totCls_1 data2 = self.totCls_2 # number of Cls: num1 = data1.shape[1] - 1 num2 = data2.shape[1] - 1 # protection against different runs if num1 != num2: print 'wrong number of Cls' return if len(data1[:, 0]) != len(data2[:, 0]): print 'different lmax' return xvalues = data1[:, 0] # set up the plots: plots_1 = CMB_plots() plots_2 = CMB_plots() plots_compa = CMB_plots() plots_1.color = self.color1 plots_2.color = self.color2 plots_compa.color = self.color_compa plots_compa.comparison = True plots_compa.axes_label_position = 'right' fig = plt.gcf() # do the plots: for ind in xrange(1, num1 + 1): temp = plt.subplot2grid((num1, 2), (ind - 1, 0)) temp_comp = plt.subplot2grid((num1, 2), (ind - 1, 1)) yvalues_1 = data1[:, ind] yvalues_2 = data2[:, ind] min2val = np.min(yvalues_1[np.nonzero(yvalues_1)]) np.place(yvalues_1, yvalues_1 == 0.0, min2val) yvalues_comp = (yvalues_1 - yvalues_2) / abs(yvalues_1) * 100 # Protection against all zero: put to machine precision the values that are zero np.place(yvalues_comp, abs(yvalues_comp) < 10.0**(-16), [10.0**(-16)]) if ind == 1: plots_1.TT_plot(temp, xvalues, yvalues_1) plots_2.TT_plot(temp, xvalues, yvalues_2) plots_compa.TT_plot(temp_comp, xvalues, yvalues_comp) temp.set_yscale('Log') temp.set_title('TT power spectrum') elif ind == 2: plots_1.EE_plot(temp, xvalues, yvalues_1) plots_2.EE_plot(temp, xvalues, yvalues_2) plots_compa.EE_plot(temp_comp, xvalues, yvalues_comp) temp.set_title('EE power spectrum') elif ind == 3: plots_1.BB_plot(temp, xvalues, yvalues_1) plots_2.BB_plot(temp, xvalues, yvalues_2) plots_compa.BB_plot(temp_comp, xvalues, yvalues_comp) temp.set_title('BB power spectrum') elif ind == 4: plots_1.TE_plot(temp, xvalues, yvalues_1) plots_2.TE_plot(temp, xvalues, yvalues_2) plots_compa.TE_plot(temp_comp, xvalues, yvalues_comp) temp.set_title('TE power spectrum') else: plots_1.TT_plot(temp, xvalues, yvalues_1) plots_2.TT_plot(temp, xvalues, yvalues_2) plots_compa.TT_plot(temp_comp, xvalues, yvalues_comp) # set the size of the image fig.set_size_inches(self.x_size_inc, self.y_size_inc) # set a tight layout fig.tight_layout(pad=0.3, h_pad=0.3, w_pad=0.3) # set the global title if self.lensing: plt.suptitle(self.name_h1 + ' VS ' + self.name_h2 + ' comparison of total lensed Cls', fontsize=16) else: plt.suptitle(self.name_h1 + ' VS ' + self.name_h2 + ' comparison of total Cls', fontsize=16) # set the global legend fig.legend(handles=[plots_1.TT_p, plots_2.TT_p, plots_compa.CV_p], labels=[self.name_h1, self.name_h2, 'Cosmic variance'], loc='lower center', ncol=3, fancybox=True) # adjust the size of the plot fig.subplots_adjust(top=0.92, bottom=0.08) # save the result and close plt.savefig(self.outpath + self.name1 + '_' + self.name2 + '_totCls_comp.pdf') plt.clf() plt.close("all")