forked from RaphaelSura/PythonPhotonicsLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPLEscan.py
More file actions
69 lines (59 loc) · 2.02 KB
/
Copy pathPLEscan.py
File metadata and controls
69 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from LowLevelModules.NIdaqAPD import APDCounter
from LowLevelModules.GeneralFunctions import *
import matplotlib.pyplot as plt
import numpy as np
import time
import nidaqmx
"""####################################### USER INPUT #################################################"""
scan_terminal = '/Dev1/ao2'
terminal = "/Dev1/PFI1"
save_data = True
collection_time = .25 #seconds
V_start = 0
V_end = 2
num_steps = 50
samp_per_reading = 20
"""#########################################################################################################"""
# initialize AO
offset_voltage = 0
task_toptica = nidaqmx.Task("Toptica scan")
output_volt = task_toptica.ao_channels.add_ao_voltage_chan(scan_terminal, 'Piezo scan', min_val=-4.5, max_val=4.5)
task_toptica.write(offset_voltage, auto_start=True, timeout=5)
# initialize the rest
voltages = np.linspace(V_start, V_end, num_steps)
volt, cts, laser_power = [], [], []
lp = LivePlot(1, 10, 6, 'o', 'Voltage (V)', 'APD counts (kHz)')
#initialize the task on DAQ board
task_PD = nidaqmx.Task("PD reading")
task_PD.ai_channels.add_ai_voltage_chan("Dev1/ai2")
task_PD.start()
for v in voltages:
# change RF value
task_toptica.write(v, auto_start=True, timeout=5)
time.sleep(.1)
#read laser power
curr_v = np.zeros(samp_per_reading)
for i in range(samp_per_reading):
curr_v[i] = task_PD.read()
time.sleep(.005)
power_now = np.mean(curr_v)
time.sleep(.1)
# collect the APD count rate
APD1 = APDCounter(terminal)
APD1.start()
time.sleep(collection_time)
APD_cts = APD1.read() / collection_time / 1000
APD1.close()
# get the new data and update the plot
volt.append(v)
cts.append(APD_cts)
laser_power.append(power_now)
lp.plot_live(volt, cts)
task_toptica.write(0)
task_toptica.close()
plt.show()
if save_data:
data_type = 'PLEscan'
data_header = "Voltage (V) APD counts (kHz) Laser power (V)"
data_array = np.array([volt, cts, laser_power]).T
data_save(data_array, lp.fig, data_type, data_header)