torchsar.autofocus package

Submodules

torchsar.autofocus.focusing module

torchsar.autofocus.focusing.defocus(x, pa=None, pr=None, isfft=True, ftshift=True)

Defocus image with given phase error

Defocus image in azimuth by

\[Y(k, n_r)=\sum_{n_a=0}^{N_a-1} X(n_a, n_r) \exp \left(j \varphi_{n_a}\right) \exp \left(-j \frac{2 \pi}{N_a} k n_a\right) \]

where, \(\varphi_{n_a}\) is the estimated azimuth phase error of the \(n_a\)-th azimuth line, \(y(k, n_r)\) is the focused pixel.

The defocus method in range is the same as azimuth.

Parameters
  • x (Tensor) – Focused image data \({\mathbf X} \in{\mathbb C}^{N\times N_c\times N_a\times N_r}\) or \({\mathbf X} \in{\mathbb R}^{N\times N_a\times N_r\times 2}\) or \({\mathbf X} \in{\mathbb R}^{N\times N_c\times N_a\times N_r\times 2}\).

  • pa (Tensor, optional) – Defocus parameters in azimuth, phase error in rad unit. (the default is None, not focus)

  • pr (Tensor, optional) – Defocus parameters in range, phase error in rad unit. (the default is None, not focus)

  • isfft (bool, optional) – Is need do fft (the default is True)

  • ftshift (bool, optional) – Is shift zero frequency to center when do fft/ifft/fftfreq (the default is True)

Returns

A tensor of defocused images.

Return type

(Tensor)

Raises

TypeErrorx is complex and should be in complex or real represent formation!

torchsar.autofocus.focusing.focus(x, pa=None, pr=None, isfft=True, ftshift=True)

Focus image with given phase error

Focus image in azimuth by

\[Y(k, n_r)=\sum_{n_a=0}^{N_a-1} X(n_a, n_r) \exp \left(-j \varphi_{n_a}\right) \exp \left(-j \frac{2 \pi}{N_a} k n_a\right) \]

where, \(\varphi_{n_a}\) is the estimated azimuth phase error of the \(n_a\)-th azimuth line, \(y(k, n_r)\) is the focused pixel.

The focus method in range is the same as azimuth.

Parameters
  • x (Tensor) – Defocused image data \({\mathbf X} \in{\mathbb C}^{N\times N_c\times N_a\times N_r}\) or \({\mathbf X} \in{\mathbb R}^{N\times N_a\times N_r\times 2}\) or \({\mathbf X} \in{\mathbb R}^{N\times N_c\times N_a\times N_r\times 2}\).

  • pa (Tensor, optional) – Focus parameters in azimuth, phase error in rad unit. (the default is None, not focus)

  • pr (Tensor, optional) – Focus parameters in range, phase error in rad unit. (the default is None, not focus)

  • isfft (bool, optional) – Is need do fft (the default is True)

  • ftshift (bool, optional) – Is shift zero frequency to center when do fft/ifft/fftfreq (the default is True)

Returns

A tensor of focused images.

Return type

(Tensor)

Raises

TypeErrorx is complex and should be in complex or real represent formation!

torchsar.autofocus.fourier_domain_optim module

torchsar.autofocus.fourier_domain_optim.af_ffo(g, w=None, p=2, niter=10, eta=0.5, tol=0.01, ftshift=False)
torchsar.autofocus.fourier_domain_optim.af_ffo_sm(x, p=2, niter=10, delta=None, toli=0.01, tolo=0.01, ftshift=True, islog=False)

Stage-by-Stage minimum entropy

[1] Morrison Jr, Robert Lee; Autofocus, Entropy-based (2002): Entropy-based autofocus for synthetic aperture radar.

Parameters
  • x (Tensor) – Corrupt complex SAR image. N-Na-Nr(complex) or N-Na-Nr-2(real)

  • niter (int, optional) – The number of iteration (the default is 10)

  • delta ({float or None}, optional) – The change step (the default is None (i.e. PI))

  • toli (int, optional) – Tolerance error for inner loop (the default is 1e-2)

  • tolo (int, optional) – Tolerance error for outer loop (the default is 1e-2)

  • ftshift (bool, optional) – Shift the zero frequency to center? (the default is True)

  • islog (bool, optional) – Print log information? (the default is False)

torchsar.autofocus.maximum_contrast module

torchsar.autofocus.maximum_contrast.mcaf_sm(x, phi=None, niter=10, tol=0.0001, eta=0.1, method='N-MCA', selscat=False, axis=- 2, ftshift=True, islog=False)

Contrast based autofocus

Maximum-Contrast based Autofocus (MCA)

Parameters
  • x (Tensor) – complex image with shape \(N×N_a×N_r\) or \(N×N_a×N_r×2\)

  • phi (float, optional) – initial value of \(\phi\) (the default is None, which means zeros)

  • niter (int, optional) – number of iterations (the default is 10)

  • method (str, optional) – method used to update the phase error - 'FP-MCA' –> Fix Point - 'CD-MCA' –> Coordinate Descent - 'SU-MCA' –> Simultaneous Update - 'N-MCA' –> Newton, see [2], [1] has problem when used to small image - 'SN-MCA' –> Simplified Newton - 'MN-MCA' –> Modified Newton

  • selscat (bool, optional) – Select brighter scatters.

  • axis (int, optional) – Compensation axis.

  • ftshift (bool, optional) – Does shift zero frequency to center?

  • islog (bool, optional) – Does print log info.

see [1] Zhang S , Liu Y , Li X . Fast Entropy Minimization Based Autofocusing Technique for ISAR Imaging[J]. IEEE Transactions on Signal Processing, 2015, 63(13):3425-3434.

[2] Zeng T , Wang R , Li F . SAR Image Autofocus Utilizing Minimum-Entropy Criterion[J]. IEEE Geoence & Remote Sensing Letters, 2013, 10(6):1552-1556.

torchsar.autofocus.minimum_entropy module

torchsar.autofocus.minimum_entropy.meaf_sm(x, phi=None, niter=10, tol=0.0001, eta=0.1, method='N-MEA', selscat=False, isunwrap=True, deg=None, axis=- 2, ftshift=True, islog=False)

Entropy based autofocus

Minimum-Entropy based Autofocus (MEA)

Parameters
  • x (Tensor) – complex image with shape \(N×N_a×N_r\) or \(N×N_a×N_r×2\)

  • phi (Tensor, optional) – initial value of \(\phi\) (the default is None, which means zeros)

  • niter (int, optional) – number of iterations (the default is 10)

  • tol (float, optional) – Error tolerance.

  • eta (float, optional) – Learning rate.

  • method (str, optional) – method used to update the phase error - 'FP-MEA' –> Fix Point - 'CD-MEA' –> Coordinate Descent - 'SU-MEA' –> Simultaneous Update - 'N-MEA' –> Newton, see [2], [1] has problem when used to small image - 'SN-MEA' –> Simplified Newton - 'MN-MEA' –> Modified Newton

  • selscat (bool, optional) – Select brighter scatters (default: False).

  • isunwrap (bool, optional) – Unwrap radian phase (default: True).

  • deg (int or None, optional) – The degree of polynominal, if None, no fitting.

  • axis (int, optional) – Compensation axis.

  • ftshift (bool, optional) – Does shift zero frequency to center?

  • islog (bool, optional) – Does print log info.

  • [1] Zhang S (see) – 3425-3434. [2] Zeng T , Wang R , Li F . SAR Image Autofocus Utilizing Minimum-Entropy Criterion[J]. IEEE Geoence & Remote Sensing Letters, 2013, 10(6):1552-1556.

  • Y (Liu) – 3425-3434. [2] Zeng T , Wang R , Li F . SAR Image Autofocus Utilizing Minimum-Entropy Criterion[J]. IEEE Geoence & Remote Sensing Letters, 2013, 10(6):1552-1556.

  • X . Fast Entropy Minimization Based Autofocusing Technique for ISAR Imaging[J] IEEE Transactions on Signal Processing (Li) – 3425-3434. [2] Zeng T , Wang R , Li F . SAR Image Autofocus Utilizing Minimum-Entropy Criterion[J]. IEEE Geoence & Remote Sensing Letters, 2013, 10(6):1552-1556.

  • 2015 (13) – 3425-3434. [2] Zeng T , Wang R , Li F . SAR Image Autofocus Utilizing Minimum-Entropy Criterion[J]. IEEE Geoence & Remote Sensing Letters, 2013, 10(6):1552-1556.

  • 63 (13) – 3425-3434. [2] Zeng T , Wang R , Li F . SAR Image Autofocus Utilizing Minimum-Entropy Criterion[J]. IEEE Geoence & Remote Sensing Letters, 2013, 10(6):1552-1556.

Returns

Description

Return type

(Tensor)

torchsar.autofocus.minimum_entropy.meaf_ssa_sm(x, niter=10, delta=None, toli=0.01, tolo=0.01, ftshift=True, islog=False)

Stage-by-Stage minimum entropy

[1] Morrison Jr, Robert Lee; Autofocus, Entropy-based (2002): Entropy-based autofocus for synthetic aperture radar.

Parameters
  • x (Tensor) – Corrupt complex SAR image. N-Na-Nr(complex) or N-Na-Nr-2(real)

  • niter (int, optional) – The number of iteration (the default is 10)

  • delta ({float or None}, optional) – The change step (the default is None (i.e. PI))

  • toli (int, optional) – Tolerance error for inner loop (the default is 1e-2)

  • tolo (int, optional) – Tolerance error for outer loop (the default is 1e-2)

  • ftshift (bool, optional) – Shift the zero frequency to center? (the default is True)

  • islog (bool, optional) – Print log information? (the default is False)

torchsar.autofocus.phase_error_model module

class torchsar.autofocus.phase_error_model.PolyPhaseErrorGenerator(carange=None, crrange=None, seed=None)

Bases: object

mkpec(n, seed=None)

Make phase error

Parameters
  • n (int) – The number of phase errors.

  • seed (None or int, optional) – The random seed.

Returns

Description

Return type

TYPE

torchsar.autofocus.phase_error_model.convert_ppec(cs, degs=None, mode='fftfreq->2fftfreq')

convert polynominal phase error

Convert polynominal phase error.

Parameters
  • cs (Tensor) – The polynominal coefficients.

  • degs (None, optional) – The degrees of polynominal.

  • mode (str, optional) – 'fftfreq->2fftfreq' or '2fftfreq->fftfreq' (the default is ‘fftfeq->2fftfreq’)

Returns

Converted phase error tensor.

Return type

Tensor

Raises

ValueError – Not support mode.

torchsar.autofocus.phase_error_model.dctpe(c, x, deg=None)

compute phase error with DCT model

compute phase error with DCT model

\[\phi_{e}(h)=\sum_{p=0}^{P} a(p) \cdot d c t(p) \cdot \cos \left[\frac{\pi\left(2 h_{a}+1\right) p}{2 N}\right] \]

where, \(a(p)=\left{\begin{array}{ll}1 / \sqrt{N} p=0 \ \sqrt{2 / N} p \neq 0\end{array},\right.\) and \(\left{\begin{array}{l}p=0,1,2, \cdots \cdots \cdots, P \ h_{a}=[0,1,2, \cdots \cdots, N-1]\end{array}\right.\)

Parameters
  • c (Tensor, optional) – The DCT coefficients matrix \({\bf P} = [{\bf p}_1, {\bf p}_2, \cdots, {\bf p}_N ]^T ∈{\mathbb R}^{N × (M + 1)}\), where, \({\bf p}_n = [p_0, \cdots, p_M]^T\)).

  • x (Tensor, optional) – Axis, such as \((0, Na)\).

  • deg (tuple or None, optional) – The degree of the coefficients, \([p_{\rm min}, p_{\rm_max}]\), default is None, which means [0, size(c, 1)]

Returns

The phase error tensor.

Return type

(Tensor)

Raises

TypeErrorc should not be None!

torchsar.autofocus.phase_error_model.polype(c, x, deg=None)

compute phase error with polynominal model

compute phase error with polynominal model

Parameters
  • c (Tensor, optional) – The polynominal coefficients matrix \({\bf P} = [{\bf p}_1, {\bf p}_2, \cdots, {\bf p}_N ]^T ∈{\mathbb R}^{N × (M -1)}\), where, \({\bf p}_n = [p_2, \cdots, p_M]^T\)).

  • x (Tensor or None, optional) – Axis, such as a vector in range of (-1, 1). If x is None, return c directly.

  • deg (tuple or None, optional) – The degree of the coefficients, \([p_{\rm min}, p_{\rm_max}]\), default is None, which means [2, size(c, 1) + 1]

Returns

The phase error tensor.

Return type

(Tensor)

Raises

TypeErrorc should not be None!

torchsar.autofocus.phase_error_model.ppeaxis(n, norm=True, shift=True, mode='fftfreq', dtype=torch.float32, device='cpu')

Return the sample axis

Return the sample frequencies axis.

Parameters
  • n (int) – Number of samples.

  • norm (bool) – Normalize the frequencies.

  • shift (bool) – Does shift the zero frequency to center.

  • mode (str or None) – Frequency sampling mode. 'fftfreq' or 'freq' normalize the frequencies in (-1/2, 1/2). '2fftfreq' or '2freq' normalize the frequencies in (-1, 1). If None, return None.

  • dtype (Tensor) – Data type, default is th.float32.

  • device (str) – device string, default is 'cpu'.

Returns

Frequency array with size \(n×1\).

Return type

torch array

torchsar.autofocus.phase_error_model.rmlpe(phi, mode='poly', deg=4, ftshift=True)

remove linear phase error

Remove linear phase error based on linear fitting, the linear phase error will cause image shift.

Parameters
  • phi (Tensor) – A \(N×N_x\) phase error tensor with linear trend, where, \(N\) is the batchsize, \(N_x\) is the samples numbers in direction x.

  • mode (str) – model mode, default is polynominal

  • deg (int) – Polynomial degrees (default 4) to fit the error, once fitted, the term of deg=[0,1] will be removed. If deg is None or lower than 2, then we do not fit the error with polynominal and not remove the linear trend.

  • ftshift (bool) – Shift zero frequency to center when do fft/ifft/fftfreq? (the default is False)

Returns

Phase without linear trend.

Return type

phi (tensor)

torchsar.autofocus.phase_gradient module

torchsar.autofocus.phase_gradient.pgaf_sm(SI, nsar, nsub=None, windb=None, est='ML', deg=4, niter=None, tol=1e-06, isplot=False, islog=False)

Phase gradient autofocus for stripmap SAR.

Phase gradient autofocus for stripmap SAR.

Parameters
  • SI (Tensor) – Complex SAR image \(N_a×N_r\).

  • nsar (int) – Number of synthetic aperture pixels.

  • nsub (int, optional) – Number of sub-aperture pixels. (the default is \({\rm min}{N_{sar}, N_a}\))

  • windb (None or float, optional) – cutoff for window (the default is None, which use the mean as the cutoff.)

  • est (str, optional) – estimator, 'ML' for Maximum Likelihood estimation, 'LUMV' for Linear Unbiased Minimum Variance estimation (the default is ‘ML’)

  • deg (int) – Polynomial degrees (default 4) to fit the error, once fitted, the term of deg=[0,1] will be removed. If deg is None or lower than 2, then we do not fit the error with polynominal and not remove the linear trend.

  • niter (int, optional) – Maximum iters (the default is None, which means using tol for stopping)

  • tol (float, optional) – Phase error tolerance. (the default is 1.e-6)

  • isplot (bool, optional) – Plot estimated phase error or corrected image. (the default is False)

  • islog (bool, optional) – Print log information? (the default is False)

Returns

Corrected SAR image \({\bm X}\in {\mathbb C}^{N_a×N_r}\). phi (Tensor): Estimated phase error \({\phi}\in {\mathbb R}^{N_a×1}\).

Return type

SI (Tensor)

Raises
  • TypeError – The input is complex and should be in complex or real represent formation!

  • ValueError – For stripmap SAR, processing sub aperture should be smaller than synthetic aperture!

torchsar.autofocus.phase_gradient.pgaf_sm_1iter(x, windb=None, est='ML', deg=4, axis=- 2, isrmlpe=False, iscrct=False, isplot=False)

perform phase gradient autofocus 1 iter

Perform phase gradient autofocus 1 iter as described in [1].

revised for stripmap SAR

  • [1] C.V. Jakowatz, D.E. Wahl, P.H. Eichel, D.C. Ghiglia, P.A. Thompson,

{em Spotlight-mode Synthetic Aperture Radar: A Signal Processing Approach.} Springer, 1996.

  • [2] D.E. Wahl, P.H. Eichel, D.C. Ghiglia, C.V. Jakowatz, “Phase

gradient autofocus-a robust tool for high resolution SAR phase correction,” IEEE Trans. Aero. & Elec. Sys., vol. 30, no. 3, 1994.

Parameters
  • x (Tensor) – Complex SAR image \({\bm X}\in {\mathbb C}^{N×N_a×N_r}\), where \(N\) is the batchsize.

  • windb (None or float, optional) – Cutoff for window (the default is None, which use the mean as the cutoff.)

  • est (str, optional) – Estimator, 'ML' for Maximum Likelihood estimation, 'LUMV' for Linear Unbiased Minimum Variance estimation (the default is ‘ML’)

  • deg (int) – The degree of polynominal

  • axis (int, optional) – Autofocus axis.

  • isrmlpe (bool, optional) – Is remove linear phase error? (the default is False)

  • iscrct (bool, optional) – Is corrected image? (the default is False)

  • isplot (bool, optional) – Is plot estimated phase error? (the default is False)

Returns

Corrected SAR image \({\bm Y}\in {\mathbb C}^{N×N_a×N_r}\), only if iscrct is True, xc is returned. phi (Tensor): Estimated phase error \(\phi\in {\mathbb R}^{N×N_a}\).

Return type

xc (Tensor)

Raises
  • TypeErrorx is complex and should be in complex or real represent formation!

  • ValueError – Not supported estimator! Supported are 'ML' and 'LUMV'.

torchsar.autofocus.phase_gradient.phase_correction(x, phi, nsub=None, axis=- 2, ftshift=True)
torchsar.autofocus.phase_gradient.spotlight_width(H, BWa, Lsar)

Module contents