Created
January 5, 2023 11:45
-
-
Save sriharijayaram5/e03df1ee2904813238122e7e1708f02b to your computer and use it in GitHub Desktop.
Running of automatic saturation measurement on AD2200 setup
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 matplotlib.pyplot as plt\n", | |
"import numpy as np\n", | |
"import pulsestreamer as ps\n", | |
"import time\n", | |
"from scipy.optimize import curve_fit\n", | |
"import visa\n", | |
"from ThorlabsPM100 import ThorlabsPM100" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"rm = visa.ResourceManager()\n", | |
"inst = rm.open_resource('USB0::0x1313::0x8078::P0034869::INSTR', timeout=1)\n", | |
"power_meter = ThorlabsPM100(inst=inst)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"power_meter.configure.scalar.power()\n", | |
"print(\"Measurement type :\", power_meter.getconfigure)\n", | |
"print(\"Current value :\", power_meter.read)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"pulsestreamer.pulse_streamer.constant(ps.OutputState([0], 0.04, 0))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Measurement loop for saturation" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"vol_range = np.linspace(0.0, 0.1, 20)\n", | |
"pow_range = np.zeros_like(vol_range)\n", | |
"counts = np.zeros_like(vol_range)\n", | |
"for i, vol in enumerate(vol_range):\n", | |
" pulsestreamer.pulse_streamer.constant(ps.OutputState([0], vol, 0))\n", | |
" time.sleep(6)\n", | |
" pow_range[i] = power_meter.read\n", | |
" counts[i] = np.mean(counterlogic.countdata)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Plotting and fitting [Momenzadeh Thesis]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def objective(P, Fs, Ps):\n", | |
" return Fs/(1+(Ps/P))\n", | |
"\n", | |
"popt,_ = curve_fit(objective, pow_range*0.738, counts, p0 = [400000, 30e-6])\n", | |
"\n", | |
"x_fit = np.linspace(pow_range.min()*0.738, pow_range.max()*0.738, 100)\n", | |
"\n", | |
"fig, ax = plt.subplots()\n", | |
"ax.plot(x_fit*1e6, objective(x_fit, *popt), 'r-')\n", | |
"ax.plot(pow_range*0.738*1e6, counts, 'b.')\n", | |
"\n", | |
"ax.ticklabel_format(axis='both', style='sci', scilimits=(0,0))\n", | |
"ax.set_xlabel('Power (uW)')\n", | |
"ax.set_ylabel('Counts/s')\n", | |
"plt.show()\n", | |
"print('Fs, Ps',*popt)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"Save routine" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"filelabel = 'tip_R03C-F7-C9_LT'\n", | |
"parameters = {'Fs':popt[0], 'Ps': popt[1]}\n", | |
"data = {'Pow (W), Counts (c/s)': np.array((pow_range*0.738, counts)).T}\n", | |
"filepath = savelogic.get_path_for_module(module_name='Saturation')\n", | |
"savelogic.save_data(data, parameters=parameters, filepath=filepath, filelabel=filelabel, plotfig=fig, delimiter='\\t')" | |
] | |
} | |
], | |
"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": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment