Untitled
unknown
python
a year ago
2.0 kB
13
Indexable
# GENERAL
from typing import Optional, Union, Dict, List, Tuple
from importlib import import_module
class Stitcher:
def __init__(
bla
) -> None:
self.bla=bla
@staticmethod
def _import_optional(module_path: str, package: str) -> Any:
try:
return import_module(module_path)
except ImportError:
raise ImportError(f"Optional dependency {package} required. Install with pip install {package}")
def process_images(self) -> None:
ashlar = self._import_optional("ashlar", "ashlar")
thumbnail = self._import_optional("ashlar.thumbnail", "ashlar")
# Use the imported modules
pass
def read_files(self) -> None:
if self.reader_type == "FilePatternReaderRescale":
filepattern = self._import_optional("filepattern", "filepattern")
# Use filepattern
elif self.reader_type == "BioformatsReaderRescale":
bioformats = self._import_optional("bioformats", "python-bioformats")
# Use bioformats
# SPECIFIC
# In your case, you have a few nested functions here that are all called in stitch, but let's just assume that we inlined it into stitch
def stitch(self) -> None:
try:
from ashlar import thumbnail
from ashlar.reg import EdgeAligner, Mosaic
from ashlar.scripts.ashlar import process_axis_flip
except ImportError:
raise ImportError(
"Optional dependency ashlar is required for stitching. "
"Install with: pip install ashlar"
)
process_axis_flip(
self.reader,
flip_x=self.orientation["flip_x"],
flip_y=self.orientation["flip_y"]
)
self.aligner = EdgeAligner(
self.reader,
channel=self.stitching_channel_id,
filter_sigma=self.filter_sigma,
verbose=True,
do_make_thumbnail=False,
max_shift=self.max_shift,
)Editor is loading...
Leave a Comment