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
Exemple #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()
Exemple #4
0
                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$')
        specstr = '_aol' + sf.float2pstr(lp['aoverl']) + '_Omk' + sf.float2pstr(lp['Omk'])
        specstr += '_delta' + sf.float2pstr(np.min(deltagrid)) + '_' + sf.float2pstr(np.max(deltagrid))
        specstr += '_abd' + sf.float2pstr(np.min(abdgrid)) + '_' + sf.float2pstr(np.max(abdgrid))
        specstr += '_ndeltas{0:05d}'.format(len(deltas)) + '_nabd{0:05d}'.format(len(abds))
        specstr += '_density{0:07d}'.format(cp['density'])
        plt.savefig(rootdir + 'kspace_cherns_mgyro/abtransition' + specstr + '.png')

def nu_gradient_excitation(kcoll, glat_name, outdir=None, check=False):
    """Compute nu gradient sum in different directions weighted by the excitation amplitude of eigenvectors (gnu_psi2).

    Parameters
    ----------
    kcoll : KitaevCollection instance
    glat_name : str
        string specifier for the name of the GyroLattice. This is the key to the Chern.chern dictionary
    outdir : str or None
        path where to store the output pickle, if not None
    check : bool
        display intermediate results

    Returns
    -------
    gnu_psi2 : len(kszf) x len(eigval)/2 float array
        For each kitaev region size (row) and unique eigenvector (column), this is the sum of gradients in different
        directions of the spatially-resolved chern number, weighted by the displacement of gyroscopes in that
        eigenvector. The order of the evects is the same as the order for eigval[0:len(eigval)/2].
        Note: len(ksf) is len(kcoll.cherns[glat_name][0].chern_finsize[:, 1])
    xyvec :
    ksizes :
        chern_finsize[:, 3] for each chern, stacked: this is the characteristic width or size (diameter, width) of the
        kitaev summation region, in true units --> same units as lengths are measured in the lattice -- which is
        usually in median bond lengths.
    kszf :
        chern_finsize[:, 1] for each chern, stacked: this is the fractional number of particles in the sum (as a
        fraction of the # particles in the system) TIMES TWO!
    nugrids :
    nugsum :
    eigval :
    """
    from scipy import ndimage
    glat = kcoll.cherns[glat_name][0].gyro_lattice

    # Assume all cherns have the same len(ksize), so preallocate array
    # Make xynu, for which xynu[:,i] is the map of chern vals for the ith ksize
    # also make xyvec, so that xyvec[i] = [x, y] for computation xynu[i,:]
    kszf = kcoll.cherns[glat_name][0].chern_finsize[:, 1]
    xynu = np.zeros((len(kcoll.cherns[glat_name]), len(kszf)), dtype=float)
    ksizes = np.zeros((len(kcoll.cherns[glat_name]), len(kszf)), dtype=float)
    xyvec = np.zeros((np.shape(xynu)[0], 2), dtype=float)
    ind = 0
    for chernii in kcoll.cherns[glat_name]:
        # Add this chern to array of stored vals
        xx = float(chernii.cp['poly_offset'].split('/')[0])
        yy = float(chernii.cp['poly_offset'].split('/')[1])
        xynu[ind] = np.real(chernii.chern_finsize[:, -1])
        ksizes[ind] = chernii.chern_finsize[:, 2]
        xyvec[ind, :] = np.array([xx, yy])
        ind += 1

    if check:
        print 'xynu = ', xynu
        plt.imshow(xynu)
        plt.show()

    # Make grid of nu values, in fact one for each ksize
    # nugrids[i] is the grid of nu values for the ith ksize
    lenx = int(np.sqrt(len(kcoll.cherns[glat_name])))
    # print 'lenx = ', lenx
    # print 'len(kcoll.cherns[glat_name]) = ', len(kcoll.cherns[glat_name])
    nugrids = xynu.reshape((lenx, lenx, len(kszf))).T

    if check:
        print 'np.shape(xynu) = ', np.shape(xynu)
        tmp = nugrids[15, :, :]
        mappable = plt.imshow(tmp,
                              interpolation='nearest',
                              cmap='rwb0',
                              vmin=-1,
                              vmax=1)
        plt.colorbar()
        plt.title('chern values in space')
        plt.show()

    # nugsum is the sum of the individual gradients of nu in different directions.
    nugsum = np.zeros_like(nugrids, dtype=float)
    ind = 0
    for nugrid in nugrids:
        # For each ksize, get 2d gradient magnitude (summed in each direction separately
        diff = np.array([[0, 1, 0], [0, -1, 0], [0, 0, 0]])
        nugsum[ind, :, :] = 0.25 * np.abs(
            ndimage.convolve(nugrid, diff, mode='reflect'))
        diff = np.array([[0, 0, 0], [1, -1, 0], [0, 0, 0]])
        nugsum[ind, :, :] += 0.25 * np.abs(
            ndimage.convolve(nugrid, diff, mode='reflect'))
        diff = np.array([[0, 0, 0], [0, -1, 1], [0, 0, 0]])
        nugsum[ind, :, :] += 0.25 * np.abs(
            ndimage.convolve(nugrid, diff, mode='reflect'))
        diff = np.array([[0, 0, 0], [0, -1, 0], [0, 1, 0]])
        nugsum[ind, :, :] += 0.25 * np.abs(
            ndimage.convolve(nugrid, diff, mode='reflect'))

        if check:
            print 'np.shape(nugrid) = ', np.shape(nugrid)
            leplt.plot_pcolormesh(xyvec[:, 0],
                                  xyvec[:, 1],
                                  nugrid.T.ravel(),
                                  100,
                                  method='nearest',
                                  cmap='rwb0',
                                  vmin=-1.0,
                                  vmax=1.0,
                                  xlabel='x',
                                  ylabel='y',
                                  cax_label=r'$\nu$',
                                  fontsize=12)
            le.movie_plot_2D(glat.lattice.xy,
                             glat.lattice.BL,
                             0 * glat.lattice.BL[:, 0],
                             None,
                             None,
                             ax=plt.gca(),
                             axcb=None,
                             bondcolor='k',
                             colorz=False,
                             ptcolor=None,
                             figsize='auto',
                             colormap='BlueBlackRed',
                             bgcolor='#ffffff',
                             axis_off=False,
                             axis_equal=True,
                             lw=0.2)
            kpfns.add_kitaev_regions_to_plot(kcoll.cherns[glat_name][0],
                                             ind,
                                             offsetxy=np.array([0, 0]))
            plt.pause(0.1)
            plt.clf()
            leplt.plot_pcolormesh(xyvec[:, 0],
                                  xyvec[:, 1],
                                  nugsum[ind].T.ravel(),
                                  100,
                                  method='nearest',
                                  cmap='viridis',
                                  vmin=0.0,
                                  vmax=None,
                                  xlabel='x',
                                  ylabel='y',
                                  cax_label=r'$|\nabla\nu|$',
                                  fontsize=12)
            le.movie_plot_2D(glat.lattice.xy,
                             glat.lattice.BL,
                             0 * glat.lattice.BL[:, 0],
                             None,
                             None,
                             ax=plt.gca(),
                             axcb=None,
                             bondcolor='k',
                             colorz=False,
                             ptcolor=None,
                             figsize='auto',
                             colormap='BlueBlackRed',
                             bgcolor='#ffffff',
                             axis_off=False,
                             axis_equal=True,
                             lw=0.2)
            kpfns.add_kitaev_regions_to_plot(kcoll.cherns[glat_name][0],
                                             ind,
                                             offsetxy=np.array([0, 0]))
            plt.pause(0.1)
            plt.clf()
        ind += 1

    # convert back to same order as xyvec for later
    # gsnu_vecs[:,i] is the vector of chern gradient magnitudes for the ith ksize, assoc with xyvec
    gsnu_vecs = nugsum.T.reshape(-1, len(kszf))

    # Smooth gradient -- I don't use this anymore
    # snugsum = np.zeros_like(nugsum, dtype=float)
    # for ind in range(len(nugsum)):
    #     snugsum[ind] = ndimage.uniform_filter(nugsum[ind], (2, 2))
    # sgsnu_vecs = snugsum.T.reshape(-1, len(kszf))

    if check:
        plt.imshow(nugrids[15, :, :],
                   interpolation='none',
                   cmap='rwb0',
                   vmin=-1,
                   vmax=1)
        plt.title(r'$\nu$')
        plt.show()

    # Associate each particle with an xy region
    # pt2loc's ith element is the index of xynu or nugrad assoc with ith gyro
    pt2loc = np.zeros_like(glat.lattice.xy[:, 0], dtype=int)
    ind = 0
    for xy in glat.lattice.xy:
        dist = np.abs(xyvec - xy)[:, 0]**2 + np.abs(xyvec - xy)[:, 1]**2
        loc = np.argmin(dist)
        pt2loc[ind] = loc
        ind += 1

    # Look at evects for this network. Compute L for each evect. Plot L as a function of evals.
    eigval, eigvect = glat.load_eigval_eigvect(attribute=True)
    gnu_psi2 = np.zeros((len(kszf), len(eigval) / 2), dtype=float)
    for ind in range(int(len(eigval) * 0.5)):
        if ind % 100 == 0:
            print 'Calculating locality for eigval ', ind, ' of ', len(
                eigval), '...'
        # Eigvect is stored as NModes x NP*2 array, with x and y components alternating, like:
        # x0, y0, x1, y1, ... xNP, yNP.
        mag1 = eigvect[ind]
        mag1x = np.array([mag1[2 * i] for i in range(len(mag1) / 2)])
        mag1y = np.array([mag1[2 * i + 1] for i in range(len(mag1) / 2)])

        # Get magnitude of displacements
        mag2 = np.array([
            abs(mag1x[i])**2 + abs(mag1y[i])**2 for i in range(len(mag1x))
        ]).flatten()
        # gnu_psi2 is gradsum of nu weighted by magnitude of displacements of eigenvector
        gnu_psi2[:, ind] = np.array([
            np.sum(mag2 * np.abs(gsnu_vecs[pt2loc, kk])) / np.sum(mag2)
            for kk in range(len(kszf))
        ])

    if outdir is not None:
        # Save results
        lld = {
            'gnu_psi2': gnu_psi2,
            'ksizes': ksizes,
            'kszf': kszf,
            'xyvec': xyvec,
            'nugrids': nugrids,
            'eigval': eigval,
            'nugsum': nugsum
        }
        outfn = outdir + '_gnu_dict.pkl'
        with open(outfn, 'wb') as fn:
            pickle.dump(lld, fn)

    return gnu_psi2, xyvec, ksizes, kszf, nugrids, nugsum, eigval