napari-tmidas 0.2.1__py3-none-any.whl → 0.2.4__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.
Files changed (56) hide show
  1. napari_tmidas/__init__.py +35 -5
  2. napari_tmidas/_crop_anything.py +1458 -499
  3. napari_tmidas/_env_manager.py +76 -0
  4. napari_tmidas/_file_conversion.py +1646 -1131
  5. napari_tmidas/_file_selector.py +1464 -223
  6. napari_tmidas/_label_inspection.py +83 -8
  7. napari_tmidas/_processing_worker.py +309 -0
  8. napari_tmidas/_reader.py +6 -10
  9. napari_tmidas/_registry.py +15 -14
  10. napari_tmidas/_roi_colocalization.py +1221 -84
  11. napari_tmidas/_tests/test_crop_anything.py +123 -0
  12. napari_tmidas/_tests/test_env_manager.py +89 -0
  13. napari_tmidas/_tests/test_file_selector.py +90 -0
  14. napari_tmidas/_tests/test_grid_view_overlay.py +193 -0
  15. napari_tmidas/_tests/test_init.py +98 -0
  16. napari_tmidas/_tests/test_intensity_label_filter.py +222 -0
  17. napari_tmidas/_tests/test_label_inspection.py +86 -0
  18. napari_tmidas/_tests/test_processing_basic.py +500 -0
  19. napari_tmidas/_tests/test_processing_worker.py +142 -0
  20. napari_tmidas/_tests/test_regionprops_analysis.py +547 -0
  21. napari_tmidas/_tests/test_registry.py +135 -0
  22. napari_tmidas/_tests/test_scipy_filters.py +168 -0
  23. napari_tmidas/_tests/test_skimage_filters.py +259 -0
  24. napari_tmidas/_tests/test_split_channels.py +217 -0
  25. napari_tmidas/_tests/test_spotiflow.py +87 -0
  26. napari_tmidas/_tests/test_tyx_display_fix.py +142 -0
  27. napari_tmidas/_tests/test_ui_utils.py +68 -0
  28. napari_tmidas/_tests/test_widget.py +30 -0
  29. napari_tmidas/_tests/test_windows_basic.py +66 -0
  30. napari_tmidas/_ui_utils.py +57 -0
  31. napari_tmidas/_version.py +16 -3
  32. napari_tmidas/_widget.py +41 -4
  33. napari_tmidas/processing_functions/basic.py +557 -20
  34. napari_tmidas/processing_functions/careamics_env_manager.py +72 -99
  35. napari_tmidas/processing_functions/cellpose_env_manager.py +415 -112
  36. napari_tmidas/processing_functions/cellpose_segmentation.py +132 -191
  37. napari_tmidas/processing_functions/colocalization.py +513 -56
  38. napari_tmidas/processing_functions/grid_view_overlay.py +703 -0
  39. napari_tmidas/processing_functions/intensity_label_filter.py +422 -0
  40. napari_tmidas/processing_functions/regionprops_analysis.py +1280 -0
  41. napari_tmidas/processing_functions/sam2_env_manager.py +53 -69
  42. napari_tmidas/processing_functions/sam2_mp4.py +274 -195
  43. napari_tmidas/processing_functions/scipy_filters.py +403 -8
  44. napari_tmidas/processing_functions/skimage_filters.py +424 -212
  45. napari_tmidas/processing_functions/spotiflow_detection.py +949 -0
  46. napari_tmidas/processing_functions/spotiflow_env_manager.py +591 -0
  47. napari_tmidas/processing_functions/timepoint_merger.py +334 -86
  48. napari_tmidas/processing_functions/trackastra_tracking.py +24 -5
  49. {napari_tmidas-0.2.1.dist-info → napari_tmidas-0.2.4.dist-info}/METADATA +92 -39
  50. napari_tmidas-0.2.4.dist-info/RECORD +63 -0
  51. napari_tmidas/_tests/__init__.py +0 -0
  52. napari_tmidas-0.2.1.dist-info/RECORD +0 -38
  53. {napari_tmidas-0.2.1.dist-info → napari_tmidas-0.2.4.dist-info}/WHEEL +0 -0
  54. {napari_tmidas-0.2.1.dist-info → napari_tmidas-0.2.4.dist-info}/entry_points.txt +0 -0
  55. {napari_tmidas-0.2.1.dist-info → napari_tmidas-0.2.4.dist-info}/licenses/LICENSE +0 -0
  56. {napari_tmidas-0.2.1.dist-info → napari_tmidas-0.2.4.dist-info}/top_level.txt +0 -0
@@ -5,105 +5,64 @@ This module manages a dedicated virtual environment for CAREamics.
5
5
 
6
6
  import contextlib
7
7
  import os
8
- import platform
9
- import shutil
10
8
  import subprocess
11
9
  import tempfile
12
- import venv
13
10
 
14
11
  import tifffile
15
12
 
16
- # Define the environment directory in user's home folder
17
- ENV_DIR = os.path.join(
18
- os.path.expanduser("~"), ".napari-tmidas", "envs", "careamics"
19
- )
13
+ from napari_tmidas._env_manager import BaseEnvironmentManager
20
14
 
21
15
 
22
- def is_careamics_installed():
23
- """Check if CAREamics is installed in the current environment."""
24
- try:
25
- import importlib.util
26
-
27
- return importlib.util.find_spec("careamics") is not None
28
- except ImportError:
29
- return False
30
-
31
-
32
- def is_env_created():
33
- """Check if the dedicated environment exists."""
34
- env_python = get_env_python_path()
35
- return os.path.exists(env_python)
36
-
37
-
38
- def get_env_python_path():
39
- """Get the path to the Python executable in the environment."""
40
- if platform.system() == "Windows":
41
- return os.path.join(ENV_DIR, "Scripts", "python.exe")
42
- else:
43
- return os.path.join(ENV_DIR, "bin", "python")
44
-
16
+ class CAREamicsEnvironmentManager(BaseEnvironmentManager):
17
+ """Environment manager for CAREamics."""
45
18
 
46
- def create_careamics_env():
47
- """Create a dedicated virtual environment for CAREamics."""
48
- # Ensure the environment directory exists
49
- os.makedirs(os.path.dirname(ENV_DIR), exist_ok=True)
50
-
51
- # Remove existing environment if it exists
52
- if os.path.exists(ENV_DIR):
53
- shutil.rmtree(ENV_DIR)
54
-
55
- print(f"Creating CAREamics environment at {ENV_DIR}...")
56
-
57
- # Create a new virtual environment
58
- venv.create(ENV_DIR, with_pip=True)
59
-
60
- # Path to the Python executable in the new environment
61
- env_python = get_env_python_path()
62
-
63
- # Upgrade pip first
64
- print("Upgrading pip...")
65
- subprocess.check_call(
66
- [env_python, "-m", "pip", "install", "--upgrade", "pip"]
67
- )
19
+ def __init__(self):
20
+ super().__init__("careamics")
68
21
 
69
- # Install PyTorch first for compatibility
70
- # Try to detect if CUDA is available
71
- cuda_available = False
72
- try:
73
- import torch
22
+ def _install_dependencies(self, env_python: str) -> None:
23
+ """Install CAREamics-specific dependencies."""
24
+ # Install PyTorch first for compatibility
25
+ # Try to detect if CUDA is available
26
+ cuda_available = False
27
+ try:
28
+ import torch
74
29
 
75
- cuda_available = torch.cuda.is_available()
76
- print(f"CUDA is {'available' if cuda_available else 'not available'}")
77
- except ImportError:
78
- print("PyTorch not detected in main environment")
30
+ cuda_available = torch.cuda.is_available()
31
+ print(
32
+ f"CUDA is {'available' if cuda_available else 'not available'}"
33
+ )
34
+ except ImportError:
35
+ print("PyTorch not detected in main environment")
36
+
37
+ if cuda_available:
38
+ # Install PyTorch with CUDA support
39
+ print("Installing PyTorch with CUDA support...")
40
+ subprocess.check_call(
41
+ [env_python, "-m", "pip", "install", "torch", "torchvision"]
42
+ )
43
+ else:
44
+ # Install PyTorch without CUDA
45
+ print("Installing PyTorch without CUDA support...")
46
+ subprocess.check_call(
47
+ [env_python, "-m", "pip", "install", "torch", "torchvision"]
48
+ )
79
49
 
80
- if cuda_available:
81
- # Install PyTorch with CUDA support
82
- print("Installing PyTorch with CUDA support...")
50
+ # Install CAREamics and dependencies
51
+ print("Installing CAREamics in the dedicated environment...")
83
52
  subprocess.check_call(
84
- [env_python, "-m", "pip", "install", "torch", "torchvision"]
53
+ [env_python, "-m", "pip", "install", "careamics[tensorboard]"]
85
54
  )
86
- else:
87
- # Install PyTorch without CUDA
88
- print("Installing PyTorch without CUDA support...")
55
+
56
+ # Install tifffile for image handling
89
57
  subprocess.check_call(
90
- [env_python, "-m", "pip", "install", "torch", "torchvision"]
58
+ [env_python, "-m", "pip", "install", "tifffile", "numpy"]
91
59
  )
92
60
 
93
- # Install CAREamics and dependencies
94
- print("Installing CAREamics in the dedicated environment...")
95
- subprocess.check_call(
96
- [env_python, "-m", "pip", "install", "careamics[tensorboard]"]
97
- )
61
+ # Check if installation was successful
62
+ self._verify_installation(env_python)
98
63
 
99
- # Install tifffile for image handling
100
- subprocess.check_call(
101
- [env_python, "-m", "pip", "install", "tifffile", "numpy"]
102
- )
103
-
104
- # Check if installation was successful
105
- try:
106
- # Run a simple script to verify CAREamics is installed and working
64
+ def _verify_installation(self, env_python: str) -> None:
65
+ """Verify CAREamics installation."""
107
66
  check_script = """
108
67
  import sys
109
68
  try:
@@ -147,13 +106,38 @@ except Exception as e:
147
106
  finally:
148
107
  os.unlink(temp_path)
149
108
 
150
- except subprocess.CalledProcessError as e:
151
- print(f"Error during CAREamics installation: {e}")
152
- print(f"Output: {e.output}")
153
- print(f"Errors: {e.stderr}")
154
- raise RuntimeError("Failed to create CAREamics environment") from e
109
+ def is_package_installed(self) -> bool:
110
+ """Check if CAREamics is installed in the current environment."""
111
+ try:
112
+ import importlib.util
113
+
114
+ return importlib.util.find_spec("careamics") is not None
115
+ except ImportError:
116
+ return False
117
+
118
+
119
+ # Global instance for backward compatibility
120
+ manager = CAREamicsEnvironmentManager()
121
+
122
+
123
+ def is_careamics_installed():
124
+ """Check if CAREamics is installed in the current environment."""
125
+ return manager.is_package_installed()
126
+
127
+
128
+ def is_env_created():
129
+ """Check if the dedicated environment exists."""
130
+ return manager.is_env_created()
131
+
132
+
133
+ def get_env_python_path():
134
+ """Get the path to the Python executable in the environment."""
135
+ return manager.get_env_python_path()
136
+
155
137
 
156
- return env_python
138
+ def create_careamics_env():
139
+ """Create a dedicated virtual environment for CAREamics."""
140
+ return manager.create_env()
157
141
 
158
142
 
159
143
  def run_careamics_in_env(func_name, args_dict):
@@ -275,17 +259,6 @@ try:
275
259
  tta={args_dict.get('use_tta', True)},
276
260
  )
277
261
 
278
- # # Handle output shape
279
- # if prediction.shape != image.shape:
280
- # print(f"Warning: Prediction shape {{prediction.shape}} differs from input shape {{image.shape}}")
281
- # prediction = np.squeeze(prediction)
282
-
283
- # # If shapes still don't match, try to reshape
284
- # if prediction.shape != image.shape:
285
- # print(f"Warning: Shapes still don't match after squeezing. Using original dimensions.")
286
-
287
- # print(f"Denoising completed. Output shape: {{prediction.shape}}")
288
-
289
262
  # Save result
290
263
  print(f"Saving result to {{os.path.basename('{output_file.name}')}}")
291
264
  tifffile.imwrite('{output_file.name}', prediction, compression="zlib")