pml_utilities 4.0.0__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.
- mbo_utilities/__init__.py +220 -0
- mbo_utilities/_cellpose_model.py +95 -0
- mbo_utilities/_shortcut.py +180 -0
- mbo_utilities/_sysmem.py +346 -0
- mbo_utilities/_writers.py +2089 -0
- mbo_utilities/analysis/__init__.py +57 -0
- mbo_utilities/analysis/dff.py +257 -0
- mbo_utilities/analysis/filters.py +129 -0
- mbo_utilities/analysis/linescan.py +176 -0
- mbo_utilities/analysis/mesc_placement.py +329 -0
- mbo_utilities/analysis/phasecorr.py +119 -0
- mbo_utilities/analysis/roi_traces.py +487 -0
- mbo_utilities/analysis/scanphase.py +556 -0
- mbo_utilities/analysis/slow_fast.py +219 -0
- mbo_utilities/analysis/spike_average.py +330 -0
- mbo_utilities/analysis/trace_readouts.py +244 -0
- mbo_utilities/annotation/__init__.py +81 -0
- mbo_utilities/annotation/display.py +387 -0
- mbo_utilities/annotation/domains.py +327 -0
- mbo_utilities/annotation/events.py +90 -0
- mbo_utilities/annotation/model.py +234 -0
- mbo_utilities/annotation/ngff.py +469 -0
- mbo_utilities/annotation/slow_fast.py +495 -0
- mbo_utilities/annotation/store.py +485 -0
- mbo_utilities/annotation/traces.py +267 -0
- mbo_utilities/arrays/__init__.py +311 -0
- mbo_utilities/arrays/_average_view.py +309 -0
- mbo_utilities/arrays/_base.py +950 -0
- mbo_utilities/arrays/_channel_view.py +92 -0
- mbo_utilities/arrays/_inverted_view.py +139 -0
- mbo_utilities/arrays/_phasecorr_view.py +255 -0
- mbo_utilities/arrays/_registration.py +777 -0
- mbo_utilities/arrays/bin.py +261 -0
- mbo_utilities/arrays/bruker.py +190 -0
- mbo_utilities/arrays/compression.py +136 -0
- mbo_utilities/arrays/demixing.py +337 -0
- mbo_utilities/arrays/features/__init__.py +203 -0
- mbo_utilities/arrays/features/_base.py +91 -0
- mbo_utilities/arrays/features/_chunks.py +89 -0
- mbo_utilities/arrays/features/_dim_labels.py +316 -0
- mbo_utilities/arrays/features/_dim_spec.py +208 -0
- mbo_utilities/arrays/features/_dim_tags.py +453 -0
- mbo_utilities/arrays/features/_frame_average.py +196 -0
- mbo_utilities/arrays/features/_motion.py +49 -0
- mbo_utilities/arrays/features/_phase_correction.py +327 -0
- mbo_utilities/arrays/features/_pyramid.py +315 -0
- mbo_utilities/arrays/features/_roi.py +234 -0
- mbo_utilities/arrays/features/_segmentation.py +121 -0
- mbo_utilities/arrays/features/_selection.py +91 -0
- mbo_utilities/arrays/features/_slicing.py +601 -0
- mbo_utilities/arrays/features/_stats.py +24 -0
- mbo_utilities/arrays/features/_summary_stats.py +396 -0
- mbo_utilities/arrays/h5.py +391 -0
- mbo_utilities/arrays/isoview/__init__.py +57 -0
- mbo_utilities/arrays/isoview/array.py +2405 -0
- mbo_utilities/arrays/isoview/consolidate.py +1822 -0
- mbo_utilities/arrays/lab4.py +257 -0
- mbo_utilities/arrays/masknmf_run.py +283 -0
- mbo_utilities/arrays/mesc.py +1780 -0
- mbo_utilities/arrays/mesc_geometry.py +375 -0
- mbo_utilities/arrays/mp4.py +921 -0
- mbo_utilities/arrays/numpy.py +434 -0
- mbo_utilities/arrays/suite2p.py +995 -0
- mbo_utilities/arrays/tiff.py +1569 -0
- mbo_utilities/arrays/zarr.py +716 -0
- mbo_utilities/assets/app_settings/icon.ico +0 -0
- mbo_utilities/assets/app_settings/icon.png +0 -0
- mbo_utilities/assets/docs/file_formats.md +39 -0
- mbo_utilities/assets/docs/gui_quickstart.md +44 -0
- mbo_utilities/assets/docs/mesc.md +84 -0
- mbo_utilities/assets/fonts/Akronim-Regular.ttf +0 -0
- mbo_utilities/assets/fonts/DroidSans.ttf +0 -0
- mbo_utilities/assets/fonts/Font_Awesome_6_Free-Solid-900.otf +0 -0
- mbo_utilities/assets/fonts/Inconsolata-Medium.ttf +0 -0
- mbo_utilities/assets/fonts/JetBrainsMono/JetBrainsMonoNerdFont-Bold.ttf +0 -0
- mbo_utilities/assets/fonts/JetBrainsMono/OFL.txt +93 -0
- mbo_utilities/assets/fonts/JetBrainsMono/README.md +48 -0
- mbo_utilities/assets/fonts/Roboto/LICENSE.txt +202 -0
- mbo_utilities/assets/fonts/Roboto/Roboto-Bold.ttf +0 -0
- mbo_utilities/assets/fonts/Roboto/Roboto-BoldItalic.ttf +0 -0
- mbo_utilities/assets/fonts/Roboto/Roboto-Regular.ttf +0 -0
- mbo_utilities/assets/fonts/Roboto/Roboto-RegularItalic.ttf +0 -0
- mbo_utilities/assets/fonts/SourceCodePro-Regular.ttf +0 -0
- mbo_utilities/assets/fonts/fontawesome-webfont.ttf +0 -0
- mbo_utilities/assets/notebooks/asap7_spine_pipeline.ipynb +345 -0
- mbo_utilities/assets/notebooks/lsp_user_guide.ipynb +1818 -0
- mbo_utilities/assets/notebooks/mbo_user_guide.ipynb +1080 -0
- mbo_utilities/assets/static/canvas_client.js +167 -0
- mbo_utilities/assets/static/icon_caiman_python.svg +1 -0
- mbo_utilities/assets/static/icon_mbo_home.png +0 -0
- mbo_utilities/assets/static/icon_mbo_home.svg +1 -0
- mbo_utilities/assets/static/icon_suite2p.svg +1 -0
- mbo_utilities/assets/static/lbm_mat_favicon.svg +1 -0
- mbo_utilities/assets/static/logo_utilities.png +0 -0
- mbo_utilities/assets/static/mbo.png +0 -0
- mbo_utilities/assets/static/mbo_home_icon.png +0 -0
- mbo_utilities/assets/static/mbo_hub_saph.svg +1 -0
- mbo_utilities/assets/static/mbo_icon.ico +0 -0
- mbo_utilities/assets/static/mbo_icon_dark.ico +0 -0
- mbo_utilities/assets/static/utilities.png +0 -0
- mbo_utilities/behavior/__init__.py +175 -0
- mbo_utilities/behavior/tdml.py +139 -0
- mbo_utilities/cli.py +2527 -0
- mbo_utilities/dashboard.py +966 -0
- mbo_utilities/env_cache.py +335 -0
- mbo_utilities/file_io.py +315 -0
- mbo_utilities/gpu.py +531 -0
- mbo_utilities/gui/__init__.py +78 -0
- mbo_utilities/gui/_availability.py +25 -0
- mbo_utilities/gui/_colormaps.py +38 -0
- mbo_utilities/gui/_dialogs.py +421 -0
- mbo_utilities/gui/_edge_window.py +25 -0
- mbo_utilities/gui/_files.py +144 -0
- mbo_utilities/gui/_fpl_config.py +45 -0
- mbo_utilities/gui/_gpu_cache.py +65 -0
- mbo_utilities/gui/_gpu_status.py +140 -0
- mbo_utilities/gui/_help_viewer.py +324 -0
- mbo_utilities/gui/_imgui_helpers.py +797 -0
- mbo_utilities/gui/_isoview_crop_state.py +286 -0
- mbo_utilities/gui/_isoview_orient_state.py +60 -0
- mbo_utilities/gui/_keyboard.py +307 -0
- mbo_utilities/gui/_metadata.py +824 -0
- mbo_utilities/gui/_metadata_editor.py +436 -0
- mbo_utilities/gui/_ndviewer.py +1189 -0
- mbo_utilities/gui/_notebook.py +47 -0
- mbo_utilities/gui/_options_popup.py +486 -0
- mbo_utilities/gui/_popups.py +641 -0
- mbo_utilities/gui/_save_as.py +1131 -0
- mbo_utilities/gui/_selection_ui.py +288 -0
- mbo_utilities/gui/_setup.py +176 -0
- mbo_utilities/gui/_stats.py +1266 -0
- mbo_utilities/gui/_theme.py +179 -0
- mbo_utilities/gui/_top_strip.py +377 -0
- mbo_utilities/gui/_worker.py +512 -0
- mbo_utilities/gui/canvas_server.py +456 -0
- mbo_utilities/gui/curation_server.py +137 -0
- mbo_utilities/gui/curation_viewer.py +483 -0
- mbo_utilities/gui/dashboard_app.py +1373 -0
- mbo_utilities/gui/dashboard_morphology.py +511 -0
- mbo_utilities/gui/dashboard_readouts.py +263 -0
- mbo_utilities/gui/data_vis.py +164 -0
- mbo_utilities/gui/event_curation.py +1903 -0
- mbo_utilities/gui/gateway.py +902 -0
- mbo_utilities/gui/imgui/__init__.py +56 -0
- mbo_utilities/gui/imgui/behavior.py +310 -0
- mbo_utilities/gui/imgui/crop.py +32 -0
- mbo_utilities/gui/imgui/labels.py +127 -0
- mbo_utilities/gui/imgui/lines.py +311 -0
- mbo_utilities/gui/imgui/motion.py +140 -0
- mbo_utilities/gui/imgui/movie_player.py +109 -0
- mbo_utilities/gui/imgui/panels.py +131 -0
- mbo_utilities/gui/imgui/scatter.py +233 -0
- mbo_utilities/gui/imgui/summary.py +518 -0
- mbo_utilities/gui/imgui/table.py +310 -0
- mbo_utilities/gui/imgui/vnoiser_help.py +1042 -0
- mbo_utilities/gui/launch.py +78 -0
- mbo_utilities/gui/linescan_viewer.py +325 -0
- mbo_utilities/gui/manual_roi.py +1472 -0
- mbo_utilities/gui/masknmf_vis.py +190 -0
- mbo_utilities/gui/mesc_reference.py +565 -0
- mbo_utilities/gui/panels/__init__.py +7 -0
- mbo_utilities/gui/panels/debug_log.py +35 -0
- mbo_utilities/gui/playhead.py +75 -0
- mbo_utilities/gui/reg_denoise_viewer.py +178 -0
- mbo_utilities/gui/roi/__init__.py +3 -0
- mbo_utilities/gui/roi/_shared.py +414 -0
- mbo_utilities/gui/roi/curation.py +821 -0
- mbo_utilities/gui/roi/jobs.py +720 -0
- mbo_utilities/gui/roi/keys.py +117 -0
- mbo_utilities/gui/roi/overlay.py +363 -0
- mbo_utilities/gui/roi/selection.py +604 -0
- mbo_utilities/gui/roi/trace_table.py +330 -0
- mbo_utilities/gui/roi/traces_panel.py +907 -0
- mbo_utilities/gui/roi_runs.py +756 -0
- mbo_utilities/gui/run_gui.py +1390 -0
- mbo_utilities/gui/slice.py +99 -0
- mbo_utilities/gui/slow_fast_panels.py +284 -0
- mbo_utilities/gui/spike_average_viewer.py +407 -0
- mbo_utilities/gui/studio_server.py +173 -0
- mbo_utilities/gui/tasks.py +1152 -0
- mbo_utilities/gui/viewers/__init__.py +84 -0
- mbo_utilities/gui/viewers/pollen_calibration.py +1274 -0
- mbo_utilities/gui/viewers/time_series.py +97 -0
- mbo_utilities/gui/widgets/__init__.py +145 -0
- mbo_utilities/gui/widgets/_base.py +74 -0
- mbo_utilities/gui/widgets/_orient.py +16 -0
- mbo_utilities/gui/widgets/diagnostics.py +1062 -0
- mbo_utilities/gui/widgets/file_dialog.py +790 -0
- mbo_utilities/gui/widgets/grid_search.py +460 -0
- mbo_utilities/gui/widgets/gui_logger.py +277 -0
- mbo_utilities/gui/widgets/imgui_debug.py +105 -0
- mbo_utilities/gui/widgets/isoview_crop.py +759 -0
- mbo_utilities/gui/widgets/isoview_deadpixel.py +805 -0
- mbo_utilities/gui/widgets/isoview_segment.py +860 -0
- mbo_utilities/gui/widgets/menu_bar.py +333 -0
- mbo_utilities/gui/widgets/mesc_units.py +764 -0
- mbo_utilities/gui/widgets/page_axis.py +97 -0
- mbo_utilities/gui/widgets/pipelines/__init__.py +324 -0
- mbo_utilities/gui/widgets/pipelines/_base.py +77 -0
- mbo_utilities/gui/widgets/pipelines/_s2p_schema.py +696 -0
- mbo_utilities/gui/widgets/pipelines/isoview.py +3078 -0
- mbo_utilities/gui/widgets/pipelines/masknmf.py +1013 -0
- mbo_utilities/gui/widgets/pipelines/settings.py +3779 -0
- mbo_utilities/gui/widgets/pipelines/suite2p.py +522 -0
- mbo_utilities/gui/widgets/pipelines/vnoiser.py +2488 -0
- mbo_utilities/gui/widgets/pipelines/vnoiser_hints.py +423 -0
- mbo_utilities/gui/widgets/preview_data.py +1213 -0
- mbo_utilities/gui/widgets/process_manager.py +599 -0
- mbo_utilities/gui/widgets/progress_bar.py +236 -0
- mbo_utilities/gui/widgets/projections.py +699 -0
- mbo_utilities/gui/widgets/simple_selector.py +120 -0
- mbo_utilities/gui/widgets/summary_image.py +885 -0
- mbo_utilities/gui/widgets/tabs.py +213 -0
- mbo_utilities/gui/widgets/tile_grid.py +1256 -0
- mbo_utilities/gui/widgets/widget_toggles.py +213 -0
- mbo_utilities/gui/widgets/window_functions.py +214 -0
- mbo_utilities/hpc/__init__.py +52 -0
- mbo_utilities/hpc/check.py +201 -0
- mbo_utilities/hpc/cli.py +427 -0
- mbo_utilities/hpc/cluster.py +145 -0
- mbo_utilities/hpc/config.py +387 -0
- mbo_utilities/hpc/history.py +131 -0
- mbo_utilities/hpc/logs.py +328 -0
- mbo_utilities/hpc/pipeline.py +654 -0
- mbo_utilities/hpc/slurm.py +150 -0
- mbo_utilities/hpc/submit.py +206 -0
- mbo_utilities/install.py +540 -0
- mbo_utilities/lazy_array.py +441 -0
- mbo_utilities/log.py +76 -0
- mbo_utilities/masknmf/__init__.py +42 -0
- mbo_utilities/masknmf/asap7.py +254 -0
- mbo_utilities/masknmf/outputs.py +234 -0
- mbo_utilities/masknmf/params.py +371 -0
- mbo_utilities/masknmf/qc.py +840 -0
- mbo_utilities/masknmf/reg_denoise.py +383 -0
- mbo_utilities/masknmf/runner.py +788 -0
- mbo_utilities/metadata/__init__.py +132 -0
- mbo_utilities/metadata/_filename_parser.py +245 -0
- mbo_utilities/metadata/base.py +769 -0
- mbo_utilities/metadata/io.py +1200 -0
- mbo_utilities/metadata/output.py +602 -0
- mbo_utilities/metadata/params.py +425 -0
- mbo_utilities/metadata/scanimage.py +547 -0
- mbo_utilities/notebook_templates.py +95 -0
- mbo_utilities/pipeline_registry.py +169 -0
- mbo_utilities/preferences.py +568 -0
- mbo_utilities/reader.py +519 -0
- mbo_utilities/results.py +1368 -0
- mbo_utilities/roi_workflow.py +1381 -0
- mbo_utilities/squeeze.py +99 -0
- mbo_utilities/vnoiser/__init__.py +34 -0
- mbo_utilities/vnoiser/params.py +344 -0
- mbo_utilities/vnoiser/pipeline.py +1189 -0
- mbo_utilities/vnoiser/session.py +629 -0
- mbo_utilities/writer.py +526 -0
- pml_utilities-4.0.0.dist-info/METADATA +164 -0
- pml_utilities-4.0.0.dist-info/RECORD +264 -0
- pml_utilities-4.0.0.dist-info/WHEEL +5 -0
- pml_utilities-4.0.0.dist-info/entry_points.txt +23 -0
- pml_utilities-4.0.0.dist-info/licenses/LICENSE.md +17 -0
- pml_utilities-4.0.0.dist-info/top_level.txt +2 -0
- pollen/__init__.py +0 -0
- pollen/_pollen_analysis.py +1032 -0
- pollen/pollen_calibration_mbo.py +1293 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"""
|
|
2
|
+
mbo_utilities - Miller Brain Observatory data processing utilities.
|
|
3
|
+
|
|
4
|
+
This package uses lazy imports to minimize startup time. Heavy dependencies
|
|
5
|
+
like numpy, dask, and tifffile are only loaded when actually needed.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import importlib.util
|
|
9
|
+
import os
|
|
10
|
+
import sys
|
|
11
|
+
import warnings
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
# Suppress annoying CuPy warning about CUDA path (usually harmless if CUDA works)
|
|
15
|
+
warnings.filterwarnings(
|
|
16
|
+
"ignore", category=UserWarning, message="CUDA path could not be detected"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
if sys.platform == "darwin":
|
|
20
|
+
# pyglfw must load imgui_bundle's libglfw: two copies in one process clash in cocoa
|
|
21
|
+
_glfw_lib = (
|
|
22
|
+
Path(importlib.util.find_spec("imgui_bundle").submodule_search_locations[0])
|
|
23
|
+
/ "libglfw.3.dylib"
|
|
24
|
+
)
|
|
25
|
+
if _glfw_lib.exists():
|
|
26
|
+
os.environ.setdefault("PYGLFW_LIBRARY", str(_glfw_lib))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"AxialShiftView",
|
|
31
|
+
"MBO_SUPPORTED_FTYPES",
|
|
32
|
+
"VoxelSize",
|
|
33
|
+
"add_recent_file",
|
|
34
|
+
"expand_paths",
|
|
35
|
+
"files_to_dask",
|
|
36
|
+
"get_all_input_patterns",
|
|
37
|
+
"get_all_marker_files",
|
|
38
|
+
"get_all_output_patterns",
|
|
39
|
+
"get_all_pipelines",
|
|
40
|
+
"get_files",
|
|
41
|
+
"get_last_open_dir",
|
|
42
|
+
"get_last_save_dir",
|
|
43
|
+
"get_mbo_dirs",
|
|
44
|
+
"MemoryMonitor",
|
|
45
|
+
"mem_snapshot",
|
|
46
|
+
"memory_monitor",
|
|
47
|
+
"start_memory_monitor",
|
|
48
|
+
"stop_memory_monitor",
|
|
49
|
+
"get_metadata",
|
|
50
|
+
"get_pipeline_info",
|
|
51
|
+
"get_recent_files",
|
|
52
|
+
"get_voxel_size",
|
|
53
|
+
"imread",
|
|
54
|
+
"imwrite",
|
|
55
|
+
"LazyArray",
|
|
56
|
+
"register_array_class",
|
|
57
|
+
"is_raw_scanimage",
|
|
58
|
+
"load_npy",
|
|
59
|
+
"load_ops",
|
|
60
|
+
"merge_zarr_zplanes",
|
|
61
|
+
"normalize_resolution",
|
|
62
|
+
"select_files",
|
|
63
|
+
"select_folder",
|
|
64
|
+
"set_last_open_dir",
|
|
65
|
+
"set_last_save_dir",
|
|
66
|
+
"DataVis",
|
|
67
|
+
"run_gui",
|
|
68
|
+
"to_video",
|
|
69
|
+
"with_axial_shifts",
|
|
70
|
+
"with_phasecorr",
|
|
71
|
+
"write_ops",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def __getattr__(name):
|
|
76
|
+
"""Lazy import attributes to avoid loading heavy dependencies at startup."""
|
|
77
|
+
# Version (importlib.metadata pulls email + zipfile; defer to keep CLI startup fast)
|
|
78
|
+
if name == "__version__":
|
|
79
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
80
|
+
|
|
81
|
+
for dist in ("pml_utilities", "mbo_utilities"):
|
|
82
|
+
try:
|
|
83
|
+
return version(dist)
|
|
84
|
+
except PackageNotFoundError:
|
|
85
|
+
continue
|
|
86
|
+
return "0.0.0"
|
|
87
|
+
|
|
88
|
+
if name == "imread":
|
|
89
|
+
from .reader import imread
|
|
90
|
+
|
|
91
|
+
return imread
|
|
92
|
+
if name == "imwrite":
|
|
93
|
+
from .writer import imwrite
|
|
94
|
+
|
|
95
|
+
return imwrite
|
|
96
|
+
if name == "MBO_SUPPORTED_FTYPES":
|
|
97
|
+
from .reader import MBO_SUPPORTED_FTYPES
|
|
98
|
+
|
|
99
|
+
return MBO_SUPPORTED_FTYPES
|
|
100
|
+
|
|
101
|
+
if name in ("LazyArray", "register_array_class"):
|
|
102
|
+
from .lazy_array import LazyArray, register_array_class
|
|
103
|
+
|
|
104
|
+
return LazyArray if name == "LazyArray" else register_array_class
|
|
105
|
+
|
|
106
|
+
if name == "get_mbo_dirs":
|
|
107
|
+
from .preferences import get_mbo_dirs
|
|
108
|
+
|
|
109
|
+
return get_mbo_dirs
|
|
110
|
+
|
|
111
|
+
if name in (
|
|
112
|
+
"MemoryMonitor",
|
|
113
|
+
"mem_snapshot",
|
|
114
|
+
"memory_monitor",
|
|
115
|
+
"start_memory_monitor",
|
|
116
|
+
"stop_memory_monitor",
|
|
117
|
+
):
|
|
118
|
+
from . import _sysmem
|
|
119
|
+
|
|
120
|
+
return getattr(_sysmem, name)
|
|
121
|
+
|
|
122
|
+
if name == "files_to_dask":
|
|
123
|
+
from .arrays import files_to_dask
|
|
124
|
+
|
|
125
|
+
return files_to_dask
|
|
126
|
+
|
|
127
|
+
if name in ("with_axial_shifts", "AxialShiftView"):
|
|
128
|
+
from .arrays import AxialShiftView, with_axial_shifts
|
|
129
|
+
|
|
130
|
+
return with_axial_shifts if name == "with_axial_shifts" else AxialShiftView
|
|
131
|
+
|
|
132
|
+
if name == "with_phasecorr":
|
|
133
|
+
from .arrays import with_phasecorr
|
|
134
|
+
|
|
135
|
+
return with_phasecorr
|
|
136
|
+
|
|
137
|
+
if name in (
|
|
138
|
+
"get_files",
|
|
139
|
+
"expand_paths",
|
|
140
|
+
"merge_zarr_zplanes",
|
|
141
|
+
):
|
|
142
|
+
from . import file_io
|
|
143
|
+
|
|
144
|
+
return getattr(file_io, name)
|
|
145
|
+
|
|
146
|
+
if name == "load_ops":
|
|
147
|
+
from .arrays.suite2p import load_ops
|
|
148
|
+
|
|
149
|
+
return load_ops
|
|
150
|
+
if name == "write_ops":
|
|
151
|
+
from ._writers import write_ops
|
|
152
|
+
|
|
153
|
+
return write_ops
|
|
154
|
+
|
|
155
|
+
if name in (
|
|
156
|
+
"is_raw_scanimage",
|
|
157
|
+
"get_metadata",
|
|
158
|
+
"get_voxel_size",
|
|
159
|
+
"normalize_resolution",
|
|
160
|
+
"VoxelSize",
|
|
161
|
+
):
|
|
162
|
+
from . import metadata
|
|
163
|
+
|
|
164
|
+
return getattr(metadata, name)
|
|
165
|
+
|
|
166
|
+
if name in (
|
|
167
|
+
"get_recent_files",
|
|
168
|
+
"add_recent_file",
|
|
169
|
+
"get_last_open_dir",
|
|
170
|
+
"set_last_open_dir",
|
|
171
|
+
"get_last_save_dir",
|
|
172
|
+
"set_last_save_dir",
|
|
173
|
+
):
|
|
174
|
+
from . import preferences
|
|
175
|
+
|
|
176
|
+
return getattr(preferences, name)
|
|
177
|
+
|
|
178
|
+
if name == "load_npy":
|
|
179
|
+
from .file_io import load_npy
|
|
180
|
+
|
|
181
|
+
return load_npy
|
|
182
|
+
|
|
183
|
+
if name == "to_video":
|
|
184
|
+
from ._writers import to_video
|
|
185
|
+
|
|
186
|
+
return to_video
|
|
187
|
+
|
|
188
|
+
# The viewer. `from .gui import run_gui` cannot be used here: importing the
|
|
189
|
+
# submodule binds `mbo_utilities.gui.run_gui` to the MODULE, which then wins
|
|
190
|
+
# over that package's lazy __getattr__ and hands callers a module instead of
|
|
191
|
+
# the function. Reaching into the submodule directly is unambiguous.
|
|
192
|
+
if name == "run_gui":
|
|
193
|
+
from .gui.run_gui import run_gui
|
|
194
|
+
|
|
195
|
+
return run_gui
|
|
196
|
+
if name == "DataVis":
|
|
197
|
+
from .gui.data_vis import DataVis
|
|
198
|
+
|
|
199
|
+
return DataVis
|
|
200
|
+
|
|
201
|
+
if name in ("select_folder", "select_files"):
|
|
202
|
+
from .gui.widgets.simple_selector import select_files, select_folder
|
|
203
|
+
|
|
204
|
+
return select_folder if name == "select_folder" else select_files
|
|
205
|
+
|
|
206
|
+
if name in (
|
|
207
|
+
"get_all_pipelines",
|
|
208
|
+
"get_pipeline_info",
|
|
209
|
+
"get_all_input_patterns",
|
|
210
|
+
"get_all_output_patterns",
|
|
211
|
+
"get_all_marker_files",
|
|
212
|
+
):
|
|
213
|
+
from .arrays import register_all_pipelines
|
|
214
|
+
|
|
215
|
+
register_all_pipelines()
|
|
216
|
+
from . import pipeline_registry
|
|
217
|
+
|
|
218
|
+
return getattr(pipeline_registry, name)
|
|
219
|
+
|
|
220
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Race-free provisioning of the cellpose model used by suite2p detection.
|
|
2
|
+
|
|
3
|
+
suite2p anatomical ROI detection loads the default "cpsam" checkpoint through
|
|
4
|
+
cellpose. When the model is not cached yet and the pipeline fans out to N
|
|
5
|
+
parallel plane workers, every worker downloads to the same path at once; the
|
|
6
|
+
overlapping writes corrupt the file and torch.load fails with a
|
|
7
|
+
PytorchStreamReader/miniz error. ensure_cellpose_model() downloads and
|
|
8
|
+
validates the file once in the parent process before fan-out.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import logging
|
|
14
|
+
import zipfile
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _log(logger: logging.Logger | None, msg: str) -> None:
|
|
19
|
+
if logger is not None:
|
|
20
|
+
logger.info(msg)
|
|
21
|
+
else:
|
|
22
|
+
print(msg)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _is_valid_checkpoint(path: Path) -> bool:
|
|
26
|
+
"""True if path is a readable torch zip checkpoint (full CRC check)."""
|
|
27
|
+
try:
|
|
28
|
+
if not path.exists() or not zipfile.is_zipfile(path):
|
|
29
|
+
return False
|
|
30
|
+
with zipfile.ZipFile(path) as zf:
|
|
31
|
+
return zf.testzip() is None
|
|
32
|
+
except Exception:
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def ensure_cellpose_model(
|
|
37
|
+
force: bool = False, logger: logging.Logger | None = None
|
|
38
|
+
) -> str | None:
|
|
39
|
+
"""Download and validate the cellpose "cpsam" model once, serially.
|
|
40
|
+
|
|
41
|
+
Returns the model path, or None if cellpose is unavailable or the file
|
|
42
|
+
could not be made valid. A ``cpsam.verified`` marker caches the
|
|
43
|
+
validation so steady-state calls only stat two files.
|
|
44
|
+
"""
|
|
45
|
+
try:
|
|
46
|
+
from cellpose import models
|
|
47
|
+
except Exception as e:
|
|
48
|
+
_log(logger, f"cellpose not available, skipping model prefetch: {e}")
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
path = Path(models.MODEL_DIR) / "cpsam"
|
|
52
|
+
marker = path.with_name("cpsam.verified")
|
|
53
|
+
|
|
54
|
+
# fast path: a validation marker newer than the model file means a prior
|
|
55
|
+
# call already CRC-checked this exact file.
|
|
56
|
+
if not force and path.exists() and marker.exists():
|
|
57
|
+
try:
|
|
58
|
+
if marker.stat().st_mtime >= path.stat().st_mtime:
|
|
59
|
+
return str(path)
|
|
60
|
+
except OSError:
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
valid = _is_valid_checkpoint(path) if path.exists() else False
|
|
64
|
+
|
|
65
|
+
if force or not valid:
|
|
66
|
+
if path.exists():
|
|
67
|
+
reason = "forced refresh" if force and valid else "corrupt"
|
|
68
|
+
_log(logger, f"cellpose model {reason}; re-downloading cpsam")
|
|
69
|
+
# the cache call only downloads when the file is absent, so remove
|
|
70
|
+
# the bad/forced one first.
|
|
71
|
+
try:
|
|
72
|
+
path.unlink()
|
|
73
|
+
except OSError:
|
|
74
|
+
pass
|
|
75
|
+
_log(logger, "Pre-fetching cellpose model (cpsam, ~1.15 GB)...")
|
|
76
|
+
try:
|
|
77
|
+
# cellpose 4.x renamed cache_CPSAM_model_path() -> cache_model_path(backbone)
|
|
78
|
+
if hasattr(models, "cache_model_path"):
|
|
79
|
+
models.cache_model_path("cpsam")
|
|
80
|
+
else:
|
|
81
|
+
models.cache_CPSAM_model_path()
|
|
82
|
+
except Exception as e:
|
|
83
|
+
_log(logger, f"cellpose model download failed: {e}")
|
|
84
|
+
return None
|
|
85
|
+
valid = _is_valid_checkpoint(path)
|
|
86
|
+
|
|
87
|
+
if valid:
|
|
88
|
+
try:
|
|
89
|
+
marker.write_text("ok", encoding="utf-8")
|
|
90
|
+
except OSError:
|
|
91
|
+
pass
|
|
92
|
+
return str(path)
|
|
93
|
+
|
|
94
|
+
_log(logger, "cellpose model still invalid after download")
|
|
95
|
+
return None
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""Create a desktop shortcut/launcher for the mbo GUI.
|
|
2
|
+
|
|
3
|
+
Windows: a .lnk on the Desktop that runs mbo.exe through a hidden-window
|
|
4
|
+
VBScript launcher (no console), using the bundled icon.
|
|
5
|
+
Linux: a freedesktop .desktop entry on the Desktop.
|
|
6
|
+
|
|
7
|
+
This mirrors the desktop-shortcut step of scripts/install.ps1 so local
|
|
8
|
+
installs (plain pip/uv pip install) can get the same icon without the web
|
|
9
|
+
installer. The bundled icon is read from the installed package, so no
|
|
10
|
+
download is needed.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import shutil
|
|
17
|
+
import subprocess
|
|
18
|
+
import sys
|
|
19
|
+
from pathlib import Path
|
|
20
|
+
|
|
21
|
+
APP_NAME = "The Studio"
|
|
22
|
+
DESCRIPTION = "MBO Image Viewer"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _find_mbo_exe() -> Path | None:
|
|
26
|
+
"""Locate the mbo launcher for the running install.
|
|
27
|
+
|
|
28
|
+
Prefer the launcher next to the running interpreter so a local env
|
|
29
|
+
targets itself rather than a global mbo that happens to be on PATH.
|
|
30
|
+
"""
|
|
31
|
+
base = Path(sys.executable).parent
|
|
32
|
+
names = ["mbo.exe", "mbo"] if os.name == "nt" else ["mbo"]
|
|
33
|
+
for d in (base, base / "Scripts", base / "bin"):
|
|
34
|
+
for n in names:
|
|
35
|
+
p = d / n
|
|
36
|
+
if p.exists():
|
|
37
|
+
return p
|
|
38
|
+
exe = shutil.which("mbo")
|
|
39
|
+
return Path(exe) if exe else None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _bundled_icon(suffix: str) -> Path | None:
|
|
43
|
+
p = Path(__file__).resolve().parent / "assets" / "app_settings" / f"icon{suffix}"
|
|
44
|
+
return p if p.exists() else None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _copy_icon(suffix: str, base: Path) -> str:
|
|
48
|
+
"""Copy the bundled icon next to the launcher so the shortcut keeps its
|
|
49
|
+
icon even if the package is upgraded or moved. Returns the path to use,
|
|
50
|
+
or "" if no icon is available.
|
|
51
|
+
"""
|
|
52
|
+
src = _bundled_icon(suffix)
|
|
53
|
+
if src is None:
|
|
54
|
+
return ""
|
|
55
|
+
dst = base / f"icon{suffix}"
|
|
56
|
+
try:
|
|
57
|
+
shutil.copyfile(src, dst)
|
|
58
|
+
return str(dst)
|
|
59
|
+
except OSError:
|
|
60
|
+
return str(src)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def create_desktop_shortcut(name: str = APP_NAME) -> Path:
|
|
64
|
+
"""Create a desktop shortcut that opens the GUI. Returns its path."""
|
|
65
|
+
if sys.platform == "win32":
|
|
66
|
+
return _create_windows_shortcut(name)
|
|
67
|
+
if sys.platform.startswith("linux"):
|
|
68
|
+
return _create_linux_shortcut(name)
|
|
69
|
+
raise RuntimeError(f"Desktop shortcuts are not supported on {sys.platform}.")
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _create_windows_shortcut(name: str) -> Path:
|
|
73
|
+
from mbo_utilities import get_mbo_dirs
|
|
74
|
+
|
|
75
|
+
exe = _find_mbo_exe()
|
|
76
|
+
if exe is None:
|
|
77
|
+
raise RuntimeError(
|
|
78
|
+
"Could not find mbo.exe. Is mbo_utilities installed on PATH?"
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
base = get_mbo_dirs()["base"]
|
|
82
|
+
icon = _copy_icon(".ico", base)
|
|
83
|
+
|
|
84
|
+
# hidden-window launcher: run mbo.exe with no console window
|
|
85
|
+
vbs = base / "mbo_launcher.vbs"
|
|
86
|
+
vbs.write_text(
|
|
87
|
+
'Set WshShell = CreateObject("WScript.Shell")\r\n'
|
|
88
|
+
f'WshShell.Run """{exe}""", 0, False\r\n',
|
|
89
|
+
encoding="ascii",
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
# create the .lnk via WScript.Shell COM; values passed as env vars to
|
|
93
|
+
# avoid quoting/escaping issues with paths
|
|
94
|
+
ps = (
|
|
95
|
+
"$ErrorActionPreference='Stop'\n"
|
|
96
|
+
"$desktop=[Environment]::GetFolderPath('Desktop')\n"
|
|
97
|
+
"$lnk=Join-Path $desktop ($env:MBO_SC_NAME + '.lnk')\n"
|
|
98
|
+
"$sc=(New-Object -ComObject WScript.Shell).CreateShortcut($lnk)\n"
|
|
99
|
+
"$sc.TargetPath='wscript.exe'\n"
|
|
100
|
+
"$sc.Arguments='\"' + $env:MBO_SC_VBS + '\"'\n"
|
|
101
|
+
"$sc.WorkingDirectory=[Environment]::GetFolderPath('UserProfile')\n"
|
|
102
|
+
"if ($env:MBO_SC_ICON) { $sc.IconLocation=$env:MBO_SC_ICON }\n"
|
|
103
|
+
"$sc.Description=$env:MBO_SC_DESC\n"
|
|
104
|
+
"$sc.Save()\n"
|
|
105
|
+
"Write-Output $lnk\n"
|
|
106
|
+
)
|
|
107
|
+
env = dict(os.environ)
|
|
108
|
+
env.update(
|
|
109
|
+
MBO_SC_NAME=name,
|
|
110
|
+
MBO_SC_VBS=str(vbs),
|
|
111
|
+
MBO_SC_ICON=icon,
|
|
112
|
+
MBO_SC_DESC=DESCRIPTION,
|
|
113
|
+
)
|
|
114
|
+
result = subprocess.run(
|
|
115
|
+
["powershell", "-NoProfile", "-NonInteractive", "-Command", ps],
|
|
116
|
+
env=env,
|
|
117
|
+
capture_output=True,
|
|
118
|
+
text=True,
|
|
119
|
+
)
|
|
120
|
+
if result.returncode != 0:
|
|
121
|
+
raise RuntimeError(
|
|
122
|
+
"Failed to create shortcut:\n"
|
|
123
|
+
+ (result.stderr.strip() or result.stdout.strip())
|
|
124
|
+
)
|
|
125
|
+
out = result.stdout.strip()
|
|
126
|
+
return Path(out) if out else base / f"{name}.lnk"
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _linux_desktop_dir() -> Path:
|
|
130
|
+
"""Resolve the user's real desktop directory, honoring xdg-user-dirs."""
|
|
131
|
+
try:
|
|
132
|
+
result = subprocess.run(
|
|
133
|
+
["xdg-user-dir", "DESKTOP"],
|
|
134
|
+
capture_output=True,
|
|
135
|
+
text=True,
|
|
136
|
+
check=True,
|
|
137
|
+
)
|
|
138
|
+
out = result.stdout.strip()
|
|
139
|
+
if out:
|
|
140
|
+
return Path(out)
|
|
141
|
+
except (FileNotFoundError, subprocess.CalledProcessError):
|
|
142
|
+
pass
|
|
143
|
+
return Path.home() / "Desktop"
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _create_linux_shortcut(name: str) -> Path:
|
|
147
|
+
from mbo_utilities import get_mbo_dirs
|
|
148
|
+
|
|
149
|
+
exe = _find_mbo_exe()
|
|
150
|
+
if exe is None:
|
|
151
|
+
raise RuntimeError(
|
|
152
|
+
"Could not find the mbo launcher. Is mbo_utilities installed on PATH?"
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
base = get_mbo_dirs()["base"]
|
|
156
|
+
icon = _copy_icon(".png", base)
|
|
157
|
+
|
|
158
|
+
desktop = _linux_desktop_dir()
|
|
159
|
+
desktop.mkdir(parents=True, exist_ok=True)
|
|
160
|
+
entry = desktop / "the-studio.desktop"
|
|
161
|
+
entry.write_text(
|
|
162
|
+
"[Desktop Entry]\n"
|
|
163
|
+
"Type=Application\n"
|
|
164
|
+
f"Name={name}\n"
|
|
165
|
+
f"Comment={DESCRIPTION}\n"
|
|
166
|
+
f"Exec={exe}\n" + (f"Icon={icon}\n" if icon else "") + "Terminal=false\n"
|
|
167
|
+
"Categories=Science;Graphics;\n",
|
|
168
|
+
encoding="utf-8",
|
|
169
|
+
)
|
|
170
|
+
entry.chmod(0o755)
|
|
171
|
+
# GNOME requires the launcher be marked trusted to run from the desktop
|
|
172
|
+
try:
|
|
173
|
+
subprocess.run(
|
|
174
|
+
["gio", "set", str(entry), "metadata::trusted", "true"],
|
|
175
|
+
check=False,
|
|
176
|
+
capture_output=True,
|
|
177
|
+
)
|
|
178
|
+
except FileNotFoundError:
|
|
179
|
+
pass
|
|
180
|
+
return entry
|