def plot_stray_field(scannum, helicities=[0, 90, 180]): path = '/Users/alec/UCSB/cofeb_analysis_data/ta/' scan_params_path = path + str(scannum) + '/' + 'scan_parameters.json' field_path = path + str(scannum) + '/stray_field_sim/' datapath = path + '1760/' with open(scan_params_path, 'r') as fread: scan_params = json.load(fread) phi = scan_params['phi'] theta = scan_params['theta'] xres = scan_params['xres'] xcenter = scan_params['xcenter'] ycenter = scan_params['ycenter'] scanSize = (1e6) * scan_params['scanSize'] # convert to microns errnames = ["lower", "mean", "upper"] ffdata = lscan.load_ff('/Users/alec/UCSB/scan_data/' + str(scannum) + '-esrdata/fitdata.txt', xres, xres, maxfgrad=20) scd = np.empty((len(helicities)), dtype=object) vcd = np.empty_like(scd) meff = np.empty_like(scd) bx = np.empty((len(helicities), len(errnames)), dtype=object) by = np.empty_like(bx) bz = np.empty_like(bx) bNV = np.empty_like(bx) fieldCutNV = np.empty_like(bx) for j in range(len(helicities)): scd[j] = np.loadtxt(field_path + 'scd_' + str(helicities[j]) + str(scannum) + '.txt', delimiter=',') vcd[j] = np.loadtxt(field_path + 'vcd_' + str(helicities[j]) + str(scannum) + '.txt', delimiter=',') meff[j] = np.loadtxt(field_path + 'meff_' + str(helicities[j]) + str(scannum) + '.txt', delimiter=',') for i in range(len(errnames)): bx[j, i] = (1e4) * np.loadtxt( field_path + 'h' + str(helicities[j]) + '_x_' + errnames[i] + '_' + str(scannum) + '.txt', delimiter=',') by[j, i] = (1e4) * np.loadtxt( field_path + 'h' + str(helicities[j]) + '_y_' + errnames[i] + '_' + str(scannum) + '.txt', delimiter=',') bz[j, i] = (1e4) * np.loadtxt( field_path + 'h' + str(helicities[j]) + '_z_' + errnames[i] + '_' + str(scannum) + '.txt', delimiter=',') bNV[j, i] = cNVf.calc_NV_field(bx[j, i], by[j, i], bz[j, i], theta, phi) slen = len(bx[0, 0]) cutSize = 2.2 phinum = 8 philist = np.linspace(0, pi, phinum, endpoint=False) ffdataCut = np.empty((phinum), dtype=object) ffdataCutErr = np.empty((phinum), dtype=object) fieldCutNV = np.empty((phinum, len(helicities), len(errnames)), dtype=object) for k in range(phinum): ffdataCut[k] = linecut.linecut(ffdata[0], scanSize, cutSize, philist[k], xcenter, ycenter) ffdataCutErr[k] = linecut.linecut(ffdata[1], scanSize, cutSize, philist[k], xcenter, ycenter) for j in range(len(helicities)): for i in range(len(errnames)): fieldCutNV[k, j, i] = linecut.linecut(bNV[j, i], scanSize, cutSize, philist[k]) #---------------- PLOTS ------------------------------------------ #----------------------------------------------------------------- savepath = '/Users/alec/UCSB/papers/tacofeb/figures/' plt.close('all') if (len(helicities) == 4): fig, ax = plt.subplots(figsize=(4, 4)) im = plt.imshow(bNV[3, 1], interpolation='nearest', cmap='bone') ax.get_yaxis().set_visible(False) ax.get_xaxis().set_visible(False) cbar = fig.colorbar(im, ax=ax, fraction=0.046, pad=0.04) plt.subplots_adjust(left=0.0, bottom=0.0, right=0.9, top=1.0, wspace=0, hspace=0) plt.savefig(savepath + 'BNV_bestFitHelicity_' + str(scannum) + '.pdf', format='pdf') fig, ax = plt.subplots(figsize=(4, 4)) im = plt.imshow(ffdata[0], interpolation='nearest', cmap='bone') ax.get_yaxis().set_visible(False) ax.get_xaxis().set_visible(False) cbar = fig.colorbar(im, ax=ax, fraction=0.046, pad=0.04) plt.subplots_adjust(left=0.0, bottom=0.0, right=0.9, top=1.0, wspace=0, hspace=0) plt.savefig(savepath + 'BNV_data_' + str(scannum) + '.pdf', format='pdf') fig, axes = plt.subplots(ncols=2, nrows=int(phinum / 2), sharex=True, sharey=True, figsize=(6, 7.5)) for j in range(0, 2): for i in range(0, int(phinum / 2)): axes[i, j].errorbar(ffdataCut[int(i + (phinum / 2) * j)][0], ffdataCut[int(i + (phinum / 2) * j)][1], color='#000000', fmt='.', linewidth=1.0, label='data') axes[i, j].plot(fieldCutNV[0, 0, 1][0], fieldCutNV[int(i + (phinum / 2) * j), 0, 1][1], linewidth=2.0, label=u'right-handed Néel') axes[i, j].plot(fieldCutNV[0, 1, 1][0], fieldCutNV[int(i + (phinum / 2) * j), 1, 1][1], linewidth=2.0, label="Bloch") axes[i, j].plot(fieldCutNV[0, 2, 1][0], fieldCutNV[int(i + (phinum / 2) * j), 2, 1][1], linewidth=2.0, label=u'left-handed Néel') if (len(fieldCutNV[0, :, 1]) == 4): axes[i, j].plot(fieldCutNV[0, 3, 1][0], fieldCutNV[int(i + (phinum / 2) * j), 3, 1][1], linewidth=2.0, label=r'$\psi_h$ = ' + str(helicities[3]) + u'°') axes[i, j].get_yaxis().set_visible(False) axes[i, j].get_xaxis().set_visible(False) axes[i, j].text( 0.04, 0.86, r'$\phi$ = ' + '{:d}{}{:d}'.format(int(i + (phinum / 2) * j), r'$\pi$/', phinum), horizontalalignment='left', verticalalignment='center', transform=axes[i, j].transAxes, fontsize=10) axes[int((phinum / 2) - 1), 1].get_yaxis().set_visible(True) axes[int((phinum / 2) - 1), 1].get_xaxis().set_visible(True) axes[int((phinum / 2) - 1), 1].yaxis.tick_right() axes[int((phinum / 2) - 1), 1].yaxis.set_label_position("right") axes[int((phinum / 2) - 1), 1].set_xlabel(r'r ($\mu$m)') axes[int((phinum / 2) - 1), 1].set_ylabel(r'B$\mathrm{_{NV}}$ (G)') axes[int((phinum / 2) - 1), 0].legend(bbox_to_anchor=(0.0, -0.74), loc=3, borderaxespad=0., frameon=False, prop={'size': 10}) plt.ylim([0, 32]) plt.subplots_adjust(left=0.0, bottom=0.15, right=0.88, top=1.0, wspace=0, hspace=0) plt.savefig(savepath + 'BNV_linecuts_' + str(scannum) + '.pdf', format='pdf') # fp.format_plots(plt, small=False, tight=False) plt.show()
path = '/Users/alec/UCSB/cofeb_analysis_data/ta/' filespec = 'Msfixed' cal_params_path = path + 'cal_parameters_' + filespec + '.json' with open(cal_params_path, 'r') as fread: cal_params = json.load(fread) Ms = cal_params['Ms'] t = cal_params['t'] phi = cal_params['phi'] theta = cal_params['theta'] thetaError = cal_params['thetaError'] height = cal_params['height'] heightError = cal_params['heightError'] data = lscan.load_ff( '/Users/alec/UCSB/scan_data/' + str(scannum) + '-esrdata/fitdata.txt', xres, yres, 20) misc.imsave('/Users/alec/UCSB/scan_images/full-field/ff1760.png', data[0]) ffmask = ndimage.imread( '/Users/alec/UCSB/scan_images/full-field/ff1760mask.png', flatten=True) ffmask = np.multiply(np.add(np.multiply(ffmask, 1 / 255), -0.5), -2) #---------------- FIT FUNCTIONS ---------------------------------- #----------------------------------------------------------------- def fit_tanh(x, *params): y = np.zeros_like(x) c = params[0] a = params[1] x0 = params[2]
def vector_m_reconstruction(scannum, kcutoff=1, mask=True, printError=False, material='ta'): path = '/Users/alec/UCSB/cofeb_analysis_data/' + material + '/' scan_path = path + str(scannum) + '/' scan_params_path = scan_path + 'scan_parameters.json' material_params_path = path + 'material_parameters.json' with open(scan_params_path, 'r') as fread: scan_params = json.load(fread) with open(material_params_path, 'r') as fread: material_params = json.load(fread) Ms = material_params['Ms'] t = material_params['t'] DWWidth = material_params['DWWidth'] phi = scan_params['phi'] theta = scan_params['theta'] thetaError = scan_params['thetaError'] height = scan_params['height'] heightError = scan_params['heightError'] scanSize = scan_params['scanSize'] xres = scan_params['xres'] yres = scan_params['yres'] xcenter = scan_params['xcenter'] ycenter = scan_params['ycenter'] zfield = scan_params['zfield'] * (1e4) # convert to G data = lscan.load_ff('/Users/alec/UCSB/scan_data/' + str(scannum) + '-esrdata/fitdata.txt', xres, yres, Dgs=2870, maxfgrad=20, fieldangle=True, printNVCalcError=printError) misc.imsave( '/Users/alec/UCSB/scan_images/full-field/ff' + str(scannum) + '.png', data[0]) np.savetxt(scan_path + '/fail_index.txt', data[7]) #---------------- RECONSTRUCTION --------------------------------- #----------------------------------------------------------------- datas = data[0] if (mask): ffmask = ndimage.imread('/Users/alec/UCSB/scan_images/full-field/ff' + str(scannum) + 'mask.png', flatten=True) ffmask = np.multiply(np.add(np.multiply(ffmask, 1 / 255), -0.5), -2) datas = np.multiply(ffmask, datas) datas0 = np.add(datas, -np.cos(theta) * zfield) wimdata = fi.window_image(datas0, power=1 / 10) recon_data = vr.vector_reconstruction(wimdata, data[1], theta, thetaError, phi, height, scanSize, t, kcutoff=kcutoff) bxdata = recon_data[0] bydata = recon_data[1] bzdata = recon_data[2] + zfield mdata = recon_data[3] Vdata = recon_data[4] bzdataError = recon_data[5] np.savetxt(scan_path + 'bNV.txt', data[0], delimiter=',') np.savetxt(scan_path + 'bNVError.txt', data[1], delimiter=',') np.savetxt(scan_path + 'bz.txt', bzdata, delimiter=',') np.savetxt(scan_path + 'bzError.txt', bzdataError, delimiter=',') np.savetxt(scan_path + 'bx.txt', bxdata, delimiter=',') np.savetxt(scan_path + 'by.txt', bydata, delimiter=',') np.savetxt(scan_path + 'mdata.txt', mdata, delimiter=',') np.savetxt(scan_path + 'V.txt', Vdata, delimiter=',')
#bz0 = 11.0 #phi = 0*pi/180 #file constants filenum = 1885 xres = 120 yres = 5 scan_size = 0.6*5000 dres = scan_size/xres hlist = np.zeros(2*yres) thetalist = np.zeros(2*yres) mstlist = np.zeros(2*yres) #bz0list = np.zeros(2*yres) ffdata = lscan.load_ff('/Users/alec/UCSB/scan_data/'+str(filenum)+'-esrdata/fitdata.txt',xres,yres,maxfgrad=30) x = np.arange(0,dres*xres,dres) plt.close('all') ploth = 1 plt.figure(1,[17,10]) gs = gridspec.GridSpec(5, 2) gs.update(left=0.05, right=0.97, top=0.97, bottom=0.05, wspace=0.25, hspace=0.25) guess = [8e5, 70, 1500, 55] rguess = guess rguess[2] = guess[2]-100 for j in range(0,yres): y = ffdata[0][j,:]
nleftnv[i][0] = simx nleftnv[i][1] = np.multiply( sfieldpre, np.abs((nleftcuts[fi] * np.sin(theta) * np.cos(phi)) + (nleftcuts[fi + rnum * hnum] * np.sin(theta) * np.sin(phi)) + (np.add(nleftcuts[fi + 2 * rnum * hnum], zfields) * np.cos(theta)))) nrightnv[i][0] = simx nrightnv[i][1] = np.multiply( sfieldpre, np.abs((nrightcuts[fi] * np.sin(theta) * np.cos(phi)) + (nrightcuts[fi + rnum * hnum] * np.sin(theta) * np.sin(phi)) + (np.add(nrightcuts[fi + 2 * rnum * hnum], zfields) * np.cos(theta)))) ffdata = ls.load_ff('/Users/alec/UCSB/scan_data/760-esrdata/fitdata.txt', dres, 5, 5) line = 2 ffycut = [ np.add(np.arange(0, dsize, dsize / dres), 0.65), ffdata[0][line, 0:dres], ffdata[1][line, 0:dres] ] #ffycut = [np.arange(0,100),ffdata[0][:,3],ffdata[1][:,3]] plt.close('all') plt.figure(1, [5, 4]) imgplot = plt.imshow(ffdata[0], cmap='gray', interpolation='nearest') plt.colorbar(fraction=0.027, pad=0.04) plt.show() plt.tight_layout()
font = {'family': 'Arial', 'weight': 'normal', 'size': 14} matplotlib.rc('font', **font) scannum = 1739 bscannum = 1740 hnum = 1 rnum = 3 dres = 50 dsize = 0.6 * 5 xres = 50 yres = 50 #ffdata = ls.load_rf_track('/Users/alec/UCSB/scan_data/'+str(scannum)+'/'+str(scannum).zfill(6)+'.scan',xres,yres) ffdata = ls.load_ff( '/Users/alec/UCSB/scan_data/' + str(scannum) + '-esrdata/fitdata.txt', xres, yres, 7) ffback = ls.load_ff( '/Users/alec/UCSB/scan_data/' + str(bscannum) + '-esrdata/fitdata.txt', xres, yres, 7) ffdatac = ffdata[0][1:50, 0:48] sub = np.zeros((5, 5)) #for j in range(0,5): # for i in range(0,5): # ffbackc = ffback[0][j:j+45,i+1:i+46] # ffdatasub = np.add(ffdatac,np.multiply(ffbackc,-1)) # ffdatacmask = ffdatasub # ffdatacmask[0:14,0:11] = np.zeros_like(ffdatacmask[0:14,0:11]) # ffdatacmask[10:35,8:33]= np.zeros_like(ffdatacmask[10:35,8:33]) # sub[i,j] = np.abs(np.sum(ffdatacmask))
#pi = np.pi #bz0 = 11.0 #phi = 0*pi/180 #file constants xres = 100 yres = 10 scan_size = 0.8*5000 dres = scan_size/xres hlist = np.zeros(2*yres) thetalist = np.zeros(2*yres) xlist = np.zeros(2*yres) mstlist = np.zeros(2*yres) ffdata = ls.load_ff('/Users/alec/UCSB/scan_data/1773-esrdata/fitdata.txt',xres,yres,10) x = np.arange(0,dres*xres,dres) plt.close('all') plt.figure(1,[17,10]) gs = gridspec.GridSpec(5, 4) gs.update(left=0.05, right=0.97, top=0.97, bottom=0.05, wspace=0.25, hspace=0.25) for j in range(0,10): y = ffdata[0][j,:] ye = ffdata[1][j,:] ry = np.flipud(ffdata[2][j,:]) rye = np.flipud(ffdata[3][j,:])
bx = (2e-3) * mstnm * h * bdenomlist bz = -(2e-3) * mstnm * (x - x0) * bdenomlist bnv = np.abs(bx * np.sin(theta) * np.cos(phi) + (bz + zfieldCal) * np.cos(theta)) return bnv hlist = np.zeros(2 * yresCal) thetalist = np.zeros(2 * yresCal) # philist = np.zeros(2*yresCal) dwlist = np.zeros(2 * yresCal) r2list = np.zeros(2 * yresCal) ffdata = lscan.load_ff('/Users/alec/UCSB/scan_data/' + str(calibrationScanNum) + '-esrdata/fitdata.txt', xresCal, yresCal, maxfgrad=20, printNVCalcError=True) x = np.arange(0, dres * xresCal, dres) plt.close('all') ploth = 1 plt.figure(1, [17, 10]) gs = gridspec.GridSpec(5, 4) gs.update(left=0.05, right=0.97, top=0.97, bottom=0.05, wspace=0.25, hspace=0.25)
from scipy import ndimage from scipy import signal import load_scan as lscan import vector_reconstruction as vr import fourier_image as fi import m_reconstruction_Dovzhenko as mr pi = np.pi scannum = 1760 xres = 50 yres = 50 zfield = 9.5 scanL = 0.6*5000 data = lscan.load_ff('fitdata_1760.txt',xres,yres,15) ffmask = ndimage.imread('ff_1760mask.png',flatten=True) ffmask = np.multiply(np.add(np.multiply(ffmask,1/255),-0.5),-2) filespec = 'Msnotfixed' cal_params = np.loadtxt('cal_parameters_'+filespec+'.txt', delimiter=',') theta = cal_params[2] phi = cal_params[3] height = cal_params[4] #---------------- FIT FUNCTIONS ---------------------------------- #----------------------------------------------------------------- def fit_arctan(x, *params): y = np.zeros_like(x)
#file constants xres = 150 yres = 5 scan_size = 1.2 * 5000 dres = scan_size / xres mstlist = np.zeros(2 * yres) hlist = np.zeros(2 * yres) thetalist = np.zeros(2 * yres) # philist = np.zeros(2*yres) r2list = np.zeros(2 * yres) ffdata = lscan.load_ff('/Users/alec/UCSB/scan_data/1572-esrdata/fitdata.txt', xres, yres, printNVCalcError=True) x = np.arange(0, dres * xres, dres) BzMeanEnd = 0 BzStdEnd = 0 BzTails = [0, 1, 2, 3, 4] BzEnd = np.zeros((len(BzTails), 12)) for i in range(len(BzTails)): BzEnd[i] = np.concatenate((ffdata[0][BzTails[i], -6:], ffdata[2][BzTails[i], :6])) BzMeanEnd = np.mean(BzEnd) BzStdEnd = np.std(BzEnd)
scanFolder = '/Users/alec/UCSB/scan_data/' dataPath = scanFolder + str(scannum) + '-esrdata/' + fileName def plot_point_fit(event): if event.dblclick: xp = int(np.round(event.xdata)) yp = int(np.round(event.ydata)) filenum = yp * res * 2 + xp + startFileNum filePath = dataPath + str(filenum).zfill(6) + '_' + str( numAvg) + '.txt' cpsf.cwesr_plot_single_fit(filePath, filenum) print(filenum) data = lscan.load_ff(scanFolder + str(scannum) + '-esrdata/fitdata.txt', res, res, fieldangle=True, printNVCalcError=True) plt.close('all') fig, ax = plt.subplots() im = plt.imshow(data[0]) cbar = fig.colorbar(im, ax=ax, fraction=0.046, pad=0.04) fp.format_plot(plt, fwidth=500, fheight=550) plt.show() cid = fig.canvas.mpl_connect('button_press_event', plot_point_fit)