Skip to content

Instantly share code, notes, and snippets.

@sriharijayaram5
Created January 5, 2023 11:43
Show Gist options
  • Save sriharijayaram5/4e9e16a9fc04e7e918c14c44d10ecef1 to your computer and use it in GitHub Desktop.
Save sriharijayaram5/4e9e16a9fc04e7e918c14c44d10ecef1 to your computer and use it in GitHub Desktop.
Running and Loading SPM Pulsed ODMR AD200 setup
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys \n",
"import matplotlib.pyplot as plt\n",
"\n",
"pml = pulsedmeasurementlogic\n",
"pmal = pulsedmasterlogic\n",
"import pprint\n",
"\n",
"import logic.pulsed.pulse_objects as po\n",
"import logic.pulsed.sampling_function_defs.basic_sampling_functions as functions\n",
"import time\n",
"import os\n",
"\n",
"from tqdm import tqdm"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"PODMR - repetitions at each point"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Necessary classes and functions"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class PulseSequence:\n",
" '''\n",
" A pulse sequence to be loaded that is made of PulseBlock instances. The pulse blocks can be repeated\n",
" as well and multiple can be added.\n",
" '''\n",
" def __init__(self):\n",
" self.pulse_dict = {'d0':[], 'd1':[], 'd2':[], 'd3':[], 'd4':[], 'd5':[], 'd6':[], 'd7':[], 'a0':[], 'a1':[]}\n",
"\n",
" def append(self, block_list):\n",
" '''\n",
" append a list of tuples of type: \n",
" [(PulseBlock_instance_1, n_repetitions), (PulseBlock_instance_2, n_repetitions)]\n",
" '''\n",
" for block, n in block_list:\n",
" for i in range(n):\n",
" for key in block.block_dict.keys():\n",
" self.pulse_dict[key].extend(block.block_dict[key])\n",
"\n",
" \n",
"class PulseBlock:\n",
" '''\n",
" Small repeating pulse blocks that can be appended to a PulseSequence instance\n",
" '''\n",
" def __init__(self):\n",
" self.block_dict = {'d0':[], 'd1':[], 'd2':[], 'd3':[], 'd4':[], 'd5':[], 'd6':[], 'd7':[], 'a0':[], 'a1':[]}\n",
" \n",
" def append(self, init_length, channels, repetition):\n",
" '''\n",
" init_length in s; will be converted by sequence class to ns\n",
" channels are digital channels of PS in swabian language\n",
" '''\n",
" for i in range(repetition):\n",
" for chn in channels.keys():\n",
" self.block_dict[chn].extend([(init_length/1e-9, channels[chn])])\n",
"\n",
"def set_up_odmr(pi_pulse=100e-9):\n",
" \"\"\" \n",
" @param float clock_frequency: if defined, this sets the frequency of the\n",
" clock\n",
" @param str clock_channel: if defined, this is the physical channel of\n",
" the clock\n",
"\n",
" @return int: error code (0:OK, -1:error)\n",
" \"\"\"\n",
" channels = {'d0': 0.0 , 'd1': 0.0 , 'd2': 0.0 , 'd3': 0.0 , 'd4': 0.0 , 'd5': 0.0 , 'd6': 0.0 , 'd7': 0.0 , 'a0': 0.0, 'a1': 0.0}\n",
" clear = lambda x: {i:0.0 for i in x.keys()}\n",
" d_ch = lambda x: f'd{x}'\n",
" a_ch = lambda x: f'a{x}'\n",
"\n",
" seq = PulseSequence()\n",
" block_1 = PulseBlock()\n",
"\n",
" channels = clear(channels)\n",
" channels[a_ch(pulsestreamer._laser_analog_channel)] = pulsestreamer._laser_power_voltage\n",
" channels[d_ch(pulsestreamer._mw_switch)] = 1.0\n",
" block_1.append(init_length = pi_pulse, channels = channels, repetition = 1)\n",
" \n",
" channels = clear(channels)\n",
" channels[a_ch(pulsestreamer._laser_analog_channel)] = pulsestreamer._laser_power_voltage\n",
" block_1.append(init_length = 1e-6, channels = channels, repetition = 1)\n",
" \n",
" channels = clear(channels)\n",
" channels[d_ch(pulsestreamer._laser_channel)] = 1.0\n",
" channels[a_ch(pulsestreamer._laser_analog_channel)] = pulsestreamer._laser_power_voltage\n",
" channels[d_ch(pulsestreamer._pixel_start)] = 1.0 # pulse to TT channel detect\n",
" block_1.append(init_length = 3e-6, channels = channels, repetition = 1)\n",
" \n",
" channels = clear(channels)\n",
" channels[a_ch(pulsestreamer._laser_analog_channel)] = pulsestreamer._laser_power_voltage\n",
" block_1.append(init_length = 1.5e-6, channels = channels, repetition = 1)\n",
"\n",
" seq.append([(block_1, 1)])\n",
"\n",
" pulse_dict = seq.pulse_dict\n",
"\n",
" pulsestreamer.load_swabian_sequence(pulse_dict)\n",
" return pulsestreamer._seq\n",
"\n",
"def set_up_next_trigger():\n",
" \"\"\" \n",
" @param float clock_frequency: if defined, this sets the frequency of the\n",
" clock\n",
" @param str clock_channel: if defined, this is the physical channel of\n",
" the clock\n",
"\n",
" @return int: error code (0:OK, -1:error)\n",
" \"\"\"\n",
" channels = {'d0': 0.0 , 'd1': 0.0 , 'd2': 0.0 , 'd3': 0.0 , 'd4': 0.0 , 'd5': 0.0 , 'd6': 0.0 , 'd7': 0.0 , 'a0': 0.0, 'a1': 0.0}\n",
" clear = lambda x: {i:0.0 for i in x.keys()}\n",
" d_ch = lambda x: f'd{x}'\n",
" a_ch = lambda x: f'a{x}'\n",
"\n",
" seq = PulseSequence()\n",
" block_1 = PulseBlock()\n",
"\n",
" channels = clear(channels)\n",
" channels[a_ch(pulsestreamer._laser_analog_channel)] = pulsestreamer._laser_power_voltage\n",
" channels[d_ch(pulsestreamer._pixel_stop)] = 1.0\n",
" block_1.append(init_length = 1e-3, channels = channels, repetition = 1)\n",
" \n",
" channels = clear(channels)\n",
" channels[a_ch(pulsestreamer._laser_analog_channel)] = pulsestreamer._laser_power_voltage\n",
" block_1.append(init_length = 1e-3, channels = channels, repetition = 1)\n",
" \n",
" seq.append([(block_1, 1)])\n",
"\n",
" pulse_dict = seq.pulse_dict\n",
"\n",
" pulsestreamer.load_swabian_sequence(pulse_dict)\n",
" return pulsestreamer._seq"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run measurement"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"var_list = np.linspace(2.844e9, 2.876e9, 75, endpoint=True)\n",
"mw_power = -10\n",
"pi_pulse=394e-9\n",
"num_runs = 147000\n",
"\n",
"mw_source_smbv.set_list(var_list, mw_power) # \n",
"mw_source_smbv.list_on()\n",
"laser_pulses = len(var_list)\n",
"\n",
"bin_width_s = 1e-9\n",
"record_length_s = 3e-6\n",
"\n",
"ret_val = time_tagger.configure_recorder(\n",
" mode=11, # pulsed mode\n",
" params={'laser_pulses': laser_pulses,\n",
" 'bin_width_s': bin_width_s,\n",
" 'record_length_s': record_length_s,\n",
" 'max_counts': 1} )\n",
"\n",
"\n",
"time_tagger.start_recorder(arm=True)\n",
"\n",
"set_up_next_trigger()\n",
"pulsestreamer.pulser_on(n=2)\n",
"\n",
"podmr = set_up_odmr(pi_pulse)\n",
"\n",
"for i in tqdm(range(laser_pulses)):\n",
" pulsestreamer.pulser_on(n=num_runs, final=pulsestreamer._mw_trig_final_state)\n",
" d =time.time()\n",
" while True:\n",
" if time_tagger.recorder.getHistogramIndex() > i or (time.time()-d)>10 or time_tagger.recorder.getCounts()>0:\n",
" time.sleep(0.001)\n",
" break\n",
"\n",
"pulsed_meas = time_tagger.get_measurements()[0]\n",
"pulsestreamer.pulser_off() \n",
"mw_source_smbv.off() "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot Jupyter data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"data,_ =afm_scanner_logic.analyse_pulsed_meas(pulsedmasterlogic.analysis_settings, pulsed_meas)\n",
"\n",
"# fit = afm_scanner_logic._fitlogic.make_lorentzian_fit(var_list,data,estimator=afm_scanner_logic._fitlogic.estimate_lorentzian_dip)\n",
"fit = afm_scanner_logic._fitlogic.make_lorentziandouble_fit(var_list,data,estimator=afm_scanner_logic._fitlogic.estimate_lorentziandouble_N15)\n",
"print(fit.fit_report())\n",
"# lm,_ = fitlogic.make_lorentzian_model()\n",
"lm,_ = fitlogic.make_lorentziandouble_model()\n",
"plt.plot(var_list, data,'bo')\n",
"x = np.linspace(var_list[0],var_list[-1],10000, endpoint=True)\n",
"plt.plot(x, lm.eval(fit.params, x=x),'r-')\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot SPM data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d = afm_scanner_logic._pulsed_scan_array['pulsed_fw']['data']\n",
"x = afm_scanner_logic._pulsed_scan_array['pulsed_fw']['coord2_arr']\n",
"data = d[0,0,:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fit = afm_scanner_logic._fitlogic.make_lorentziandouble_fit(x,data,estimator=afm_scanner_logic._fitlogic.estimate_lorentziandouble_N15)\n",
"print(fit.fit_report())\n",
"lm,_ = fitlogic.make_lorentziandouble_model()\n",
"plt.plot(x, data,'bo')\n",
"x = np.linspace(x[0],x[-1],10000, endpoint=True)\n",
"plt.plot(x, lm.eval(fit.params, x=x),'r-')\n",
"\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": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment