torchbp.grid module

class torchbp.grid.CartesianGrid(x_range, y_range, nx, ny)[source]

Bases: Grid

Cartesian grid.

Parameters:
  • x_range (Tuple[float, float]) – X extent (x0, x1) in meters. x1 must be > x0.

  • y_range (Tuple[float, float]) – Y extent (y0, y1) in meters. y1 must be > y0.

  • nx (int) – Number of X samples. Must be positive.

  • ny (int) – Number of Y samples. Must be positive.

Examples

>>> grid = CartesianGrid(x_range=(-50, 50), y_range=(-50, 50), nx=100, ny=100)
>>> grid.dx
1.0
>>> grid.dy
1.0
>>> grid.shape()
(100, 100)
property dx: float

X spacing in meters (cached).

property dy: float

Y spacing in meters (cached).

classmethod from_dict(d)[source]

Create CartesianGrid from dict format.

Parameters:

d (dict) – Dict with keys: “x”, “y”, “nx”, “ny”

Returns:

Grid object

Return type:

CartesianGrid

resize(nx=None, ny=None)[source]

Return new grid with different resolution.

Parameters:
  • nx (int, optional) – New number of X samples. If None, keep current nx.

  • ny (int, optional) – New number of Y samples. If None, keep current ny.

Returns:

New grid with updated resolution

Return type:

CartesianGrid

shape()[source]

Return grid dimensions (nx, ny).

Return type:

Tuple[int, int]

spacing()[source]

Return grid spacing (dx, dy).

Return type:

Tuple[float, float]

to_dict()[source]

Convert to dict format.

Returns:

Grid dict with keys: “x”, “y”, “nx”, “ny”

Return type:

dict

property x0: float

Minimum X coordinate in meters.

property x1: float

Maximum X coordinate in meters.

property y0: float

Minimum Y coordinate in meters.

property y1: float

Maximum Y coordinate in meters.

class torchbp.grid.Grid[source]

Bases: ABC

Base class for all grid types.

abstractmethod shape()[source]

Return grid dimensions.

Return type:

Tuple[int, …]

abstractmethod spacing()[source]

Return grid spacing.

Return type:

Tuple[float, …]

abstractmethod to_dict()[source]

Convert to dict format for backward compatibility.

Return type:

dict

class torchbp.grid.PolarGrid(r_range, theta_range, nr, ntheta)[source]

Bases: Grid

Pseudo-polar grid (theta stored as sin(angle)).

Parameters:
  • r_range (Tuple[float, float]) – Range extent (r0, r1) in meters. r1 must be > r0.

  • theta_range (Tuple[float, float]) – Azimuth extent (theta0, theta1) as sin(angle). Must be in [-1, 1].

  • nr (int) – Number of range bins. Must be positive.

  • ntheta (int) – Number of azimuth bins. Must be positive.

Examples

>>> grid = PolarGrid(r_range=(50, 100), theta_range=(-1, 1), nr=100, ntheta=200)
>>> grid.dr  # Range spacing (cached)
0.5
>>> grid.dtheta  # Azimuth spacing (cached)
0.01
>>> grid.shape()
(100, 200)
property dr: float

Range spacing in meters (cached).

property dtheta: float

Azimuth spacing (cached).

classmethod from_dict(d)[source]

Create PolarGrid from dict format.

Parameters:

d (dict) – Dict with keys: “r”, “theta”, “nr”, “ntheta”

Returns:

Grid object

Return type:

PolarGrid

property r0: float

Minimum range in meters.

property r1: float

Maximum range in meters.

resize(nr=None, ntheta=None)[source]

Return new grid with different resolution.

Parameters:
  • nr (int, optional) – New number of range bins. If None, keep current nr.

  • ntheta (int, optional) – New number of azimuth bins. If None, keep current ntheta.

Returns:

New grid with updated resolution

Return type:

PolarGrid

shape()[source]

Return grid dimensions (nr, ntheta).

Return type:

Tuple[int, int]

spacing()[source]

Return grid spacing (dr, dtheta).

Return type:

Tuple[float, float]

property theta0: float

Minimum azimuth (sin of angle).

property theta1: float

Maximum azimuth (sin of angle).

to_dict()[source]

Convert to dict format.

Returns:

Grid dict with keys: “r”, “theta”, “nr”, “ntheta”

Return type:

dict

with_doubled_azimuth()[source]

Create grid with 2x azimuth resolution.

Used in FFBP algorithm for azimuth upsampling.

Returns:

New grid with ntheta *= 2

Return type:

PolarGrid

torchbp.grid.unpack_cartesian_grid(grid)[source]

Unpack cartesian grid to (x0, x1, y0, y1, nx, ny, dx, dy).

Accepts both CartesianGrid objects and dicts.

Parameters:

grid (CartesianGrid or dict) – Cartesian grid specification

Returns:

(x0, x1, y0, y1, nx, ny, dx, dy)

Return type:

tuple

torchbp.grid.unpack_polar_grid(grid)[source]

Unpack polar grid to (r0, r1, theta0, theta1, nr, ntheta, dr, dtheta).

Accepts both PolarGrid objects and dicts.

Parameters:

grid (PolarGrid or dict) – Polar grid specification

Returns:

(r0, r1, theta0, theta1, nr, ntheta, dr, dtheta)

Return type:

tuple