Skip to content

Commit

Permalink
rework FCS
Browse files Browse the repository at this point in the history
small changes to g(2) too
small PTU fixes
fix timetrace if historySize is set before numBins
  • Loading branch information
tpoint75 committed Jul 5, 2023
1 parent 2b2d1ac commit c7b81db
Show file tree
Hide file tree
Showing 37 changed files with 115 additions and 52 deletions.
11 changes: 7 additions & 4 deletions demos/GetCorrelationFCS.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
sn.getDeviceIDs()
sn.getDevice()
#sn.getFileDevice(r"E:\Data\PicoQuant\CW_Shelved.ptu")
sn.initDevice(MeasMode.T2)
#sn.getFileDevice(r"e:\Data\PicoQuant\cell01_55pct_1.ptu")
#sn.getFileDevice(r"e:\Data\PicoQuant\Correaltion_T3.ptu")
#sn.getFileDevice(r"e:\Data\PicoQuant\OpenCLTest\Atto655+Cy5_diff_FCS+FLCS_Conv.ptu")
sn.initDevice(MeasMode.T3)
#sn.device.setInputDeadTime(-1,1000)
sn.correlation.setFCSparameters(1, 2, 20, 8)
sn.correlation.measure(100000)
sn.correlation.setFCSparameters(1, 2, 1e4, 5)
sn.correlation.measure(10000,savePTU=True)

while True:
finished = sn.correlation.isFinished()
Expand All @@ -32,7 +35,7 @@
plt.title("FCS")
plt.pause(0.1)

sn.correlation.clearMeasure()
#sn.correlation.clearMeasure()

if finished:
break
Expand Down
23 changes: 13 additions & 10 deletions demos/GetCorrelationG2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@
if(__name__ == "__main__"):

sn = snAPI()
sn.getDevice()
#sn.getFileDevice(r"E:\Data\PicoQuant\CW_Shelved.ptu")
#sn.getFileDevice(r"E:\Data\PicoQuant\PMT-cw-1MHz.ptu")
#sn.getFileDevice(r"E:\Data\PicoQuant\HH400-PMT-cw-1MHz.ptu")
#sn.getDevice()
sn.getFileDevice(r"E:\Data\PicoQuant\CW_Shelved.ptu")
#sn.getFileDevice(r"e:\Data\PicoQuant\cell01_55pct_1.ptu")
#sn.getFileDevice(r"e:\Data\PicoQuant\Correaltion_T3.ptu")
#sn.getFileDevice(r"e:\Data\PicoQuant\Datasets Metrologia 56 025004\Metrologia_g2_SPS1550_INRIM-PTB-NPL\20171023_INRIM-NPL\acq_NPL\g2_1550nm_NPL\acq002_001.ptu")
sn.initDevice(MeasMode.T2)
#sn.device.setInputDeadTime(-1,1000)

# set filter window to 1ns
sn.filter.setRowParams(0, 1000, 1, False, [0,1], [])
sn.filter.enableRow(0,True)
#sn.filter.setRowParams(0, 1000, 1, False, [0,1], [])
#sn.filter.enableRow(0,True)
#sn.manipulators.coincidence([1,2], 200000)

sn.correlation.setG2parameters(1, 2, 1000, 5)
sn.correlation.measure(100000)
#sn.setPTUFilePath("test.ptu")
sn.correlation.setG2parameters(1, 2, 200000, 200)
sn.correlation.measure(10000,savePTU=True)

plt.ion()
while True:
Expand All @@ -36,9 +39,9 @@
plt.legend()
plt.title("g(2)")
plt.pause(0.1)
sn.correlation.clearMeasure()
#sn.correlation.clearMeasure()

if sn.correlation.isFinished():
break

plt.show(block=True)
plt.show(block=True)
44 changes: 44 additions & 0 deletions demos/GetHistogramHerald.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
"""
Spyder Editor
"""




import time
import numpy as np
import matplotlib.pyplot as plt
from snAPI.Main import snAPI, MeasMode

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

# Time Gating
GateStart = 36300
GateWidth = 3450
ch = sn.manipulators.herald(0, [1,2], GateStart, GateWidth, True)

# Measure
tic = time.time()
sn.histogram.measure(2000, waitFinished=True, savePTU=False)
print(time.time()-tic)

# Plot
data, bins = sn.histogram.getData()
print(data.shape, bins.shape)

plt.figure()
plt.plot(bins*1e-3, data[0])
plt.plot(bins*1e-3, data[1])
plt.plot(bins*1e-3, data[2])
plt.plot(bins*1e-3, data[ch[0]])
plt.plot(bins*1e-3, data[ch[1]])
plt.show()





6 changes: 3 additions & 3 deletions demos/RecordViewerRaw.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

sn = snAPI()
sn.getDevice()
#sn.getFileDevice(r"E:\Data\PicoQuant\HH400-PMT-cw-1MHz.ptu")
sn.getFileDevice(r"E:\Data\PicoQuant\cell01_55pct_1.ptu")
sn.initDevice(MeasMode.T2)
sn.raw.measure(1000,1024*1024*1024, True, True)
sn.raw.measure(100,1024*1024*1024, True, False)
data = sn.raw.getData(25)
sn.logPrint("from raw data")
sn.logPrint("channel | timetag")
sn.logPrint("channel | timetag")
sn.logPrint("-------------------")
for i in range(25):
time = sn.raw.timeTag_T2(data[i])
Expand Down
9 changes: 5 additions & 4 deletions demos/RecordViewerUF.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

sn = snAPI()
sn.getDevice()
sn.getFileDevice(r"E:\Data\PicoQuant\11_1.ptu")
sn.getFileDevice(r"E:\Data\PicoQuant\MH160_Sun.ptu")
sn.initDevice(MeasMode.T2)
sn.unfold.measure(1000,1024*1024*1024, True, True)

sn.unfold.measure(1000,1024*1024*1024, True, False)
times, channels = sn.unfold.getData()
sn.logPrint("from unfold data")
sn.logPrint("channel | timetag")
sn.logPrint("channel | timetag")
sn.logPrint("-------------------")
for i in range(1000):
for i in range(100):
sn.logPrint(f"{channels[i]:9} | {times[i]:7}")
Binary file removed dist/snAPI-0.2.4-cp311-cp311-win_amd64.whl
Binary file not shown.
Binary file removed dist/snAPI-0.2.4.tar.gz
Binary file not shown.
Binary file added dist/snAPI-0.2.5-cp311-cp311-win_amd64.whl
Binary file not shown.
Binary file added dist/snAPI-0.2.5.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions docs/snAPI.Main.html
Original file line number Diff line number Diff line change
Expand Up @@ -3351,7 +3351,7 @@ <h2>Info<a class="headerlink" href="#info" title="Permalink to this heading">#</
<p>sample of a g(2) <cite>Correlation</cite> measurement drawn with matplotlib</p>
<dl class="py method">
<dt class="sig sig-object py" id="snAPI_Main_Correlation_setG2parameters">
<span class="sig-name descname"><span class="pre">setG2parameters</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">startChannel</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clickChannel</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numBins</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">binWidth</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#snAPI_Main_Correlation_setG2parameters" title="Permalink to this definition">#</a></dt>
<span class="sig-name descname"><span class="pre">setG2parameters</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">startChannel</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clickChannel</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">windowSize</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">binWidth</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#snAPI_Main_Correlation_setG2parameters" title="Permalink to this definition">#</a></dt>
<dd><p>This function sets the the parameters for the g(2) correlation. If the startChannel is the same as the
clickChannel an autocorrelation is calculated and if the channels are different a
cross calculation is calculated.</p>
Expand All @@ -3369,7 +3369,7 @@ <h2>Info<a class="headerlink" href="#info" title="Permalink to this heading">#</
<dd class="field-odd"><ul class="simple">
<li><p><strong>startChannel</strong> (<em>int</em><em> (</em><em>0 is sync channel</em><em>)</em>) – start channel</p></li>
<li><p><strong>clickChannel</strong> (<em>int</em><em> (</em><em>0 is sync channel</em><em>)</em>) – click channel</p></li>
<li><p><strong>numBins</strong> (<em>int</em><em> (</em><em>default: 10000</em><em>)</em>) – number of bins</p></li>
<li><p><strong>windowSize</strong> (<em>int</em><em> [</em><em>ps</em><em>]</em>) – size of the correlation window</p></li>
<li><p><strong>binWidth</strong> (<em>int</em><em> [</em><em>ps</em><em>]</em>) – width of bins</p></li>
</ul>
</dd>
Expand All @@ -3378,15 +3378,15 @@ <h2>Info<a class="headerlink" href="#info" title="Permalink to this heading">#</
</dd>
</dl>
<p class="rubric">Example</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># sets thew number of bins to 10000</span>
<span class="n">sn</span><span class="o">.</span><span class="n">correlation</span><span class="o">.</span><span class="n">setG2parameters</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span> <span class="p">,</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">200</span><span class="p">)</span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># sets the window size to 5000ps with a bin width of 5ps (that means 1000 bins will be calculated)</span>
<span class="n">sn</span><span class="o">.</span><span class="n">correlation</span><span class="o">.</span><span class="n">setG2parameters</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span> <span class="p">,</span> <span class="mi">5000</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="snAPI_Main_Correlation_setFCSparameters">
<span class="sig-name descname"><span class="pre">setFCSparameters</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">startChannel</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clickChannel</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">numIntervals</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">10</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">intervalLength</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">8</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#snAPI_Main_Correlation_setFCSparameters" title="Permalink to this definition">#</a></dt>
<span class="sig-name descname"><span class="pre">setFCSparameters</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">startChannel</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">clickChannel</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">windowSize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1000000000000.0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">startTime</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#snAPI_Main_Correlation_setFCSparameters" title="Permalink to this definition">#</a></dt>
<dd><p>This function sets the the parameters for the FCS correlation. If the startChannel is the same as the
clickChannel an autocorrelation is calculated and if the channels are different a
cross calculation is calculated.</p>
Expand All @@ -3409,17 +3409,17 @@ <h2>Info<a class="headerlink" href="#info" title="Permalink to this heading">#</
<dd class="field-odd"><ul class="simple">
<li><p><strong>startChannel</strong> (<em>int</em><em> (</em><em>0 is sync channel</em><em>)</em>) – start channel</p></li>
<li><p><strong>clickChannel</strong> (<em>int</em><em> (</em><em>0 is sync channel</em><em>)</em>) – click channel</p></li>
<li><p><strong>numIntervals</strong> (<em>int</em><em> (</em><em>default: 10</em><em>)</em>) – number of intervals</p></li>
<li><p><strong>intervalLength</strong> (<em>int</em><em> (</em><em>default: 8</em><em>)</em>) – num of bins</p></li>
<li><p><strong>windowSize</strong> (<em>int</em><em> [</em><em>ps</em><em>]</em>) – size of the correlation window</p></li>
<li><p><strong>startTime</strong> (<em>int</em><em> [</em><em>ps</em><em>]</em>) – width of bins None: T2: BaseResolution, T3: Resolution</p></li>
</ul>
</dd>
<dt class="field-even">Return type<span class="colon">:</span></dt>
<dd class="field-even"><p>none</p>
</dd>
</dl>
<p class="rubric">Example</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># sets thew number of bins to 10000</span>
<span class="n">sn</span><span class="o">.</span><span class="n">correlation</span><span class="o">.</span><span class="n">setG2parameters</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span> <span class="p">,</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">200</span><span class="p">)</span>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># sets the window size to 1s with a startTime of 50000ps</span>
<span class="n">sn</span><span class="o">.</span><span class="n">correlation</span><span class="o">.</span><span class="n">setG2parameters</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span> <span class="p">,</span> <span class="mf">1e12</span><span class="p">,</span> <span class="mf">5e4</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
Expand Down
54 changes: 33 additions & 21 deletions snAPI/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3459,7 +3459,7 @@ def __init__(self, parent):
self.finished = ct.pointer(ct.c_bool(False))


def setG2parameters(self, startChannel: int, clickChannel: int, numBins: int, binWidth: int):
def setG2parameters(self, startChannel: int, clickChannel: int, windowSize: float, binWidth: float):
"""
This function sets the the parameters for the g(2) correlation. If the startChannel is the same as the
clickChannel an autocorrelation is calculated and if the channels are different a
Expand All @@ -3484,8 +3484,8 @@ def setG2parameters(self, startChannel: int, clickChannel: int, numBins: int, bi
start channel
clickChannel: int (0 is sync channel)
click channel
numBins: int (default: 10000)
number of bins
windowSize: int [ps]
size of the correlation window
binWidth: int [ps]
width of bins
Expand All @@ -3497,21 +3497,22 @@ def setG2parameters(self, startChannel: int, clickChannel: int, numBins: int, bi
-------
::
# sets thew number of bins to 10000
sn.correlation.setG2parameters(1, 2 ,1000, 200)
# sets the window size to 5000ps with a bin width of 5ps (that means 1000 bins will be calculated)
sn.correlation.setG2parameters(1, 2 , 5000, 5)
"""
self.startChannel = startChannel
self.clickChannel = clickChannel
self.numIntervals = 1
self.intervalLength = numBins
self.windowSize = windowSize
self.binWidth = binWidth
self.intervalLength = int(windowSize / binWidth)
self.isFcs = False

self.parent.dll.setCorrelationParams(startChannel, clickChannel, False, 1, numBins, binWidth)
self.parent.dll.setG2Params.argtypes = [ct.c_int, ct.c_int, ct.c_double, ct.c_double]
self.parent.dll.setG2Params(startChannel, clickChannel, windowSize, binWidth)


def setFCSparameters(self, startChannel: int, clickChannel: int, numIntervals: typing.Optional[int] = 10, intervalLength: typing.Optional[int] = 8):
def setFCSparameters(self, startChannel: int, clickChannel: int, windowSize: typing.Optional[float] = 1e12, startTime: typing.Optional[int] = None):
"""
This function sets the the parameters for the FCS correlation. If the startChannel is the same as the
clickChannel an autocorrelation is calculated and if the channels are different a
Expand Down Expand Up @@ -3541,10 +3542,10 @@ def setFCSparameters(self, startChannel: int, clickChannel: int, numIntervals: t
start channel
clickChannel: int (0 is sync channel)
click channel
numIntervals: int (default: 10)
number of intervals
intervalLength: int (default: 8)
num of bins
windowSize: int [ps]
size of the correlation window
startTime: int [ps]
width of bins None: T2: BaseResolution, T3: Resolution
Returns
-------
Expand All @@ -3554,18 +3555,29 @@ def setFCSparameters(self, startChannel: int, clickChannel: int, numIntervals: t
-------
::
# sets thew number of bins to 10000
sn.correlation.setG2parameters(1, 2 ,1000, 200)
# sets the window size to 1s with a startTime of 50000ps
sn.correlation.setG2parameters(1, 2 , 1e12, 5e4)
"""
if startTime is None:
if self.parent.deviceConfig["MeasMode"] == MeasMode.T2.value:
startTime = self.parent.deviceConfig["BaseResolution"]
elif self.parent.deviceConfig["MeasMode"] == MeasMode.T3.value:
startTime = self.parent.deviceConfig["Resolution"]

self.startChannel = startChannel
self.clickChannel = clickChannel
self.numIntervals = numIntervals
self.intervalLength = intervalLength
self.isFcs = intervalLength
self.windowSize = windowSize
self.startTime = startTime
self.isFcs = True
pNumIntervals = ct.pointer(ct.c_int(0))
pIntervalLength = ct.pointer(ct.c_int(0))

self.parent.dll.setFCSParams.argtypes = [ct.c_int, ct.c_int, ct.POINTER(ct.c_int), ct.POINTER(ct.c_int), ct.c_double, ct.c_double]
self.parent.dll.setFCSParams(startChannel, clickChannel, pNumIntervals, pIntervalLength, windowSize, startTime)
self.numIntervals = pNumIntervals.contents.value
self.intervalLength = pIntervalLength.contents.value

self.parent.dll.setCorrelationParams(startChannel, clickChannel, True, numIntervals, intervalLength, 0)


def measure(self, acqTime: typing.Optional[int] = 1000, waitFinished: typing.Optional[bool] = False, savePTU: typing.Optional[bool] = False):
"""
Expand Down Expand Up @@ -3724,7 +3736,7 @@ def getFCSdata(self):
"""
return np.lib.stride_tricks.as_strided(self.data, shape=(2, self.numBins),
strides=(ct.sizeof(self.data._type_) * self.numBins, ct.sizeof(self.data._type_))), self.bins
strides=(ct.sizeof(self.data._type_) * self.numBins, ct.sizeof(self.data._type_)))[:, 4:], self.bins[4:]


def stopMeasure(self):
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed snAPI/__pycache__/Constants.cpython-311.pyc
Binary file not shown.
Binary file removed snAPI/__pycache__/Main.cpython-311.pyc
Binary file not shown.
Binary file removed snAPI/__pycache__/Utils.cpython-311.pyc
Binary file not shown.
Binary file removed snAPI/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file modified snAPI/snAPI64.dll
Binary file not shown.

0 comments on commit c7b81db

Please sign in to comment.