def plot_bott_lpparam_glatparam(self, lgbott=None, lpparam='delta', glatparam='ABDelta',
                                    outname=None, xlabel=None, ylabel=None, title=None, check_omegacs=False):
        """Plot phase diagram with lattice param varying on x axis and glatparam varying on y axis

        Parameters
        ----------
        lgbott : N x 3 float array or None
            lattice params array, glatparam array, bott indices array
        glatparam : str

        outname : str or None
        """
        if lgbott is None:
            lpV, glatV, botts, omegacs = self.collect_botts_lpparam_glatparam(glatparam=glatparam)
            # lgbott is the [lattice param, glat param, botts] vector
            lgbott = np.dstack((lpV, glatV, botts, omegacs))[0]

        print 'lpV, glatV, botts:'
        print 'lgbott = ', lgbott
        ngrid = len(lgbott) + 7
        fig, ax, cbar_ax = leplt.initialize_1panel_cbar_cent()
        leplt.plot_pcolormesh(lgbott[:, 0], lgbott[:, 1], lgbott[:, 2], ngrid, ax=ax, cax=cbar_ax, method='nearest',
                              make_cbar=True, cmap=lecmaps.diverging_cmap(250, 10, l=30),
                              vmin=-1., vmax=1., title=None, xlabel=None, ylabel=None, ylabel_right=True,
                              ylabel_rot=90, cax_label=r'Bott index, $B$',
                              cbar_labelpad=-30, cbar_orientation='horizontal',
                              ticks=[-1, 0, 1], fontsize=8, title_axX=None, title_axY=None, alpha=1.0)
        if title is not None:
            cbar_ax.text(0.5, 0.95, title, ha='center', va='center', transform=fig.transFigure)

        if xlabel is None:
            xlabel = leplt.param2description(glatparam)
        if ylabel is None:
            ylabel = leplt.param2description(lpparam)

        ax.set_xlabel(xlabel)
        ax.set_ylabel(ylabel)

        if outname is not None:
            print 'saving figure to ' + outname
            plt.savefig(outname)

        if check_omegacs:
            fig2, ax2 = leplt.initialize_1panel_centered_fig(wsfrac=0.5, tspace=4)
            leplt.plot_pcolormesh(lgbott[:, 0], lgbott[:, 1], omegacs[:, 3], ngrid, ax=ax2, cax=cbar_ax, method='nearest',
                                  make_cbar=True, cmap=lecmaps.diverging_cmap(250, 10, l=30),
                                  vmin=-1., vmax=1., title=None, xlabel=None, ylabel=None, ylabel_right=True,
                                  ylabel_rot=90, cax_label=r'Bott index, $B$',
                                  cbar_labelpad=-30, cbar_orientation='horizontal',
                                  ticks=[-1, 0, 1], fontsize=8, title_axX=None, title_axY=None, alpha=1.0)


        return fig, ax
Esempio n. 2
0
    def plot_bott_lpparam_glatparam(self,
                                    lgbott=None,
                                    glatparam='ABDelta',
                                    outname=None):
        """Plot phase diagram with lattice param varying on x axis and glatparam varying on y axis

        Parameters
        ----------
        lgbott : N x 3 float array or None
            lattice params array, glatparam array, bott indices array
        glatparam : str

        outname : str or None
        """
        if lgbott is None:
            lpV, glatV, botts = self.collect_botts_lpparam_glatparam(
                glatparam=glatparam)
            # lgbott is the [lattice param, glat param, botts] vector
            lgbott = np.dstack((lpV, glatV, botts))[0]

        print 'lgbott = ', lgbott
        ngrid = len(lgbott) + 7
        fig, ax, cbar_ax = leplt.initialize_1panel_cbar_cent()
        leplt.plot_pcolormesh(lgbott[:, 0],
                              lgbott[:, 1],
                              lgbott[:, 2],
                              ngrid,
                              ax=ax,
                              cax=cbar_ax,
                              method='nearest',
                              make_cbar=True,
                              cmap=lecmaps.diverging_cmap(250, 10, l=30),
                              vmin=-1.,
                              vmax=1.,
                              title=None,
                              xlabel=None,
                              ylabel=None,
                              ylabel_right=True,
                              ylabel_rot=90,
                              cax_label=r'Bott index, $B$',
                              cbar_labelpad=-30,
                              cbar_orientation='horizontal',
                              ticks=[-1, 0, 1],
                              fontsize=8,
                              title_axX=None,
                              title_axY=None,
                              alpha=1.0)
        if outname is not None:
            plt.savefig(outname)

        return fig, ax
    def plot_maxchern_lpparam_hlatparam(self, lhchern=None, hlatparam='ABDelta'):
        """"""
        if lhchern is None:
            lpV, hlatV, maxcherns = self.collect_maxchern_lpparam_hlatparam(hlatparam=hlatparam)
            lhchern = np.dstack((lpV, hlatV, maxcherns))[0]

        print 'lhchern = ', lhchern
        ngrid = len(lhchern) + 7
        fig, ax, cbar_ax = leplt.initialize_1panel_cbar_cent()
        leplt.plot_pcolormesh(lhchern[:, 0], lhchern[:, 1], lhchern[:, 2], ngrid, ax=ax, cax=cbar_ax, method='nearest',
                              make_cbar=True, cmap=lecmaps.diverging_cmap(250, 10, l=30),
                              vmin=-1., vmax=1., title=None, xlabel=None, ylabel=None, ylabel_right=True,
                              ylabel_rot=90, cax_label=r'Chern number, $\nu$',
                              cbar_labelpad=-30, cbar_orientation='horizontal',
                              ticks=[-1, 0, 1], fontsize=8, title_axX=None, title_axY=None, alpha=1.0)
        plt.show()
Esempio n. 4
0
 def save_maxdiff_frame(self, name='maxdiff_frame'):
     fig, ax, cax = leplt.initialize_1panel_cbar_cent(Wfig=180,
                                                      Hfig=200,
                                                      wsfrac=1.0)
     # img = cine.asimage(self.variance_frame)
     img = self.maxdiff_frame
     ax.imshow(img,
               cmap=cm.Greys_r,
               vmin=0.,
               vmax=np.mean(self.maxdiff_frame.ravel()))
     # Set color limits for cbar
     sm = leplt.empty_scalar_mappable(vmin=0.,
                                      vmax=np.mean(
                                          self.maxdiff_frame.ravel()),
                                      cmap=cm.Greys_r)
     plt.colorbar(sm, cax=cax, orientation='horizontal')
     plt.savefig(name + '.png')
     print 'img = ', img
     print 'np.min(img) = ', np.min(img)
     print 'np.max(img) = ', np.max(img)
     sys.exit()
     plt.close()
Esempio n. 5
0
                cherns.append(np.real(chernii.chern['chern'][-1]))

            deltas = np.array(deltas)
            abds = np.array(abds)
            cherns = np.array(cherns)
            if len(abdgrid) == 0:
                deltagrid = deltas
                abdgrid = abds
                cherngrid = cherns
            else:
                deltagrid = np.vstack((deltagrid, deltas))
                abdgrid = np.vstack((abdgrid, abds))
                cherngrid = np.vstack((cherngrid, cherns))

        plt.close('all')
        fig, ax, cax = leplt.initialize_1panel_cbar_cent()
        lecmaps.register_colormaps()
        cmap = 'bbr0'
        # deltagrid.reshape((len(abds), -1))
        # abdgrid.reshape((len(abds), -1))
        # cherngrid.reshape((len(abds), -1))
        # leplt.plot_pcolormesh_scalar(deltagrid, abdgrid, cherngrid, outpath=None, cmap=cmap, vmin=-1.0, vmax=1.0)
        leplt.plot_pcolormesh(deltagrid / np.pi, abdgrid, cherngrid, 100, ax=ax,
                              make_cbar=False, cmap=cmap, vmin=-1.0, vmax=1.0)
        # ax.scatter(deltagrid, abdgrid, c=cherngrid, cmap=cmap, vmin=-1.0, vmax=1.0)
        sm = leplt.empty_scalar_mappable(vmin=-1.0, vmax=1.0, cmap=cmap)
        cb = plt.colorbar(sm, cax=cax, orientation='horizontal')
        cb.set_label(label=r'Chern number, $\nu$', labelpad=-35)
        cb.set_ticks([-1, 0, 1])
        ax.set_xlabel(r'Lattice deformation angle, $\delta/\pi$')
        ax.set_ylabel(r'Inversion symmetry breaking, $\Delta$')
Esempio n. 6
0
def lowest_mode(mlat, nkxy=20, save=False, save_plot=True, name=None, outdir=None, imtype='png'):
    """

    Parameters
    ----------
    mlat : MassLattice class instance
    nkxy : int
    save :bool
    save_plot : bool
    name : str or None
    outdir : str or None
    imtype : str ('png', 'pdf', 'jpg', etc)

    Returns
    -------
    omegas : n x 1 float array
        the frequencies at each evaluated point in kspace
    kxy : n x 2 float array
        the kspace points at which the frequency of modes are evaluated
    vtcs : #vertices x 2 float array
        the vertices of the brillouin zone in kspace
    """
    # First check for saved dispersion
    if outdir is None:
        outdir = dio.prepdir(mlat.lp['meshfn'])
    else:
        outdir = dio.prepdir(outdir)

    if name is None:
        name = 'lowest_mode' + mlat.lp['meshfn_exten']
        name += '_nkxy{0:06d}'.format(np.max(np.abs(nkxy)))

    name = outdir + name
    fn = glob.glob(name + '.pkl')
    if fn:
        with open(fn[0], "rb") as fn:
            res = pkl.load(fn)

        vtcs = res['vtcs']
        kxy = res['kxy']
        omegas = res['omegas']
    else:
        pvs = mlat.lattice.PV
        a1, a2 = pvs[0], pvs[1]
        vtx, vty = bzf.bz_vertices(a1, a2)
        vtcs = np.dstack((vtx, vty))[0]
        polygon = np.dstack((vtx, vty))[0]
        xlims = (np.min(vtx), np.max(vtx))
        ylims = (np.min(vty), np.max(vty))
        xextent, yextent = xlims[1] - xlims[0], ylims[1] - ylims[0]
        step = float(max(xextent, yextent)) / float(nkxy)
        print 'extent = ', xextent
        print 'step = ', step
        pts = dh.generate_gridpts_in_polygons(xlims, ylims, [polygon], dx=step, dy=step)
        # print 'tkspacefns: pts = ', np.shape(pts)
        omegas = np.zeros(len(pts))
        matk = lambda k: dynamical_matrix_kspace(k, mlat, eps=1e-10)
        ii = 0
        for kxy in pts:
            print 'mlatkspace_fns: infinite_dispersion(): ii = ', ii
            # print 'jj = ', jj
            kx, ky = kxy[0], kxy[1]
            matrix = matk([kx, ky])
            print 'mlatkspace_fns: diagonalizing...'
            eigval, eigvect = np.linalg.eig(matrix)
            si = np.argsort(np.real(-eigval))
            omegas[ii] = np.real(np.min(np.sqrt(-eigval)[si]))
            ii += 1

        # Save results to pickle if save == True
        res = {'omegas': omegas, 'kxy': pts, 'vtcs': vtcs}
        kxy = pts
        if save:
            with open(name + '.pkl', "wb") as fn:
                pkl.dump(res, fn)

    if save_plot:
        fig, ax, cax = leplt.initialize_1panel_cbar_cent(wsfrac=0.5, tspace=4)
        xgrid, ygrid, ZZ = dh.interpol_meshgrid(kxy[:, 0], kxy[:, 1], omegas, int(nkxy), method='nearest')
        inrois = dh.gridpts_in_polygons(xgrid, ygrid, [vtcs])
        vmax = np.max(omegas)
        ZZ[~inrois] = 0.0
        if ax is None:
            ax = plt.gca()
        pcm = ax.pcolormesh(xgrid, ygrid, ZZ, cmap=lecmaps.colormap_from_hex('#2F5179'), vmin=0., vmax=vmax, alpha=1.0)
        print 'vmax = ', vmax
        plt.colorbar(pcm, cax=cax, label=r'$\omega_0$', orientation='horizontal', ticks=[0., vmax])
        ax.axis('off')
        ax.axis('scaled')
        plt.savefig(name + '.' + imtype)

    return omegas, kxy, vtcs