Fix typing issues

This commit is contained in:
mbsantiago 2026-08-08 13:39:32 +01:00
parent bbe89e2315
commit 2b582fc2a0
3 changed files with 13 additions and 8 deletions

View File

@ -1,5 +1,5 @@
from pathlib import Path from pathlib import Path
from typing import List, Literal, Sequence from typing import List, Literal, Sequence, TypedDict
from uuid import UUID from uuid import UUID
import numpy as np import numpy as np
@ -26,6 +26,11 @@ class ParquetOutputConfig(BaseConfig):
include_geometry: bool = True include_geometry: bool = True
class ClipInfo(TypedDict):
clip: data.Clip
preds: list[Detection]
class ParquetFormatter(OutputFormatterProtocol[ClipDetections]): class ParquetFormatter(OutputFormatterProtocol[ClipDetections]):
def __init__( def __init__(
self, self,
@ -120,7 +125,7 @@ class ParquetFormatter(OutputFormatterProtocol[ClipDetections]):
else: else:
df = pd.read_parquet(path) df = pd.read_parquet(path)
predictions_by_clip = {} predictions_by_clip: dict[UUID, ClipInfo] = {}
for _, row in df.iterrows(): for _, row in df.iterrows():
clip_uuid = row["clip_uuid"] clip_uuid = row["clip_uuid"]

View File

@ -185,25 +185,25 @@ def plot_clip_evaluation(
label="found GT", label="found GT",
edgecolor=gt_color, edgecolor=gt_color,
facecolor="none" if not fill else gt_color, facecolor="none" if not fill else gt_color,
linestyle=gt_linestyle, linestyle=gt_linestyle, # type: ignore
), ),
patches.Patch( patches.Patch(
label="missed GT", label="missed GT",
edgecolor=missed_gt_color, edgecolor=missed_gt_color,
facecolor="none" if not fill else missed_gt_color, facecolor="none" if not fill else missed_gt_color,
linestyle=missed_gt_linestyle, linestyle=missed_gt_linestyle, # type: ignore
), ),
patches.Patch( patches.Patch(
label="true Det", label="true Det",
edgecolor=true_pred_color, edgecolor=true_pred_color,
facecolor="none" if not fill else true_pred_color, facecolor="none" if not fill else true_pred_color,
linestyle=true_pred_linestyle, linestyle=true_pred_linestyle, # type: ignore
), ),
patches.Patch( patches.Patch(
label="false Det", label="false Det",
edgecolor=false_pred_color, edgecolor=false_pred_color,
facecolor="none" if not fill else false_pred_color, facecolor="none" if not fill else false_pred_color,
linestyle=false_pred_linestyle, linestyle=false_pred_linestyle, # type: ignore
), ),
] ]
) )

View File

@ -1,9 +1,9 @@
"""Plot heatmaps.""" """Plot heatmaps."""
import matplotlib.pyplot as plt
import numpy as np import numpy as np
import torch import torch
from matplotlib import axes, patches from matplotlib import axes, patches
from matplotlib.cm import get_cmap
from matplotlib.colors import Colormap, LinearSegmentedColormap, to_rgba from matplotlib.colors import Colormap, LinearSegmentedColormap, to_rgba
from batdetect2.plotting.common import create_ax from batdetect2.plotting.common import create_ax
@ -80,7 +80,7 @@ def plot_classification_heatmap(
raise ValueError("Inconsistent number of class names") raise ValueError("Inconsistent number of class names")
if not isinstance(cmap, Colormap): if not isinstance(cmap, Colormap):
cmap = get_cmap(cmap) cmap = plt.get_cmap(cmap)
handles = [] handles = []