style: ruff check --fix --unsafe-fixes

This commit is contained in:
2026-07-31 15:57:17 +02:00
parent 70c81abdd8
commit f63107a1e0
87 changed files with 413 additions and 481 deletions
+10 -13
View File
@@ -1,7 +1,7 @@
import json
import threading
import time
from typing import Any, Dict
from typing import Any
import cv2
import numpy as np
@@ -33,7 +33,7 @@ class ImageStatsReceiver:
self.connection_attempts = 0
self.last_message_time = None
def calculate_projections(self, image: np.ndarray) -> Dict[str, Any]:
def calculate_projections(self, image: np.ndarray) -> dict[str, Any]:
"""Calculate X and Y projections of the image"""
# Convert to grayscale if color image
if len(image.shape) == 3:
@@ -99,7 +99,7 @@ class ImageStatsReceiver:
"y_coords": list(range(len(y_projection))),
}
def calculate_radial_integration(self, image: np.ndarray, num_bins: int = 50) -> Dict[str, Any]:
def calculate_radial_integration(self, image: np.ndarray, num_bins: int = 50) -> dict[str, Any]:
"""Calculate radial integration of the image"""
# Convert to grayscale if color image
if len(image.shape) == 3:
@@ -153,7 +153,7 @@ class ImageStatsReceiver:
"num_bins": num_bins,
}
def calculate_image_stats(self, image: np.ndarray) -> Dict[str, Any]:
def calculate_image_stats(self, image: np.ndarray) -> dict[str, Any]:
"""Calculate comprehensive statistics for an image"""
image_float = image.astype(np.float64)
@@ -250,7 +250,7 @@ class ImageStatsReceiver:
else:
print(f"[{time.strftime('%H:%M:%S')}] Waiting for image data...")
def print_formatted_stats(self, stats: Dict[str, Any]):
def print_formatted_stats(self, stats: dict[str, Any]):
"""Print formatted statistics in a compact terminal format"""
timestamp = time.strftime("%H:%M:%S", time.localtime(stats["timestamp"]))
@@ -295,7 +295,7 @@ class ImageStatsReceiver:
)
# Optional: Print per-channel stats if available
if any(k.startswith("mean_ch") for k in stats.keys()):
if any(k.startswith("mean_ch") for k in stats):
channels = []
i = 0
while f"mean_ch{i}" in stats:
@@ -327,7 +327,7 @@ class ImageStatsReceiver:
}
return None
def save_radial_profile_to_file(self, filename: str = None):
def save_radial_profile_to_file(self, filename: str | None = None):
"""Save the current radial profile to a file"""
if filename is None:
filename = f"radial_profile_{int(time.time())}.txt"
@@ -343,13 +343,10 @@ class ImageStatsReceiver:
f.write(f"# Center: {radial['center']}\n")
f.write("# Radius(pixels)\tMean_Intensity\tStd_Intensity\tPixel_Count\n")
for i in range(len(radial["r_centers"])):
f.write(
f"{radial['r_centers'][i]:.2f}\t"
f.writelines(f"{radial['r_centers'][i]:.2f}\t"
f"{radial['radial_profile'][i]:.2f}\t"
f"{radial['radial_std'][i]:.2f}\t"
f"{radial['pixel_counts'][i]}\n"
)
f"{radial['pixel_counts'][i]}\n" for i in range(len(radial["r_centers"])))
print(f"Radial profile saved to {filename}")
return filename
@@ -425,7 +422,7 @@ def get_radial_profile():
return None
def save_current_radial_profile(filename: str = None):
def save_current_radial_profile(filename: str | None = None):
"""Save the current radial profile to a file"""
global stats_receiver