torchbp.ops.polar_interp module
- torchbp.ops.polar_interp.div_2d_interp_linear(img1, img2)[source]
Calculate img1 / img2 and interpolate img2 dimensions to match img1.
Gradient is not supported.
- Parameters:
img1 (Tensor) – 2D or 3D image with complex64 or float type.
img2 (Tensor) – 2D or 3D image with complex64 or float type. If 3D, the first dimension must match with img1.
- Returns:
out – img1 / img2.
- Return type:
Tensor
- torchbp.ops.polar_interp.ffbp_merge2(img0, img1, dorigin0, dorigin1, grid_polars, fc, grid_polar_new=None, z0=0, method=('knab', 6, 1.5), alias=False, alias_fmod=0, output_alias=True, use_poly=True, poly_coefs=None)[source]
Interpolate two pseudo-polar radar images to new grid and change origin position by dorigin.
Gradient not supported.
- Parameters:
img0 (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polars grid. Image dimension can be different for each element in the list.
img1 (Tensor) – Same format as img0.
dorigin0 (Tensor) – Difference between the origin of the old image to the new image. Units in meters. Shape: [3].
dorigin1 (Tensor) – Same format as dorigin0.
grid_polar (list of PolarGrid or dict) –
List of polar grid definitions for each input image. Each element can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)fc (float) – RF center frequency in Hz.
grid_polar_new (dict, optional) – Grid definition of the new image. If None uses the same grid as input, but with double the angle points.
z0 (float) – Height of the antenna phase center in the new image.
method (tuple) – Interpolation method: (“knab”, n, v) where n is the number of samples used and v is the oversampling factor in the data.
alias (bool) – Add back range dependent phase. Inverse of util.bp_polar_range_dealias.
alias_fmod (float) – Range modulation frequency applied to input.
output_alias (bool) – If True and alias is True apply alias_fmod to output.
use_poly (bool) – If True (default), use polynomial-approximation kernel for knab interpolation.
poly_coefs (Tensor, optional) – Precomputed polynomial coefficients. Use compute_knab_poly_coefs_full() to compute these for Knab kernels.
grid_polars (list[PolarGrid | dict])
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- torchbp.ops.polar_interp.ffbp_merge2_knab(img0, img1, dorigin0, dorigin1, grid_polars, fc, grid_polar_new=None, z0=0, order=6, oversample=1.5, alias=False, alias_fmod=0, output_alias=True)[source]
Interpolate two pseudo-polar radar images to new grid and change origin position by dorigin. Uses truncated sinc with Knab pulse for interpolation [1].
Gradient not supported.
- Parameters:
img0 (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polars grid. Image dimension can be different for each element in the list.
img1 (Tensor) – Same format as img0.
dorigin0 (Tensor) – Difference between the origin of the old image to the new image. Units in meters. Shape: [3].
dorigin1 (Tensor) – Same format as dorigin0.
grid_polar (list of PolarGrid or dict) –
List of polar grid definitions for each input image. Each element can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)fc (float) – RF center frequency in Hz.
grid_polar_new (dict, optional) – Grid definition of the new image. If None uses the same grid as input, but with double the angle points.
z0 (float) – Height of the antenna phase center in the new image.
order (int) – Number of nearby samples to use for interpolation of one new sample. Even number is preferred.
oversample (float) – Oversampling factor in the input data.
alias (bool) – Add back range dependent phase. Inverse of util.bp_polar_range_dealias.
alias_fmod (float) – Range modulation frequency applied to input.
output_alias (bool) – If True and alias is True apply alias_fmod to output.
grid_polars (list[PolarGrid | dict])
- Return type:
Tensor
References
[1]J. Knab, “The sampling window,” in IEEE Transactions on Information Theory, vol. 29, no. 1, pp. 157-159, January 1983.
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- Parameters:
- torchbp.ops.polar_interp.ffbp_merge2_lanczos(img0, img1, dorigin0, dorigin1, grid_polars, fc, grid_polar_new=None, z0=0, order=6, alias=False, alias_fmod=0, output_alias=True)[source]
Interpolate two pseudo-polar radar images to new grid and change origin position by dorigin.
Gradient not supported.
- Parameters:
img0 (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polars grid. Image dimension can be different for each element in the list.
img1 (Tensor) – Same format as img0.
dorigin0 (Tensor) – Difference between the origin of the old image to the new image. Units in meters. Shape: [3].
dorigin1 (Tensor) – Same format as dorigin0.
grid_polar (list of PolarGrid or dict) –
List of polar grid definitions for each input image. Each element can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)fc (float) – RF center frequency in Hz.
grid_polar_new (dict, optional) – Grid definition of the new image. If None uses the same grid as input, but with double the angle points.
z0 (float) – Height of the antenna phase center in the new image.
order (int) – Number of nearby samples to use for interpolation of one new sample.
alias (bool) – Add back range dependent phase. Inverse of util.bp_polar_range_dealias.
alias_fmod (float) – Range modulation frequency applied to input.
output_alias (bool) – If True and alias is True apply alias_fmod to output.
grid_polars (list[PolarGrid | dict])
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- torchbp.ops.polar_interp.ffbp_merge2_poly(img0, img1, dorigin0, dorigin1, grid_polars, fc, grid_polar_new=None, z0=0, order=6, oversample=1.5, alias=False, alias_fmod=0, output_alias=True, poly_degree=None, poly_coefs=None)[source]
Interpolate two pseudo-polar radar images to new grid and change origin position by dorigin. Uses polynomial approximation for interpolation.
This function uses polynomial approximation of the Knab kernel, avoiding expensive exp and sqrt operations.
Gradient not supported.
- Parameters:
img0 (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polars grid. Image dimension can be different for each element in the list.
img1 (Tensor) – Same format as img0.
dorigin0 (Tensor) – Difference between the origin of the old image to the new image. Units in meters. Shape: [3].
dorigin1 (Tensor) – Same format as dorigin0.
grid_polar (list of PolarGrid or dict) –
List of polar grid definitions for each input image. Each element can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)fc (float) – RF center frequency in Hz.
grid_polar_new (dict, optional) – Grid definition of the new image. If None uses the same grid as input, but with double the angle points.
z0 (float) – Height of the antenna phase center in the new image.
order (int) – Number of nearby samples to use for interpolation of one new sample. Even number is preferred. Must be in [2, 8].
oversample (float) – Oversampling factor in the input data.
alias (bool) – Add back range dependent phase. Inverse of util.bp_polar_range_dealias.
alias_fmod (float) – Range modulation frequency applied to input.
output_alias (bool) – If True and alias is True apply alias_fmod to output.
poly_degree (int, optional) – Degree of polynomial approximation for the full Knab kernel. The polynomial approximates sinc(x)*window(x) as a single polynomial in x², eliminating expensive sinpif and division operations. If None (default), automatically selected based on oversample: - oversample < 1.5: degree 10 - oversample >= 1.5: degree 12
poly_coefs (Tensor, optional) – Precomputed polynomial coefficients. If provided, poly_degree is ignored. Use compute_knab_poly_coefs_full() to compute these coefficients. Precomputing is useful when calling this function multiple times with the same order and oversample parameters.
grid_polars (list[PolarGrid | dict])
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- torchbp.ops.polar_interp.ffbp_merge2_poly_weighted(img0, img1, dorigin0, dorigin1, grid_polars, fc, grid_polar_new=None, z0=0, order=6, oversample=1.5, alias=False, alias_fmod=0, output_alias=True, poly_coefs=None, w1_map0=None, w2_map0=None, weight_grid0=None, w1_map1=None, w2_map1=None, weight_grid1=None, output_weight_map=False, output_weight_decimation=1)[source]
Interpolate two pseudo-polar radar images to new grid with antenna pattern weighting.
This is the weighted version of ffbp_merge2_poly that applies antenna pattern weights during the merge. Uses both W1 (sum of gains) and W2 (sum of squared gains) to correctly reconstruct the direct backprojection result.
The merge formula recovers the unnormalized accumulation A from normalized images (img = A * W1/W2) using:
A = img * W2 / W1
Then combines:
merged = (A0 + A1) * (W1_0 + W1_1) / (W2_0 + W2_1)
Gradient not supported.
- Parameters:
img0 (Tensor) – 2D radar image in [range, angle] format.
img1 (Tensor) – Same format as img0.
dorigin0 (Tensor) – Origin offset for img0. Shape: [3].
dorigin1 (Tensor) – Origin offset for img1. Shape: [3].
grid_polars (list of PolarGrid or dict) – List of polar grid definitions for each input image.
fc (float) – RF center frequency in Hz.
grid_polar_new (PolarGrid or dict, optional) – Grid definition of the output image.
z0 (float) – Height of the antenna phase center in the new image.
order (int) – Interpolation order. Must be in [2, 8].
oversample (float) – Oversampling factor in the input data.
alias (bool) – Add back range dependent phase.
alias_fmod (float) – Range modulation frequency applied to input.
output_alias (bool) – If True and alias is True, apply alias_fmod to output.
poly_coefs (Tensor, optional) – Precomputed polynomial coefficients.
w1_map0 (Tensor, optional) – W1 weight map (sum of gains) for img0. Shape: [w_nr0, w_ntheta0].
w2_map0 (Tensor, optional) – W2 weight map (sum of squared gains) for img0. Shape: [w_nr0, w_ntheta0].
weight_grid0 (PolarGrid or dict, optional) – Grid definition for weight maps of img0.
w1_map1 (Tensor, optional) – W1 weight map (sum of gains) for img1. Shape: [w_nr1, w_ntheta1].
w2_map1 (Tensor, optional) – W2 weight map (sum of squared gains) for img1. Shape: [w_nr1, w_ntheta1].
weight_grid1 (PolarGrid or dict, optional) – Grid definition for weight maps of img1.
output_weight_map (bool) – If True, return merged weight maps for propagation through hierarchy.
output_weight_decimation (int) – Decimation factor for output weight maps (1 = no decimation, 4 = 1/16 size). Higher values reduce VRAM usage but may reduce weight accuracy.
- Returns:
out (Tensor) – Interpolated radar image.
w1_out (Tensor or None) – Merged W1 weight map if output_weight_map is True, else None. Shape is [nr // decimation, ntheta // decimation].
w2_out (Tensor or None) – Merged W2 weight map if output_weight_map is True, else None. Shape is [nr // decimation, ntheta // decimation].
merged_weight_grid (dict or None) – Grid definition for the output weight maps if output_weight_map is True, else None.
- Return type:
tuple[Tensor, Tensor | None, Tensor | None, dict | None]
- torchbp.ops.polar_interp.mul_2d_interp_linear(img1, img2)[source]
Calculate img1 * img2 and interpolate img2 dimensions to match img1.
Gradient is not supported.
- Parameters:
img1 (Tensor) – 2D or 3D image with complex64 or float type.
img2 (Tensor) – 2D or 3D image with complex64 or float type. If 3D, the first dimension must match with img1.
- Returns:
out – img1 * img2.
- Return type:
Tensor
- torchbp.ops.polar_interp.polar_interp(img, origin_old, origin_new, grid_polar, fc, rotation=0, grid_polar_new=None, method='linear', alias_fmod=0)[source]
Interpolate pseudo-polar radar image to new grid and change origin position by dorigin. Allows choosing the interpolation method.
Gradient calculation is only supported with “linear” method.
- Parameters:
img (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polar grid. [nbatch, range, angle] if interpolating multiple images at the same time.
origin_old (Tensor) – Origin of the img. Units in meters. [nbatch, 3] if img shape is 3D.
origin_new (Tensor) – Origin after interpolation.
grid_polar (PolarGrid or dict) –
Polar grid definition. Can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)fc (float) – RF center frequency in Hz.
rotation (float) – Angle rotation to apply in radians.
grid_polar_new (dict, optional) – Grid definition of the new image. If None uses the same grid as input, but with double the angle points.
method (str or tuple) – Interpolation method. Valid choices are: - “linear”: Linear interpolation. - (“lanczos”, n): Lanczos resampling. n is the half of kernel length.
alias_fmod (float) – Range modulation frequency applied to input.
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- torchbp.ops.polar_interp.polar_interp_lanczos(img, dorigin, grid_polar, fc, rotation=0, grid_polar_new=None, z0=0, order=6, alias_fmod=0)[source]
Interpolate pseudo-polar radar image to new grid and change origin position by dorigin.
Gradient not supported.
- Parameters:
img (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polar grid. [nbatch, range, angle] if interpolating multiple images at the same time.
dorigin (Tensor) – Difference between the origin of the old image to the new image. Units in meters [nbatch, 3] if img shape is 3D.
grid_polar (PolarGrid or dict) –
Polar grid definition. Can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)fc (float) – RF center frequency in Hz.
rotation (float) – Angle rotation to apply in radians.
grid_polar_new (dict, optional) – Grid definition of the new image. If None uses the same grid as input, but with double the angle points.
z0 (float) – Height of the antenna phase center in the new image.
order (int) – Number of nearby samples to use for interpolation of one new sample.
alias_fmod (float) – Range modulation frequency applied to input.
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- torchbp.ops.polar_interp.polar_interp_linear(img, dorigin, grid_polar, fc, rotation=0, grid_polar_new=None, z0=0, alias_fmod=0)[source]
Interpolate pseudo-polar radar image to new grid and change origin position by dorigin.
Gradient can be calculated with respect to img and dorigin.
- Parameters:
img (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polar grid. [nbatch, range, angle] if interpolating multiple images at the same time.
dorigin (Tensor) – Difference between the origin of the old image to the new image. Units in meters [nbatch, 3] if img shape is 3D.
grid_polar (PolarGrid or dict) –
Polar grid definition. Can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)fc (float) – RF center frequency in Hz.
rotation (float) – Angle rotation to apply in radians.
grid_polar_new (dict, optional) – Grid definition of the new image. If None uses the same grid as input, but with double the angle points.
z0 (float) – Height of the antenna phase center in the new image.
alias_fmod (float) – Range modulation frequency applied to input.
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- torchbp.ops.polar_interp.polar_to_cart(img, origin, grid_polar, grid_cart, fc, rotation=0, alias_fmod=0, method='linear')[source]
Interpolate polar radar image to cartesian grid.
The input image should be either generated with dealias=True or call torchbp.util.bp_polar_range_dealias first.
- Parameters:
img (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polar grid. [nbatch, range, angle] if interpolating multiple images at the same time.
origin (Tensor) – 3D antenna phase center of the old image in with respect to new image. Units in meters [nbatch, 3] if img shape is 3D.
grid_polar (PolarGrid or dict) –
Polar grid definition. Can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)grid_cart (CartesianGrid or dict) –
Cartesian grid definition. Can be:
CartesianGrid object:
CartesianGrid(x_range=(x0, x1), y_range=(y0, y1), nx=nx, ny=ny)dict:
{"x": (x0, x1), "y": (y0, y1), "nx": nx, "ny": ny}
fc (float) – RF center frequency in Hz.
rotation (float) – Polar origin rotation angle.
method (str or tuple) – Interpolation method. Valid choices are: - “linear”: Linear interpolation. - (“lanczos”, n): Lanczos resampling. n is the half of kernel length.
alias_fmod (float) – Range modulation frequency applied to input.
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- torchbp.ops.polar_interp.polar_to_cart_lanczos(img, origin, grid_polar, grid_cart, fc, rotation=0, alias_fmod=0, order=6)[source]
Interpolate polar radar image to cartesian grid with linear interpolation.
The input image should be either generated with dealias=True or call torchbp.util.bp_polar_range_dealias first.
- Parameters:
img (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polar grid. [nbatch, range, angle] if interpolating multiple images at the same time.
origin (Tensor) – 3D antenna phase center of the old image in with respect to new image. Units in meters [nbatch, 3] if img shape is 3D.
grid_polar (PolarGrid or dict) –
Polar grid definition. Can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)grid_cart (CartesianGrid or dict) –
Cartesian grid definition. Can be:
CartesianGrid object:
CartesianGrid(x_range=(x0, x1), y_range=(y0, y1), nx=nx, ny=ny)dict:
{"x": (x0, x1), "y": (y0, y1), "nx": nx, "ny": ny}
fc (float) – RF center frequency in Hz.
rotation (float) – Polar origin rotation angle.
order (int) – Number of nearby samples to use for interpolation of one new sample.
alias_fmod (float) – Range modulation frequency applied to input.
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- torchbp.ops.polar_interp.polar_to_cart_linear(img, origin, grid_polar, grid_cart, fc, rotation=0, alias_fmod=0)[source]
Interpolate polar radar image to cartesian grid with linear interpolation.
The input image should be either generated with dealias=True or call torchbp.util.bp_polar_range_dealias first.
- Parameters:
img (Tensor) – 2D radar image in [range, angle] format. Dimensions should match with grid_polar grid. [nbatch, range, angle] if interpolating multiple images at the same time.
origin (Tensor) – 3D antenna phase center of the old image in with respect to new image. Units in meters [nbatch, 3] if img shape is 3D.
grid_polar (PolarGrid or dict) –
Polar grid definition. Can be:
PolarGrid object:
PolarGrid(r_range=(r0, r1), theta_range=(theta0, theta1), nr=nr, ntheta=ntheta)dict:
{"r": (r0, r1), "theta": (theta0, theta1), "nr": nr, "ntheta": ntheta}
where
thetarepresents sin of angle (-1, 1 for 180 degree view)grid_cart (CartesianGrid or dict) –
Cartesian grid definition. Can be:
CartesianGrid object:
CartesianGrid(x_range=(x0, x1), y_range=(y0, y1), nx=nx, ny=ny)dict:
{"x": (x0, x1), "y": (y0, y1), "nx": nx, "ny": ny}
fc (float) – RF center frequency in Hz.
rotation (float) – Polar origin rotation angle.
alias_fmod (float) – Range modulation frequency applied to input.
- Returns:
out – Interpolated radar image.
- Return type:
Tensor
- torchbp.ops.polar_interp.select_knab_poly_degree(oversample, order)[source]
Select minimum polynomial degree for full Knab kernel polynomial approximation.
Based on empirical testing with MSE threshold = 0.1 dB.
- Parameters:
oversample (float) – Oversampling ratio.
order (int) – Kernel order (number of samples used in interpolation).
- Returns:
Polynomial degree.
- Return type:
int