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_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_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")
Exemple #5
0
    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")
Exemple #6
0
    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")