lightfall 0.1.1__py3-none-any.whl
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.
- lightfall/__init__.py +8 -0
- lightfall/__main__.py +10 -0
- lightfall/_version.py +24 -0
- lightfall/acquire/__init__.py +74 -0
- lightfall/acquire/buffer.py +363 -0
- lightfall/acquire/device_wrapper.py +416 -0
- lightfall/acquire/engine/__init__.py +155 -0
- lightfall/acquire/engine/base.py +587 -0
- lightfall/acquire/engine/bluesky.py +358 -0
- lightfall/acquire/engine/mock.py +165 -0
- lightfall/acquire/engine/plugins/__init__.py +9 -0
- lightfall/acquire/engine/plugins/bluesky_plugin.py +56 -0
- lightfall/acquire/engine/plugins/mock_plugin.py +55 -0
- lightfall/acquire/engine/protocol.py +145 -0
- lightfall/acquire/engine/registry.py +152 -0
- lightfall/acquire/engine/state.py +32 -0
- lightfall/acquire/engine/waiting_hook.py +225 -0
- lightfall/acquire/nats_bridge.py +62 -0
- lightfall/acquire/plan_ui.py +78 -0
- lightfall/acquire/plans/__init__.py +38 -0
- lightfall/acquire/plans/adaptive.py +288 -0
- lightfall/acquire/plans/example_plans.py +995 -0
- lightfall/acquire/plans/lightfall_plans.py +587 -0
- lightfall/acquire/plans/registry.py +543 -0
- lightfall/acquire/plans/standard_plans.py +186 -0
- lightfall/acquire/plans/user_plans.py +470 -0
- lightfall/acquire/runengine.py +36 -0
- lightfall/acquire/signals.py +452 -0
- lightfall/acquire/triggers/__init__.py +16 -0
- lightfall/acquire/triggers/base.py +25 -0
- lightfall/acquire/triggers/filter.py +37 -0
- lightfall/acquire/triggers/manager.py +73 -0
- lightfall/acquire/triggers/manual.py +36 -0
- lightfall/acquire/triggers/run_end.py +74 -0
- lightfall/acquire/triggers/run_start.py +52 -0
- lightfall/auth/__init__.py +38 -0
- lightfall/auth/policy.py +518 -0
- lightfall/auth/providers/__init__.py +30 -0
- lightfall/auth/providers/base.py +124 -0
- lightfall/auth/providers/keycloak.py +1017 -0
- lightfall/auth/providers/local.py +319 -0
- lightfall/auth/providers/pam.py +250 -0
- lightfall/auth/service_key.py +173 -0
- lightfall/auth/service_key_auth.py +79 -0
- lightfall/auth/session.py +656 -0
- lightfall/claude/__init__.py +52 -0
- lightfall/claude/_internal/__init__.py +1 -0
- lightfall/claude/_internal/serialization.py +195 -0
- lightfall/claude/_internal/threading.py +61 -0
- lightfall/claude/_internal/worker.py +757 -0
- lightfall/claude/_session_assembly.py +124 -0
- lightfall/claude/agent.py +596 -0
- lightfall/claude/lightfall_core_tools.py +410 -0
- lightfall/claude/markdown.py +103 -0
- lightfall/claude/permission_manager.py +588 -0
- lightfall/claude/tools/__init__.py +45 -0
- lightfall/claude/tools/controller.py +143 -0
- lightfall/claude/tools/interaction.py +177 -0
- lightfall/claude/tools/introspection.py +127 -0
- lightfall/claude/tools/logs.py +155 -0
- lightfall/claude/tools/screenshot.py +87 -0
- lightfall/claude/widget.py +851 -0
- lightfall/claude/widgets/__init__.py +5 -0
- lightfall/claude/widgets/permission_request.py +282 -0
- lightfall/claude/widgets/question_request.py +227 -0
- lightfall/claude/widgets/task_card.py +223 -0
- lightfall/config/__init__.py +23 -0
- lightfall/config/layers.py +317 -0
- lightfall/config/manager.py +244 -0
- lightfall/config/schema.py +154 -0
- lightfall/core/__init__.py +23 -0
- lightfall/core/application.py +727 -0
- lightfall/core/services.py +235 -0
- lightfall/devices/__init__.py +53 -0
- lightfall/devices/backends/__init__.py +17 -0
- lightfall/devices/backends/bcs.py +448 -0
- lightfall/devices/backends/happi.py +986 -0
- lightfall/devices/backends/mock.py +646 -0
- lightfall/devices/base.py +338 -0
- lightfall/devices/catalog.py +1039 -0
- lightfall/devices/connection_manager.py +676 -0
- lightfall/devices/model.py +290 -0
- lightfall/devices/monitoring.py +442 -0
- lightfall/devices/sim/__init__.py +26 -0
- lightfall/devices/sim/areadetector.py +436 -0
- lightfall/devices/sim/generators.py +223 -0
- lightfall/devices/sim/plugins.py +116 -0
- lightfall/epics/__init__.py +28 -0
- lightfall/epics/ca/__init__.py +10 -0
- lightfall/epics/ca/context.py +100 -0
- lightfall/epics/ca/pv.py +303 -0
- lightfall/epics/widgets/__init__.py +49 -0
- lightfall/epics/widgets/areadetector/__init__.py +16 -0
- lightfall/epics/widgets/areadetector/areadetector.py +281 -0
- lightfall/epics/widgets/areadetector/controls.py +478 -0
- lightfall/epics/widgets/areadetector/image_view.py +447 -0
- lightfall/epics/widgets/auto.py +319 -0
- lightfall/epics/widgets/base.py +404 -0
- lightfall/epics/widgets/checkbox.py +239 -0
- lightfall/epics/widgets/combobox.py +202 -0
- lightfall/epics/widgets/label.py +176 -0
- lightfall/epics/widgets/lineedit.py +253 -0
- lightfall/epics/widgets/motor.py +694 -0
- lightfall/epics/widgets/ophyd_base.py +469 -0
- lightfall/epics/widgets/ophyd_combobox.py +86 -0
- lightfall/epics/widgets/ophyd_label.py +54 -0
- lightfall/epics/widgets/ophyd_lineedit.py +170 -0
- lightfall/epics/widgets/ophyd_spinbox.py +79 -0
- lightfall/epics/widgets/slider.py +272 -0
- lightfall/epics/widgets/status_indicator.py +98 -0
- lightfall/epics/widgets/style.py +188 -0
- lightfall/exporter/__init__.py +1 -0
- lightfall/exporter/cli.py +67 -0
- lightfall/exporter/converters/__init__.py +26 -0
- lightfall/exporter/converters/base.py +39 -0
- lightfall/exporter/converters/noop.py +39 -0
- lightfall/exporter/converters/nxsas.py +73 -0
- lightfall/exporter/service.py +200 -0
- lightfall/exporter/tiled_utils.py +92 -0
- lightfall/ipc/__init__.py +6 -0
- lightfall/ipc/service.py +701 -0
- lightfall/ipc/trust.py +144 -0
- lightfall/logbook/__init__.py +46 -0
- lightfall/logbook/action_dialog.py +207 -0
- lightfall/logbook/action_logger.py +432 -0
- lightfall/logbook/block_mapper.py +562 -0
- lightfall/logbook/client.py +799 -0
- lightfall/logbook/converter.py +273 -0
- lightfall/logbook/editors/__init__.py +19 -0
- lightfall/logbook/editors/highlighter.py +305 -0
- lightfall/logbook/editors/markdown_editor.py +319 -0
- lightfall/logbook/editors/richtext_editor.py +1397 -0
- lightfall/logbook/entry_widget.py +1065 -0
- lightfall/logbook/event_listener.py +221 -0
- lightfall/logbook/fragment_widgets.py +925 -0
- lightfall/logbook/position_mapper.py +320 -0
- lightfall/logbook/protection.py +402 -0
- lightfall/logbook/style.py +394 -0
- lightfall/logbook/url.py +29 -0
- lightfall/logbook/visual_protection.py +330 -0
- lightfall/logbook/widget.py +680 -0
- lightfall/main.py +1091 -0
- lightfall/pipelines/__init__.py +4 -0
- lightfall/pipelines/client.py +148 -0
- lightfall/plugins/__init__.py +119 -0
- lightfall/plugins/agent_plugin.py +106 -0
- lightfall/plugins/agents/__init__.py +10 -0
- lightfall/plugins/agents/_mcp_helpers.py +52 -0
- lightfall/plugins/agents/alignment.py +94 -0
- lightfall/plugins/agents/autonomous_experiment/__init__.py +12 -0
- lightfall/plugins/agents/autonomous_experiment/nats_tools.py +210 -0
- lightfall/plugins/agents/autonomous_experiment/plugin.py +60 -0
- lightfall/plugins/agents/autonomous_experiment/prompts.py +164 -0
- lightfall/plugins/agents/current_esaf.py +435 -0
- lightfall/plugins/agents/device_tools.py +1043 -0
- lightfall/plugins/agents/engine_tools.py +720 -0
- lightfall/plugins/agents/ipython_tools.py +444 -0
- lightfall/plugins/agents/panel_builder.py +637 -0
- lightfall/plugins/agents/panel_design/references/cross_panel_patterns.md +95 -0
- lightfall/plugins/agents/panel_design/references/panel_design.md +680 -0
- lightfall/plugins/agents/panel_design.py +94 -0
- lightfall/plugins/agents/plan_design/references/plan_design.md +398 -0
- lightfall/plugins/agents/plan_design.py +90 -0
- lightfall/plugins/agents/plan_tools.py +878 -0
- lightfall/plugins/agents/scan_planning.py +101 -0
- lightfall/plugins/builtin_manifest.py +348 -0
- lightfall/plugins/controller_plugin.py +162 -0
- lightfall/plugins/engine_plugin.py +124 -0
- lightfall/plugins/errors.py +104 -0
- lightfall/plugins/info.py +112 -0
- lightfall/plugins/loader.py +878 -0
- lightfall/plugins/manifest.py +150 -0
- lightfall/plugins/panel_plugin.py +119 -0
- lightfall/plugins/plan_plugin.py +163 -0
- lightfall/plugins/registry.py +309 -0
- lightfall/plugins/settings_plugin.py +226 -0
- lightfall/plugins/statusbar_plugin.py +289 -0
- lightfall/plugins/theme_plugin.py +165 -0
- lightfall/plugins/types.py +136 -0
- lightfall/plugins/user_plugins.py +764 -0
- lightfall/project/__init__.py +37 -0
- lightfall/project/model.py +375 -0
- lightfall/project/service.py +427 -0
- lightfall/project/welcome.py +106 -0
- lightfall/resources/__init__.py +126 -0
- lightfall/resources/images/__init__.py +1 -0
- lightfall/resources/images/icon.ico +0 -0
- lightfall/resources/images/icon.png +0 -0
- lightfall/resources/images/logo.png +0 -0
- lightfall/services/__init__.py +33 -0
- lightfall/services/_alshub_client.py +73 -0
- lightfall/services/access_stamper.py +240 -0
- lightfall/services/als_beam_status.py +347 -0
- lightfall/services/ca_tunnel.py +325 -0
- lightfall/services/threaded_tiled_writer.py +174 -0
- lightfall/services/tiled_auth.py +21 -0
- lightfall/services/tiled_service.py +971 -0
- lightfall/services/tiled_writer_patch.py +301 -0
- lightfall/settings/__init__.py +1 -0
- lightfall/settings/image_helpers.py +30 -0
- lightfall/settings/user_settings_client.py +232 -0
- lightfall/ui/__init__.py +28 -0
- lightfall/ui/annotations.py +208 -0
- lightfall/ui/common/__init__.py +7 -0
- lightfall/ui/dialogs/__init__.py +26 -0
- lightfall/ui/dialogs/about_dialog.py +131 -0
- lightfall/ui/dialogs/add_trigger_dialog.py +152 -0
- lightfall/ui/dialogs/base.py +44 -0
- lightfall/ui/dialogs/bug_report_dialog.py +353 -0
- lightfall/ui/dialogs/create_plan_dialog.py +189 -0
- lightfall/ui/dialogs/device_edit_dialog.py +183 -0
- lightfall/ui/dialogs/export_dialog.py +565 -0
- lightfall/ui/dialogs/go_to_position_dialog.py +192 -0
- lightfall/ui/dialogs/login_dialog.py +756 -0
- lightfall/ui/dialogs/oauth_browser_dialog.py +305 -0
- lightfall/ui/dialogs/run_pipeline_dialog.py +131 -0
- lightfall/ui/dialogs/sample_metadata_dialog.py +316 -0
- lightfall/ui/docking/__init__.py +22 -0
- lightfall/ui/docking/icon_sidebar.py +806 -0
- lightfall/ui/docking/manager.py +682 -0
- lightfall/ui/docking/state.py +113 -0
- lightfall/ui/docking/theme.py +399 -0
- lightfall/ui/docking/widget.py +214 -0
- lightfall/ui/events.py +75 -0
- lightfall/ui/mainwindow.py +1006 -0
- lightfall/ui/models/__init__.py +49 -0
- lightfall/ui/models/device_selection.py +389 -0
- lightfall/ui/models/device_tree.py +1095 -0
- lightfall/ui/models/thread_model.py +667 -0
- lightfall/ui/models/tiled_model.py +384 -0
- lightfall/ui/panels/__init__.py +28 -0
- lightfall/ui/panels/base.py +525 -0
- lightfall/ui/panels/bluesky_panel.py +619 -0
- lightfall/ui/panels/claude/__init__.py +9 -0
- lightfall/ui/panels/claude/agent_registry.py +168 -0
- lightfall/ui/panels/claude_panel.py +887 -0
- lightfall/ui/panels/device_panel.py +370 -0
- lightfall/ui/panels/documents_panel.py +166 -0
- lightfall/ui/panels/ipython_panel.py +580 -0
- lightfall/ui/panels/logbook_entries_panel.py +84 -0
- lightfall/ui/panels/logbook_panel.py +627 -0
- lightfall/ui/panels/logging_panel.py +587 -0
- lightfall/ui/panels/pipeline_jobs_panel.py +160 -0
- lightfall/ui/panels/pipeline_triggers_panel.py +170 -0
- lightfall/ui/panels/plugins/__init__.py +34 -0
- lightfall/ui/panels/plugins/bluesky_plugin.py +27 -0
- lightfall/ui/panels/plugins/claude_plugin.py +29 -0
- lightfall/ui/panels/plugins/device_plugin.py +27 -0
- lightfall/ui/panels/plugins/documents_plugin.py +26 -0
- lightfall/ui/panels/plugins/ipython_plugin.py +27 -0
- lightfall/ui/panels/plugins/logbook_entries_plugin.py +23 -0
- lightfall/ui/panels/plugins/logbook_plugin.py +27 -0
- lightfall/ui/panels/plugins/logging_plugin.py +27 -0
- lightfall/ui/panels/plugins/pipeline_jobs_plugin.py +23 -0
- lightfall/ui/panels/plugins/pipeline_triggers_plugin.py +25 -0
- lightfall/ui/panels/plugins/queue_plugin.py +29 -0
- lightfall/ui/panels/plugins/synoptic_plugin.py +38 -0
- lightfall/ui/panels/plugins/threads_plugin.py +27 -0
- lightfall/ui/panels/plugins/tiled_browser_plugin.py +27 -0
- lightfall/ui/panels/plugins/visualization_plugin.py +27 -0
- lightfall/ui/panels/queue.py +754 -0
- lightfall/ui/panels/registry.py +483 -0
- lightfall/ui/panels/synoptic/__init__.py +27 -0
- lightfall/ui/panels/synoptic/editors.py +481 -0
- lightfall/ui/panels/synoptic/items.py +556 -0
- lightfall/ui/panels/synoptic/models.py +336 -0
- lightfall/ui/panels/synoptic/panel.py +889 -0
- lightfall/ui/panels/synoptic/serialization.py +300 -0
- lightfall/ui/panels/synoptic/view.py +504 -0
- lightfall/ui/panels/threads_panel.py +621 -0
- lightfall/ui/panels/tiled_browser_panel.py +854 -0
- lightfall/ui/panels/visualization_panel.py +508 -0
- lightfall/ui/preferences/__init__.py +24 -0
- lightfall/ui/preferences/backend.py +148 -0
- lightfall/ui/preferences/builtin.py +220 -0
- lightfall/ui/preferences/claude_settings.py +762 -0
- lightfall/ui/preferences/device_settings.py +461 -0
- lightfall/ui/preferences/dialog.py +234 -0
- lightfall/ui/preferences/editor_settings.py +227 -0
- lightfall/ui/preferences/ipc_settings.py +226 -0
- lightfall/ui/preferences/logbook_settings.py +232 -0
- lightfall/ui/preferences/login_settings.py +183 -0
- lightfall/ui/preferences/manager.py +562 -0
- lightfall/ui/preferences/plugin_settings.py +392 -0
- lightfall/ui/preferences/proxy_settings.py +561 -0
- lightfall/ui/preferences/skill_settings.py +28 -0
- lightfall/ui/preferences/tiled_settings.py +469 -0
- lightfall/ui/preferences/tool_settings.py +393 -0
- lightfall/ui/preferences/user_portable_backend.py +131 -0
- lightfall/ui/preferences/user_profile_settings.py +316 -0
- lightfall/ui/preferences/visualization_settings.py +159 -0
- lightfall/ui/resources/__init__.py +1 -0
- lightfall/ui/resources/logo.png +0 -0
- lightfall/ui/statusbar/__init__.py +11 -0
- lightfall/ui/statusbar/manager.py +379 -0
- lightfall/ui/statusbar/plugins/__init__.py +28 -0
- lightfall/ui/statusbar/plugins/als_beam_status.py +218 -0
- lightfall/ui/statusbar/plugins/auth_status.py +116 -0
- lightfall/ui/statusbar/plugins/connection_status.py +100 -0
- lightfall/ui/statusbar/plugins/thread_status.py +556 -0
- lightfall/ui/statusbar/plugins/tiled_status.py +179 -0
- lightfall/ui/statusbar/plugins/user_status.py +84 -0
- lightfall/ui/theater/__init__.py +28 -0
- lightfall/ui/theater/manager.py +124 -0
- lightfall/ui/theater/overlay.py +279 -0
- lightfall/ui/theater/proxy.py +111 -0
- lightfall/ui/theme/__init__.py +18 -0
- lightfall/ui/theme/builtin.py +1015 -0
- lightfall/ui/theme/manager.py +875 -0
- lightfall/ui/theme/registry.py +195 -0
- lightfall/ui/toast.py +221 -0
- lightfall/ui/tutorial.py +1100 -0
- lightfall/ui/widgets/__init__.py +110 -0
- lightfall/ui/widgets/base_control.py +259 -0
- lightfall/ui/widgets/camera/__init__.py +36 -0
- lightfall/ui/widgets/camera/base.py +815 -0
- lightfall/ui/widgets/camera/dark_frames.py +213 -0
- lightfall/ui/widgets/camera/image_view.py +649 -0
- lightfall/ui/widgets/camera/panels/__init__.py +14 -0
- lightfall/ui/widgets/camera/panels/cooler.py +320 -0
- lightfall/ui/widgets/camera/panels/temperature.py +192 -0
- lightfall/ui/widgets/camera/plan_based.py +202 -0
- lightfall/ui/widgets/compact_motor.py +522 -0
- lightfall/ui/widgets/controller_matcher.py +278 -0
- lightfall/ui/widgets/controller_registry.py +144 -0
- lightfall/ui/widgets/device_control.py +411 -0
- lightfall/ui/widgets/device_selector.py +438 -0
- lightfall/ui/widgets/device_tree_tab.py +461 -0
- lightfall/ui/widgets/document_stream.py +1028 -0
- lightfall/ui/widgets/favorites_tab.py +191 -0
- lightfall/ui/widgets/motor_control.py +1120 -0
- lightfall/ui/widgets/observers/__init__.py +8 -0
- lightfall/ui/widgets/observers/camera.py +48 -0
- lightfall/ui/widgets/observers/image_view.py +130 -0
- lightfall/ui/widgets/plan_config.py +954 -0
- lightfall/ui/widgets/plan_edit_dialog.py +294 -0
- lightfall/ui/widgets/plan_selector.py +452 -0
- lightfall/ui/widgets/profile_avatar.py +128 -0
- lightfall/ui/widgets/queue_view.py +647 -0
- lightfall/ui/widgets/runengine_control.py +549 -0
- lightfall/ui/widgets/signal_control.py +793 -0
- lightfall/ui/widgets/skill_trigger_button.py +183 -0
- lightfall/ui/widgets/tiled_filter_widget.py +314 -0
- lightfall/ui/widgets/tiled_status.py +149 -0
- lightfall/ui/widgets/warning_banner.py +185 -0
- lightfall/utils/__init__.py +53 -0
- lightfall/utils/crash_diagnostics.py +454 -0
- lightfall/utils/data_migration.py +22 -0
- lightfall/utils/editor_launcher.py +594 -0
- lightfall/utils/error_collector.py +245 -0
- lightfall/utils/git_tracker.py +197 -0
- lightfall/utils/log_buffer.py +233 -0
- lightfall/utils/logging.py +229 -0
- lightfall/utils/module_resolver.py +70 -0
- lightfall/utils/sentry.py +722 -0
- lightfall/utils/threads.py +991 -0
- lightfall/utils/tiled_helpers.py +96 -0
- lightfall/visualization/__init__.py +50 -0
- lightfall/visualization/base.py +5 -0
- lightfall/visualization/base_visualization.py +74 -0
- lightfall/visualization/fitting/__init__.py +24 -0
- lightfall/visualization/fitting/base.py +267 -0
- lightfall/visualization/fitting/fitters.py +325 -0
- lightfall/visualization/fitting/panel.py +265 -0
- lightfall/visualization/memory.py +392 -0
- lightfall/visualization/motor_mixin.py +524 -0
- lightfall/visualization/pg.py +156 -0
- lightfall/visualization/registry.py +144 -0
- lightfall/visualization/spec.py +79 -0
- lightfall/visualization/theme.py +266 -0
- lightfall/visualization/widgets/__init__.py +28 -0
- lightfall/visualization/widgets/adaptive/__init__.py +1 -0
- lightfall/visualization/widgets/adaptive/heatmap.py +655 -0
- lightfall/visualization/widgets/adaptive/plot.py +233 -0
- lightfall/visualization/widgets/heatmap.py +264 -0
- lightfall/visualization/widgets/image_stack.py +316 -0
- lightfall/visualization/widgets/image_view_toolbar.py +227 -0
- lightfall/visualization/widgets/lazy_image_view.py +590 -0
- lightfall/visualization/widgets/plot_1d.py +262 -0
- lightfall/visualization/widgets/scatter.py +247 -0
- lightfall/visualization/widgets/table.py +221 -0
- lightfall/visualization/widgets/time_axis.py +93 -0
- lightfall-0.1.1.dist-info/METADATA +223 -0
- lightfall-0.1.1.dist-info/RECORD +388 -0
- lightfall-0.1.1.dist-info/WHEEL +4 -0
- lightfall-0.1.1.dist-info/entry_points.txt +6 -0
- lightfall-0.1.1.dist-info/licenses/LEGAL.md +13 -0
- lightfall-0.1.1.dist-info/licenses/LICENSE.md +33 -0
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
"""Scientific image viewer for ophyd area detector devices.
|
|
2
|
+
|
|
3
|
+
Displays live image data with:
|
|
4
|
+
- Axis ticks via PlotItem
|
|
5
|
+
- Histogram/LUT control
|
|
6
|
+
- Correct orientation (col-major axis order, matching Xi-CAM convention)
|
|
7
|
+
- Background-threaded device polling and data preprocessing
|
|
8
|
+
|
|
9
|
+
Device I/O (array_data.get(), roi stats, progress counters) and numpy
|
|
10
|
+
preprocessing (reshape, BG subtraction, log transform, histogram) all
|
|
11
|
+
run on a background thread. The main thread only does Qt widget updates.
|
|
12
|
+
|
|
13
|
+
The LUT is auto-scaled on the first frame received using percentile bounds
|
|
14
|
+
(1st percentile as min, 99th percentile as max). Subsequent frames preserve
|
|
15
|
+
the user's manual LUT adjustments until Reset LUT is pressed.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
import threading
|
|
21
|
+
import warnings
|
|
22
|
+
from dataclasses import dataclass
|
|
23
|
+
from typing import TYPE_CHECKING, Any
|
|
24
|
+
|
|
25
|
+
import numpy as np
|
|
26
|
+
import pyqtgraph as pg
|
|
27
|
+
from PySide6.QtCore import Qt, QTimer
|
|
28
|
+
from PySide6.QtWidgets import (
|
|
29
|
+
QHBoxLayout,
|
|
30
|
+
QLabel,
|
|
31
|
+
QProgressBar,
|
|
32
|
+
QPushButton,
|
|
33
|
+
QVBoxLayout,
|
|
34
|
+
QWidget,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
from lightfall.ui.widgets.camera.dark_frames import DarkFrameManager
|
|
38
|
+
from lightfall.utils.logging import logger
|
|
39
|
+
|
|
40
|
+
if TYPE_CHECKING:
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass
|
|
45
|
+
class _FrameData:
|
|
46
|
+
"""Preprocessed frame data produced by the background thread."""
|
|
47
|
+
|
|
48
|
+
raw_image: np.ndarray
|
|
49
|
+
display_image: np.ndarray
|
|
50
|
+
log_mode: bool # whether display_image was log-transformed
|
|
51
|
+
hist_x: np.ndarray | None = None
|
|
52
|
+
hist_y: np.ndarray | None = None
|
|
53
|
+
roi_stats: list[str] | None = None
|
|
54
|
+
progress: tuple[int, int] | None = None # (current, total) or None if idle
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class OphydImageView(QWidget):
|
|
58
|
+
"""PyQtGraph-based scientific image viewer for ophyd area detectors.
|
|
59
|
+
|
|
60
|
+
Device polling and data preprocessing run on a background thread.
|
|
61
|
+
The main thread timer picks up the latest preprocessed frame and
|
|
62
|
+
only does Qt widget updates.
|
|
63
|
+
|
|
64
|
+
Image orientation uses col-major axis order (matching Xi-CAM convention)
|
|
65
|
+
with no Y-axis inversion, so no QTransform or data preprocessing needed.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
_STAT_FIELDS = (
|
|
69
|
+
"min_value", "max_value", "mean_value", "total",
|
|
70
|
+
"centroid_x", "centroid_y",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
def __init__(self, ophyd_device: Any, parent: QWidget | None = None) -> None:
|
|
74
|
+
super().__init__(parent)
|
|
75
|
+
self._device = ophyd_device
|
|
76
|
+
self._first_frame = True
|
|
77
|
+
self._log_mode = False
|
|
78
|
+
self._bg_correct = False
|
|
79
|
+
self._raw_image: np.ndarray | None = None
|
|
80
|
+
self._updating_levels = False
|
|
81
|
+
|
|
82
|
+
self._dark_manager = DarkFrameManager(
|
|
83
|
+
device_name=ophyd_device.name if hasattr(ophyd_device, "name") else "unknown"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
# Background thread state
|
|
87
|
+
self._pending_frame: _FrameData | None = None
|
|
88
|
+
self._poll_thread: threading.Thread | None = None
|
|
89
|
+
self._poll_stop = threading.Event()
|
|
90
|
+
self._frame_count = 0
|
|
91
|
+
|
|
92
|
+
self._setup_ui()
|
|
93
|
+
self._start_updates()
|
|
94
|
+
|
|
95
|
+
# =====================================================================
|
|
96
|
+
# UI Setup
|
|
97
|
+
# =====================================================================
|
|
98
|
+
|
|
99
|
+
def _setup_ui(self) -> None:
|
|
100
|
+
"""Build the viewer layout: [toolbar | image+histogram | coords | progress]."""
|
|
101
|
+
layout = QVBoxLayout(self)
|
|
102
|
+
layout.setContentsMargins(0, 0, 0, 0)
|
|
103
|
+
|
|
104
|
+
# Toolbar
|
|
105
|
+
import qtawesome as qta
|
|
106
|
+
|
|
107
|
+
toolbar = QHBoxLayout()
|
|
108
|
+
toolbar.setContentsMargins(0, 0, 0, 0)
|
|
109
|
+
toolbar.setSpacing(4)
|
|
110
|
+
|
|
111
|
+
self._reset_lut_btn = QPushButton(qta.icon("mdi6.chart-histogram"), "Reset LUT")
|
|
112
|
+
self._reset_lut_btn.setFixedHeight(24)
|
|
113
|
+
self._reset_lut_btn.clicked.connect(self.reset_lut)
|
|
114
|
+
toolbar.addWidget(self._reset_lut_btn)
|
|
115
|
+
|
|
116
|
+
self._reset_axes_btn = QPushButton(qta.icon("mdi6.magnify"), "Reset Axes")
|
|
117
|
+
self._reset_axes_btn.setFixedHeight(24)
|
|
118
|
+
self._reset_axes_btn.clicked.connect(self.reset_axes)
|
|
119
|
+
toolbar.addWidget(self._reset_axes_btn)
|
|
120
|
+
|
|
121
|
+
self._log_icon_off = qta.icon("mdi6.lightbulb")
|
|
122
|
+
self._log_icon_on = qta.icon("mdi6.lightbulb-on-outline")
|
|
123
|
+
self._log_intensity_btn = QPushButton(self._log_icon_off, "Log Intensity")
|
|
124
|
+
self._log_intensity_btn.setFixedHeight(24)
|
|
125
|
+
self._log_intensity_btn.setCheckable(True)
|
|
126
|
+
self._log_intensity_btn.toggled.connect(self._on_log_intensity_toggled)
|
|
127
|
+
toolbar.addWidget(self._log_intensity_btn)
|
|
128
|
+
|
|
129
|
+
self._bg_icon_off = qta.icon("mdi6.lightbulb-night")
|
|
130
|
+
self._bg_icon_on = qta.icon("mdi6.lightbulb-night-outline")
|
|
131
|
+
self._bg_correct_btn = QPushButton(self._bg_icon_off, "BG Correct")
|
|
132
|
+
self._bg_correct_btn.setFixedHeight(24)
|
|
133
|
+
self._bg_correct_btn.setCheckable(True)
|
|
134
|
+
self._bg_correct_btn.toggled.connect(self._on_bg_correct_toggled)
|
|
135
|
+
toolbar.addWidget(self._bg_correct_btn)
|
|
136
|
+
|
|
137
|
+
toolbar.addStretch()
|
|
138
|
+
layout.addLayout(toolbar)
|
|
139
|
+
|
|
140
|
+
# Main horizontal split: image view | histogram
|
|
141
|
+
h_layout = QHBoxLayout()
|
|
142
|
+
h_layout.setContentsMargins(0, 0, 0, 0)
|
|
143
|
+
h_layout.setSpacing(0)
|
|
144
|
+
|
|
145
|
+
# PlotItem provides axes around the image
|
|
146
|
+
self._plot_item = pg.PlotItem()
|
|
147
|
+
self._plot_item.setDefaultPadding(0)
|
|
148
|
+
self._plot_item.hideButtons()
|
|
149
|
+
self._plot_item.setMenuEnabled(False)
|
|
150
|
+
self._plot_item.getViewBox().setAspectLocked(True)
|
|
151
|
+
self._plot_item.setLabel("bottom", "x (px)")
|
|
152
|
+
self._plot_item.setLabel("left", "y (px)")
|
|
153
|
+
|
|
154
|
+
# ImageItem uses col-major axis order (Xi-CAM convention).
|
|
155
|
+
self._image_item = pg.ImageItem()
|
|
156
|
+
self._image_item.setOpts(axisOrder="col-major")
|
|
157
|
+
self._plot_item.addItem(self._image_item)
|
|
158
|
+
|
|
159
|
+
# ROI stats overlay
|
|
160
|
+
self._stats_text = pg.TextItem(anchor=(1, 0), color="#00FF00")
|
|
161
|
+
self._stats_text.setFont(pg.QtGui.QFont("monospace", 9))
|
|
162
|
+
self._stats_text.setVisible(False)
|
|
163
|
+
self._plot_item.addItem(self._stats_text)
|
|
164
|
+
|
|
165
|
+
# Crosshair
|
|
166
|
+
linepen = pg.mkPen("#FFA500", width=1)
|
|
167
|
+
self._vline = pg.InfiniteLine(angle=90, movable=False, pen=linepen)
|
|
168
|
+
self._hline = pg.InfiniteLine(angle=0, movable=False, pen=linepen)
|
|
169
|
+
self._vline.setVisible(False)
|
|
170
|
+
self._hline.setVisible(False)
|
|
171
|
+
self._plot_item.addItem(self._vline)
|
|
172
|
+
self._plot_item.addItem(self._hline)
|
|
173
|
+
|
|
174
|
+
# GraphicsView to host the PlotItem
|
|
175
|
+
self._graphics_view = pg.GraphicsView()
|
|
176
|
+
self._graphics_view.setCentralItem(self._plot_item)
|
|
177
|
+
|
|
178
|
+
# Mouse tracking (must connect after PlotItem has a scene via GraphicsView)
|
|
179
|
+
self._plot_item.scene().sigMouseMoved.connect(self._on_mouse_moved)
|
|
180
|
+
h_layout.addWidget(self._graphics_view, stretch=1)
|
|
181
|
+
|
|
182
|
+
# HistogramLUTItem — manually wired so we can decouple log display
|
|
183
|
+
# from linear histogram.
|
|
184
|
+
self._histogram = pg.HistogramLUTItem()
|
|
185
|
+
self._histogram.sigLevelsChanged.connect(self._apply_display_levels)
|
|
186
|
+
self._histogram.gradient.sigGradientChanged.connect(
|
|
187
|
+
self._on_gradient_changed,
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
self._hist_view = pg.GraphicsView()
|
|
191
|
+
self._hist_view.setCentralItem(self._histogram)
|
|
192
|
+
self._hist_view.setFixedWidth(120)
|
|
193
|
+
h_layout.addWidget(self._hist_view)
|
|
194
|
+
|
|
195
|
+
layout.addLayout(h_layout)
|
|
196
|
+
|
|
197
|
+
# Coordinate display label
|
|
198
|
+
self._coords_label = QLabel("")
|
|
199
|
+
self._coords_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
200
|
+
self._coords_label.setFixedHeight(20)
|
|
201
|
+
self._coords_label.setStyleSheet("font-family: monospace; font-size: 11px;")
|
|
202
|
+
layout.addWidget(self._coords_label)
|
|
203
|
+
|
|
204
|
+
# Progress bar
|
|
205
|
+
self._progress_bar = QProgressBar()
|
|
206
|
+
self._progress_bar.setFixedHeight(16)
|
|
207
|
+
self._progress_bar.setTextVisible(True)
|
|
208
|
+
self._progress_bar.setFormat("%v / %m (%p%)")
|
|
209
|
+
self._progress_bar.setVisible(False)
|
|
210
|
+
layout.addWidget(self._progress_bar)
|
|
211
|
+
|
|
212
|
+
# =====================================================================
|
|
213
|
+
# Background polling thread
|
|
214
|
+
# =====================================================================
|
|
215
|
+
|
|
216
|
+
def _start_updates(self) -> None:
|
|
217
|
+
"""Start the background polling thread and main-thread UI timer."""
|
|
218
|
+
# Background thread: polls device, preprocesses data
|
|
219
|
+
self._poll_stop.clear()
|
|
220
|
+
self._poll_thread = threading.Thread(
|
|
221
|
+
target=self._poll_loop, daemon=True, name="imageview-poll"
|
|
222
|
+
)
|
|
223
|
+
self._poll_thread.start()
|
|
224
|
+
|
|
225
|
+
# Main thread timer: picks up preprocessed frames, updates widgets
|
|
226
|
+
self._ui_timer = QTimer(self)
|
|
227
|
+
self._ui_timer.timeout.connect(self._apply_frame)
|
|
228
|
+
self._ui_timer.start(50) # 20 fps check rate (only updates if new frame)
|
|
229
|
+
|
|
230
|
+
def _poll_loop(self) -> None:
|
|
231
|
+
"""Background thread: poll device and preprocess frames.
|
|
232
|
+
|
|
233
|
+
Runs continuously at ~10 fps. All device .get() calls and numpy
|
|
234
|
+
operations happen here, never on the main thread.
|
|
235
|
+
"""
|
|
236
|
+
while not self._poll_stop.is_set():
|
|
237
|
+
try:
|
|
238
|
+
self._poll_once()
|
|
239
|
+
except Exception as e:
|
|
240
|
+
logger.debug(f"Poll error: {e}")
|
|
241
|
+
self._poll_stop.wait(0.1) # ~10 fps
|
|
242
|
+
|
|
243
|
+
def _poll_once(self) -> None:
|
|
244
|
+
"""Single poll iteration — read device, preprocess, store result."""
|
|
245
|
+
if self._device is None:
|
|
246
|
+
return
|
|
247
|
+
|
|
248
|
+
# --- Read image data (blocking I/O) ---
|
|
249
|
+
image_plugin = None
|
|
250
|
+
for attr in ("image1", "image"):
|
|
251
|
+
plugin = getattr(self._device, attr, None)
|
|
252
|
+
if plugin is not None and hasattr(plugin, "array_data"):
|
|
253
|
+
image_plugin = plugin
|
|
254
|
+
break
|
|
255
|
+
|
|
256
|
+
if image_plugin is None:
|
|
257
|
+
return
|
|
258
|
+
|
|
259
|
+
image_data = image_plugin.array_data.get()
|
|
260
|
+
if image_data is None:
|
|
261
|
+
return
|
|
262
|
+
|
|
263
|
+
# --- Preprocess (all numpy, no Qt) ---
|
|
264
|
+
arr = np.squeeze(image_data)
|
|
265
|
+
|
|
266
|
+
if arr.ndim == 1:
|
|
267
|
+
width, height = self._get_image_dimensions(image_plugin)
|
|
268
|
+
if width and height and width * height == arr.size:
|
|
269
|
+
arr = arr.reshape((height, width))
|
|
270
|
+
else:
|
|
271
|
+
return
|
|
272
|
+
|
|
273
|
+
if arr.ndim != 2:
|
|
274
|
+
return
|
|
275
|
+
|
|
276
|
+
# Snapshot toggle states at the start of processing so the frame
|
|
277
|
+
# is internally consistent even if the user toggles mid-poll.
|
|
278
|
+
log_mode = self._log_mode
|
|
279
|
+
bg_correct = self._bg_correct
|
|
280
|
+
|
|
281
|
+
# Background correction (reads cached dark, no I/O)
|
|
282
|
+
if bg_correct:
|
|
283
|
+
arr = self._dark_manager.subtract(arr)
|
|
284
|
+
|
|
285
|
+
# Log transform
|
|
286
|
+
if log_mode:
|
|
287
|
+
with warnings.catch_warnings():
|
|
288
|
+
warnings.simplefilter("ignore", RuntimeWarning)
|
|
289
|
+
display_arr = np.log1p(arr.astype(np.float64))
|
|
290
|
+
else:
|
|
291
|
+
display_arr = arr
|
|
292
|
+
|
|
293
|
+
# Histogram (throttled, subsampled)
|
|
294
|
+
self._frame_count += 1
|
|
295
|
+
hist_x, hist_y = None, None
|
|
296
|
+
if self._frame_count % 5 == 1:
|
|
297
|
+
with warnings.catch_warnings():
|
|
298
|
+
warnings.simplefilter("ignore", RuntimeWarning)
|
|
299
|
+
step = max(1, arr.size // 500_000)
|
|
300
|
+
vals = arr.ravel()[::step]
|
|
301
|
+
hist_y_arr, hist_x_arr = np.histogram(vals, bins=256)
|
|
302
|
+
hist_x = (hist_x_arr[:-1] + hist_x_arr[1:]) / 2
|
|
303
|
+
hist_y = hist_y_arr
|
|
304
|
+
|
|
305
|
+
# --- ROI stats (blocking I/O) ---
|
|
306
|
+
roi_stats = self._read_roi_stats()
|
|
307
|
+
|
|
308
|
+
# --- Progress (blocking I/O) ---
|
|
309
|
+
progress = self._read_progress()
|
|
310
|
+
|
|
311
|
+
# Store for main thread pickup
|
|
312
|
+
self._pending_frame = _FrameData(
|
|
313
|
+
raw_image=arr,
|
|
314
|
+
display_image=display_arr,
|
|
315
|
+
log_mode=log_mode,
|
|
316
|
+
hist_x=hist_x,
|
|
317
|
+
hist_y=hist_y,
|
|
318
|
+
roi_stats=roi_stats,
|
|
319
|
+
progress=progress,
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
def _read_roi_stats(self) -> list[str] | None:
|
|
323
|
+
"""Read ROI statistics from device (background thread)."""
|
|
324
|
+
stats_plugin = getattr(self._device, "roi_stat1", None)
|
|
325
|
+
if stats_plugin is None:
|
|
326
|
+
return None
|
|
327
|
+
try:
|
|
328
|
+
lines = []
|
|
329
|
+
for field_name in self._STAT_FIELDS:
|
|
330
|
+
signal = getattr(stats_plugin, field_name, None)
|
|
331
|
+
if signal is not None:
|
|
332
|
+
value = signal.get()
|
|
333
|
+
label = field_name.replace("_", " ").title()
|
|
334
|
+
if isinstance(value, float):
|
|
335
|
+
lines.append(f"{label}: {value:.1f}")
|
|
336
|
+
else:
|
|
337
|
+
lines.append(f"{label}: {value}")
|
|
338
|
+
return lines if lines else None
|
|
339
|
+
except Exception:
|
|
340
|
+
return None
|
|
341
|
+
|
|
342
|
+
def _read_progress(self) -> tuple[int, int] | None:
|
|
343
|
+
"""Read acquisition progress from device (background thread)."""
|
|
344
|
+
cam = getattr(self._device, "cam", None)
|
|
345
|
+
if cam is None:
|
|
346
|
+
return None
|
|
347
|
+
try:
|
|
348
|
+
acquiring = getattr(cam, "acquire", None)
|
|
349
|
+
if acquiring is None or not acquiring.get():
|
|
350
|
+
return None
|
|
351
|
+
|
|
352
|
+
# Try HDF5 plugin first
|
|
353
|
+
hdf5 = getattr(self._device, "hdf5", None)
|
|
354
|
+
if hdf5 is not None:
|
|
355
|
+
capture = getattr(hdf5, "capture", None)
|
|
356
|
+
if capture is not None and capture.get():
|
|
357
|
+
return int(hdf5.num_captured.get()), int(cam.num_images.get())
|
|
358
|
+
|
|
359
|
+
# Fall back to cam.array_counter
|
|
360
|
+
counter = getattr(cam, "array_counter", None)
|
|
361
|
+
num_images = getattr(cam, "num_images", None)
|
|
362
|
+
if counter is not None and num_images is not None:
|
|
363
|
+
return int(counter.get()), int(num_images.get())
|
|
364
|
+
except Exception:
|
|
365
|
+
pass
|
|
366
|
+
return None
|
|
367
|
+
|
|
368
|
+
# =====================================================================
|
|
369
|
+
# Main thread: apply preprocessed frame to widgets
|
|
370
|
+
# =====================================================================
|
|
371
|
+
|
|
372
|
+
def _apply_frame(self) -> None:
|
|
373
|
+
"""Main thread: pick up the latest preprocessed frame and update widgets."""
|
|
374
|
+
frame = self._pending_frame
|
|
375
|
+
if frame is None:
|
|
376
|
+
return
|
|
377
|
+
self._pending_frame = None
|
|
378
|
+
|
|
379
|
+
# Cache raw image for coordinate readback
|
|
380
|
+
self._raw_image = frame.raw_image
|
|
381
|
+
|
|
382
|
+
# Update image display
|
|
383
|
+
self._image_item.setImage(frame.display_image, autoLevels=False)
|
|
384
|
+
|
|
385
|
+
# First frame: auto-levels and auto-range
|
|
386
|
+
if self._first_frame:
|
|
387
|
+
self._first_frame = False
|
|
388
|
+
self._auto_levels()
|
|
389
|
+
self.reset_axes()
|
|
390
|
+
|
|
391
|
+
# Use the frame's log_mode (not current self._log_mode) so levels
|
|
392
|
+
# match the data that was actually computed by the background thread.
|
|
393
|
+
self._apply_display_levels(log_mode=frame.log_mode)
|
|
394
|
+
|
|
395
|
+
# Update histogram bins
|
|
396
|
+
if frame.hist_x is not None and frame.hist_y is not None:
|
|
397
|
+
self._histogram.plot.setData(frame.hist_x, frame.hist_y)
|
|
398
|
+
|
|
399
|
+
# Update ROI stats overlay
|
|
400
|
+
if frame.roi_stats is not None:
|
|
401
|
+
self._stats_text.setText("\n".join(frame.roi_stats))
|
|
402
|
+
vb = self._plot_item.getViewBox()
|
|
403
|
+
view_range = vb.viewRange()
|
|
404
|
+
self._stats_text.setPos(view_range[0][1], view_range[1][0])
|
|
405
|
+
self._stats_text.setVisible(True)
|
|
406
|
+
else:
|
|
407
|
+
self._stats_text.setVisible(False)
|
|
408
|
+
|
|
409
|
+
# Update progress bar
|
|
410
|
+
if frame.progress is not None:
|
|
411
|
+
current, total = frame.progress
|
|
412
|
+
self._progress_bar.setMaximum(total)
|
|
413
|
+
self._progress_bar.setValue(current)
|
|
414
|
+
self._progress_bar.setVisible(True)
|
|
415
|
+
else:
|
|
416
|
+
self._progress_bar.setVisible(False)
|
|
417
|
+
|
|
418
|
+
def _display_array(self, array: np.ndarray, image_plugin: Any = None) -> None:
|
|
419
|
+
"""Synchronous display for testing and direct use.
|
|
420
|
+
|
|
421
|
+
Preprocesses the array and updates widgets in one call on the
|
|
422
|
+
current thread. The normal runtime path uses the background
|
|
423
|
+
poll thread instead.
|
|
424
|
+
"""
|
|
425
|
+
if array is None or array.size == 0:
|
|
426
|
+
return
|
|
427
|
+
|
|
428
|
+
arr = np.squeeze(array)
|
|
429
|
+
|
|
430
|
+
if arr.ndim == 1:
|
|
431
|
+
width, height = self._get_image_dimensions(image_plugin)
|
|
432
|
+
if width and height and width * height == arr.size:
|
|
433
|
+
arr = arr.reshape((height, width))
|
|
434
|
+
else:
|
|
435
|
+
return
|
|
436
|
+
|
|
437
|
+
if arr.ndim != 2:
|
|
438
|
+
return
|
|
439
|
+
|
|
440
|
+
if self._bg_correct:
|
|
441
|
+
arr = self._dark_manager.subtract(arr)
|
|
442
|
+
|
|
443
|
+
self._raw_image = arr
|
|
444
|
+
|
|
445
|
+
if self._log_mode:
|
|
446
|
+
with warnings.catch_warnings():
|
|
447
|
+
warnings.simplefilter("ignore", RuntimeWarning)
|
|
448
|
+
display_arr = np.log1p(arr.astype(np.float64))
|
|
449
|
+
else:
|
|
450
|
+
display_arr = arr
|
|
451
|
+
|
|
452
|
+
self._image_item.setImage(display_arr, autoLevels=False)
|
|
453
|
+
|
|
454
|
+
if self._first_frame:
|
|
455
|
+
self._first_frame = False
|
|
456
|
+
self._auto_levels()
|
|
457
|
+
self.reset_axes()
|
|
458
|
+
|
|
459
|
+
self._apply_display_levels()
|
|
460
|
+
|
|
461
|
+
# =====================================================================
|
|
462
|
+
# LUT / Axes / Log / BG controls
|
|
463
|
+
# =====================================================================
|
|
464
|
+
|
|
465
|
+
def reset_lut(self) -> None:
|
|
466
|
+
"""Reset LUT using percentile-based bounds from current image."""
|
|
467
|
+
if self._raw_image is not None:
|
|
468
|
+
self._auto_levels()
|
|
469
|
+
self._apply_display_levels()
|
|
470
|
+
else:
|
|
471
|
+
self._first_frame = True
|
|
472
|
+
|
|
473
|
+
def reset_axes(self) -> None:
|
|
474
|
+
"""Reset view to fit the image bounds exactly."""
|
|
475
|
+
if self._raw_image is not None:
|
|
476
|
+
bounds = self._image_item.mapRectToView(
|
|
477
|
+
self._image_item.boundingRect()
|
|
478
|
+
)
|
|
479
|
+
self._plot_item.getViewBox().setRange(bounds, padding=0.02)
|
|
480
|
+
else:
|
|
481
|
+
self._plot_item.getViewBox().autoRange()
|
|
482
|
+
|
|
483
|
+
def _auto_levels(self) -> None:
|
|
484
|
+
"""Set histogram levels using percentile-based bounds.
|
|
485
|
+
|
|
486
|
+
Uses 1st percentile as min and 99th percentile as max.
|
|
487
|
+
This excludes hot pixels and dead pixels from dominating the
|
|
488
|
+
color scale.
|
|
489
|
+
"""
|
|
490
|
+
arr = self._raw_image
|
|
491
|
+
if arr is None:
|
|
492
|
+
return
|
|
493
|
+
|
|
494
|
+
with warnings.catch_warnings():
|
|
495
|
+
warnings.simplefilter("ignore", RuntimeWarning)
|
|
496
|
+
|
|
497
|
+
# Subsample large images for speed
|
|
498
|
+
step = max(1, arr.size // 1_000_000)
|
|
499
|
+
data = arr.ravel()[::step].astype(np.float64)
|
|
500
|
+
|
|
501
|
+
if data.size == 0:
|
|
502
|
+
return
|
|
503
|
+
|
|
504
|
+
lo = float(np.nanpercentile(data, 1))
|
|
505
|
+
hi = float(np.nanpercentile(data, 99))
|
|
506
|
+
|
|
507
|
+
if lo >= hi:
|
|
508
|
+
lo = float(np.nanmin(data))
|
|
509
|
+
hi = float(np.nanmax(data))
|
|
510
|
+
if lo == hi:
|
|
511
|
+
hi = lo + 1.0
|
|
512
|
+
|
|
513
|
+
self._histogram.setLevels(lo, hi)
|
|
514
|
+
|
|
515
|
+
def _on_log_intensity_toggled(self, checked: bool) -> None:
|
|
516
|
+
"""Toggle log intensity mode.
|
|
517
|
+
|
|
518
|
+
The background thread reads this flag and applies the transform.
|
|
519
|
+
Re-render the current cached frame immediately for responsiveness.
|
|
520
|
+
"""
|
|
521
|
+
self._log_mode = checked
|
|
522
|
+
self._log_intensity_btn.setIcon(self._log_icon_on if checked else self._log_icon_off)
|
|
523
|
+
if self._raw_image is not None:
|
|
524
|
+
if self._log_mode:
|
|
525
|
+
with warnings.catch_warnings():
|
|
526
|
+
warnings.simplefilter("ignore", RuntimeWarning)
|
|
527
|
+
display_arr = np.log1p(self._raw_image.astype(np.float64))
|
|
528
|
+
else:
|
|
529
|
+
display_arr = self._raw_image
|
|
530
|
+
self._image_item.setImage(display_arr, autoLevels=False)
|
|
531
|
+
self._apply_display_levels()
|
|
532
|
+
|
|
533
|
+
def _on_bg_correct_toggled(self, checked: bool) -> None:
|
|
534
|
+
"""Toggle background correction. The background thread reads this flag."""
|
|
535
|
+
self._bg_correct = checked
|
|
536
|
+
self._bg_correct_btn.setIcon(self._bg_icon_on if checked else self._bg_icon_off)
|
|
537
|
+
|
|
538
|
+
def _apply_display_levels(self, log_mode: bool | None = None) -> None:
|
|
539
|
+
"""Map histogram levels (real units) to the displayed ImageItem.
|
|
540
|
+
|
|
541
|
+
Args:
|
|
542
|
+
log_mode: Whether the currently displayed image is log-transformed.
|
|
543
|
+
If None, uses self._log_mode (for interactive updates).
|
|
544
|
+
When called from _apply_frame, pass the frame's log_mode
|
|
545
|
+
to ensure levels match the data.
|
|
546
|
+
"""
|
|
547
|
+
if self._updating_levels:
|
|
548
|
+
return
|
|
549
|
+
self._updating_levels = True
|
|
550
|
+
try:
|
|
551
|
+
if log_mode is None:
|
|
552
|
+
log_mode = self._log_mode
|
|
553
|
+
lo, hi = self._histogram.getLevels()
|
|
554
|
+
if log_mode:
|
|
555
|
+
lo = np.log1p(max(lo, 0.0))
|
|
556
|
+
hi = np.log1p(max(hi, 0.0))
|
|
557
|
+
self._image_item.setLevels([lo, hi])
|
|
558
|
+
finally:
|
|
559
|
+
self._updating_levels = False
|
|
560
|
+
|
|
561
|
+
def _on_gradient_changed(self) -> None:
|
|
562
|
+
"""Propagate colormap changes from the histogram to the ImageItem."""
|
|
563
|
+
lut = self._histogram.gradient.getLookupTable(256)
|
|
564
|
+
self._image_item.setLookupTable(lut)
|
|
565
|
+
|
|
566
|
+
# =====================================================================
|
|
567
|
+
# Crosshair / coordinates
|
|
568
|
+
# =====================================================================
|
|
569
|
+
|
|
570
|
+
def _on_mouse_moved(self, pos) -> None:
|
|
571
|
+
vb = self._plot_item.getViewBox()
|
|
572
|
+
if not vb.sceneBoundingRect().contains(pos):
|
|
573
|
+
self._vline.setVisible(False)
|
|
574
|
+
self._hline.setVisible(False)
|
|
575
|
+
self._coords_label.setText("")
|
|
576
|
+
return
|
|
577
|
+
mouse_point = vb.mapSceneToView(pos)
|
|
578
|
+
x, y = mouse_point.x(), mouse_point.y()
|
|
579
|
+
text = self._format_coordinates(x, y)
|
|
580
|
+
if text:
|
|
581
|
+
self._vline.setPos(x)
|
|
582
|
+
self._hline.setPos(y)
|
|
583
|
+
self._vline.setVisible(True)
|
|
584
|
+
self._hline.setVisible(True)
|
|
585
|
+
self._coords_label.setText(text)
|
|
586
|
+
else:
|
|
587
|
+
self._vline.setVisible(False)
|
|
588
|
+
self._hline.setVisible(False)
|
|
589
|
+
self._coords_label.setText("")
|
|
590
|
+
|
|
591
|
+
def _format_coordinates(self, x: float, y: float) -> str:
|
|
592
|
+
"""Format pixel coordinates and intensity at view position (x, y).
|
|
593
|
+
|
|
594
|
+
With col-major axis order, view (x, y) maps directly to
|
|
595
|
+
array[int(x), int(y)] — x is the row axis, y is the column axis.
|
|
596
|
+
"""
|
|
597
|
+
image = self._raw_image
|
|
598
|
+
if image is None:
|
|
599
|
+
return ""
|
|
600
|
+
|
|
601
|
+
row, col = int(x), int(y)
|
|
602
|
+
if row < 0 or col < 0 or row >= image.shape[0] or col >= image.shape[1]:
|
|
603
|
+
return ""
|
|
604
|
+
|
|
605
|
+
intensity = image[row, col]
|
|
606
|
+
return f"x={x:.1f} y={y:.1f} I={intensity:.0f}"
|
|
607
|
+
|
|
608
|
+
# =====================================================================
|
|
609
|
+
# Device dimension helpers (called from background thread)
|
|
610
|
+
# =====================================================================
|
|
611
|
+
|
|
612
|
+
def _get_image_dimensions(self, image_plugin: Any = None) -> tuple[int | None, int | None]:
|
|
613
|
+
"""Get image width and height from plugin or cam."""
|
|
614
|
+
try:
|
|
615
|
+
if image_plugin is not None:
|
|
616
|
+
w = getattr(image_plugin, "width", None)
|
|
617
|
+
h = getattr(image_plugin, "height", None)
|
|
618
|
+
if w is not None and h is not None:
|
|
619
|
+
width, height = int(w.get()), int(h.get())
|
|
620
|
+
if width > 0 and height > 0:
|
|
621
|
+
return width, height
|
|
622
|
+
|
|
623
|
+
cam = getattr(self._device, "cam", None)
|
|
624
|
+
if cam is not None:
|
|
625
|
+
size = getattr(cam, "array_size", None)
|
|
626
|
+
if size is not None:
|
|
627
|
+
dims = size.get()
|
|
628
|
+
if hasattr(dims, "array_size_x") and hasattr(dims, "array_size_y"):
|
|
629
|
+
width = int(dims.array_size_x)
|
|
630
|
+
height = int(dims.array_size_y)
|
|
631
|
+
if width > 0 and height > 0:
|
|
632
|
+
return width, height
|
|
633
|
+
except Exception as e:
|
|
634
|
+
logger.debug(f"Failed to get image dimensions: {e}")
|
|
635
|
+
|
|
636
|
+
return None, None
|
|
637
|
+
|
|
638
|
+
# =====================================================================
|
|
639
|
+
# Lifecycle
|
|
640
|
+
# =====================================================================
|
|
641
|
+
|
|
642
|
+
def close(self) -> None:
|
|
643
|
+
"""Stop background thread and timers."""
|
|
644
|
+
self._poll_stop.set()
|
|
645
|
+
if self._poll_thread is not None:
|
|
646
|
+
self._poll_thread.join(timeout=2.0)
|
|
647
|
+
if hasattr(self, "_ui_timer") and self._ui_timer is not None:
|
|
648
|
+
self._ui_timer.stop()
|
|
649
|
+
super().close()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Device-specific panels for camera control widgets.
|
|
2
|
+
|
|
3
|
+
Panels:
|
|
4
|
+
CoolerPanel: Andor-style cooler controls
|
|
5
|
+
TemperaturePanel: PIMTE-style temperature display
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from lightfall.ui.widgets.camera.panels.cooler import CoolerPanel
|
|
9
|
+
from lightfall.ui.widgets.camera.panels.temperature import TemperaturePanel
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"CoolerPanel",
|
|
13
|
+
"TemperaturePanel",
|
|
14
|
+
]
|