def plot_Transfer(self): """ Plots and saves all the transfer functions in a unique image """ # protection from direct calls if transfer functions are not included if not self.transfer: return # number of transfer functions: num = self.transfer_func.shape[1] - 1 # k values: xvalues = self.transfer_func[:, 0] # set up the plots: plots = CMB_plots() plots.color = self.color index = 0 fig = plt.gcf() labels = [ 'CDM', 'baryons', 'photons', 'massless neutrinos', 'massive neutrinos', 'CDM+baryons+massive neutrinos', 'CDM+baryons', 'CDM+baryons+massive neutrinos+ de', 'The Weyl potential', 'vel_Newt_cdm', 'vel_Newt_b', 'relative baryon-CDM velocity' ] for ind in xrange(1, num + 1): yvalues = self.transfer_func[:, ind] index2 = int((ind - 1) / 2) temp = plt.subplot2grid((int(math.ceil(num / 2.0)), 2), (index2, index)) plots.Transfer_plot(temp, xvalues, yvalues) temp.set_title(labels[ind - 1]) if index == 0: index = 1 elif index == 1: index = 0 if ind == num or ind == num - 1: temp.set_xlabel(r'$k$') plt.suptitle(self.name_h + ' transfer functions', fontsize=16) # define the image size and layout fig.set_size_inches(self.x_size_inc, 1.61803398875 * self.x_size_inc) fig.tight_layout() fig.subplots_adjust( top=0.94 ) # adjust for the fact that tight_layout does not consider suptitle # save the figure and close plt.savefig(self.outpath + self.name + '_transfer.png') plt.clf()
def plot_tensCls(self): """ Plots and saves all the tensor Cls in a unique image """ # protection from direct calls if tensors is not included if not self.tensor: return # number of Cls: num = self.tensCls.shape[1]-1 # l values: xvalues = self.tensCls[:,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.tensCls[:,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_yscale('Log') 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+' tensor 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) # save the figure and close plt.savefig(self.outpath+self.name+'_tensCls.png') plt.clf()
def plot_scalCovCls(self): """ Plots and saves all the scalar covariance Cls in a unique image """ # number of Cls: num = int(math.sqrt(self.scalCovCls.shape[1] - 1)) # l values: xvalues = self.scalCovCls[:, 0] # set up the plots: plots = CMB_plots() plots.color = self.color fig = plt.gcf() # setup a dictionary with the names of the Cls dict = {1: 'T', 2: 'E', 3: '$\phi$'} for i in xrange(4, num + 1): dict[i] = 'W' + str(i) for ind in xrange(1, num + 1): for ind2 in xrange(1, ind + 1): temp = plt.subplot2grid((num, num), (ind - 1, ind2 - 1)) col = ind + num * (ind2 - 1) yvalues = self.scalCovCls[:, col] temp.text(0.15, 0.15, dict[ind] + dict[ind2], ha='center', va='center', transform=temp.transAxes) plots.Generic_Cl(temp, xvalues, yvalues) if ind == num: temp.set_xlabel(r'$l$') # global title of the plot plt.suptitle(self.name_h + ' scalar Cov Cls', fontsize=16) # define the image size and layout. We need a bigger image for the covariance. fig.set_size_inches(1.61803398875 * self.x_size_inc, self.x_size_inc) fig.tight_layout() fig.subplots_adjust(hspace=0) 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 + '_scalCovCls.png') plt.clf()
def plot_Transfer(self): """ Plots and saves all the transfer functions in a unique image """ # protection from direct calls if transfer functions are not included if not self.transfer: return # number of transfer functions: num = self.transfer_func.shape[1]-1 # k values: xvalues = self.transfer_func[:,0] # set up the plots: plots = CMB_plots() plots.color = self.color index = 0 fig = plt.gcf() labels = [ 'CDM', 'baryons', 'photons', 'massless neutrinos', 'massive neutrinos', 'CDM+baryons+massive neutrinos', 'CDM+baryons', 'CDM+baryons+massive neutrinos+ de', 'The Weyl potential', 'vel_Newt_cdm', 'vel_Newt_b', 'relative baryon-CDM velocity' ] for ind in xrange(1,num+1): yvalues = self.transfer_func[:,ind] index2 = int((ind-1)/2) temp = plt.subplot2grid((int(math.ceil(num/2.0)),2),(index2, index)) plots.Transfer_plot(temp, xvalues, yvalues) temp.set_title(labels[ind-1]) if index==0: index = 1 elif index==1: index = 0 if ind == num or ind == num-1: temp.set_xlabel(r'$k$') plt.suptitle(self.name_h+' transfer functions', fontsize=16) # define the image size and layout fig.set_size_inches(self.x_size_inc, 1.61803398875*self.x_size_inc) fig.tight_layout() fig.subplots_adjust(top=0.94) # adjust for the fact that tight_layout does not consider suptitle # save the figure and close plt.savefig(self.outpath+self.name+'_transfer.png') plt.clf()
def plot_scalCovCls(self): """ Plots and saves all the scalar covariance Cls in a unique image """ # number of Cls: num = int(math.sqrt(self.scalCovCls.shape[1]-1)) # l values: xvalues = self.scalCovCls[:,0] # set up the plots: plots = CMB_plots() plots.color = self.color fig = plt.gcf() # setup a dictionary with the names of the Cls dict = { 1: 'T', 2: 'E', 3: '$\phi$'} for i in xrange(4, num+1): dict[i] = 'W'+str(i) for ind in xrange(1, num+1): for ind2 in xrange(1, ind+1): temp = plt.subplot2grid((num, num),(ind-1, ind2-1)) col = ind + num*(ind2-1) yvalues = self.scalCovCls[:,col] temp.text( 0.15, 0.15, dict[ind]+dict[ind2] , ha='center', va='center', transform=temp.transAxes) plots.Generic_Cl(temp, xvalues, yvalues) if ind == num: temp.set_xlabel(r'$l$') # global title of the plot plt.suptitle(self.name_h+' scalar Cov Cls', fontsize=16) # define the image size and layout. We need a bigger image for the covariance. fig.set_size_inches(1.61803398875*self.x_size_inc, self.x_size_inc) fig.tight_layout() fig.subplots_adjust(hspace=0) 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+'_scalCovCls.png') plt.clf()
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 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")
def plot_compare_scalCovCls(self): """ Plots and saves the comparison of all the scalar Cov Cls in a unique image """ # number of Cls: num1 = self.scalCovCls_1.shape[1] - 1 num2 = self.scalCovCls_2.shape[1] - 1 # protection against different runs if num1 != num2: print "wrong number of Cls" return if len(self.scalCovCls_1[:, 0]) != len(self.scalCovCls_2[:, 0]): print "different lmax" return # size of the Cl Cov matrix: num1 = int(math.sqrt(num1)) num_tot = sum(xrange(1, num1 + 1)) # 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() # setup a dictionary with the names of the Cls dict = {1: "T", 2: "E", 3: "$\phi$"} for i in xrange(4, num1 + 1): dict[i] = "W" + str(i) # values of the multipoles: xvalues = self.scalCovCls_1[:, 0] # other stuff: ind_tot = 0 # do the plots: for ind in xrange(1, num1 + 1): for ind2 in xrange(1, ind + 1): ind_tot += 1 # place the plots: temp = plt.subplot2grid((num_tot, 2), (ind_tot - 1, 0)) temp_comp = plt.subplot2grid((num_tot, 2), (ind_tot - 1, 1)) # values of the Cls: col = ind + num1 * (ind2 - 1) yvalues_1 = self.scalCovCls_1[:, col] yvalues_2 = self.scalCovCls_2[:, col] # protection against values equal to zero: yvalues_temp = np.array(map(abs, yvalues_1)) try: min2val = np.min(yvalues_temp[np.nonzero(yvalues_temp)]) except: min2val = 10 ** (-16) 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) temp.set_title(dict[ind2] + dict[ind] + " power spectrum") # set the size of the image fig.set_size_inches(self.x_size_inc, self.y_size_inc / 5.0 * num_tot) # set a tight layout fig.tight_layout(pad=0.3, h_pad=0.3, w_pad=0.3) # set the global legend fig.legend( handles=[plots_1.Generic_Cl_plot, plots_2.Generic_Cl_plot, plots_compa.CV_p], labels=[self.name_h1, self.name_h2, "Cosmic variance"], loc="lower center", ncol=3, fancybox=True, ) # set the global title plt.suptitle(self.name_h1 + " VS " + self.name_h2 + " comparison of scalar Cov Cls", fontsize=16) # adjust the size of the plot fig.subplots_adjust(top=0.92, bottom=0.08) # fig.subplots_adjust(top=0.96, bottom=0.01) # save the result and close plt.savefig(self.outpath + self.name1 + "_" + self.name2 + "_scalCovCls_comp.pdf") plt.clf() plt.close("all")
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_Transfer(self): """ Plots and saves the comparison of all the transfer functions in a unique image """ # protection from direct calls if transfer functions are not included if not self.transfer: return data1 = self.transfer_func_1 data2 = self.transfer_func_2 # number of transfer functions: num1 = data1.shape[1] - 1 num2 = data2.shape[1] - 1 # protection against different runs if num1 != num2: print 'wrong number of transfer functions' return if len(data1[:, 0]) != len(data2[:, 0]): print 'Different values of k' 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() labels = [ 'CDM', 'baryons', 'photons', 'massless neutrinos', 'massive neutrinos', 'CDM+baryons+massive neutrinos', 'CDM+baryons', 'CDM+baryons+massive neutrinos+ de', 'The Weyl potential', 'vel_Newt_cdm', 'vel_Newt_b', 'relative baryon-CDM velocity' ] if not len(labels) == num1: print 'Not enough transfer functions' return # 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)]) plots_1.Transfer_plot(temp, xvalues, yvalues_1) plots_2.Transfer_plot(temp, xvalues, yvalues_2) plots_compa.Transfer_plot(temp_comp, xvalues, yvalues_comp) temp.set_title(labels[ind - 1]) # set the size of the image fig.set_size_inches(self.x_size_inc, 1.61803398875 * self.x_size_inc / 6. * num1) # 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 transfer functions', fontsize=16) # set the global legend fig.legend(handles=[plots_1.Transfer_p, plots_2.Transfer_p], labels=[self.name_h1, self.name_h2], loc='lower center', ncol=3, fancybox=True) # adjust the size of the plot fig.subplots_adjust(top=0.95, bottom=0.05) # save the result and close plt.savefig(self.outpath + self.name1 + '_' + self.name2 + '_transfer_comp.pdf') plt.clf() plt.close("all")
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 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")
def plot_compare_scalCovCls(self): """ Plots and saves the comparison of all the scalar Cov Cls in a unique image """ # number of Cls: num1 = self.scalCovCls_1.shape[1]-1 num2 = self.scalCovCls_2.shape[1]-1 # protection against different runs if num1!=num2: print 'wrong number of Cls' return # size of the Cl Cov matrix: num1 = int(math.sqrt(num1)) num_tot = sum(xrange(1,num1+1)) # 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() # setup a dictionary with the names of the Cls dict = { 1: 'T', 2: 'E', 3: '$\phi$'} for i in xrange(4, num1+1): dict[i] = 'W'+str(i) # values of the multipoles: xvalues_1 = self.scalCovCls_1[:,0] xvalues_2 = self.scalCovCls_2[:,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) # other stuff: ind_tot = 0 # do the plots: for ind in xrange(1,num1+1): for ind2 in xrange(1, ind+1): ind_tot += 1 # place the plots: temp = plt.subplot2grid((num_tot,2), (ind_tot-1, 0)) temp_comp = plt.subplot2grid((num_tot,2), (ind_tot-1, 1)) # values of the Cls: col = ind + num1*(ind2-1) # get the y values: yvalues_1 = self.scalCovCls_1[:,col] yvalues_2 = self.scalCovCls_2[:,col] # 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]) # make the plots: 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) temp.set_title(dict[ind2]+dict[ind]+' power spectrum') # set the size of the image fig.set_size_inches( self.x_size_inc, self.y_size_inc/5.0*num_tot) # set a tight layout fig.tight_layout(pad=0.3, h_pad=0.3, w_pad=0.3) # set the global legend fig.legend( handles = [plots_1.Generic_Cl_plot, plots_2.Generic_Cl_plot, plots_compa.CV_p], labels = [self.name_h1, self.name_h2, 'Cosmic variance'], loc='lower center', ncol=3 ,fancybox=True) # set the global title plt.suptitle(self.name_h1+' VS '+self.name_h2+ ' comparison of scalar Cov Cls', fontsize=16) # adjust the size of the plot fig.subplots_adjust(top=0.92, bottom=0.08) # fig.subplots_adjust(top=0.96, bottom=0.01) # save the result and close plt.savefig(self.outpath+self.name1+'_'+self.name2+'_scalCovCls_comp.pdf') plt.clf() plt.close("all")
def plot_compare_Transfer(self): """ Plots and saves the comparison of all the transfer functions in a unique image """ # protection from direct calls if transfer functions are not included if not self.transfer: return data1 = self.transfer_func_1 data2 = self.transfer_func_2 # number of transfer functions: num1 = data1.shape[1] - 1 num2 = data2.shape[1] - 1 # protection against different runs if num1 != num2: print "wrong number of transfer functions" return if len(data1[:, 0]) != len(data2[:, 0]): print "Different values of k" 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() labels = [ "CDM", "baryons", "photons", "massless neutrinos", "massive neutrinos", "CDM+baryons+massive neutrinos", "CDM+baryons", "CDM+baryons+massive neutrinos+ de", "The Weyl potential", "vel_Newt_cdm", "vel_Newt_b", "relative baryon-CDM velocity", ] if not len(labels) == num1: print "Not enough transfer functions" return # 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)]) plots_1.Transfer_plot(temp, xvalues, yvalues_1) plots_2.Transfer_plot(temp, xvalues, yvalues_2) plots_compa.Transfer_plot(temp_comp, xvalues, yvalues_comp) temp.set_title(labels[ind - 1]) # set the size of the image fig.set_size_inches(self.x_size_inc, 1.61803398875 * self.x_size_inc / 6.0 * num1) # 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 transfer functions", fontsize=16) # set the global legend fig.legend( handles=[plots_1.Transfer_p, plots_2.Transfer_p], labels=[self.name_h1, self.name_h2], loc="lower center", ncol=3, fancybox=True, ) # adjust the size of the plot fig.subplots_adjust(top=0.95, bottom=0.05) # save the result and close plt.savefig(self.outpath + self.name1 + "_" + self.name2 + "_transfer_comp.pdf") plt.clf() plt.close("all")
def plot_compare_tensCls(self): """ Plots and saves the comparison of all the tensor Cls in a unique image """ # protection from direct calls if tensors are not included if not self.tensor: return # number of Cls: num1 = self.tensCls_1.shape[1]-1 num2 = self.tensCls_2.shape[1]-1 # protection against different runs if num1!=num2: print 'wrong number of Cls' return if len(self.tensCls_1[:,0])!=len(self.tensCls_2[:,0]): print 'different lmax' return xvalues = self.tensCls_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): temp = plt.subplot2grid((num1,2), (ind-1, 0)) temp_comp = plt.subplot2grid((num1,2), (ind-1, 1)) yvalues_1 = self.tensCls_1[:,ind] yvalues_2 = self.tensCls_2[:,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 plt.suptitle(self.name_h1+' VS '+self.name_h2+ ' comparison of tensor 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+'_tensCls_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 # 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_Transfer(self): """ Plots and saves the comparison of all the transfer functions in a unique image """ # protection from direct calls if transfer functions are not included if not self.transfer: return data1 = self.transfer_func_1 data2 = self.transfer_func_2 # number of transfer functions: num1 = data1.shape[1]-1 num2 = data2.shape[1]-1 # protection against different runs if num1!=num2: print 'wrong number of transfer functions' return # get the x values: xvalues_1 = data1[:,0] xvalues_2 = data2[:,0] # 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) # 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() labels = [ 'CDM', 'baryons', 'photons', 'massless neutrinos', 'massive neutrinos', 'CDM+baryons+massive neutrinos', 'CDM+baryons', 'CDM+baryons+massive neutrinos+ de', 'The Weyl potential', 'vel_Newt_cdm', 'vel_Newt_b', 'relative baryon-CDM velocity', ] if not len(labels) == num1: print 'Not enough transfer functions for labels' print 'Labels are:' print labels return # 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(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]) if not ( np.all( np.abs(yvalues_1) <= cutoff) ): plots_1.Transfer_plot(temp, k_values, yvalues_1) if not ( np.all( np.abs(yvalues_2) <= cutoff) ): plots_2.Transfer_plot(temp, k_values, yvalues_2) if not ( np.all( np.abs(yvalues_comp) <= cutoff) ): plots_compa.Transfer_plot(temp_comp, k_values, yvalues_comp) temp.set_title(labels[ind-1]) # set the size of the image fig.set_size_inches( self.x_size_inc, 1.61803398875*self.x_size_inc/6.*num1 ) # 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 transfer functions', fontsize=16) # set the global legend fig.legend( handles = [plots_1.Transfer_p, plots_2.Transfer_p], labels = [self.name_h1, self.name_h2], loc='lower center', ncol=3 ,fancybox=True) # adjust the size of the plot fig.subplots_adjust(top=0.95, bottom=0.05) # save the result and close plt.savefig(self.outpath+self.name1+'_'+self.name2+'_transfer_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_scalCovCls(self): """ Plots and saves the comparison of all the scalar Cov Cls in a unique image """ # number of Cls: num1 = self.scalCovCls_1.shape[1] - 1 num2 = self.scalCovCls_2.shape[1] - 1 # protection against different runs if num1 != num2: print 'wrong number of Cls' return if len(self.scalCovCls_1[:, 0]) != len(self.scalCovCls_2[:, 0]): print 'different lmax' return # size of the Cl Cov matrix: num1 = int(math.sqrt(num1)) num_tot = sum(xrange(1, num1 + 1)) # 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() # setup a dictionary with the names of the Cls dict = {1: 'T', 2: 'E', 3: '$\phi$'} for i in xrange(4, num1 + 1): dict[i] = 'W' + str(i) # values of the multipoles: xvalues = self.scalCovCls_1[:, 0] # other stuff: ind_tot = 0 # do the plots: for ind in xrange(1, num1 + 1): for ind2 in xrange(1, ind + 1): ind_tot += 1 # place the plots: temp = plt.subplot2grid((num_tot, 2), (ind_tot - 1, 0)) temp_comp = plt.subplot2grid((num_tot, 2), (ind_tot - 1, 1)) # values of the Cls: col = ind + num1 * (ind2 - 1) yvalues_1 = self.scalCovCls_1[:, col] yvalues_2 = self.scalCovCls_2[:, col] # 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) temp.set_title(dict[ind2] + dict[ind] + ' power spectrum') # set the size of the image fig.set_size_inches(self.x_size_inc, self.y_size_inc / 5.0 * num_tot) # set a tight layout fig.tight_layout(pad=0.3, h_pad=0.3, w_pad=0.3) # set the global legend fig.legend(handles=[ plots_1.Generic_Cl_plot, plots_2.Generic_Cl_plot, plots_compa.CV_p ], labels=[self.name_h1, self.name_h2, 'Cosmic variance'], loc='lower center', ncol=3, fancybox=True) # set the global title plt.suptitle(self.name_h1 + ' VS ' + self.name_h2 + ' comparison of scalar Cov Cls', fontsize=16) # adjust the size of the plot fig.subplots_adjust(top=0.92, bottom=0.08) # fig.subplots_adjust(top=0.96, bottom=0.01) # save the result and close plt.savefig(self.outpath + self.name1 + '_' + self.name2 + '_scalCovCls_comp.pdf') plt.clf() plt.close("all")