pyTelops 0.2.3__tar.gz → 0.2.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. {pytelops-0.2.3 → pytelops-0.2.4}/AGENTS.md +1 -1
  2. {pytelops-0.2.3 → pytelops-0.2.4}/PKG-INFO +2 -2
  3. {pytelops-0.2.3 → pytelops-0.2.4}/README.rst +92 -3
  4. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/camera.rst +16 -0
  5. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/changelog.rst +81 -0
  6. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/conf.py +1 -1
  7. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/examples.rst +10 -1
  8. pytelops-0.2.4/docs/source/streaming_and_buffer.rst +441 -0
  9. {pytelops-0.2.3 → pytelops-0.2.4}/examples/03_buffer_record.py +2 -0
  10. {pytelops-0.2.3 → pytelops-0.2.4}/examples/05_external_trigger.py +10 -0
  11. pytelops-0.2.4/examples/08_pretrigger_software_moi.py +127 -0
  12. {pytelops-0.2.3 → pytelops-0.2.4}/examples/README.rst +2 -0
  13. {pytelops-0.2.3 → pytelops-0.2.4}/pyTelops/__init__.py +15 -1
  14. {pytelops-0.2.3 → pytelops-0.2.4}/pyTelops/camera.py +765 -63
  15. pytelops-0.2.4/pyTelops/header.py +483 -0
  16. {pytelops-0.2.3 → pytelops-0.2.4}/pyproject.toml +1 -1
  17. {pytelops-0.2.3 → pytelops-0.2.4}/tests/test_camera.py +709 -1
  18. {pytelops-0.2.3 → pytelops-0.2.4}/tests/test_hardware.py +64 -4
  19. pytelops-0.2.4/tests/test_header.py +352 -0
  20. pytelops-0.2.3/docs/source/streaming_and_buffer.rst +0 -237
  21. {pytelops-0.2.3 → pytelops-0.2.4}/.gitignore +0 -0
  22. {pytelops-0.2.3 → pytelops-0.2.4}/CONTRIBUTING.rst +0 -0
  23. {pytelops-0.2.3 → pytelops-0.2.4}/LICENSE +0 -0
  24. {pytelops-0.2.3 → pytelops-0.2.4}/PYPI_README.rst +0 -0
  25. {pytelops-0.2.3 → pytelops-0.2.4}/docs/requirements.txt +0 -0
  26. {pytelops-0.2.3 → pytelops-0.2.4}/docs/rtd_postbuild.py +0 -0
  27. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/_static/.gitkeep +0 -0
  28. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/_static/ai-buttons.css +0 -0
  29. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/_static/ai-buttons.js +0 -0
  30. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/_static/logo.png +0 -0
  31. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/calibration.rst +0 -0
  32. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/getting_started.rst +0 -0
  33. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/index.rst +0 -0
  34. {pytelops-0.2.3 → pytelops-0.2.4}/docs/source/troubleshooting.rst +0 -0
  35. {pytelops-0.2.3 → pytelops-0.2.4}/examples/01_connect_and_grab.py +0 -0
  36. {pytelops-0.2.3 → pytelops-0.2.4}/examples/02_continuous_live.py +0 -0
  37. {pytelops-0.2.3 → pytelops-0.2.4}/examples/04_calibration_load.py +0 -0
  38. {pytelops-0.2.3 → pytelops-0.2.4}/examples/06_force_ip.py +0 -0
  39. {pytelops-0.2.3 → pytelops-0.2.4}/examples/07_robust_download.py +0 -0
  40. {pytelops-0.2.3 → pytelops-0.2.4}/pyTelops/cli.py +0 -0
  41. {pytelops-0.2.3 → pytelops-0.2.4}/pyTelops/connection.py +0 -0
  42. {pytelops-0.2.3 → pytelops-0.2.4}/pyTelops/errors.py +0 -0
  43. {pytelops-0.2.3 → pytelops-0.2.4}/pyTelops/gui.py +0 -0
  44. {pytelops-0.2.3 → pytelops-0.2.4}/pyTelops/provisioning.py +0 -0
  45. {pytelops-0.2.3 → pytelops-0.2.4}/pyTelops/py.typed +0 -0
  46. {pytelops-0.2.3 → pytelops-0.2.4}/pyTelops/registers.py +0 -0
  47. {pytelops-0.2.3 → pytelops-0.2.4}/requirements.dev.txt +0 -0
  48. {pytelops-0.2.3 → pytelops-0.2.4}/requirements.txt +0 -0
  49. {pytelops-0.2.3 → pytelops-0.2.4}/sync_version.py +0 -0
  50. {pytelops-0.2.3 → pytelops-0.2.4}/tests/conftest.py +0 -0
  51. {pytelops-0.2.3 → pytelops-0.2.4}/tests/test_cli.py +0 -0
  52. {pytelops-0.2.3 → pytelops-0.2.4}/tests/test_connection.py +0 -0
  53. {pytelops-0.2.3 → pytelops-0.2.4}/tests/test_discovery_reachability.py +0 -0
  54. {pytelops-0.2.3 → pytelops-0.2.4}/tests/test_download_integrity.py +0 -0
  55. {pytelops-0.2.3 → pytelops-0.2.4}/tests/test_enum_resolution.py +0 -0
  56. {pytelops-0.2.3 → pytelops-0.2.4}/tests/test_registers.py +0 -0
@@ -71,7 +71,7 @@ hardware tests, or camera discovery fails. See troubleshooting.md.
71
71
  ```
72
72
  pyTelops/ driver package: camera.py, registers.py, cli.py, gui.py
73
73
  tests/ pytest suite (test_hardware.py is camera-gated)
74
- examples/ runnable scripts (01_connect_and_grab.py ... 07_robust_download.py)
74
+ examples/ runnable scripts (01_connect_and_grab.py ... 08_pretrigger_software_moi.py)
75
75
  docs/source/ Sphinx docs (RST source)
76
76
  ```
77
77
 
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: pyTelops
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Pure-Python driver for Telops thermal cameras over GigE Vision
5
5
  Project-URL: Homepage, https://github.com/ladisk/pyTelops
6
6
  Project-URL: Documentation, https://pytelops.readthedocs.io
@@ -272,7 +272,7 @@ slots before recording:
272
272
 
273
273
  ``buffer_record()`` prints progress::
274
274
 
275
- Arming (seq 1/3)... Recording... Done (10000 frames)
275
+ Arming (seq 1/3)... Waiting for ring buffer (2.0 s)... Recording... Done (10000 frames)
276
276
  Firing (seq 2/3)... Recording... Done (10000 frames)
277
277
  Firing (seq 3/3)... Recording... Done (10000 frames)
278
278
 
@@ -287,6 +287,88 @@ If a download finishes with missing frames, ``buffer_download()`` raises
287
287
  <https://pytelops.readthedocs.io/en/latest/streaming_and_buffer.html>`_ for
288
288
  tolerating drops and inspecting ``cam.last_download_stats``.
289
289
 
290
+ Pre-trigger recording (pre-MOI)
291
+ -------------------------------
292
+
293
+ The armed camera fills the buffer as a ring. The MOI (moment of interest)
294
+ marks the split: the ``pre_moi`` frames before it and the rest of the sequence
295
+ after it are kept. Fire the MOI at the event, not right after arming, or the
296
+ pre-trigger window holds fewer frames than configured.
297
+
298
+ The ring keeps nothing for the first 2.02 s after acquisition starts. A MOI
299
+ fired inside that window is latched, but the sequence then starts at the first
300
+ frame the ring could keep, so the pre-trigger part is truncated.
301
+ ``buffer_arm()`` therefore blocks until the ring holds the configured
302
+ ``pre_moi`` frames, about 2 s plus ``pre_moi / frame_rate``. Pass
303
+ ``wait_ready=False`` to return at once, and use ``buffer_ready_in()`` or
304
+ ``buffer_wait_ready()`` if you schedule the event yourself. This is measured
305
+ with a software MOI; the same is expected for an external trigger, so send the
306
+ trigger after ``buffer_arm()`` returns.
307
+
308
+ ``pre_moi`` can be as large as ``frames_per_seq``. The whole slot is then
309
+ pre-trigger and the MOI lands on its last frame, at index
310
+ ``frames_per_seq - 1``.
311
+
312
+ ``buffer_record()`` is a shortcut over ``buffer_arm()``, ``buffer_fire_moi()``
313
+ and ``buffer_wait()``, and takes the waiting step as ``wait_for``: a delay in
314
+ seconds, or a callable that returns at the event. Every variant waits for the
315
+ ring buffer first.
316
+
317
+ .. code-block:: python
318
+
319
+ cam.buffer_configure(frames_per_seq=400, pre_moi=100) # frames, not seconds
320
+
321
+ cam.buffer_record(wait_for=0.5) # 0.5 s after the ring is ready
322
+ cam.buffer_record(wait_for=lambda: my_event.wait())
323
+
324
+ # or drive the same flow yourself
325
+ cam.buffer_arm() # blocks about 2.1 s at 2000 fps
326
+ wait_for_my_event()
327
+ cam.buffer_fire_moi()
328
+ cam.buffer_wait(timeout=30.0)
329
+ data = cam.buffer_download()
330
+
331
+ With ``pre_moi > 0`` and no ``wait_for``, ``buffer_record()`` warns and fires
332
+ the MOI as soon as the ring is ready, because the split point is then set by a
333
+ timer and not by an event. Pass ``wait_for=0`` to silence the warning. See
334
+ ``examples/08_pretrigger_software_moi.py``.
335
+
336
+ Frame headers and timestamps
337
+ ----------------------------
338
+
339
+ Every frame carries a Telops header written by the camera at exposure time, so
340
+ its timestamp has no host-side delay. Call ``cam.sync_time()`` before recording
341
+ to put the camera clock on host time, then ask the download for the headers:
342
+
343
+ .. code-block:: python
344
+
345
+ cam.sync_time()
346
+ data, headers = cam.buffer_download(sequence=0, return_headers=True)
347
+
348
+ print(headers[0].datetime) # exposure time of the first frame, UTC
349
+ moi = cam.buffer_moi_index(0) # index of the moment of interest
350
+ if 0 <= moi < len(headers):
351
+ print(headers[moi].timestamp - headers[0].timestamp)
352
+
353
+ Entry ``i`` belongs to frame ``i`` of the array. For very large downloads use
354
+ ``header_timestamps(raw)`` on a raw download (``strip_header=False,
355
+ convert=False``) instead; it reads the same bytes without building an object
356
+ per frame.
357
+
358
+ ``sync_time()`` writes whole seconds, so absolute timestamps are good to about
359
+ 1 s. Differences between frames are exact. Sub-second alignment to the host
360
+ clock is not available from the driver yet: the camera sub-second register is
361
+ read-only, and ``cam.posix_time = ...`` also writes whole seconds only.
362
+
363
+ ``buffer_moi_index()`` is verified on the TS-IR: with the MOI fired after the
364
+ ring warm-up it equals the configured ``pre_moi``. It is the authority for the
365
+ split index. In the header timestamps the event sits about 7 to 8 ms later than
366
+ the host-side ``buffer_fire_moi()`` call, which is the GVCP command latency, so
367
+ do not derive the split from a host clock reading. The camera's MOI frame id
368
+ maps directly onto ``FrameHeader.frame_id``: in every campaign recording,
369
+ ``REG_MEMORY_BUFFER_SEQ_FIRST_FRAME_ID`` equalled ``headers[0].frame_id``, so
370
+ ``headers[buffer_moi_index()].frame_id`` equals ``buffer_moi_frame_id()``.
371
+
290
372
  External trigger
291
373
  ----------------
292
374
 
@@ -301,15 +383,22 @@ For triggered recording from an external BNC signal:
301
383
  pre_moi=1000,
302
384
  moi_source="external")
303
385
 
304
- cam.buffer_arm() # arm and wait for trigger
386
+ cam.buffer_arm() # blocks until the ring is ready
305
387
  cam.buffer_wait(timeout=60.0) # blocks until recording completes
306
388
  data = cam.buffer_download()
307
389
 
390
+ Send the trigger after ``buffer_arm()`` returns. An edge that arrives during
391
+ the ring warm-up is expected to behave like an early software MOI, that is
392
+ latched with a truncated pre-trigger part, but only the software MOI has been
393
+ measured. Check ``cam.buffer_moi_index(0)`` against the configured ``pre_moi``
394
+ afterwards.
395
+
308
396
  For manual control with software MOI (instead of ``buffer_record()``):
309
397
 
310
398
  .. code-block:: python
311
399
 
312
- cam.buffer_arm() # arm the buffer
400
+ cam.buffer_arm() # arm the buffer, wait for the ring
401
+ wait_for_my_event() # returns at the moment of interest
313
402
  cam.buffer_fire_moi() # software MOI trigger
314
403
  cam.buffer_wait(timeout=30.0) # wait for recording to finish
315
404
  data = cam.buffer_download()
@@ -32,6 +32,22 @@ Errors and results
32
32
  .. autoexception:: FrameIntegrityError
33
33
  :members:
34
34
 
35
+ Frame headers
36
+ -------------
37
+
38
+ .. autoclass:: FrameHeader
39
+ :members:
40
+
41
+ .. autoclass:: BufferingFlag
42
+
43
+ .. autofunction:: parse_header
44
+
45
+ .. autofunction:: parse_headers
46
+
47
+ .. autofunction:: header_timestamps
48
+
49
+ .. autofunction:: header_frame_ids
50
+
35
51
  Enumerations
36
52
  ------------
37
53
 
@@ -1,6 +1,87 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ Version 0.2.4
5
+ -------------
6
+
7
+ - **Pre-trigger recordings now keep the frames they were asked for.** The
8
+ camera's ring buffer keeps nothing for the first 2.02 s after acquisition
9
+ starts (measured on a TS-IR, the same at 250 and 1000 fps). A MOI fired
10
+ inside that window is latched, and the sequence then starts at the first
11
+ frame the ring could keep, so the pre-trigger part came out truncated or
12
+ empty. The driver now holds the MOI back until the ring can hold the
13
+ configured ``pre_moi`` frames: ``Camera.BUFFER_RING_WARMUP_S`` (2.05 s)
14
+ plus ``pre_moi / frame_rate`` after arming.
15
+ - ``buffer_arm()`` blocks until the ring buffer is ready, so about 2 s plus
16
+ ``pre_moi / frame_rate``. Pass ``wait_ready=False`` for the old immediate
17
+ return.
18
+ - ``buffer_record()`` and ``buffer_arm()`` now take about 1.5 s longer than in
19
+ 0.2.3 even with ``pre_moi=0``, because the ring dead time applies to the
20
+ sequence start as well.
21
+ - New ``buffer_ready_in()`` (seconds left of the ring warm-up, 0 when ready)
22
+ and ``buffer_wait_ready()`` (sleep that long), for callers that schedule the
23
+ event themselves.
24
+ - ``buffer_fire_moi()`` warns when it is called before the ring is ready, and
25
+ says how many pre-trigger frames the camera will actually keep. It reads no
26
+ registers, so the event path is a single register write.
27
+ - ``buffer_fire_moi()`` raises ``RuntimeError`` when ``buffer_arm()`` was not
28
+ called first. The camera rejects the write while it is not acquiring, so the
29
+ old silent write did nothing.
30
+ - ``buffer_arm()`` and ``buffer_record()`` write ``ACQUISITION_STOP`` before
31
+ ``ACQUISITION_ARM``, and raise ``RuntimeError`` if the buffer still reads
32
+ RECORDING 5 s later. The stop write is unconditional, so an unreadable status
33
+ register no longer lets the guard pass. Arming during a recording aborts it:
34
+ the status drops to IDLE, the recorded count stays 0 and the sequence counter
35
+ sticks at 0 until ``buffer_clear()``.
36
+ - ``buffer_configure()`` warns when ``moi_source="acquisition_started"`` is
37
+ combined with ``pre_moi > 0``. That MOI fires inside the ring dead time, so
38
+ the pre-trigger window is always empty.
39
+ - Verified on hardware (TS-IR, header 12.7): with the MOI fired after the ring
40
+ warm-up, ``buffer_moi_index()`` equals the configured ``pre_moi``, for every
41
+ sequence of a three-sequence recording at 1000 and 2000 fps. Frame ids are
42
+ contiguous and ``buffering_flag`` is ``None``, as expected below header 12.9.
43
+ In the header timestamps the event sits about 7 to 8 ms after the host-side
44
+ ``buffer_fire_moi()`` call, which is the GVCP command latency, so the MOI
45
+ register is the authority for the split index.
46
+ - ``buffer_record()`` takes a keyword-only ``wait_for``: a delay in seconds or
47
+ a zero-argument callable that returns at the moment of interest. It runs once
48
+ per sequence, after the ring buffer is ready and before the software MOI is
49
+ fired, so a ``pre_moi`` window can be placed around a real event instead of
50
+ around the arming call. Previously the MOI fired about 0.5 s after arming for
51
+ the first sequence and immediately for the following ones.
52
+ - ``buffer_record()`` warns when ``pre_moi > 0`` and no ``wait_for`` is given,
53
+ since the split point is then set by a timer and not by an event. It fires
54
+ the MOI as soon as the ring is ready. Pass ``wait_for=0`` to fire there
55
+ without the warning.
56
+ - ``buffer_record()`` raises ``ValueError`` when the configured ``moi_source``
57
+ is not ``"software"``, pointing at ``buffer_arm()`` and ``buffer_wait()``,
58
+ and it now stops acquisition on any exception, so Ctrl-C during a wait no
59
+ longer leaves the camera armed.
60
+ - ``buffer_configure()`` rejects a negative ``pre_moi`` or one larger than the
61
+ frames per sequence.
62
+ - New example ``examples/08_pretrigger_software_moi.py``: pre-trigger recording
63
+ with a software MOI, through the manual flow and through
64
+ ``buffer_record(wait_for=...)``.
65
+
66
+ - New module ``pyTelops.header`` parses the 256-byte Telops header every frame
67
+ carries in its two metadata rows: ``FrameHeader``, ``parse_header()``,
68
+ ``parse_headers()`` and the ``BufferingFlag`` enum. The camera writes the
69
+ header at exposure time, so the timestamp in it has no host-side delay. The
70
+ buffering flag exists only from header version 12.9 on and reads as ``None``
71
+ below that.
72
+ - ``header_timestamps()`` and ``header_frame_ids()`` read the same fields off a
73
+ raw frame stack with numpy views, for downloads too large to build one object
74
+ per frame.
75
+ - ``buffer_download()`` takes ``return_headers=True`` and then returns
76
+ ``(data, headers)``, one header per frame of the array. The headers are parsed
77
+ before calibration and header stripping. A frame whose header does not parse
78
+ gives ``None``, and a single warning reports how many. The paths that return
79
+ no data return ``(None, [])``.
80
+ - New ``buffer_moi_frame_id()`` and ``buffer_moi_index()`` report where the
81
+ moment of interest sits in a recorded sequence. ``buffer_moi_index()`` is the
82
+ index of the MOI frame in a full download and equals the configured
83
+ ``pre_moi``.
84
+
4
85
  Version 0.2.3
5
86
  -------------
6
87
 
@@ -10,7 +10,7 @@ sys.path.insert(0, os.path.abspath("../.."))
10
10
  project = "pyTelops"
11
11
  author = "Jaša Šonc, Janko Slavič"
12
12
  copyright = "2026, Jaša Šonc and Ladisk group, University of Ljubljana"
13
- release = "0.2.3"
13
+ release = "0.2.4"
14
14
  # -- General configuration ---------------------------------------------------
15
15
  extensions = [
16
16
  "sphinx.ext.autodoc",
@@ -1,7 +1,7 @@
1
1
  Examples
2
2
  ========
3
3
 
4
- Seven runnable scripts ship in the ``examples/`` directory. Each needs a
4
+ Eight runnable scripts ship in the ``examples/`` directory. Each needs a
5
5
  connected Telops camera.
6
6
 
7
7
  01_connect_and_grab.py
@@ -47,3 +47,12 @@ See :doc:`troubleshooting`.
47
47
  Record a sequence, tune the link with :func:`~pyTelops.tune_connection`, then
48
48
  download with integrity checking and inspect
49
49
  :attr:`~pyTelops.Camera.last_download_stats`. See :doc:`streaming_and_buffer`.
50
+
51
+ 08_pretrigger_software_moi.py
52
+ -----------------------------
53
+
54
+ Keep frames from before an event with a software MOI. Shows the manual flow
55
+ (:meth:`~pyTelops.Camera.buffer_arm`, wait for the event,
56
+ :meth:`~pyTelops.Camera.buffer_fire_moi`, :meth:`~pyTelops.Camera.buffer_wait`)
57
+ and the same recording through ``buffer_record(wait_for=...)``. See
58
+ :doc:`streaming_and_buffer`.