Created
December 16, 2020 15:39
-
-
Save sriharijayaram5/86e4e39925ce72fadc1c9c391a8616bb to your computer and use it in GitHub Desktop.
Pulsed Analysis Notebook for Qudi Kernel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import matplotlib.pyplot as plt\n", | |
"import glob\n", | |
"import scipy.signal\n", | |
"plt.style.use(savelogic.mpl_qd_style)\n", | |
"plt.rcParams.update({'lines.markeredgewidth': 1})\n", | |
"import cv2\n", | |
"from matplotlib_scalebar.scalebar import ScaleBar\n", | |
"import time\n", | |
"import matplotlib\n", | |
"from tqdm.auto import tqdm\n", | |
"import datetime\n", | |
"from joblib import Parallel, delayed\n", | |
"import multiprocessing\n", | |
"from lmfit import Parameters" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Rabi analysis" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#### Load data in new format and plot rabi" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"loc ='20201215-1241-06_rabi_ROI60_210_0_-5_20_(60, 300)pxs_-25dBm.npz'\n", | |
"locs = f'C:/Users/yy3/Work/Data/12_2020/Pulsed_15_12_2020/{loc}'\n", | |
"\n", | |
"data = np.load(locs)\n", | |
"a = (-data['data'][:,0,:,:]+data['data'][:,1,:,:])/(data['data'][:,1,:,:]+data['data'][:,0,:,:])\n", | |
"# Median blur\n", | |
"a = np.asarray([cv2.medianBlur(a.astype(np.float32), 5) for a in a])\n", | |
"y = np.flip(np.mean(a, axis=(1,2)), axis=0)\n", | |
"try:\n", | |
" x = np.flip(data['x']/1e9*1e6, axis=0)\n", | |
"except:\n", | |
" x = np.flip(np.arange(2010,0,-50)*1e-9*1e6, axis=0)\n", | |
"plt.plot(x, y, 'ro-', label='Data')\n", | |
"# plt.plot(x, y-0.001*x, 'ro-', label='Data')\n", | |
"# plt.plot(x, -y+0.001*x+0.005, 'ro-', label='Data')\n", | |
"\n", | |
"yerr = data['err']\n", | |
"yerr_1 = np.sqrt(np.square(yerr[:,0])+np.square(yerr[:,1]))\n", | |
"a = np.mean(-data['data'][:,1,:,:]+data['data'][:,0,:,:], axis=(1,2))\n", | |
"b = np.mean(data['data'][:,1,:,:]+data['data'][:,0,:,:], axis=(1,2))\n", | |
"yerr_2 = np.flip(np.sqrt(np.square(yerr_1/a) + np.square(yerr_1/b)), axis=0)\n", | |
"yerr_3 = y*yerr_2\n", | |
"# plt.errorbar(x, y, yerr_3, label='Error', fmt='.k', markersize=5, capsize=6)\n", | |
"\n", | |
"fit = fitlogic.make_sineexponentialdecay_fit(x_axis=x/1e6, data=y, estimator=fitlogic.estimate_sineexponentialdecay)\n", | |
"plt.plot(x, fit.best_fit, 'bo-', label='Fit')\n", | |
"# plt.xlim(0, 0.21)\n", | |
"plt.grid()\n", | |
"plt.xlabel('MW Pulse Width (us)')\n", | |
"plt.ylabel('Delta of MW_off and MW_on (Mich. Contrast)')\n", | |
"plt.legend()\n", | |
"plt.figtext(0.5, -0.05, loc, wrap=True, horizontalalignment='center', fontsize=12)\n", | |
"\n", | |
"dely = fit.eval_uncertainty(x=x/1e6)\n", | |
"# plt.fill_between(x, fit.best_fit-dely, fit.best_fit+dely, color='#b3b3b3')\n", | |
"\n", | |
"plt.show()\n", | |
"print(fit.fit_report())\n", | |
"# print(fit.params['frequency']/1e6)\n", | |
"\n", | |
"all_data = (-data['data'][:,0,:,:]+data['data'][:,1,:,:])/(data['data'][:,1,:,:]+data['data'][:,0,:,:])\n", | |
"ref_data = data['data'][:,1,:,:]-data['data'][:,0,:,:]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"1/1068739" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"all_data.shape" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"fs = 1/(5e-9) # sampling frequency, (Hz) " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### FFTn of rabi sequence" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"a = all_data\n", | |
"# Median denoising - takes median which makes more sense\n", | |
"a = np.asarray([cv2.medianBlur(a.astype(np.float32), 3) for a in all_data])\n", | |
"## Blur denoising - takes average\n", | |
"# a = np.asarray([cv2.blur(a, (4,4)) for a in all_data])\n", | |
"## Time series denoising\n", | |
"# b = all_data*1e6\n", | |
"# a = np.asarray([cv2.fastNlMeansDenoisingMulti(b.astype(np.uint8), i, 1, None, 1, 1, 1) for i,a in enumerate(b)])\n", | |
"s = scipy.signal.detrend(a, axis=0)\n", | |
"s = np.fft.fftn(s, axes=(0,))\n", | |
"x = np.fft.fftfreq(s.shape[0]) * fs\n", | |
"# x = np.linspace(0.0, s.shape[0]*fs, s.shape[0]//2)\n", | |
"# s = 2.0/s.shape[0] * np.abs(s[:s.shape[0]//2])\n", | |
"# ids = abs(s).argmax(axis=0)\n", | |
"order = 0\n", | |
"# for order in range(0,6,1):\n", | |
"ids = np.argsort(-abs(s), axis=0, kind= 'quicksort', order=None)[order]\n", | |
"# print(abs(s[:,50,50]))\n", | |
"# print(abs(s[:,50,50]).argmax(axis=0), abs(s[abs(s[:,50,50]).argmax(axis=0),50,50]))\n", | |
"# coord = -1\n", | |
"# plt.plot(x, abs(s[:]),'bo-')\n", | |
"# ind = np.argsort(-abs(s[:]), axis=0, kind= 'quicksort', order=None)[order]\n", | |
"# plt.plot(x[ind], abs(s[ind]),'ro')\n", | |
"# print(x[ind])\n", | |
"# #plt.xlim(-50e6,50e6)\n", | |
"# plt.show()\n", | |
"img = abs(x[ids[:,:]])/1e6\n", | |
"plt.imshow(img, cmap=plt.get_cmap('inferno'), origin='lower',vmax=30)#, vmin=7)\n", | |
"print(f'Mean freq: {np.mean(abs(x[ids[:,:]])/1e6)}MHz')\n", | |
"cb = plt.colorbar()\n", | |
"cb.set_label('Freq (MHz)',size=10)\n", | |
"scalebar = ScaleBar(0.07, 'um', 'si-length') # 1 pixel = 0.2 meter\n", | |
"scalebar.length_fraction = 1\n", | |
"scalebar.frameon = False\n", | |
"scalebar.color = 'white'\n", | |
"plt.gca().add_artist(scalebar)\n", | |
"\n", | |
"plt.figtext(0.75, 0.05, loc, wrap=True, horizontalalignment='center', fontsize=6)\n", | |
"plt.show()\n", | |
"\n", | |
"plt.hist(img.ravel(),100,[img.min(),20])\n", | |
"plt.ticklabel_format(axis=\"x\", style=\"sci\", scilimits=(0,0))\n", | |
"plt.title('Histogram of FFT')\n", | |
"plt.ylabel('Counts')\n", | |
"plt.xlabel('Freq (MHz)')\n", | |
"plt.show()\n", | |
"# plt.imshow(np.mean(ref_data, axis=0), cmap=plt.get_cmap('inferno'), origin='lower')#, vmax=23.0, vmin=10))\n", | |
"# cb = plt.colorbar()\n", | |
"# cb.set_label('Normalized counts',size=10)\n", | |
"# plt.show()\n", | |
"\n", | |
"# plt.imshow(np.mean(all_data, axis=0), cmap=plt.get_cmap('inferno'), origin='lower')#, vmax=23.0, vmin=10))\n", | |
"# cb = plt.colorbar()\n", | |
"# cb.set_label('Normalized counts',size=10)\n", | |
"# plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# T1 analysis" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"#### Load data and plot T1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": false | |
}, | |
"outputs": [], | |
"source": [ | |
"loc = '20201215-2051-47_T1_ROI60_3501000_0_-500000_300_(60, 300)pxs_-25dBm.npz'\n", | |
"locs = f'C:/Users/yy3/Work/Data/12_2020/Pulsed_15_12_2020/{loc}'\n", | |
"\n", | |
"data = np.load(locs)\n", | |
"a = (data['data'][:,1,:,:]-data['data'][:,0,:,:])/(data['data'][:,1,:,:]+data['data'][:,0,:,:])\n", | |
"y = np.flip(np.mean(a, axis=(1,2)), axis=0)\n", | |
"# y = np.delete(y, 6)\n", | |
"try:\n", | |
" x = np.flip(data['x']/1e9*1e6, axis=0)\n", | |
"except:\n", | |
" x = np.flip(np.arange(3501000,0,-500000)/1e9*1e6, axis=0)\n", | |
"# x = np.flip(np.array([3.500000000000000e+06,\n", | |
"# 3.000000000000000e+06,\n", | |
"# 2.500000000000000e+06,\n", | |
"# 2.000000000000000e+06,\n", | |
"# 1.500000000000000e+06,\n", | |
"# 1.000000000000000e+06,\n", | |
"# 5.000000000000000e+05,\n", | |
"# 1.000000000000000e+05,\n", | |
"# 1.000000000000000e+04,\n", | |
"# 1.000000000000000e+03,\n", | |
"# 1.000000000000000e+02,\n", | |
"# 1.000000000000000e+01\n", | |
"# ])/1e9*1e6, axis=0)\n", | |
"\n", | |
"x1 = np.flip(x, axis=0)\n", | |
"# x = np.delete(x, 6)\n", | |
"# x1 = np.delete(x1, 6)\n", | |
"plt.plot(x[::], y[::], label='Data')\n", | |
"\n", | |
"yerr = data['err']\n", | |
"yerr_1 = np.sqrt(np.square(yerr[:,0])+np.square(yerr[:,1]))\n", | |
"a = np.mean(-data['data'][:,1,:,:]+data['data'][:,0,:,:], axis=(1,2))\n", | |
"b = np.mean(data['data'][:,1,:,:]+data['data'][:,0,:,:], axis=(1,2))\n", | |
"yerr_2 = np.flip(np.sqrt(np.square(yerr_1/a) + np.square(yerr_1/b)), axis=0)\n", | |
"yerr_3 = y*yerr_2\n", | |
"plt.errorbar(x, y, yerr_3, label='Error', fmt='.k', markersize=5, capsize=6)\n", | |
"\n", | |
"fit = fitlogic.make_decayexponential_fit(x_axis=x[::]/1e6, data=y[::], estimator=fitlogic.estimate_decayexponential)\n", | |
"plt.plot(x[:], fit.best_fit, label='Fit')\n", | |
"plt.xlabel('Tau (us)')\n", | |
"plt.ylabel('Delta of MW_off and MW_on (Mich. Contrast)')\n", | |
"plt.figtext(0.5, -0.05, loc, wrap=True, horizontalalignment='center', fontsize=12)\n", | |
"\n", | |
"# dely = fit.eval_uncertainty(x=x*1e9)\n", | |
"# plt.fill_between(x, fit.best_fit-dely, fit.best_fit+dely, color='#b3b3b3')\n", | |
"plt.legend()\n", | |
"plt.show()\n", | |
"plt.semilogx(x1, np.mean(data['data'][:,1,:,:], axis=(1,2)), 'bo-', label='MW Off')\n", | |
"# plt.show()\n", | |
"plt.semilogx(x1, np.mean(data['data'][:,0,:,:], axis=(1,2)), 'ro-', label='MW On')\n", | |
"plt.xlabel('Tau (us)')\n", | |
"plt.ylabel('Avg. pixel value')\n", | |
"plt.legend()\n", | |
"plt.figtext(0.5, -0.05, loc, wrap=True, horizontalalignment='center', fontsize=12)\n", | |
"plt.show()\n", | |
"print(fit.fit_report(), fit.params['lifetime']*1e3)\n", | |
"\n", | |
"# all_data = a\n", | |
"# ref_data = np.mean(data['data'][:,1,:,:], axis=0)\n", | |
"# plt.imshow(ref_data, cmap=plt.get_cmap('inferno'), origin='lower')#, vmax=23.0, vmin=10))\n", | |
"# cb = plt.colorbar()\n", | |
"# cb.set_label('Normalized counts',size=10)\n", | |
"# plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Median blurred voxel fitting" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": false | |
}, | |
"outputs": [], | |
"source": [ | |
"a = (data['data'][:,1,:,:]-data['data'][:,0,:,:])/(data['data'][:,1,:,:]+data['data'][:,0,:,:])\n", | |
"img = np.flip(np.asarray([cv2.medianBlur(a.astype(np.float32),3) for a in a]), axis=0)\n", | |
"x = np.flip(data['x'], axis=0)\n", | |
"# img = np.delete(img, 6, axis=0)\n", | |
"# x = np.delete(x, 6)\n", | |
"t1 = np.zeros((img.shape[1], img.shape[2]))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def do_fit(i):\n", | |
" for j in range(img.shape[2]): \n", | |
" coord = (i,j)\n", | |
" y_data = all_data[:, coord[0], coord[1]]\n", | |
" try:\n", | |
" fit_result = fitlogic.make_decayexponential_fit(x_axis=x[3::], data=y_data[3::], estimator=fitlogic.estimate_decayexponential)#, add_params=params)\n", | |
" lifetime = fit_result.params['lifetime']\n", | |
" except:\n", | |
" lifetime = np.nan\n", | |
" t1[i,j] = lifetime\n", | |
"\n", | |
"all_data = img\n", | |
"Parallel(n_jobs=4, prefer=\"threads\")(delayed(do_fit)(i) for i in tqdm(range(img.shape[1])))\n", | |
"\n", | |
"timestamp = datetime.datetime.now()\n", | |
"t = timestamp.strftime(\"%Y%m%d-%H%M-%S\")\n", | |
"tag = loc\n", | |
"np.savez_compressed(f'{savelogic.get_path_for_module(\"Pulsed\")}/'+t+'_lifetime_of_'+loc, data=t1)\n", | |
"saveloc = f'{savelogic.get_path_for_module(\"Pulsed\")}/'+t+'_lifetime_of_'+loc" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": false | |
}, | |
"outputs": [], | |
"source": [ | |
"data = np.load('C:/Data/2020/12/20201216/Pulsed/20201216-1029-51_lifetime_of_20201215-2051-47_T1_ROI60_3501000_0_-500000_300_(60, 300)pxs_-25dBm.npz')\n", | |
"# %matplotlib inline\n", | |
"# data = np.load(saveloc)\n", | |
"lifetime = data['data']\n", | |
"current_cmap = matplotlib.cm.get_cmap()\n", | |
"current_cmap.set_bad(color='white')\n", | |
"times = 1e3\n", | |
"img = abs(lifetime)/1e9*times\n", | |
"plt.imshow(img, cmap=plt.get_cmap('inferno'), origin='lower', vmax=1, vmin=0)\n", | |
"cb = plt.colorbar()\n", | |
"cb.set_label(f'T1 * {times}',size=10)\n", | |
"scalebar = ScaleBar(0.07, 'um', 'si-length') # 1 pixel = 0.2 meter\n", | |
"scalebar.length_fraction = 1\n", | |
"scalebar.frameon = False\n", | |
"scalebar.color = 'white'\n", | |
"plt.gca().add_artist(scalebar)\n", | |
"plt.figtext(0.75, 0.05, saveloc, wrap=True, horizontalalignment='center', fontsize=4)\n", | |
"plt.show()\n", | |
"\n", | |
"plt.hist(img.ravel(),1000,[0,1])\n", | |
"plt.ticklabel_format(axis=\"x\", style=\"sci\", scilimits=(0,0))\n", | |
"plt.title('Histogram of T1 fit')\n", | |
"plt.ylabel('Counts')\n", | |
"plt.xlabel(f'T1 (s*{times})')\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# T2 analysis" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Direct common mode rejection" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"loc = '20201216-1443-25_T2_ROI60_35100_0_-1000_30_(60, 300)pxs_-25dBm.npz'\n", | |
"locs = f'C:/Users/yy3/Work/Data/12_2020/Pulsed_16_12_2020/{loc}'\n", | |
"\n", | |
"data = np.load(locs)\n", | |
"a = (-data['data'][:,1,:,:]+data['data'][:,0,:,:])/(data['data'][:,1,:,:]+data['data'][:,0,:,:])\n", | |
"y = np.flip(np.mean(a, axis=(1,2)), axis=0)\n", | |
"try:\n", | |
" x1 = np.flip(data['x']/1e9*1e6, axis=0)\n", | |
"except:\n", | |
" x1 = np.arange(401000,0,-5000)/1e9*1e6\n", | |
"x = np.flip(x1, axis=0)\n", | |
"plt.plot(x[::], y[::], label='Data')\n", | |
"\n", | |
"yerr = data['err']\n", | |
"yerr_1 = np.sqrt(np.square(yerr[:,0])+np.square(yerr[:,1]))\n", | |
"a = np.mean(-data['data'][:,1,:,:]+data['data'][:,0,:,:], axis=(1,2))\n", | |
"b = np.mean(data['data'][:,1,:,:]+data['data'][:,0,:,:], axis=(1,2))\n", | |
"yerr_2 = np.flip(np.sqrt(np.square(yerr_1/a) + np.square(yerr_1/b)), axis=0)\n", | |
"yerr_3 = y*yerr_2\n", | |
"# plt.errorbar(x, y, yerr_3, label='Error', fmt='.k', markersize=5, capsize=6)\n", | |
"\n", | |
"fit = fitlogic.make_decayexponentialstretched_fit(x_axis=x1[5::]/1e6, data=y[5::], estimator=fitlogic.estimate_decayexponentialstretched)\n", | |
"plt.plot(x1[5:], fit.best_fit, label='Fit')\n", | |
"plt.xlabel('Tau (us)')\n", | |
"plt.ylabel('Delta of $MW_{\\pi/2}$ and $MW_{3\\pi/2}$ (Mich. Contrast)')\n", | |
"plt.figtext(0.5, -0.05, loc, wrap=True, horizontalalignment='center', fontsize=12)\n", | |
"plt.legend()\n", | |
"plt.grid(which='both', linestyle='--')\n", | |
"# dely = fit.eval_uncertainty(x=x1[10:]/1e6)\n", | |
"# plt.fill_between(x1[10:], fit.best_fit-dely, fit.best_fit+dely, color='#b3b3b3')\n", | |
"plt.show()\n", | |
"\n", | |
"plt.plot(x1, np.mean(data['data'][:,1,:,:], axis=(1,2)), 'bo-', label='$3\\pi/2$')\n", | |
"plt.plot(x1, np.mean(data['data'][:,0,:,:], axis=(1,2)), 'ro-', label='$\\pi/2$')\n", | |
"plt.xlabel('Tau (us)')\n", | |
"plt.ylabel('Avg. pixel value')\n", | |
"plt.legend()\n", | |
"plt.figtext(0.5, -0.05, loc, wrap=True, horizontalalignment='center', fontsize=12)\n", | |
"plt.show()\n", | |
"print(fit.fit_report())#, fit.params['lifetime'])\n", | |
"\n", | |
"# all_data = a\n", | |
"# ref_data = np.mean(data['data'][:,1,:,:], axis=0)\n", | |
"# plt.imshow(ref_data, cmap=plt.get_cmap('inferno'), origin='lower')#, vmax=23.0, vmin=10))\n", | |
"# cb = plt.colorbar()\n", | |
"# cb.set_label('Normalized counts',size=10)\n", | |
"# plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# T2<sup>*</sup> analysis" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Common mode rejection with reference" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"loc = '20201207-1116-04_T2S_ROI3_5000_0_-100_30_(66, 80)pxs_-16dBm.npz'\n", | |
"locs = f'C:/Users/yy3/Work/Data/12_2020/Pulsed_07_12_2020/{loc}'\n", | |
"\n", | |
"data = np.load(locs)\n", | |
"a = (-data['data'][:,0,:,:]+data['data'][:,1,:,:])/(data['data'][:,1,:,:]+data['data'][:,0,:,:])\n", | |
"y = np.flip(np.mean(a, axis=(1,2)), axis=0)\n", | |
"x1 = np.arange(5000,0,-100)/1e9*1e6\n", | |
"x = np.flip(x1, axis=0) \n", | |
"plt.plot(x[::], y[::], label='Data')\n", | |
"\n", | |
"yerr = data['err']\n", | |
"yerr_1 = np.sqrt(np.square(yerr[:,0])+np.square(yerr[:,1]))\n", | |
"a = np.mean(-data['data'][:,1,:,:]+data['data'][:,0,:,:], axis=(1,2))\n", | |
"b = np.mean(data['data'][:,1,:,:]+data['data'][:,0,:,:], axis=(1,2))\n", | |
"yerr_2 = np.flip(np.sqrt(np.square(yerr_1/a) + np.square(yerr_1/b)), axis=0)\n", | |
"yerr_3 = y*yerr_2\n", | |
"div=100\n", | |
"plt.errorbar(x, y, yerr_3/div, label=f'Error/{div}', fmt='.k', markersize=5, capsize=6)\n", | |
"\n", | |
"fit = fitlogic.make_sinetriplewithexpdecay_fit(x_axis=x[::]/1e6, data=y[::], estimator=fitlogic.estimate_sinetriplewithexpdecay)\n", | |
"plt.plot(x[:], fit.best_fit, label='Fit')\n", | |
"plt.xlabel('Tau (us)')\n", | |
"plt.ylabel('Delta of $MW_{off}$ and $MW_{on}$ (Mich. Contrast)')\n", | |
"plt.figtext(0.5, -0.05, loc, wrap=True, horizontalalignment='center', fontsize=12)\n", | |
"plt.legend()\n", | |
"\n", | |
"dely = fit.eval_uncertainty(x=x/1e6)\n", | |
"plt.fill_between(x, fit.best_fit-dely, fit.best_fit+dely, color='#b3b3b3')\n", | |
"plt.show()\n", | |
"plt.plot(x1, np.mean(data['data'][:,1,:,:], axis=(1,2)), 'bo-', label='$Ref$')\n", | |
"# plt.show()\n", | |
"plt.plot(x1, np.mean(data['data'][:,0,:,:], axis=(1,2)), 'ro-', label='$Signal$')\n", | |
"plt.xlabel('Tau (us)')\n", | |
"plt.ylabel('Avg. pixel value')\n", | |
"plt.legend()\n", | |
"plt.figtext(0.5, -0.05, loc, wrap=True, horizontalalignment='center', fontsize=12)\n", | |
"plt.show()\n", | |
"print(fit.fit_report('Variables'))#, fit.params['lifetime'])\n", | |
"\n", | |
"fs = 1/100e-9\n", | |
"s = scipy.signal.detrend(y, axis=0)\n", | |
"s = np.fft.fftn(y, axes=(0,)) \n", | |
"x = np.fft.fftfreq(s.shape[0]) * fs\n", | |
"plt.plot(x,s)\n", | |
"plt.show()\n", | |
"# all_data = a\n", | |
"# ref_data = np.mean(data['data'][:,1,:,:], axis=0)\n", | |
"# plt.imshow(ref_data, cmap=plt.get_cmap('inferno'), origin='lower')#, vmax=23.0, vmin=10))\n", | |
"# cb = plt.colorbar()\n", | |
"# cb.set_label('Normalized counts',size=10)\n", | |
"# plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Pulsed ODMR" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"loc = '20201216-1147-58_odmr_ROI60_2845000000.0_2905000000.0_1000000.0_1_(60, 300)pxs_-25dBm.npz'\n", | |
"locs = f'C:/Users/yy3/Work/Data/12_2020/Pulsed_16_12_2020/{loc}'\n", | |
"\n", | |
"data = np.load(locs)\n", | |
"a = (-data['data'][:,0,:,:]+data['data'][:,1,:,:])/(data['data'][:,1,:,:]+data['data'][:,0,:,:])*100\n", | |
"# a = (data['data'][:,0,:,:])/(data['data'][:,1,:,:])\n", | |
"y = np.mean(a, axis=(1,2))\n", | |
"try:\n", | |
" x = data['x']/1e9\n", | |
"except:\n", | |
" x = np.arange(2850000000.0,2891000000.0,500000.0)/1e9\n", | |
"plt.plot(x[::], y[::])\n", | |
"\n", | |
"# fit = fitlogic.make_lorentziandouble_fit(x_axis=x[::]*1e9, data=y[::], estimator=fitlogic.estimate_lorentziandouble_peak)\n", | |
"fit = fitlogic.make_lorentziandouble_fit(x_axis=x[::]*1e9, data=y[::], estimator=fitlogic.estimate_lorentziandouble_peak)\n", | |
"plt.plot(x[::], fit.best_fit)\n", | |
"plt.xlabel('MW Freq (GHz)')\n", | |
"plt.ylabel('Mich. contrast of norm. counts')\n", | |
"plt.figtext(0.5, -0.05, loc, wrap=True, horizontalalignment='center', fontsize=12)\n", | |
"plt.grid(which='both', linestyle='--')\n", | |
"\n", | |
"dely = fit.eval_uncertainty(x=x*1e9)\n", | |
"# plt.fill_between(x, fit.best_fit-dely, fit.best_fit+dely, color='#b3b3b3')\n", | |
"plt.show()\n", | |
"print(fit.fit_report())#, fit.params['l0_sigma']/1e6)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Median blurred voxel fitting" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": false | |
}, | |
"outputs": [], | |
"source": [ | |
"a = (data['data'][:,1,:,:]-data['data'][:,0,:,:])/(data['data'][:,1,:,:]+data['data'][:,0,:,:])\n", | |
"img = np.asarray([cv2.medianBlur(a.astype(np.float32),3) for a in a])\n", | |
"x = data['x']\n", | |
"# img = np.delete(img, 6, axis=0)\n", | |
"# x = np.delete(x, 6)\n", | |
"split = np.zeros((img.shape[1], img.shape[2]))\n", | |
"fwhm0 = np.zeros((img.shape[1], img.shape[2]))\n", | |
"fwhm1 = np.zeros((img.shape[1], img.shape[2]))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def do_fit(i):\n", | |
" for j in range(img.shape[2]): \n", | |
" coord = (i,j)\n", | |
" y_data = all_data[:, coord[0], coord[1]]\n", | |
" try:\n", | |
" fit_result = fitlogic.make_lorentziandouble_fit(x_axis=x[::], data=y_data[::], estimator=fitlogic.estimate_lorentziandouble_peak)#, add_params=params)\n", | |
" split_ij = np.abs(fit_result.params['l1_center']-fit_result.params['l0_center'])\n", | |
" if split_ij>60e6:\n", | |
" raise Exception\n", | |
" fwhm0_ij = (fit_result.params['l0_fwhm'])\n", | |
" fwhm1_ij = (fit_result.params['l1_fwhm'])\n", | |
" except:\n", | |
" split_ij = np.nan\n", | |
" fwhm0_ij = np.nan\n", | |
" fwhm1_ij = np.nan\n", | |
" split[i,j] = split_ij\n", | |
" fwhm0[i,j] = fwhm0_ij\n", | |
" fwhm1[i,j] = fwhm1_ij\n", | |
"\n", | |
"all_data = img\n", | |
"loop_list = tqdm(range(img.shape[1]))\n", | |
"Parallel(n_jobs=4, prefer=\"threads\")(delayed(do_fit)(i) for i in loop_list)\n", | |
"\n", | |
"timestamp = datetime.datetime.now()\n", | |
"t = timestamp.strftime(\"%Y%m%d-%H%M-%S\")\n", | |
"tag = loc\n", | |
"np.savez_compressed(f'{savelogic.get_path_for_module(\"Pulsed\")}/'+t+'_SPODMR_of_'+loc, splitting=split, fwhm0=fwhm0, fwhm1=fwhm1)\n", | |
"saveloc = f'{savelogic.get_path_for_module(\"Pulsed\")}/'+t+'_SPODMR_of_'+loc" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# data1 = np.load('C:/Users/yy3/Work/Data/12_2020/Pulsed_16_12_2020/20200825-2128-3320200825-1939-57_YBC_10K_Bext_0.55mT_MW_-20dBm_ODMR_data_splitting_fullxfull_parallel.npz')\n", | |
"data1 = np.load('C:/Data/2020/12/20201216/Pulsed/20201216-1230-04_SPODMR_of_20201216-1147-58_odmr_ROI60_2845000000.0_2905000000.0_1000000.0_1_(60, 300)pxs_-25dBm.npz')\n", | |
"# %matplotlib inline\n", | |
"# data1 = np.load(saveloc)\n", | |
"splitting = data1['splitting']\n", | |
"splitting = cv2.medianBlur(splitting.astype(np.float32),3)\n", | |
"current_cmap = matplotlib.cm.get_cmap()\n", | |
"current_cmap.set_bad(color='white')\n", | |
"img = abs(splitting)/1e6\n", | |
"plt.imshow(img, cmap=plt.get_cmap('inferno'), origin='lower', vmax=33, vmin=28)\n", | |
"cb = plt.colorbar()\n", | |
"cb.set_label(f'Splitting (Mhz)',size=10)\n", | |
"scalebar = ScaleBar(0.07, 'um', 'si-length') # 1 pixel = 0.2 meter\n", | |
"scalebar.length_fraction = 1\n", | |
"scalebar.frameon = False\n", | |
"scalebar.color = 'white'\n", | |
"plt.gca().add_artist(scalebar)\n", | |
"plt.figtext(0.75, 0.05, saveloc, wrap=True, horizontalalignment='center', fontsize=4)\n", | |
"plt.show()\n", | |
"\n", | |
"plt.hist(abs(img).ravel(),500,[np.nanmin(img),50])\n", | |
"plt.ticklabel_format(axis=\"x\", style=\"sci\", scilimits=(0,0))\n", | |
"plt.title('Histogram of splitting fit')\n", | |
"plt.ylabel('Counts')\n", | |
"plt.xlabel(f'Splitting (Mhz)')\n", | |
"plt.show()" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Qudi", | |
"language": "python", | |
"name": "qudi" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": "3.6.5" | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment