moved pulse ID treatment into separate file

This commit is contained in:
2024-03-30 17:27:26 +01:00
parent 5b465c635c
commit 2eafdba7b3
2 changed files with 31 additions and 29 deletions
+1 -29
View File
@@ -10,6 +10,7 @@ from slic.utils import xrange, tqdm_mod, tqdm_sleep
from slic.utils import json_validate
from .brokerconfig import BrokerConfig, flatten_detectors
from .pids import aligned_pid_and_n, align_pid_left, align_pid_right
from .tools import get_current_pulseid, get_endstation
@@ -296,35 +297,6 @@ class BrokerError(Exception):
def aligned_pid_and_n(start, n, rm):
start, stop = aligned_pids(start, n, rm)
return start, stop - start
def aligned_pids(start, n, rm):
"""
return start/stop pids aligned to rep rate
"""
# start -= 1 #TODO: count from zero?
block_start = (start // rm) + 1 # calc block where start is in, then take following block
block_stop = block_start + n
start = block_start * rm # adjust to actual rep rate (example: recording is at 100 Hz; for a 50 Hz device, 2*n pulses need to be recorded to get n pulses with that device)
stop = block_stop * rm #TODO: check whether upper boundary is excluded (otherwise -1 here)
return int(start), int(stop)
def align_pid_left(pid, rm):
return align_pid(pid, rm, 0)
def align_pid_right(pid, rm):
return align_pid(pid, rm, 1)
def align_pid(pid, rm, block_offset=0):
block = pid // rm
block += block_offset
return block * rm
def wait_for_files(label, fnames):
with yaspin(Spinners.clock, text=f"elapsed time: {label}", timer=True) as sp:
while True:
+30
View File
@@ -0,0 +1,30 @@
def aligned_pid_and_n(start, n, rm):
start, stop = aligned_pids(start, n, rm)
return start, stop - start
def aligned_pids(start, n, rm):
"""
return start/stop pids aligned to rep rate
"""
# start -= 1 #TODO: count from zero?
block_start = (start // rm) + 1 # calc block where start is in, then take following block
block_stop = block_start + n
start = block_start * rm # adjust to actual rep rate (example: recording is at 100 Hz; for a 50 Hz device, 2*n pulses need to be recorded to get n pulses with that device)
stop = block_stop * rm #TODO: check whether upper boundary is excluded (otherwise -1 here)
return int(start), int(stop)
def align_pid_left(pid, rm):
return align_pid(pid, rm, 0)
def align_pid_right(pid, rm):
return align_pid(pid, rm, 1)
def align_pid(pid, rm, block_offset=0):
block = pid // rm
block += block_offset
return block * rm