Skip to content

Commit

Permalink
API:
Browse files Browse the repository at this point in the history
- add White Rabbit support (synchronize clocks between different Harps over fiber optics)
- add hardware triggered measurements support
- remove unfoldT3Format
- add getAbsTime for Unfold measurement class in T3 mode
- auto detect library - getDeviceIDs() detects all supported devics

Python:
- add Demo_TimeTrace_Coincidence.py
- add Demo_WR_Configure_Master.py
- add Demo_WR_Configure_Slave.py
- add Demo_WR_TimeTrace_Master.py
- add Demo_WR_TimeTrace_Slave.py
- add Demo_HW_Start.py
- add Demo_HW_StartGated.py
- add Demo_HW_StartStop.py

Docu:
- add Control Connector
  • Loading branch information
tpoint75 committed Mar 26, 2024
1 parent 70a3032 commit c4f4fa8
Show file tree
Hide file tree
Showing 50 changed files with 3,247 additions and 479 deletions.
60 changes: 60 additions & 0 deletions demos/Demo_CoincidenceTimestamps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from snAPI.Main import *

if(__name__ == "__main__"):

start = 0
length = 10

sn = snAPI()
sn.getDevice()

# offline processing:
# sn.getFileDevice(r"E:\Data\PicoQuant\G2_T3_sameTTs.ptu")
sn.initDevice(MeasMode.T2)

# set the trigger level
sn.loadIniConfig("config\MH.ini")

#list of channels to build the coincidence from
chans= [1,2]
ciIndex = sn.manipulators.coincidence(chans, 1000, mode = CoincidenceMode.CountOnce,
time = CoincidenceTime.Last,
keepChannels=True) #set keepChannels to false to get the coincidences only
# ciIndex is the 'channel number' where the coincidences are stored
sn.logPrint(f"coincidence index: {ciIndex}")

# block measurement for continuous (acqTime = 0 is until stop) measurement
sn.unfold.startBlock(acqTime=1000, size=1024*1024*1024, savePTU=False)

while(True):
times, channels = sn.unfold.getBlock()

if(len(times) > 9):
sn.logPrint("new data block:")
sn.logPrint(" channel | time tag")
sn.logPrint("--------------------")

# only print the first 10 time tags per block out
# for performance reasons
# but it here should all data be stored to disc
for i in range(10):
sn.logPrint(f"{channels[i]:9} | {times[i]:8}")


# filter the time tags of coincidences
ciTimes = sn.unfold.getTimesByChannel(ciIndex)
sn.logPrint("new coincidence block:")
sn.logPrint("time tag")
sn.logPrint("--------")
if len(ciTimes) > 9:
for i in range(10):
sn.logPrint(f"{ciTimes[i]:8}")


if sn.unfold.finished.contents:
break

# if otherBreakCondition:
sn.unfold.stopMeasure

sn.logPrint("end")
8 changes: 4 additions & 4 deletions demos/Demo_CorrelationFCS.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

if(__name__ == "__main__"):

sn = snAPI(libType=LibType.HH)
sn = snAPI()
sn.getDeviceIDs()
sn.getDevice()
sn.initDevice(MeasMode.T2)

# set the configuration for your device type
sn.loadIniConfig("config\HH.ini")
sn.loadIniConfig("config\MH.ini")

# 1. shift the signals to max correlation max at tau = 0
#sn.device.setInputChannelOffset(1, 1564)

# 2. set windowSize and startTime
sn.correlation.setFCSParameters(1, 2, 1e10, 1e5)
sn.correlation.measure(100,savePTU=True)
sn.correlation.setFCSParameters(1, 2, 1e10, 1e5, 8)
sn.correlation.measure(2000,savePTU=True)

while True:
finished = sn.correlation.isFinished()
Expand Down
6 changes: 3 additions & 3 deletions demos/Demo_CorrelationG2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

if(__name__ == "__main__"):

sn = snAPI(libType=LibType.HH)
sn = snAPI()
sn.getDeviceIDs()
sn.getDevice()
sn.initDevice(MeasMode.T2)

# set the configuration for your device type
sn.loadIniConfig("config\HH.ini")
sn.loadIniConfig("config\MH.ini")

# 1. shift the signals to max correlation max at tau = 0
#sn.device.setInputChannelOffset(1, 1588)

# 2. set windowSize and startTime
sn.correlation.setG2Parameters(1, 2, 100000, 100)
sn.correlation.setG2Parameters(1, 2, 50000, 5)
sn.correlation.measure(1000,savePTU=False)

while True:
Expand Down
4 changes: 2 additions & 2 deletions demos/Demo_DeviceConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
if(__name__ == "__main__"):

# set the library for your device type
sn = snAPI(libType=LibType.HH)
sn = snAPI()
sn.getDevice()
sn.initDevice()

# set the configuration for your device type
sn.loadIniConfig("config\HH.ini")
sn.loadIniConfig("config\MH.ini")

# print complete device config structure
sn.logPrint(json.dumps(sn.deviceConfig, indent=2))
Expand Down
42 changes: 42 additions & 0 deletions demos/Demo_HW_Start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from snAPI.Main import *
import matplotlib
matplotlib.use('TkAgg',force=True)
from matplotlib import pyplot as plt
print("Switched to:",matplotlib.get_backend())


if(__name__ == "__main__"):

sn = snAPI()
sn.getDevice()
sn.initDevice(MeasMode.T2)

# a trigger signal on C1 starts the measurement
sn.device.setMeasControl(MeasControl.C1StartCtcStop)
sn.loadIniConfig("config\MH.ini")

# configure timetrace
sn.timeTrace.setNumBins(10000)
sn.timeTrace.setHistorySize(10)
# prepare measurement for triggered start (stop after 10s)
sn.timeTrace.measure(10000, waitFinished=False, savePTU=False)

plt.figure(f'Figure: {sn.deviceConfig["Model"]}')
while True:
finished = sn.timeTrace.isFinished()
counts, times = sn.timeTrace.getData()
plt.clf()
plt.plot(times, counts[0], linewidth=2.0, label='sync')
for c in range(1, 1+sn.deviceConfig["NumChans"]):
plt.plot(times, counts[c], linewidth=2.0, label=f'chan{c}')

plt.xlabel('Time [s]')
plt.ylabel('Counts[Cts/s]')
plt.legend()
plt.title(f'TimeTrace Master {sn.deviceConfig["ID"]}')
plt.pause(0.1)

if finished:
break

plt.show(block=True)
44 changes: 44 additions & 0 deletions demos/Demo_HW_StartGated.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from snAPI.Main import *
import matplotlib
matplotlib.use('TkAgg',force=True)
from matplotlib import pyplot as plt
print("Switched to:",matplotlib.get_backend())


if(__name__ == "__main__"):

sn = snAPI()
sn.getDevice()
sn.initDevice(MeasMode.T2)

# a trigger signal on C1 starts and holds the measurement
# a low to high slope starts the measurement until the signal on the control connector Pin C1
# is getting low again.
sn.device.setMeasControl(MeasControl.C1Gated, 1, 0)
sn.loadIniConfig("config\MH.ini")

# configure timetrace
sn.timeTrace.setNumBins(10000)
sn.timeTrace.setHistorySize(10)
# prepare measurement for triggered start (stop after 10s)
sn.timeTrace.measure(10000, waitFinished=False, savePTU=False)

plt.figure(f'Figure: {sn.deviceConfig["Model"]}')
while True:
finished = sn.timeTrace.isFinished()
counts, times = sn.timeTrace.getData()
plt.clf()
plt.plot(times, counts[0], linewidth=2.0, label='sync')
for c in range(1, 1+sn.deviceConfig["NumChans"]):
plt.plot(times, counts[c], linewidth=2.0, label=f'chan{c}')

plt.xlabel('Time [s]')
plt.ylabel('Counts[Cts/s]')
plt.legend()
plt.title(f'TimeTrace Master {sn.deviceConfig["ID"]}')
plt.pause(0.1)

if finished:
break

plt.show(block=True)
41 changes: 41 additions & 0 deletions demos/Demo_HW_StartStop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from snAPI.Main import *
import matplotlib
matplotlib.use('TkAgg',force=True)
from matplotlib import pyplot as plt
print("Switched to:",matplotlib.get_backend())

if(__name__ == "__main__"):

sn = snAPI()
sn.getDevice()
sn.initDevice(MeasMode.T2)

# a trigger signal on C1 starts and one on C2 stops the measurement
sn.device.setMeasControl(MeasControl.C1StartC2Stop)
sn.loadIniConfig("config\MH.ini")

# configure timetrace
sn.timeTrace.setNumBins(10000)
sn.timeTrace.setHistorySize(10)
# prepare measurement for triggered start and stop
sn.timeTrace.measure(waitFinished=False, savePTU=False)

plt.figure(f'Figure: {sn.deviceConfig["Model"]}')
while True:
finished = sn.timeTrace.isFinished()
counts, times = sn.timeTrace.getData()
plt.clf()
plt.plot(times, counts[0], linewidth=2.0, label='sync')
for c in range(1, 1+sn.deviceConfig["NumChans"]):
plt.plot(times, counts[c], linewidth=2.0, label=f'chan{c}')

plt.xlabel('Time [s]')
plt.ylabel('Counts[Cts/s]')
plt.legend()
plt.title(f'TimeTrace Master {sn.deviceConfig["ID"]}')
plt.pause(0.1)

if finished:
break

plt.show(block=True)
4 changes: 2 additions & 2 deletions demos/Demo_HeraldedCorrelationG2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

if(__name__ == "__main__"):

sn = snAPI(libType=LibType.PH330)
sn = snAPI()
sn.getDeviceIDs()
sn.getDevice()
sn.initDevice(MeasMode.T2)
sn.loadIniConfig("config\PH330_CFD.ini")
sn.loadIniConfig("config\MH.ini")

windowSize = 2000 #ps
# move the histograms of the both channels to the same time after the sync to filter both at once
Expand Down
7 changes: 3 additions & 4 deletions demos/Demo_HistogramRefresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@

if(__name__ == "__main__"):

sn = snAPI(libType=LibType.PH330)
sn = snAPI(libType=LibType.TH260)
sn.getDevice()
sn.initDevice(MeasMode.T3)
sn.device.setBinning(2)
sn.initDevice(MeasMode.T2)

# temporarily enable logging of configuration
sn.setLogLevel(LogLevel.Config, True)
# set the configuration for your device type
sn.loadIniConfig("config\PH330_Edge.ini")
sn.loadIniConfig("config\TH.ini")
sn.setLogLevel(LogLevel.Config, False)

# change histogram parameter in T2 mode
Expand Down
6 changes: 3 additions & 3 deletions demos/Demo_HistogramSimple.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

if(__name__ == "__main__"):

# select the device library
sn = snAPI(libType=LibType.HH)
# initialize the API
sn = snAPI()
# get first available device
sn.getDevice()
sn.setLogLevel(logLevel=LogLevel.DataFile, onOff=True)
Expand All @@ -16,7 +16,7 @@
sn.initDevice(MeasMode.T2)

# set the configuration for your device type
sn.loadIniConfig("config\HH.ini")
sn.loadIniConfig("config\MH.ini")

# start histogram measurement
sn.histogram.measure(acqTime=1000,savePTU=True)
Expand Down
2 changes: 1 addition & 1 deletion demos/Demo_RecordViewer_Raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
start = 0
length = 10

sn = snAPI(libType=LibType.HH)
sn = snAPI()
sn.getDevice()

#sn.getFileDevice(r"C:\Data\PicoQuant\default.ptu")
Expand Down
10 changes: 5 additions & 5 deletions demos/Demo_RecordViewer_UF.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
start = 0
length = 10

sn = snAPI(libType=LibType.HH)
sn = snAPI()
sn.getDevice()

sn.getFileDevice(r"E:\Data\PicoQuant\default.ptu") # T2 File
#sn.getFileDevice(r"E:\Data\PicoQuant\default.ptu") # T2 File
#sn.getFileDevice(r"E:\Data\PicoQuant\G2_T3_sameTTs.ptu") # T3 File
sn.initDevice(MeasMode.T3)
#sn.setLogLevel(LogLevel.Config, True)
sn.loadIniConfig("config\HH.ini")
sn.loadIniConfig("config\MH.ini")

countRates = sn.getCountRates()

Expand All @@ -28,7 +28,7 @@

syncPeriod = 1e12 / countRates[0] # in ps
for i in range(start,start+length):
sn.logPrint(f"{channels[i]:9} | {sn.unfold.nSync_T3(times[i]):7} | {(resolution * sn.unfold.dTime_T3(times[i])):8} | {(syncPeriod * sn.unfold.nSync_T3(times[i]) + (resolution * sn.unfold.dTime_T3(times[i]))):.1f}")
sn.logPrint(f"{channels[i]:9} | {sn.unfold.nSync_T3(times[i]):7} | {(resolution * sn.unfold.dTime_T3(times[i])):8} | {sn.unfold.abs_T3(times[i]):.1f}")

else: # T2
sn.logPrint("Unfold T2 Data:")
Expand All @@ -39,4 +39,4 @@
for i in range(start,start+length):
sn.logPrint(f"{channels[i]:9} | {times[i]:.1f}")

print("end")
sn.logPrint("end")
2 changes: 1 addition & 1 deletion demos/Demo_TimeTrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

if(__name__ == "__main__"):

sn = snAPI(libType=LibType.PH330)
sn = snAPI()
sn.getDevice()

# alternatively read data from file
Expand Down
4 changes: 2 additions & 2 deletions demos/Demo_TimeTrace_Coincidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

if(__name__ == "__main__"):

sn = snAPI(libType=LibType.HH)
sn = snAPI()
sn.getDevice()
sn.getFileDevice("C:\Data\PicoQuant\default_109.ptu")
#sn.getFileDevice("C:\Data\PicoQuant\default.ptu")

# alternatively read data from file
sn.setLogLevel(LogLevel.DataFile, True)
Expand Down
Loading

0 comments on commit c4f4fa8

Please sign in to comment.