def projector_site_vs_dist_glatparam(gcoll, omegac, proj_XY, plot_mag=True, plot_diff=False, save_plt=True, alpha=1.0, maxdistlines=True, reverse_order=False, check=True): """THIS HAS NOT BEEN UPDATED FOR BOTT INDEX SPECIFIC CALC Compare the projector values at distances relative to a particular site (gyro at location proj_XY). Parameters ---------- gcoll : GyroCollection instance The collection of gyro_lattices for which to compare projectors as fn of distance from a given site. omegac : float Cutoff frequency for the projector proj_XY : 2 x 1 float numpy array The location at which to find the nearest gyro and consider projector elements relative to this site. plot : bool Whether to plot magproj vs dist for all GyroLattices in gcoll check : bool Display intermediate results Returns ------- dist_list : list of NP x NP float arrays Euclidean distances between points. Element i,j is the distance between particle i and j proj_list : list of evxyprojs (2 x 2*NP float arrays) Each element is like magproj, but with x and y components separate. So, element 0,2*j gives the magnitude of the x component of the projector connecting the site in question to the x component of particle j and element 1,2*j+1 gives the magnitude of the y component of the projector connecting the site in question to the y component of particle j. """ proj_list = [] dist_list = [] kk = 0 if plot_mag: # magnitude plot mfig, magax, mcbar = leplt.initialize_1panel_cbar_fig() if plot_diff: # difference plot dfig, dax, dcbar = leplt.initialize_1panel_cbar_fig() # difference fraction plot dffig, dfax, dfcbar = leplt.initialize_1panel_cbar_fig() if maxdistlines: maxdist = [] sat = 1 light = 0.6 colors = lecmaps.husl_palette(n_colors=len(gcoll.gyro_lattices), s=sat, l=light) if reverse_order: glat_list = gcoll.gyro_lattices[::-1] else: glat_list = gcoll.gyro_lattices for glat in glat_list: proj_ind = ((glat.lattice.xy - proj_XY)[:, 0]**2 + (glat.lattice.xy - proj_XY)[:, 1]**2).argmin() outdir = dio.prepdir(glat.lp['meshfn'].replace('networks', 'projectors')) outfn = outdir + glat.lp[ 'LatticeTop'] + "_dist_singlept_{0:06d}".format(proj_ind) + ".pkl" if check: print 'identified proj_ind = ', proj_ind newfig = plt.figure() glat.lattice.plot_numbered(ax=plt.gca()) # attempt to load if glob.glob(outfn): with open(outfn, "rb") as fn: dist = pickle.load(fn) outfn = outdir + glat.lp[ 'LatticeTop'] + "_evxyproj_singlept_{0:06d}".format( proj_ind) + ".pkl" with open(outfn, "rb") as fn: evxyproj = pickle.load(fn) else: # compute dists and evxyproj_proj_ind xydiff = glat.lattice.xy - glat.lattice.xy[proj_ind] dist = np.sqrt(xydiff[:, 0]**2 + xydiff[:, 1]**2) print 'bottmagneticgyrofns: calculating projector...' proj = calc_small_projector(glat, omegac, attribute=False) outdir = dio.prepdir(glat.lp['meshfn'].replace( 'networks', 'projectors')) le.ensure_dir(outdir) # save dist as pickle with open(outfn, "wb") as fn: pickle.dump(dist, fn) # evxyproj has dims 2 xlen(evect) evxyproj = np.dstack( (proj[2 * proj_ind, :], proj[2 * proj_ind + 1, :]))[0].T # save evxyproj as pickle outfn = outdir + glat.lp[ 'LatticeTop'] + "_evxyproj_singlept_{0:06d}".format( proj_ind) + ".pkl" with open(outfn, "wb") as fn: pickle.dump(evxyproj, fn) proj_list.append(evxyproj) dist_list.append(dist) if plot_mag: tmp = np.sqrt( np.abs(evxyproj[0]).ravel()**2 + np.abs(evxyproj[1]).ravel()**2) magproj = np.array([ np.sqrt(tmp[2 * ind].ravel()**2 + tmp[2 * ind + 1].ravel()**2) for ind in range(len(dist)) ]) magax.scatter(dist, np.log10(magproj), s=1, color=colors[kk], alpha=alpha) if plot_diff: if kk > 0: # find particles that are the same as in the reference network same_inds = np.where(le.dist_pts(glat.lattice.xy, xy0) == 0) # Order them by distance current = np.array( [[2 * same_inds[0][ii], 2 * same_inds[0][ii] + 1] for ii in range(len(same_inds[0]))]) current = current.ravel() orig = np.array( [[2 * same_inds[1][ii], 2 * same_inds[1][ii] + 1] for ii in range(len(same_inds[0]))]) orig = orig.ravel() # if check: # origfig = plt.figure() # origax = origfig.gca() # [origax, origaxcb] = glat.lattice.plot_numbered(fig=origfig, ax=origax, axis_off=False, # title='Original lattice for proj comparison') # origax.scatter(glat.lattice.xy[same_inds[0], 0], glat.lattice.xy[same_inds[0], 1]) # plt.pause(5) # plt.close() if len(current) > 0: evxydiff = evxyproj[:, current] - evxyproj0[:, orig] tmp = np.sqrt( np.abs(evxydiff[0]).ravel()**2 + np.abs(evxydiff[1]).ravel()**2) magdiff = np.array([ np.sqrt(tmp[2 * ind].ravel()**2 + tmp[2 * ind + 1].ravel()**2) for ind in range(len(same_inds[0])) ]) # magnitude of fractional difference magfdiff = np.array([ magdiff[same_inds[0][ii]] / mag0[same_inds[1][ii]] for ii in range(len(same_inds[0])) ]) dax.scatter(dist[same_inds[0]], magdiff, s=1, color=colors[kk], alpha=alpha) dfax.scatter(dist[same_inds[0]], magfdiff, s=1, color=colors[kk], alpha=alpha) if maxdistlines: maxdist.append(np.max(dist[same_inds[0]])) else: origfig = plt.figure() origax = origfig.gca() [origax, origaxcb] = glat.lattice.plot_numbered( fig=origfig, ax=origax, axis_off=False, title='Original lattice for proj comparison') origfig.show() plt.close() evxyproj0 = copy.deepcopy(evxyproj) xy0 = copy.deepcopy(glat.lattice.xy) tmp = np.sqrt( np.abs(evxyproj[0]).ravel()**2 + np.abs(evxyproj[1]).ravel()**2) mag0 = np.array([ np.sqrt(tmp[2 * ind].ravel()**2 + tmp[2 * ind + 1].ravel()**2) for ind in range(len(dist)) ]) kk += 1 # Save plots outsplit = dio.prepdir(glat.lp['meshfn'].replace('networks', 'projectors')).split('/') outdir = '/' for sdir in outsplit[0:-2]: outdir += sdir + '/' outdir += '/' if plot_mag: if maxdistlines and plot_diff: ylims = magax.get_ylim() print 'ylims = ', ylims ii = 1 for dd in maxdist: magax.plot([dd, dd], np.array([ylims[0], ylims[1]]), '-', color=colors[ii]) ii += 1 magax.set_title('Magnitude of projector vs distance') magax.set_xlabel(r'$|\mathbf{x}_i - \mathbf{x}_0|$') magax.set_ylabel(r'$|P_{i0}|$') # make a scalar mappable for colorbar' husl_cmap = lecmaps.husl_cmap(s=sat, l=light) sm = plt.cm.ScalarMappable(cmap=husl_cmap, norm=plt.Normalize(vmin=0, vmax=1)) sm._A = [] cbar = plt.colorbar(sm, cax=mcbar, ticks=[0, 1]) cbar.ax.set_ylabel(r'$\alpha$', rotation=0) if save_plt: print 'kfns: saving magnitude comparison plot for gcoll (usually run from kitaev_collection)...' mfig.savefig(outdir + glat.lp['LatticeTop'] + "_magproj_singlept.png", dpi=300) else: plt.show() if plot_diff: dax.set_title('Projector differences') dax.set_xlabel(r'$|\mathbf{x}_i - \mathbf{x}_0|$') dax.set_ylabel(r'$|\Delta P_{i0}|$') # make a scalar mappable for colorbar' husl_cmap = lecmaps.husl_cmap(s=sat, l=light) sm = plt.cm.ScalarMappable(cmap=husl_cmap, norm=plt.Normalize(vmin=0, vmax=1)) sm._A = [] cbar = plt.colorbar(sm, cax=dcbar, ticks=[0, 1]) cbar.ax.set_ylabel(r'$\alpha$', rotation=0) if maxdistlines: # Grab ylimits for setting after adding lines ylims = dax.get_ylim() df_ylims = dfax.get_ylim() ii = 1 for dd in maxdist: dax.plot([dd, dd], np.array([-0.05, -0.005]), '-', color=colors[ii]) dfax.plot([dd, dd], np.array([df_ylims[0], -0.01]), '-', color=colors[ii]) ii += 1 dax.set_ylim(-0.05, ylims[1]) dfax.set_ylim(df_ylims[0], df_ylims[1]) # now do fractional difference magnitude plot dfax.set_title('Fractional projector differences') dfax.set_xlabel(r'$|\mathbf{x}_i - \mathbf{x}_0|$') dfax.set_ylabel(r'$|\Delta P_{i0}|/|P_{i0}|$') # make a scalar mappable for colorbar' cbar = plt.colorbar(sm, cax=dfcbar, ticks=[0, 1]) cbar.ax.set_ylabel(r'$\alpha$', rotation=0) if save_plt: print 'kfns: saving diff plot for gcoll projecctors (usually run from kitaev_collection)...' dfig.savefig(outdir + glat.lp['LatticeTop'] + "_diffproj_singlept.png", dpi=300) dffig.savefig(outdir + glat.lp['LatticeTop'] + "_diffproj_singlept_fractionaldiff.png", dpi=300) dfax.set_ylim(-0.1, 1) dffig.savefig(outdir + glat.lp['LatticeTop'] + "_diffproj_singlept_fractionaldiff_zoom.png", dpi=300) dfax.set_ylim(-0.02, 0.1) dffig.savefig(outdir + glat.lp['LatticeTop'] + "_diffproj_singlept_fractionaldiff_extrazoom.png", dpi=300) elif not plot_mag: plt.show() return dist_list, proj_list
'ksize_frac_arr': np.arange( 0.0, 0.51, 0.01 ), # sf.string_sequence_to_numpy_array('0.0:0.01:0.70', dtype=float), 'omegac': 2.25, 'shape': 'square', 'polyT': False, 'poly_offset': 'none', 'basis': 'XY', 'modsave': 10, 'save_ims': False, 'rootdir': cprootdir, 'ortho': ortho, } eps = 1e-7 colorv = lecmaps.husl_palette(len(Vpinlist)) # set limits of delta for color limits based on delta minvpin = np.min(np.array(Vpinlist)) maxvpin = np.max(np.array(Vpinlist)) kk = 0 for vpin in Vpinlist: if vpin > eps: confv = np.arange(0, npinconfs, dtype=int) else: confv = np.array([0]) netconfv = np.arange(1, nconfs + 1) nuchern = np.zeros((len(NNlist), len(confv) * len(netconfv)), dtype=float) ksznumax = np.zeros((len(NNlist), len(confv) * len(netconfv)), dtype=float)
plt.plot(xy[:, 0], xy[:, 1], 'rx') plt.plot(xyout[:, 0], xyout[:, 1], 'b.') print 'xyout - xy = ', xyout - xy plt.show() if args.calibrate_Sk_epsilon: """Calibrate S(k) scaling versus epsilon""" import lepm.structure as struct nksteps = 200 klim_frac = 0.1 LL = (float(nh), float(nv)) print 'LL = ', LL gammav = np.arange(0.1, 1., 0.2) epsv = [1e-15, 1e-11, 1e-7, 1e-3, 1., 10] colorv = lecmaps.husl_palette(len(epsv)) # Naming seriesname = 'structure/nksteps{0:03d}'.format(nksteps) + '_sz{0:04d}'.format(nh) + '{0:04d}'.format(nv) + \ '_klim' + sf.float2pstr(klim_frac) + 'LL' caloutdir = args.rootdir + 'calibration/' + seriesname + '/' datoutdir = args.rootdir + 'calibration_data/' + seriesname + '/' dio.ensure_dir(caloutdir) dio.ensure_dir(datoutdir) kk = 0 for gamma in gammav: kk = 0 ymax = 0. fig, ax = leplt.initialize_1panel_fig(wsfrac=0.45, hsfrac=0.35,
sz_mat.append(szmat) sz_lil.append(szlil) sz_csr.append(szcsr) nnlist.append(nn) # Look at spectra fig, ax = leplt.initialize_1panel_centered_fig() rla = np.sort(rla[0]) rsla = np.sort(rsla[0]) rlil = np.sort(rlil[0]) rcsr = np.sort(rcsr[0]) print 'rla = ', rla print 'np.shape(rla) = ', np.shape(rla) markers = leplt.get_markerstyles(4) colors = lecmap.husl_palette(4) ax.plot(np.arange(len(rla)), rla, '.-', color=colors[0], label='la', alpha=alpha, markersize=mksz) ax.plot(np.arange(len(rsla)), rsla, '^-', color=colors[1], label='sla', alpha=alpha, markersize=mksz) ax.plot(np.arange(len(rlil)), rlil, 'o-', color=colors[2], label='LIL', alpha=alpha, markersize=mksz) ax.plot(np.arange(len(rcsr)), rcsr, 's-', color=colors[3], label='CSR', alpha=alpha, markersize=mksz) ax.legend() ax.set_xlabel('Eigenvalue index') ax.set_ylabel('Eigenvalue') ax.text(0.5, 1.1, 'Matrix Spectra', ha='center', va='center', transform=ax.transAxes) plt.savefig(outdir + 'script_test_sparse_matrices_scaling_sz' + str(int(nh)) + '.png') plt.close('all') # save data res = {'s_la': s_la, 's_sla': s_sla, 's_lil': s_lil,