Skip to content

Commit

Permalink
format and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianHirt committed Oct 11, 2024
1 parent aaa560a commit 8149780
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions pedpy/methods/method_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from collections import defaultdict
from dataclasses import dataclass
from enum import Enum, auto
from typing import Final, Callable, List, Optional, Tuple
from typing import Callable, Final, List, Optional, Tuple

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -1162,10 +1162,10 @@ def compute_individual_areas(

def _process_frame(
frame: int,
shape_and_speedmap_framegroup,
shape_and_speedmap_framegroup: pd.DataFrame,
grid: GridInfo,
cutoff_distance: float,
):
) -> pd.DataFrame:
"""Process one frame with the Fast-Marching-Method.
Processing a frame involves transferring the position of the pedestrians
Expand Down Expand Up @@ -1209,7 +1209,7 @@ def _process_frame(
def _form_to_grid(
grid: GridInfo,
form: shapely.Point | shapely.Polygon | shapely.MultiPolygon,
):
) -> List[tuple[int, int]]:
"""Transfers the form to the grid.
Args:
Expand Down Expand Up @@ -1240,7 +1240,7 @@ def _form_to_grid(
return []

Check warning on line 1240 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1240

Added line #L1240 was not covered by tests


def _cartesian_to_grid(grid: GridInfo, point: shapely.Point):
def _cartesian_to_grid(grid: GridInfo, point: shapely.Point) -> tuple[int, int]:
"""Converts Cartesian coordinates of point to grid coordinates."""
minx, miny, maxx, maxy = grid.boundary.bounds

Check warning on line 1245 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1245

Added line #L1245 was not covered by tests

Expand All @@ -1258,7 +1258,9 @@ def _cartesian_to_grid(grid: GridInfo, point: shapely.Point):
return int(round(i)), int(round(j))

Check warning on line 1258 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1258

Added line #L1258 was not covered by tests


def _grid_cells_of_polygon(grid: GridInfo, polygon: shapely.Polygon):
def _grid_cells_of_polygon(
grid: GridInfo, polygon: shapely.Polygon
) -> List[tuple[int, int]]:
"""Returns a list of all cells located on the border of the polygon."""
cart_coordinates = list(polygon.exterior.coords)
used_cells = []
Expand All @@ -1275,7 +1277,9 @@ def _grid_cells_of_polygon(grid: GridInfo, polygon: shapely.Polygon):
return unique_cells

Check warning on line 1277 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1276-L1277

Added lines #L1276 - L1277 were not covered by tests


def _bresenham_line(y1: int, x1: int, y2: int, x2: int) -> list[tuple]:
def _bresenham_line(
y1: int, x1: int, y2: int, x2: int
) -> list[tuple[int, int]]:
"""Determines all Grid cells used on a line with Bresenham's line algorithm.
The line starts at the Point (x1, y1) and ends at (x2, y2).
Expand All @@ -1289,17 +1293,11 @@ def _bresenham_line(y1: int, x1: int, y2: int, x2: int) -> list[tuple]:
dx = x2 - x1
dy = y2 - y1

Check warning on line 1294 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1291-L1294

Added lines #L1291 - L1294 were not covered by tests

if dy < 0:
ystep = -1
dy = -dy
else:
ystep = 1
ystep = -1 + 2 * (dy >= 0)
dy = abs(dy)

Check warning on line 1297 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1296-L1297

Added lines #L1296 - L1297 were not covered by tests

if dx < 0:
xstep = -1
dx = -dx
else:
xstep = 1
xstep = -1 + 2 * (dx >= 0)
dx = abs(dx)

Check warning on line 1300 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1299-L1300

Added lines #L1299 - L1300 were not covered by tests

ddy = 2 * dy
ddx = 2 * dx

Check warning on line 1303 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1302-L1303

Added lines #L1302 - L1303 were not covered by tests
Expand Down Expand Up @@ -1400,8 +1398,8 @@ def _calc_arrivaltime(


def _fast_marching_algorithm(
shape_and_speedmap: pd.DataFrame, cutoff_distance: int = np.inf
) -> tuple:
shape_and_speedmap: pd.DataFrame, cutoff_distance: float = np.inf
) -> tuple[np.array, np.array]:
"""Uses the fast-marching method to assign grid cells to the pedestrians.
for each pedestrian a wavefront is calculated. Each grid cell is assigned
Expand Down Expand Up @@ -1481,7 +1479,9 @@ def _fast_marching_algorithm(
return time_map, wave_map

Check warning on line 1479 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1479

Added line #L1479 was not covered by tests


def _get_polygons_by_shapely_boxes(wave_map: np.array, grid: GridInfo):
def _get_polygons_by_shapely_boxes(
wave_map: np.array, grid: GridInfo
) -> dict[int, shapely.Polygon]:
"""Determins the Polygons of the assigned wave_map.
Determins the Polygons for every unique value exept np.isnan.
Expand Down Expand Up @@ -1789,7 +1789,7 @@ def apply_point_as_shape(


def apply_speedmap_from_additions(
group: pd.DataFrame, grid: GridInfo, additions: dict
group: pd.DataFrame, grid: GridInfo, additions: dict[str, np.array]
) -> pd.DataFrame:
"""Assigns a precomputed speedmap to each entry in the frame group.
Expand Down Expand Up @@ -1870,7 +1870,7 @@ def apply_individual_speedmap(

def apply_computed_speedmap(
group: pd.DataFrame, grid: GridInfo, additions: None
):
) -> pd.DataFrame:
"""Computes speedmap for the grid and assigns to the entire frame group.
This function computes a speed map based on the provided grid's boundary
Expand Down Expand Up @@ -1900,7 +1900,9 @@ def apply_computed_speedmap(
return group

Check warning on line 1900 in pedpy/methods/method_utils.py

View check run for this annotation

Codecov / codecov/patch

pedpy/methods/method_utils.py#L1900

Added line #L1900 was not covered by tests


def create_elipse(point, width, length, alpha) -> shapely.Polygon:
def create_elipse(
point: shapely.Point, width: float, length: float, alpha: float
) -> shapely.Polygon:
"""Creates an ellipse at point with specified width, length and rotation.
This function generates an elliptical shape using the Shapely library
Expand Down Expand Up @@ -1945,7 +1947,7 @@ def compute_width_length_alpha(
b_max: float = 0.4,
v0: float = 1.2,
a_v: float = 1,
) -> tuple:
) -> tuple[float, float, float]:
r"""Computes the width, length, and angle of the ellipse of the GCFM.
This function calculates the dimensions (width and length) and
Expand Down

0 comments on commit 8149780

Please sign in to comment.