Skip to content

Commit

Permalink
move functions to avoid circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
hongquanli committed Feb 23, 2025
1 parent d7269bc commit c845331
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
7 changes: 4 additions & 3 deletions software/control/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from control.multipoint_built_in_functionalities import malaria_rtp

import control.utils as utils
import control.utils_channel as utils_channel
import control.utils_config as utils_config
import control.tracking as tracking
import control.serial_peripherals as serial_peripherals
Expand Down Expand Up @@ -499,7 +500,7 @@ def __init__(
def turn_on_illumination(self):
if self.illuminationController is not None and not "LED matrix" in self.currentConfiguration.name:
self.illuminationController.turn_on_illumination(
int(utils.extract_wavelength_from_config_name(self.currentConfiguration.name))
int(utils_channel.extract_wavelength_from_config_name(self.currentConfiguration.name))
)
elif SUPPORT_SCIMICROSCOPY_LED_ARRAY and "LED matrix" in self.currentConfiguration.name:
self.led_array.turn_on_illumination()
Expand All @@ -510,7 +511,7 @@ def turn_on_illumination(self):
def turn_off_illumination(self):
if self.illuminationController is not None and not "LED matrix" in self.currentConfiguration.name:
self.illuminationController.turn_off_illumination(
int(utils.extract_wavelength_from_config_name(self.currentConfiguration.name))
int(utils_channel.extract_wavelength_from_config_name(self.currentConfiguration.name))
)
elif SUPPORT_SCIMICROSCOPY_LED_ARRAY and "LED matrix" in self.currentConfiguration.name:
self.led_array.turn_off_illumination()
Expand Down Expand Up @@ -563,7 +564,7 @@ def set_illumination(self, illumination_source, intensity, update_channel_settin
# update illumination
if self.illuminationController is not None:
self.illuminationController.set_intensity(
int(utils.extract_wavelength_from_config_name(self.currentConfiguration.name)), intensity
int(utils_channel.extract_wavelength_from_config_name(self.currentConfiguration.name)), intensity
)
elif ENABLE_NL5 and NL5_USE_DOUT and "Fluorescence" in self.currentConfiguration.name:
wavelength = int(self.currentConfiguration.name[13:16])
Expand Down
17 changes: 0 additions & 17 deletions software/control/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from scipy.ndimage import label
from scipy import signal
import os
from control._def import CHANNEL_COLORS_MAP
from typing import Optional, Tuple
from enum import Enum, auto
import squid.logging
Expand Down Expand Up @@ -175,22 +174,6 @@ def ensure_directory_exists(raw_string_path: str):
path.mkdir(parents=True, exist_ok=True)


def extract_wavelength_from_config_name(name):
# Split the string and find the wavelength number immediately after "Fluorescence"
parts = name.split()
if "Fluorescence" in parts:
index = parts.index("Fluorescence") + 1
if index < len(parts):
return parts[index].split()[0] # Assuming 'Fluorescence 488 nm Ex' and taking '488'
for color in ["R", "G", "B"]:
if color in parts or "full_" + color in parts:
return color
return None


def get_channel_color(channel):
channel_info = CHANNEL_COLORS_MAP.get(extract_wavelength_from_config_name(channel), {"hex": 0xFFFFFF, "name": "gray"})
return channel_info["hex"]
class SpotDetectionMode(Enum):
"""Specifies which spot to detect when multiple spots are present.
Expand Down
18 changes: 18 additions & 0 deletions software/control/utils_channel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from control._def import CHANNEL_COLORS_MAP

def extract_wavelength_from_config_name(name):
# Split the string and find the wavelength number immediately after "Fluorescence"
parts = name.split()
if "Fluorescence" in parts:
index = parts.index("Fluorescence") + 1
if index < len(parts):
return parts[index].split()[0] # Assuming 'Fluorescence 488 nm Ex' and taking '488'
for color in ["R", "G", "B"]:
if color in parts or "full_" + color in parts:
return color
return None


def get_channel_color(channel):
channel_info = CHANNEL_COLORS_MAP.get(extract_wavelength_from_config_name(channel), {"hex": 0xFFFFFF, "name": "gray"})
return channel_info["hex"]
5 changes: 2 additions & 3 deletions software/control/utils_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from pydantic_xml import BaseXmlModel, element, attr
from typing import List, Optional
from pathlib import Path
import control.utils as utils

import control.utils_channel as utils_channel

class LaserAFConfig(BaseModel):
"""Pydantic model for laser autofocus configuration"""
Expand Down Expand Up @@ -34,7 +33,7 @@ class ChannelMode(BaseXmlModel, tag='mode'):

def __init__(self, **data):
super().__init__(**data)
self.color = utils.get_channel_color(self.name)
self.color = utils_channel.get_channel_color(self.name)

class ChannelConfig(BaseXmlModel, tag='modes'):
"""Root configuration file model"""
Expand Down

0 comments on commit c845331

Please sign in to comment.