Skip to main content

A Python package for phase unwrapping

Project description

Kamui

Kamui is a python package for robust and accurate phase unwrapping on 2-D, 3-D, or sparse data.

Kamui unwrap the phases by viewing the data points as vertices $V = \{v: v \in [0, 2\pi)\}$ connected with edges $E = \{(u, v): u, v\in V \cap u \neq v\}$ and solving the following integer linear programming (ILP) problem:

\min_{k} w^T |k|,
\text{s.t.} Ak = -A\frac{x}{2\pi},

where $k_{i \in [0, M)} \in \mathbb{Z}$ is the edge ambiguities to be computed, $w_{i \in [0, M)} \in \mathbb{R}^+$ is the weights, $x_i = \{(v - u + \pi) \pmod {2\pi} - \pi: (u, v) \in E\}_{i \in [0, M)}$ is the pseudo phase derivatives, $M = |E|$. $A_{ij} \in \{-1, 0, 1\} \cap i \in [0, N), j \in [0, M)$ and $N$ is the number of elementary cycles enclosed by $E$.

This formulation is based on the fact that the true phase differences, $2\pi k + x$, should fulfill the irrotationality constraint, which means the summation of phase derivatives of each elementary cycles is zero. This is the general form of the network programming approach proposed in the paper "A novel phase unwrapping method based on network programming".

Unwrapping phase with Kamui can be computationally heavy due to the fact that ILP is NP-hard. Acceleration techniques, such as dividing the graph into subgraphs, will be implemented in the future.

Installation

pip install kamui

Kamui also provides PUMA, a fast and robust phase unwrapping algorithm based on graph cuts as an alternative. To install PUMA, run

pip install kamui[extra]

However, it uses the original maxflow implementation by Vladimir Kolmogorov with GPL license. Please follow the licensing instruction in PyMaxflow if you use this version of Kamui.

Usage

For regular 2-D or 3-D data such as interferograms, use kamui.unwrap_dimensional:

import numpy as np

def unwrap_dimensional(
    x: np.ndarray,
    start_pixel: Optional[Union[Tuple[int, int], Tuple[int, int, int]]] = None,
    use_edgelist: bool = False,
    **kwargs
) -> np.ndarray:
    """
    Unwrap the phase of a 2-D or 3-D array.

    Parameters
    ----------
    x : 2-D or 3-D np.ndarray
        The phase to be unwrapped.
    start_pixel : the reference pixel to start unwrapping.
        Default to (0, 0) for 2-D data and (0, 0, 0) for 3-D data.
    use_edgelist : bool
        Whether to use the edgelist method.
        Default to False.
    kwargs : dict
        Other arguments passed to `kamui.unwrap_arbitrary`.
    """

For sparse data, use kamui.unwrap_arbitrary:

import numpy as np

def unwrap_arbitrary(
    psi: np.ndarray,
    edges: np.ndarray,
    simplices: Iterable[Iterable[int]] = None,
    method: str = "ilp",
    period: float = 2 * np.pi,
    start_i: int = 0,
    **kwargs,
) -> np.ndarray:
    """
    Unwrap the phase of arbitrary data.

    Parameters
    ----------
    psi : 1D np.ndarray of shape (P,)
        The phase (vertices) to be unwrapped. 
    edges : 2-D np.ndarray of shape (M, 2)
        The edges of the graph.
    simplices : Iterable[Iterable[int]] of length (N,)
        Each element is a list of vertices that form a simplex (a.k.a elementary cycle).
        The connections should be consistent with the edges.
        This is also used to compute automatic weights for each edge.
        If not provided and method is "ilp", an edgelist-based ILP solver will be used without weighting.
    method : str
        The method to be used. Valid options are "ilp" and "gc", where "gc" correponds to PUMA.
        Default to "ilp".
    period : float
        The period of the phase.
        Default to 2 * np.pi.
    start_i : int
        The index of the reference vertex to start unwrapping.
        Default to 0.
    kwargs : dict
        Other arguments passed to the solver.
    """

Examples

WIP.

TODO

  • subgraph division
  • edges-based custom weighting
  • vertices-based custom weighting

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kamui-0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

kamui-0.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file kamui-0.1.tar.gz.

File metadata

  • Download URL: kamui-0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for kamui-0.1.tar.gz
Algorithm Hash digest
SHA256 3930942781d16804193b86e119e290fb6079754ca982574cbc1f68d7b11547d7
MD5 f2c9e4573d11b62a44270625c8ffcecc
BLAKE2b-256 b75ac8d7fcd739551190b595273f829d2b72dd07c45edb4409b5e8c371f3e809

See more details on using hashes here.

File details

Details for the file kamui-0.1-py3-none-any.whl.

File metadata

  • Download URL: kamui-0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for kamui-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 038a39f236f485e32a8b9a0b1f981023bd480ab17c203484f9be4a1a8767e32b
MD5 52285cef57cd78f854d975c14e78ab3c
BLAKE2b-256 a1fc49eaf999e960b802def41f09630a4a404a1f42aecc8d6615a73b3f9108c6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page