A simple Python wrapper for SNAPHU
Project description
snaphu-py
A simple Python wrapper for the Statistical-Cost, Network-Flow Algorithm for Phase Unwrapping (SNAPHU)
Installation
Install with conda
You can install snaphu-py with conda using
$ conda install -c conda-forge snaphu
Install with pip
You can install snaphu-py with pip using
$ pip install snaphu
Install from source
To install snaphu-py from source, you will need:
- Python 3.9 or newer + pip
- A C compiler
The latest source code can be installed using
$ pip install git+https://github.com/isce-framework/snaphu-py.git
Alternatively, clone the repository (be sure to use the --recursive
flag to fetch the
Git submodules) and install the local copy using
$ git clone --recursive https://github.com/isce-framework/snaphu-py.git
$ cd snaphu-py
$ pip install .
[!NOTE] Editable installs are experimentally supported, with some caveats and configuration. See here for details.
Usage
Basic usage
The main interface is the snaphu.unwrap
function, which takes input interferogram and
coherence arrays and returns the unwrapped phase and connected component labels.
The inputs may be NumPy arrays or any other type of object that supports a similar interface (h5py Datasets, Zarr Arrays, etc).
The following example illustrates basic usage:
import numpy as np
import snaphu
# Simulate a 512x512 interferogram containing a simple diagonal phase ramp with multiple
# fringes.
y, x = np.ogrid[-3:3:512j, -3:3:512j]
igram = np.exp(1j * np.pi * (x + y))
# Sample coherence for an interferogram with no noise.
corr = np.ones(igram.shape, dtype=np.float32)
# Unwrap using the 'SMOOTH' cost mode and 'MCF' initialization method.
unw, conncomp = snaphu.unwrap(igram, corr, nlooks=1.0, cost="smooth", init="mcf")
The wrapped and unwrapped phase are shown below.
Working with geospatial raster data
Optional support for working with geospatial raster data is provided via the
snaphu.io.Raster
class, which implements a NumPy-like interface for accessing raster
data in GDAL-compatible formats.
This functionality requires the rasterio package.
import snaphu
# Open the input interferogram and coherence rasters as well as a water mask.
igram = snaphu.io.Raster("igram.tif")
corr = snaphu.io.Raster("corr.tif")
mask = snaphu.io.Raster("mask.tif")
# Create output rasters to store the unwrapped phase & connected component labels with
# the same shape, driver, CRS/geotransform, etc as the input interferogram raster.
unw = snaphu.io.Raster.create("unw.tif", like=igram, dtype="f4")
conncomp = snaphu.io.Raster.create("conncomp.tif", like=igram, dtype="u4")
# Unwrap and store the results in the `unw` and `conncomp` rasters.
snaphu.unwrap(igram, corr, nlooks=50.0, mask=mask, unw=unw, conncomp=conncomp)
The wrapped[^1] and unwrapped phase for an example case are shown below.
snaphu.io.Raster
implements Python's context manager protocol, so the above snippet
could also be written as:
import snaphu
# Open the input rasters and create output rasters as context managers. The data will be
# flushed and the files closed upon exiting the 'with' block. (Note that this syntax
# requires Python 3.10 or newer -- see https://github.com/python/cpython/issues/56991.)
with (
snaphu.io.Raster("igram.tif") as igram,
snaphu.io.Raster("corr.tif") as corr,
snaphu.io.Raster("mask.tif") as mask,
snaphu.io.Raster.create("unw.tif", like=igram, dtype="f4") as unw,
snaphu.io.Raster.create("conncomp.tif", like=igram, dtype="u4") as conncomp,
):
# Unwrap and store the results in the `unw` and `conncomp` rasters.
snaphu.unwrap(igram, corr, nlooks=50.0, mask=mask, unw=unw, conncomp=conncomp)
This has the advantage of ensuring that the raster datasets are flushed and closed upon
exiting the with
block.
Tiling and parallelism
The interferogram may be partitioned into multiple (possibly overlapping) regularly-sized rectangular blocks, each of which is unwrapped independently before being reassembled. This tiling strategy can significantly improve unwrapping runtime and reduce peak memory utilization, but may also introduce phase discontinuities between tiles. In order to mitigate such tiling artifacts, choosing a substantial overlap between tiles is recommended.
Multiple tiles may be unwrapped simultaneously in parallel processes.
The following example demonstrates tiled unwrapping using multiple processes:
import numpy as np
import snaphu
# Simulate a 2048x2048 interferogram containing a simple diagonal phase ramp with many
# fringes.
y, x = np.ogrid[-12:12:2048j, -12:12:2048j]
igram = np.exp(1j * np.pi * (x + y))
# Sample coherence for an interferogram with no noise.
corr = np.ones(igram.shape, dtype=np.float32)
# Unwrap using a 4x4 grid of tiles in parallel using 8 processes.
unw, conncomp = snaphu.unwrap(
igram, corr, nlooks=1.0, ntiles=(4, 4), tile_overlap=256, nproc=8
)
The wrapped and unwrapped phase are shown below.
FAQ
Why isn't [some configuration parameter] exposed?
The full set of SNAPHU parameters includes >100 configurable options. This project takes a pragmatic (and somewhat opinionated) approach to managing this complexity. Only the most commonly manipulated parameters are exposed.
If there's an option that's not currently supported that you'd like to see added to the interface, feel free to open an issue requesting the addition.
What version of SNAPHU is used?
Our goal is to support the latest available SNAPHU release. The SNAPHU version used by the library can be obtained using
>>> import snaphu
>>> print(snaphu.get_snaphu_version())
What platforms are supported?
Unix-like systems (e.g. Linux, macOS) are supported. Installation on Windows is not currently supported.
Copyright
Copyright (c) 2023 California Institute of Technology ("Caltech"). U.S. Government sponsorship acknowledged.
All rights reserved.
License
This software is licensed under your choice of BSD-3-Clause or Apache-2.0 licenses. The exact terms of each license can be found in the accompanying LICENSE-BSD-3-Clause and LICENSE-Apache-2.0 files, respectively.
SPDX-License-Identifier: BSD-3-Clause OR Apache-2.0
[!NOTE] The SNAPHU source code (which is included as a Git submodule) is subject to different license terms, the details of which can be found here. In particular, note that parts of the SNAPHU codebase are subject to terms that prohibit commercial use.
[^1]: InSAR product processed by ASF DAAC HyP3 2023 using GAMMA software. Contains modified Copernicus Sentinel data 2023, processed by ESA.
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
Built Distributions
Hashes for snaphu-0.4.1-pp310-pypy310_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d70b3fd731dae7241c4c092cec138fed71021b06f72d6c487f3d5e266e2650c |
|
MD5 | fe7fb20f42443308ff54fcb171d7dedf |
|
BLAKE2b-256 | 2b8d67597d0c7fd1022b77425b1b3bc7e5e3ca8bfb69cf3530e55a78cb87c159 |
Hashes for snaphu-0.4.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 097c0eb53b3cda3f01bcce5a88a55ed86fa15c83735a070d1b3552ba8378cf91 |
|
MD5 | b9264d10eb5de3659cf98b063a28626c |
|
BLAKE2b-256 | 64e9927d2a1f4209a033360135e0e22c24ab472133137999d2fc5abf3d8e4f23 |
Hashes for snaphu-0.4.1-pp310-pypy310_pp73-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fac136ed69b2f89899190bb58710535c59914a1150366cc86d3133f225bde545 |
|
MD5 | f905d2931afc5585d2c483d9a978b1db |
|
BLAKE2b-256 | 00616c5459f2a511b3a5c12e4564b52f321da45d49db68041f1438aae99ad037 |
Hashes for snaphu-0.4.1-pp39-pypy39_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c73cd7b6ffae33c76e862d005ab8de37501e0cc00ab83608058dcf73205174be |
|
MD5 | ca507271b5ca549b9e7a7c8973cdb320 |
|
BLAKE2b-256 | 6bf82cbc0f35c25d293f097cbd310e0d9f1223027d23d120eda33b931f3798be |
Hashes for snaphu-0.4.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c126194502f1b08e1a2a7fe41904c2d6656c0f0594fee227f299db8ffab30ee |
|
MD5 | 1a7fa9f80e0658405f2fda11f33c5c1b |
|
BLAKE2b-256 | a04a4bee10449e5a1cef5dd96de03472abacf1ac27d324cb3e077811e2beb952 |
Hashes for snaphu-0.4.1-pp39-pypy39_pp73-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48aa168702a3c4bbc77115d201766c0f3cb902ba8d12e5939714105645f61ff0 |
|
MD5 | 3a493f2cd14e1cb78cc37c7b6d614c40 |
|
BLAKE2b-256 | 45eb5a2daa6e7ed782a013d2b41f3977a52ab543657aefe17865e2bb7c538ee6 |
Hashes for snaphu-0.4.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cf5e8252dd2ac52bd1003f51e5c0de3bb5e9323248aad1b4d8001fca883ff12 |
|
MD5 | 6a99704a1edc4a9af1e62a3526774c3e |
|
BLAKE2b-256 | d907daaab9a5588fcf53b428ea0ff141aaa2f02234cb14de218ced8812a88e44 |
Hashes for snaphu-0.4.1-cp313-cp313-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b1a2037dfab887d7837c10d125530b0fc67563e68240051c5e90077db4b92cb |
|
MD5 | 8bac057ba044805b698861833914b792 |
|
BLAKE2b-256 | 27794198fd39f660d5fc06ef999d78e4d3976ddf348d14c4d0aafabdeaa2de46 |
Hashes for snaphu-0.4.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d81600c71d2fa533ef22b9fb9ca2271ec1cf5b19da4ee05ddd3a181e60bfd09 |
|
MD5 | b682fe4384ff40f2caff0d40a127a544 |
|
BLAKE2b-256 | d05c7eca15911a45b63e60612e2047147149dfa5c5bad259c5c94dc6d55b38df |
Hashes for snaphu-0.4.1-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e4f039807fa2cab1c372e3d5bf6cb72739fe8bdb78cab43234c4add09a3a896 |
|
MD5 | 92654ce5c83ccdd87e5ac8a8bb7925d8 |
|
BLAKE2b-256 | f2d3a9d496a9e5a5e2e0388fc49e2710f0103f53404c7ac17628e38728c4ae6c |
Hashes for snaphu-0.4.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7c9a9410560795da41048a586ecef7e1efa351027577a77e52baa6df77cd5f4 |
|
MD5 | db5d728eb56e14e9d3390bf380e70abf |
|
BLAKE2b-256 | 6d25732c1b93de2e130af4afc9817022a168a1e96410d7d67a9ec4e69c14713d |
Hashes for snaphu-0.4.1-cp312-cp312-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d38d0b016718b0945cc1a6d3240ca0257d415b416e62a06964140ad0cd8c261d |
|
MD5 | 23536f275cb6666c667587f96d98ea17 |
|
BLAKE2b-256 | 56f3b594fe851ad520a07127a9680bbf9732c74f8d4e6b6dc5a2cdd196bf5974 |
Hashes for snaphu-0.4.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ed89e57afce7ef3df748553e283b0ba606a14eb844147ce4e9a917fd87158e8 |
|
MD5 | f6c93e43d529b4183122ccfc285fb5e3 |
|
BLAKE2b-256 | ce634ac4488f3999d8f0d5fcfce5ed8cbe9abc0d64daffd59c5411e15a7fdb40 |
Hashes for snaphu-0.4.1-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72c00be8d876cebf66b5874c35076f48ba4484dd94d176f21527763b03549a3a |
|
MD5 | 686330f9d70b70f993f958dbf9fb9da3 |
|
BLAKE2b-256 | d3a029a539efd9ae67a8c5d1c20d849fe9f468e0e0184475d501e5a1298dd6cb |
Hashes for snaphu-0.4.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34cf7111865e1a5d2451ff3d97421473edd8c4ffd99d692e02a6cc23f5629cf5 |
|
MD5 | 5408c6b0fe5f8bc56b6e05a8a93a8ca9 |
|
BLAKE2b-256 | 68670295a8cfb1d88a5863dd1ff5e5a5514cd40513d6d604cbf9fd64977215ba |
Hashes for snaphu-0.4.1-cp311-cp311-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7a55e7be04891931d4020fe0055920d4944fb6c611f4566bfbe05c113c5d79e |
|
MD5 | 32abc88d9fa0d2340b98dac9a0942ab2 |
|
BLAKE2b-256 | 2a448c6be346b217c805202b967b96ca04caa586c53f9427c948b7797ef15a36 |
Hashes for snaphu-0.4.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5888b15f68f55109b36c2784e6ac06143f3bb02a0eee2cb0171061ca116e7967 |
|
MD5 | 1dd31cc83faf265f0d80a83aa655a70a |
|
BLAKE2b-256 | aa7e2a44545d63bfb87d42ec28fb748b75ce1c4dc5de22be7b72294c035c9079 |
Hashes for snaphu-0.4.1-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3d069a7815834f0d72c6fdeac72c69a76069e14c03bca80fd5e78f0ea40bdb7 |
|
MD5 | 6119149bc6fa1b3d807c878c6156b56c |
|
BLAKE2b-256 | 8c198279587822a695b339afd985357f835858f6c20b3f05cc81f232b86895e5 |
Hashes for snaphu-0.4.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17702735ccdad2305b13428d7d6df0664ab32b9aaa8e8f7d28f158029767bacb |
|
MD5 | 16adcacdabbb34fc5351ee068df7a108 |
|
BLAKE2b-256 | d271e884a8cb4638f866b1931d30493e370edbf42dd097a9d730152bba24ea1b |
Hashes for snaphu-0.4.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2bb5cf03d0cefead7a2287a4e51b10242d6778024883128eb3f63062811beb7 |
|
MD5 | b7a60180e74283845a28822a61b3aa01 |
|
BLAKE2b-256 | 5d8360f442b7675cd9148a97e1474dc4049b13cc3fc69fb096fd50f0098c6ee7 |
Hashes for snaphu-0.4.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4d05abc74e4ce8ce89b2bbcbc8cf22504c069ee0925ee8219a8c1c18e901615 |
|
MD5 | aa765531fb6552d94942ae21d9eec069 |
|
BLAKE2b-256 | edcfb7484df6eed8677423946681f1254dcdd74b40e72102274bf8afd155a24b |
Hashes for snaphu-0.4.1-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c9d4935461a34f9138bb45bb742e3b0aff13349b70adbbf4fc40cb894922401 |
|
MD5 | 9ee76c24e896585af09a43b47f48cac3 |
|
BLAKE2b-256 | e4fe4661a52e319fbda1f204528aaad284c414b92726e6e8ebb38ef2d5eb3df9 |
Hashes for snaphu-0.4.1-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0d3f396347bbcae4ea21434b22579b6cb60b200248b09239fcc7692683d36e1 |
|
MD5 | 97b3b44d329433dc3e36690119666011 |
|
BLAKE2b-256 | 19dd47c43d3ee2bd63310ef0bb33df0a0b77628551ee38e4fb94b8f3be72596c |
Hashes for snaphu-0.4.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c785b1f9358b01bfa821a900020e265c4cc7fb6aef6d6362c4de3a50f74429fc |
|
MD5 | ac52e3143b3d2cffc2deb2350d8c3a54 |
|
BLAKE2b-256 | 945e55737102d781dc57e6e06f218546b65a20cdb322bd098eefd30c7b4d554f |
Hashes for snaphu-0.4.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82376b85a59b255728fc774a4f8b08a78382ac4142473db698edd08f4e3df984 |
|
MD5 | 5938664d3b070754812daa3f638be799 |
|
BLAKE2b-256 | e41120b1f04723d65cf0e6b782a57df16ad355f5f9f92d49e283791097915dbf |
Hashes for snaphu-0.4.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4390820cce19ae5f71394c66ea08fbb9de34e046e251f06509fcd9654ac90e0 |
|
MD5 | 55e22f7fae6d29d3ee9580caabb3da4e |
|
BLAKE2b-256 | ec766c8e7714ed75176c242d3bd672b83c53ea97b00447b9677ffff464d6911a |