Ejemplo n.º 1
0
def plot_diagnostics(z, norm_diag, roots, output_path='/.', boundary=None):
    figs = {}
    apjfig = analysis.APJSingleColumnFigure()

    min_plot = 1
    max_plot = np.log(5)  # half a log-space unit above 1
    plot_floor = 1e-7

    for key in norm_diag:
        color = next(apjfig.ax._get_lines.prop_cycler)['color']

        analysis.semilogy_posneg(apjfig.ax,
                                 z,
                                 norm_diag[key][1],
                                 label=norm_diag[key][0],
                                 color=color)

        apjfig.ax.axvline(x=roots[key], linestyle='dotted', color=color)
        min_plot = min(min_plot, np.min(np.abs(norm_diag[key][1])))
        logger.debug("{} : {} : {}".format(key, norm_diag[key][0],
                                           norm_diag[key][1]))
    min_plot = max(plot_floor, min_plot)

    #apjfig.ax.axhline(y=1e-2, color='black', linestyle='dashed')
    #apjfig.ax.axhline(y=1e-4, color='black', linestyle='dashed')
    if boundary is not None:
        apjfig.ax.axvline(x=boundary, color='black', linestyle='dotted')
    apjfig.legend(loc="upper left", title="normalized by max", fontsize=6)
    apjfig.ax.set_xlabel("z")
    apjfig.ax.set_ylabel("overshoot diagnostics")
    apjfig.ax.set_ylim(min_plot, max_plot)
    padding = 0.1 * np.max(z)
    xmin = np.min(z) - padding
    xmax = np.max(z) + padding
    apjfig.ax.set_xlim(xmin, xmax)
    figs["diagnostics"] = apjfig

    for key in figs.keys():
        figs[key].savefig(output_path + 'overshoot_{}.png'.format(key),
                          dpi=600)
Ejemplo n.º 2
0
    def plot_atmosphere(self):

        for key in self.necessary_quantities:
            logger.debug("plotting atmospheric quantity {}".format(key))
            fig_q = plt.figure()
            ax = fig_q.add_subplot(2, 1, 1)
            quantity = self.necessary_quantities[key]
            quantity.set_scales(1, keep_data=True)
            ax.plot(self.z[0, :], quantity['g'][0, :])
            if np.min(quantity['g'][0, :]) != np.max(quantity['g'][0, :]):
                ax.set_ylim(
                    np.min(quantity['g'][0, :]) -
                    0.05 * np.abs(np.min(quantity['g'][0, :])),
                    np.max(quantity['g'][0, :]) +
                    0.05 * np.abs(np.max(quantity['g'][0, :])))
            ax.set_xlabel('z')
            ax.set_ylabel(key)

            ax = fig_q.add_subplot(2, 1, 2)
            power_spectrum = np.abs(quantity['c'][0, :] *
                                    np.conj(quantity['c'][0, :]))
            ax.plot(np.arange(len(quantity['c'][0, :])), power_spectrum)
            ax.axhline(y=1e-20, color='black',
                       linestyle='dashed')  # ncc_cutoff = 1e-10
            ax.set_xlabel('z')
            ax.set_ylabel("Tn power spectrum: {}".format(key))
            ax.set_yscale("log", nonposy='clip')
            ax.set_xscale("log", nonposx='clip')

            fig_q.savefig("atmosphere_{}_p{}.png".format(
                key, self.domain.distributor.rank),
                          dpi=300)
            plt.close(fig_q)

        for key in self.necessary_quantities:
            if key not in ['P0', 'rho0']:
                continue
            logger.debug("plotting atmosphereic quantity ln({})".format(key))
            fig_q = plt.figure()
            ax = fig_q.add_subplot(1, 1, 1)
            quantity = self.necessary_quantities[key]
            quantity.set_scales(1, keep_data=True)
            ax.plot(self.z[0, :], np.log(quantity['g'][0, :]))
            if np.min(quantity['g'][0, :]) != np.max(quantity['g'][0, :]):
                ax.set_ylim(
                    np.min(np.log(quantity['g'][0, :])) -
                    0.05 * np.abs(np.min(np.log(quantity['g'][0, :]))),
                    np.max(np.log(quantity['g'][0, :])) +
                    0.05 * np.abs(np.max(np.log(quantity['g'][0, :]))))
            ax.set_xlabel('z')
            ax.set_ylabel('ln_' + key)
            fig_q.savefig(self.fig_dir + "atmosphere_ln_{}_p{}.png".format(
                key, self.domain.distributor.rank),
                          dpi=300,
                          bbox_inches='tight')
            plt.close(fig_q)

        fig_atm = plt.figure()
        axT = fig_atm.add_subplot(2, 2, 1)
        axT.plot(self.z[0, :], self.T0['g'][0, :])
        axT.set_ylabel('T0')
        axP = fig_atm.add_subplot(2, 2, 2)
        axP.semilogy(self.z[0, :], self.P0['g'][0, :])
        axP.set_ylabel('P0')
        axR = fig_atm.add_subplot(2, 2, 3)
        axR.semilogy(self.z[0, :], self.rho0['g'][0, :])
        axR.set_ylabel(r'$\rho0$')
        axS = fig_atm.add_subplot(2, 2, 4)
        analysis.semilogy_posneg(axS,
                                 self.z[0, :],
                                 self.del_s0['g'][0, :],
                                 color_neg='red')

        axS.set_ylabel(r'$\nabla s0$')
        fig_atm.savefig("atmosphere_quantities_p{}.png".format(
            self.domain.distributor.rank),
                        dpi=300)

        fig_atm = plt.figure()
        axS = fig_atm.add_subplot(2, 2, 1)
        axdelS = fig_atm.add_subplot(2, 2, 2)
        axlnP = fig_atm.add_subplot(2, 2, 3)
        axdellnP = fig_atm.add_subplot(2, 2, 4)

        Cv_inv = self.gamma - 1
        axS.plot(self.z[0, :],
                 1 / Cv_inv * np.log(self.T0['g'][0, :]) - 1 / Cv_inv *
                 (self.gamma - 1) * np.log(self.rho0['g'][0, :]),
                 label='s0',
                 linewidth=2)
        axS.plot(self.z[0, :], (1 + (self.gamma - 1) / self.gamma * self.g) *
                 np.log(self.T0['g'][0, :]),
                 label='s based on lnT',
                 linewidth=2)
        axS.plot(self.z[0, :],
                 np.log(self.T0['g'][0, :]) -
                 (self.gamma - 1) / self.gamma * np.log(self.P0['g'][0, :]),
                 label='s based on lnT and lnP',
                 linewidth=2)

        axdelS.plot(self.z[0, :],
                    self.del_s0['g'][0, :],
                    label=r'$\nabla s0$',
                    linewidth=2)
        axdelS.plot(self.z[0, :],
                    self.T0_z['g'][0, :] / self.T0['g'][0, :] + self.g *
                    (self.gamma - 1) / self.gamma * 1 / self.T0['g'][0, :],
                    label=r'$\nabla s0$ from T0',
                    linewidth=2,
                    linestyle='dashed',
                    color='red')

        axlnP.plot(self.z[0, :],
                   np.log(self.P0['g'][0, :]),
                   label='ln(P)',
                   linewidth=2)
        axlnP.plot(self.z[0, :],
                   self.ln_P0['g'][0, :],
                   label='lnP',
                   linestyle='dashed',
                   linewidth=2)
        axlnP.plot(self.z[0, :],
                   -self.g * np.log(self.T0['g'][0, :]) *
                   (self.T0_z['g'][0, :]),
                   label='-g*lnT',
                   linewidth=2,
                   linestyle='dotted')

        axdellnP.plot(self.z[0, :],
                      self.del_ln_P0['g'][0, :],
                      label='dellnP',
                      linewidth=2)
        axdellnP.plot(self.z[0, :],
                      -self.g / self.T0['g'][0, :],
                      label='-g/T',
                      linestyle='dashed',
                      linewidth=2,
                      color='red')

        #axS.legend()
        axS.set_ylabel(r'$s0$')
        fig_atm.savefig("atmosphere_s0_p{}.png".format(
            self.domain.distributor.rank),
                        dpi=300)
Ejemplo n.º 3
0
    def plot_atmosphere(self):
        for key in self.problem.parameters:
            try:
                self.problem.parameters[key].require_layout(
                    self.domain.dist.layouts[1])
                logger.debug("plotting atmospheric quantity {}".format(key))
                fig_q = plt.figure()
                ax = fig_q.add_subplot(2, 1, 1)
                quantity = self.problem.parameters[key]
                quantity.set_scales(1, keep_data=True)
                ax.plot(self.z[0, :], quantity['g'][0, :])
                if np.min(quantity['g'][0, :]) != np.max(quantity['g'][0, :]):
                    ax.set_ylim(
                        np.min(quantity['g'][0, :]) -
                        0.05 * np.abs(np.min(quantity['g'][0, :])),
                        np.max(quantity['g'][0, :]) +
                        0.05 * np.abs(np.max(quantity['g'][0, :])))
                ax.set_xlabel('z')
                ax.set_ylabel(key)

                ax = fig_q.add_subplot(2, 1, 2)
                power_spectrum = np.abs(quantity['c'][0, :] *
                                        np.conj(quantity['c'][0, :]))
                ax.plot(np.arange(len(quantity['c'][0, :])), power_spectrum)
                ax.axhline(y=1e-20, color='black',
                           linestyle='dashed')  # ncc_cutoff = 1e-10
                ax.set_xlabel('z')
                ax.set_ylabel("Tn power spectrum: {}".format(key))
                ax.set_yscale("log", nonposy='clip')
                ax.set_xscale("log", nonposx='clip')

                fig_q.savefig(
                    self.fig_dir +
                    "{:s}_p{:d}.png".format(key, self.domain.distributor.rank),
                    dpi=300)
                plt.close(fig_q)
            except:
                logger.debug("printing atmospheric quantity {}={}".format(
                    key, self.problem.parameters[key]))

        fig_m = plt.figure()
        ax_m = fig_m.add_subplot(1, 1, 1)
        del_ln_T0 = self.problem.parameters['T0_z']['g'][
            0, :] / self.problem.parameters['T0']['g'][0, :]
        ax_m.plot(self.z[0, :],
                  self.problem.parameters['del_ln_rho0']['g'][0, :] /
                  del_ln_T0,
                  label=r'$m$')
        ax_m.axhline(y=self.m_ad,
                     label=r'$m_{ad}$',
                     color='black',
                     linestyle='dashed')
        ax_m.legend()
        fig_m.savefig(
            self.fig_dir +
            "polytropic_m_p{}.png".format(self.domain.distributor.rank),
            dpi=300)

        for key in ['T0', 'P0', 'rho0', 'del_s0']:
            self.necessary_quantities[key].require_layout(
                self.domain.dist.layouts[1])
        fig_atm = plt.figure()
        axT = fig_atm.add_subplot(2, 2, 1)
        axT.plot(self.z[0, :], self.necessary_quantities['T0']['g'][0, :])
        axT.set_ylabel('T0')
        axP = fig_atm.add_subplot(2, 2, 2)
        axP.semilogy(self.z[0, :], self.necessary_quantities['P0']['g'][0, :])
        axP.set_ylabel('P0')
        axR = fig_atm.add_subplot(2, 2, 3)
        axR.semilogy(self.z[0, :],
                     self.necessary_quantities['rho0']['g'][0, :])
        axR.set_ylabel(r'$\rho0$')
        axS = fig_atm.add_subplot(2, 2, 4)
        analysis.semilogy_posneg(
            axS,
            self.z[0, :],
            self.necessary_quantities['del_s0']['g'][0, :],
            color_neg='red')

        axS.set_ylabel(r'$\nabla s0$')
        fig_atm.savefig(
            self.fig_dir +
            "quantities_p{}.png".format(self.domain.distributor.rank),
            dpi=300)

        fig_atm = plt.figure()
        ax1 = fig_atm.add_subplot(2, 2, 1)
        ax2 = fig_atm.add_subplot(2, 2, 2)
        ax3 = fig_atm.add_subplot(2, 2, 3)
        ax4 = fig_atm.add_subplot(2, 2, 4)

        Cv_inv = self.gamma - 1
        ax1.plot(self.z[0, :],
                 1 / Cv_inv * np.log(self.T0['g'][0, :]) - 1 / Cv_inv *
                 (self.gamma - 1) * np.log(self.rho0['g'][0, :]),
                 label='s',
                 linewidth=2)
        ax1.axhline(y=0, color='black', linestyle='dashed')
        ax1.set_ylabel(r'$s$')

        ax2.plot(self.z[0, :],
                 self.del_s0['g'][0, :],
                 label=r'$\nabla s$',
                 linewidth=2)
        ax2.yaxis.tick_right()
        ax2.yaxis.set_label_position("right")
        ax2.set_ylabel(r'$\nabla s$')

        ax3.plot(self.z[0, :],
                 self.problem.parameters['del_ln_rho0']['g'][0, :] / del_ln_T0,
                 label=r'$m(z)$')
        ax3.axhline(y=self.m_ad,
                    color='black',
                    linestyle='dashed',
                    label=r'$m_{ad}$')
        ax3.set_ylabel(r'$m(z)=\nabla \ln \rho/\nabla \ln T$')
        ax3.legend(loc="center left")

        ax4.plot(self.z[0, :],
                 np.log(self.P0['g'][0, :]),
                 label=r'$\ln$P',
                 linewidth=2)
        ax4.plot(self.z[0, :],
                 np.log(self.rho0['g'][0, :]),
                 label=r'$\ln \rho$',
                 linewidth=2)
        ax4.yaxis.tick_right()
        ax4.yaxis.set_label_position("right")
        ax4.set_ylabel(r'$\ln$P,$\ln \rho$')
        ax4.legend()
        plt.tight_layout()
        fig_atm.savefig(self.fig_dir + "atmosphere_parameters_p{}.png".format(
            self.domain.distributor.rank),
                        dpi=300)