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_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_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")