mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-05 17:40:40 +02:00
added python examples in source
This commit is contained in:
parent
c4fde7f7bc
commit
9b26f5a6c8
@ -74,34 +74,38 @@ But lets start looking at the at the manual way:
|
|||||||
::
|
::
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from slsdet import Eiger, runStatus
|
from slsdet import Detector, runStatus
|
||||||
d = Eiger()
|
|
||||||
|
|
||||||
n = 10
|
|
||||||
t = 1
|
|
||||||
|
|
||||||
d.exptime = t
|
|
||||||
d.frames = n
|
|
||||||
|
|
||||||
|
|
||||||
#Start the measurement
|
n_frames = 10
|
||||||
|
t_exp = 1
|
||||||
|
|
||||||
|
# Set exposure time and number of frames
|
||||||
|
d = Detector()
|
||||||
|
d.exptime = t_exp
|
||||||
|
d.frames = n_frames
|
||||||
|
|
||||||
|
# Start the measurement
|
||||||
t0 = time.time()
|
t0 = time.time()
|
||||||
d.startDetector()
|
d.startDetector()
|
||||||
d.startReceiver()
|
d.startReceiver()
|
||||||
|
|
||||||
#Wait for the detector to be ready or do other important stuff
|
# Wait for the detector to be ready or do other important stuff
|
||||||
time.sleep(t*n)
|
time.sleep(t_exp * n_frames)
|
||||||
|
|
||||||
#check if the detector is ready otherwise wait a bit longer
|
# check if the detector is ready otherwise wait a bit longer
|
||||||
while d.status != runStatus.IDLE:
|
while d.status != runStatus.IDLE:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
#Stop the receiver after we got the frames
|
# Stop the receiver after we got the frames
|
||||||
#Detector is already idle so we don't need to stop it
|
# Detector is already idle so we don't need to stop it
|
||||||
d.stopReceiver()
|
d.stopReceiver()
|
||||||
|
|
||||||
lost = d.rx_framescaught - n
|
lost = d.rx_framescaught - n_frames
|
||||||
print(f'{n} frames of {t}s took {time.time()-t0:{.3}}s with {lost} frames lost ')
|
print(
|
||||||
|
f"{n_frames} frames of {t_exp}s took {time.time()-t0:{.3}}s with {lost} frames lost "
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Instead launching d.acq() from a different process is a bit easier since the control of receiver and detector
|
Instead launching d.acq() from a different process is a bit easier since the control of receiver and detector
|
||||||
@ -112,29 +116,21 @@ hang around until the main process exits.
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
from slsdet import Eiger
|
from slsdet import Detector, runStatus
|
||||||
|
|
||||||
def acquire():
|
|
||||||
"""
|
|
||||||
Create a new Eiger object that still referes to the same actual detector
|
|
||||||
and same shared memory. Then launch acq.
|
|
||||||
"""
|
|
||||||
detector = Eiger()
|
|
||||||
detector.acq()
|
|
||||||
|
|
||||||
#This is the detector we use throughout the session
|
d = Detector()
|
||||||
d = Eiger()
|
|
||||||
|
|
||||||
#Process to run acquire
|
#Create a separate process to run acquire in
|
||||||
p = Process(target=acquire)
|
p = Process(target=d.acquire)
|
||||||
|
|
||||||
#Start the thread and short sleep to allow the acq to start
|
#Start the thread and short sleep to allow the acq to start
|
||||||
p.start()
|
p.start()
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
|
||||||
#Do some other work
|
#Do some other work
|
||||||
while d.busy is True:
|
while d.status != runStatus.IDLE:
|
||||||
print(d.busy)
|
print("Working")
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
#Join the process
|
#Join the process
|
||||||
|
21
python/examples/non-blocking-acquire-process.py
Normal file
21
python/examples/non-blocking-acquire-process.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import time
|
||||||
|
from multiprocessing import Process
|
||||||
|
from slsdet import Detector, runStatus
|
||||||
|
|
||||||
|
|
||||||
|
d = Detector()
|
||||||
|
|
||||||
|
#Create a separate process to run acquire in
|
||||||
|
p = Process(target=d.acquire)
|
||||||
|
|
||||||
|
#Start the thread and short sleep to allow the acq to start
|
||||||
|
p.start()
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
|
#Do some other work
|
||||||
|
while d.status != runStatus.IDLE:
|
||||||
|
print("Working")
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
#Join the process
|
||||||
|
p.join()
|
33
python/examples/non-blocking-acquire.py
Normal file
33
python/examples/non-blocking-acquire.py
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import time
|
||||||
|
from slsdet import Detector, runStatus
|
||||||
|
|
||||||
|
|
||||||
|
n_frames = 10
|
||||||
|
t_exp = 1
|
||||||
|
|
||||||
|
# Set exposure time and number of frames
|
||||||
|
d = Detector()
|
||||||
|
d.exptime = t_exp
|
||||||
|
d.frames = n_frames
|
||||||
|
|
||||||
|
# Start the measurement
|
||||||
|
t0 = time.time()
|
||||||
|
d.startDetector()
|
||||||
|
d.startReceiver()
|
||||||
|
|
||||||
|
# Wait for the detector to be ready or do other important stuff
|
||||||
|
time.sleep(t_exp * n_frames)
|
||||||
|
|
||||||
|
# check if the detector is ready otherwise wait a bit longer
|
||||||
|
while d.status != runStatus.IDLE:
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
# Stop the receiver after we got the frames
|
||||||
|
# Detector is already idle so we don't need to stop it
|
||||||
|
d.stopReceiver()
|
||||||
|
|
||||||
|
lost = d.rx_framescaught - n_frames
|
||||||
|
print(
|
||||||
|
f"{n_frames} frames of {t_exp}s took {time.time()-t0:{.3}}s with {lost} frames lost "
|
||||||
|
)
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user