Skip to content

Multiple scan XY API Change#51

Open
CSSFrancis wants to merge 19 commits intodirectelectron:mainfrom
CSSFrancis:multiple-scans
Open

Multiple scan XY API Change#51
CSSFrancis wants to merge 19 commits intodirectelectron:mainfrom
CSSFrancis:multiple-scans

Conversation

@CSSFrancis
Copy link
Copy Markdown
Member

This pull request introduces several improvements and bug fixes to the deapi client and its test suite. The most significant changes are focused on enhancing the flexibility and robustness of scan pattern handling, improving test reliability and performance, and refining property and acquisition management. Below is a summary of the most important changes, grouped by theme.

Scan Pattern Handling and Client Improvements:

  • Enhanced set_xy_array in deapi/client.py to support lists of numpy arrays, handle both 2D and 3D input, ensure integer types, validate shapes, and correctly compute scan dimensions. This improves flexibility and error handling for scan pattern input.
  • Modified the property setter to convert boolean values to "On"/"Off" strings, ensuring consistent property value handling.
  • Changed the default pixel_format in get_result to "AUTO" for better compatibility.

Test Suite Reliability and Performance:

  • Updated test fixtures to use scope="session" for the client fixture, reducing setup/teardown overhead and improving test performance.
  • Removed unnecessary time.sleep calls and replaced them with more robust idle-waiting logic (e.g., wait_for_idle(client)), leading to more reliable and faster tests. [1] [2] [3]
  • Set up a consistent initial state in test fixtures and removed redundant property assignments from individual tests. [1] [2]

Test Coverage and Robustness:

  • Added additional property setting and validation in tests, such as explicitly setting hardware binning before testing software binning options, to ensure test correctness. [1] [2]
  • Updated scan and acquisition tests to use more appropriate parameter values and improved error handling for edge cases. [1] [2]

File Saving and Loading Tests:

  • Marked slow or unreliable tests with @pytest.mark.skip(reason="Slow and broken") to improve test suite reliability and focus on stable tests. [1] [2]
  • Moved import of libertem.api into the test function to avoid unnecessary imports and potential issues when the library is not available.

@CSSFrancis
Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

@CSSFrancis
Copy link
Copy Markdown
Member Author

pre-commit.ci autofix

@CSSFrancis CSSFrancis requested review from CoolFanyu and Copilot May 7, 2026 19:58
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 7, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 16.76892% with 407 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...api/tests/test_scanning/test_continual_scanning.py 13.86% 236 Missing ⚠️
deapi/client.py 9.82% 101 Missing ⚠️
deapi/simulated_server/fake_server.py 17.39% 38 Missing ⚠️
deapi/tests/test_utils/test_utils.py 16.66% 15 Missing ⚠️
deapi/tests/test_client.py 47.05% 9 Missing ⚠️
deapi/data_types.py 36.36% 7 Missing ⚠️
...sts/test_file_saving/test_file_loading_libertem.py 50.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the deapi client protocol and test suite to better support advanced scanning workflows, most notably multiple XY scan patterns and (commandVer 16) virtual image buffer retrieval, along with documentation and test reliability improvements.

Changes:

  • Extend the client scan-pattern API (set_xy_array) to accept multiple patterns and broaden input handling/validation.
  • Add client + simulated server support for virtual image buffer metadata/data retrieval (GET_VIRTUAL_IMAGE_INFO / GET_VIRTUAL_IMAGE) and expose VirtualImageInfo.
  • Update docs and tests (Sphinx tabs, new scan design doc, fixture scoping, reduced sleeps, skip flaky/slow file tests).

Reviewed changes

Copilot reviewed 16 out of 17 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
pyproject.toml Add Windows-only dependency and adjust optional test/doc extras.
doc/reference/scan_design.rst New design document describing scan/XY pattern behavior and usage examples.
doc/reference/index.rst Include design document section in reference toctree.
doc/conf.py Enable sphinx_tabs extension for tabbed code examples.
deapi/version.py Change commandVersion definition (now hard-coded).
deapi/tests/test_utils/test_utils.py Refactor gain-reference setup into a session fixture; reduce sleeps/poll instead.
deapi/tests/test_scanning/test_continual_scanning.py Add comprehensive “continual scanning” server tests for repeated/multi-pattern scans and timing edge cases.
deapi/tests/test_scanning/init.py Package marker for scanning tests.
deapi/tests/test_file_saving/test_scan_pattern_saving.py Skip slow/broken scan saving test.
deapi/tests/test_file_saving/test_file_loading_rsciio.py Skip slow/broken RSCIO loading test; remove an extra sleep.
deapi/tests/test_file_saving/test_file_loading_libertem.py Move libertem import into test function.
deapi/tests/test_client.py Adjust fixtures/state handling; update timings and a few property interactions.
deapi/tests/conftest.py Make client fixture session-scoped and remove teardown sleep.
deapi/simulated_server/fake_server.py Implement fake handlers for virtual image buffer info/data commands.
deapi/data_types.py Add VirtualImageInfo type for virtual image buffer metadata/dtype mapping.
deapi/client.py Add virtual image buffer APIs, queue flags in start_acquisition, boolean property normalization, enhance set_xy_array, default pixel_format to AUTO.
deapi/init.py Export VirtualImageInfo from package root.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread deapi/client.py
Comment thread deapi/client.py
Comment thread deapi/client.py
Comment thread deapi/client.py Outdated
Comment thread deapi/version.py
Comment thread deapi/tests/test_scanning/test_continual_scanning.py
Comment thread deapi/tests/test_scanning/test_continual_scanning.py
Comment thread deapi/client.py Outdated
Comment thread deapi/client.py
Comment thread deapi/tests/test_file_saving/test_file_loading_libertem.py
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

Preview for PR #51
View the preview here
(Built from a fork branch and deployed to PreviewDE/deapi-preview)

Copy link
Copy Markdown
Collaborator

@CoolFanyu CoolFanyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At start_acquisition, need to consider back compatible.

Comment thread deapi/client.py
self.START_ACQUISITION,
None,
[number_of_acquisitions, request_movie_buffer],
[number_of_acquisitions, request_movie_buffer] + vb,
Copy link
Copy Markdown
Collaborator

@CoolFanyu CoolFanyu May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only need to add vb if command versions are greater than 15. Otherwise, it will send more information to the old server which does not support this feature

Comment thread deapi/client.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants