Skip to content

Commit 369aa45

Browse files
committed
Update docstrings for functions with detailed descriptions and types
1 parent c1a8514 commit 369aa45

1 file changed

Lines changed: 47 additions & 17 deletions

File tree

src/flametrack/analysis/ir_analysis.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,28 @@
11
from __future__ import annotations
22

3-
import logging
43
from typing import Any, Sequence, Tuple
54

65
import cv2
76
import numpy as np
87
from numpy.typing import NDArray
98

10-
from flametrack.analysis import dataset_handler
11-
129

1310
def compute_remap_from_homography(
1411
homography: NDArray[np.float32] | NDArray[np.float64],
1512
width: int,
1613
height: int,
1714
) -> Tuple[NDArray[np.float32], NDArray[np.float32]]:
1815
"""
19-
Compute remap grids from a homography matrix H.
16+
Compute pixelwise remap grids from a homography.
2017
2118
Args:
22-
homography (np.ndarray): Homography matrix.
23-
width (int): Width of the target image.
24-
height (int): Height of the target image.
19+
homography (numpy.ndarray): 3×3 homography mapping output → input coordinates.
20+
width (int): Target image width in pixels.
21+
height (int): Target image height in pixels.
2522
2623
Returns:
27-
Tuple[np.ndarray, np.ndarray]: src_x and src_y remap matrices.
24+
tuple[numpy.ndarray, numpy.ndarray]: Two arrays ``(src_x, src_y)`` with shape
25+
``(height, width)``, dtype ``float32`` suitable for ``cv2.remap``.
2826
"""
2927
# Pixelzentren (x+0.5, y+0.5)
3028
map_x_f = np.arange(width, dtype=np.float32) + 0.5
@@ -46,13 +44,19 @@ def compute_remap_from_homography(
4644

4745
def read_ir_data(filename: str) -> NDArray[np.float64]:
4846
"""
49-
Read raw IR data from a CSV-like ASCII export format.
47+
Read raw IR data from a CSV-like ASCII export.
48+
49+
The file is scanned until a line ``[Data]`` is found; subsequent lines are
50+
parsed using ``;`` as delimiter and a comma-to-dot decimal replacement.
5051
5152
Args:
5253
filename (str): Path to the IR data file.
5354
5455
Returns:
55-
np.ndarray: 2D array of IR values.
56+
numpy.ndarray: 2D array of IR values (dtype ``float64``).
57+
58+
Raises:
59+
ValueError: If no ``[Data]`` section is found in the file.
5660
"""
5761
with open(filename, "r", encoding="latin-1") as f:
5862
line = f.readline()
@@ -80,15 +84,41 @@ def get_dewarp_parameters(
8084
pixels_per_millimeter: int = 1,
8185
) -> dict[str, Any]:
8286
"""
83-
Calculate the transformation matrix and target geometry for dewarping.
87+
Calculate homography and target geometry for dewarping.
88+
89+
You can either pass physical plate dimensions (``plate_width_m``,
90+
``plate_height_m``) plus a pixel density, or infer target geometry
91+
from the selected corners and a desired aspect ratio.
92+
93+
Args:
94+
corners (numpy.ndarray | Sequence[tuple[float, float]]): Four corner points
95+
in pixel coordinates, ordered clockwise starting at top-left.
96+
target_pixels_width (int, optional): Target width in pixels. If omitted,
97+
it will be derived from ``target_ratio`` and the measured corner distances.
98+
target_pixels_height (int, optional): Target height in pixels. If omitted,
99+
it will be derived from ``target_ratio`` and the measured corner distances.
100+
target_ratio (float, optional): Desired aspect ratio ``height / width``.
101+
Required if target size is not specified and no physical plate size is provided.
102+
plate_width_m (float, optional): Physical plate width in meters. Used with
103+
``pixels_per_millimeter`` to derive target size if provided with ``plate_height_m``.
104+
plate_height_m (float, optional): Physical plate height in meters. Used with
105+
``pixels_per_millimeter`` to derive target size if provided with ``plate_width_m``.
106+
pixels_per_millimeter (int, optional): Pixel density (px/mm) used when physical
107+
dimensions are given. Default is 1.
84108
85109
Returns:
86-
{
87-
"transformation_matrix": np.ndarray(float32, 3x3),
88-
"target_pixels_width": int,
89-
"target_pixels_height": int,
90-
"target_ratio": float, # height/width
91-
}
110+
dict[str, Any]: Dictionary with:
111+
- ``transformation_matrix`` (numpy.ndarray): 3×3 homography (float32).
112+
- ``target_pixels_width`` (int): Target width in pixels.
113+
- ``target_pixels_height`` (int): Target height in pixels.
114+
- ``target_ratio`` (float): ``height / width`` of the target.
115+
116+
Raises:
117+
ValueError: If neither physical dimensions nor a target ratio are provided.
118+
119+
Notes:
120+
Current conversion multiplies meter values by ``pixels_per_millimeter``.
121+
For strict unit consistency, consider using millimeters or ``pixels_per_meter``.
92122
"""
93123
buffer = 1.1
94124
source_corners: NDArray[np.float32] = np.asarray(corners, dtype=np.float32)

0 commit comments

Comments
 (0)