|
11 | 11 | import logging |
12 | 12 | import traceback |
13 | 13 | from collections.abc import Collection |
| 14 | +from functools import cached_property |
14 | 15 | from importlib.metadata import entry_points |
15 | 16 | from pathlib import Path |
16 | 17 | from typing import Literal, Optional |
17 | 18 |
|
18 | | -from pydantic import BaseModel |
| 19 | +from pydantic import BaseModel, computed_field |
19 | 20 | from sqlmodel import Session, select |
20 | 21 |
|
21 | 22 | import murfey.util.db as MurfeyDB |
@@ -53,16 +54,21 @@ class CLEMPreprocessingResult(BaseModel): |
53 | 54 | resolution: float |
54 | 55 | extent: list[float] # [x0, x1, y0, y1] |
55 | 56 |
|
56 | | - |
57 | | -def _is_clem_atlas(result: CLEMPreprocessingResult): |
58 | | - # If an image has a width/height of at least 1.5 mm, it should qualify as an atlas |
59 | | - return ( |
60 | | - max( |
61 | | - result.pixels_x * result.pixel_size, |
62 | | - result.pixels_y * result.pixel_size, |
| 57 | + # Valid Pydantic decorator not supported by MyPy |
| 58 | + @computed_field # type: ignore |
| 59 | + @cached_property |
| 60 | + def is_atlas(self) -> bool: |
| 61 | + """ |
| 62 | + Incoming image sets with a width/height greater/equal to the pre-set threshold, |
| 63 | + it should qualify as an atlas. |
| 64 | + """ |
| 65 | + return ( |
| 66 | + max( |
| 67 | + self.pixels_x * self.pixel_size, |
| 68 | + self.pixels_y * self.pixel_size, |
| 69 | + ) |
| 70 | + >= processing_params.atlas_threshold |
63 | 71 | ) |
64 | | - >= processing_params.atlas_threshold |
65 | | - ) |
66 | 72 |
|
67 | 73 |
|
68 | 74 | COLOR_FLAGS_MURFEY = { |
@@ -105,7 +111,7 @@ def _register_clem_imaging_site( |
105 | 111 | # Add metadata for this series |
106 | 112 | output_file = list(result.output_files.values())[0] |
107 | 113 | clem_img_site.image_path = str(output_file.parent / "*tiff") |
108 | | - clem_img_site.data_type = "atlas" if _is_clem_atlas(result) else "grid_square" |
| 114 | + clem_img_site.data_type = "atlas" if result.is_atlas else "grid_square" |
109 | 115 | clem_img_site.number_of_members = result.number_of_members |
110 | 116 | for col_name, value in _get_color_flags(result.output_files.keys()).items(): |
111 | 117 | setattr(clem_img_site, col_name, value) |
@@ -188,7 +194,7 @@ def _register_dcg_and_atlas( |
188 | 194 | dcg_name += f"--{result.series_name.split('--')[1]}" |
189 | 195 |
|
190 | 196 | # Determine values for atlas |
191 | | - if _is_clem_atlas(result): |
| 197 | + if result.is_atlas: |
192 | 198 | output_file = list(result.output_files.values())[0] |
193 | 199 | # Register the thumbnail entries if they are provided |
194 | 200 | if result.thumbnails and result.thumbnail_size is not None: |
@@ -227,7 +233,7 @@ def _register_dcg_and_atlas( |
227 | 233 | dcg_entry = dcg_search[0] |
228 | 234 | # Update atlas if registering atlas dataset |
229 | 235 | # and data collection group already exists |
230 | | - if _is_clem_atlas(result): |
| 236 | + if result.is_atlas: |
231 | 237 | atlas_message = { |
232 | 238 | "session_id": session_id, |
233 | 239 | "dcgid": dcg_entry.id, |
|
0 commit comments