Skip to main content

Kamui

CI PyPI version

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$ connected with edges $E$ 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 \in [0, M)} = (V_v - V_u + \pi) \pmod {2\pi} - \pi | (u, v) = E_i$ is the pseudo phase derivatives, $M = |E|$. $A_{ij} \in \{-1, 0, 1\} | i \in [0, N) \cap 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. 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 : (2,) or (3,) tuple
        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`.

    Returns
    -------
    np.ndarray
        The unwrapped phase of the same shape as x.
    """

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.

    Returns
    -------
    np.ndarray
        The unwrapped phase of the same shape as psi.
    """

Examples

TODO

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

References

Metadata

Release files for kamui 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kamui 0.2.0
File Size Uploaded
kamui-0.2.0.tar.gz 15.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for kamui 0.2.0
File Interpreter ABI Platform
kamui-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.6 kB

Release files / kamui-0.2.0.tar.gz

Download URL kamui-0.2.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7eaf349f898c2395a7a2b2c268b62f956fd340f1361530ea353b91058ee254e0
BLAKE2b-256 checksum
How to use checksums
41f66d0323140f3f8c4770b692bf73ddb7a5127b6afe81038190bf2b20d5c87a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / kamui-0.2.0-py3-none-any.whl

Download URL kamui-0.2.0-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ead467c47077eddf620e8b93f4b01f857056f5574970847cf79e44d007a8d0e
BLAKE2b-256 checksum
How to use checksums
0cd169276aff25c96733d6aa2f91e95630a010de112f03d52f4e8cbb73a8fe25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.0

2 release files

0.2.1

2 release files

This release

0.2.0 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page