Skip to main content

viewinsar

Interactive swath (buffered) profile viewer for InSAR velocity and time-series products, built on MintPy.

plot_transection.py samples a single line of pixels. viewinsar samples a corridor: you draw the same line with two clicks, it gets buffered by ±W km, every valid pixel inside the buffer is linearly referenced onto the line, and the resulting cloud is shown as a 2-D point-density profile with the density-weighted median and the 25th–75th percentile envelope.

In GIS terms, one click-click does this:

step GIS equivalent
1. buffer the line by ±W km, flat caps QGIS buffer() with square cap style
2. clip the raster with that polygon Clip raster by mask layer
3. project each pixel onto the line → along-profile measure + off-profile distance QGIS LRS / ArcGIS Locate Features Along Routes
4. bin (distance, value) into a log-scaled density grid —

The map, every cross-section and the point time series each get their own window. Press = to add another section: the line you already drew stays on the map as A-A', the new one becomes B-B', and so on. Give it fault traces (-fault faults.shp, any vector format, any CRS) and they are drawn on the map and marked with a dashed "Fault line" on every profile that crosses them.

The pieces come from three MintPy tools: the map is view.py, the click-to-draw interaction is plot_transection.py, and the optional displacement time series is tsview.py.


Install

pip install viewinsar

or, once the conda-forge feedstock is live:

conda install -c conda-forge viewinsar

From a checkout, for development:

git clone https://github.com/drwahyudi/viewinsar
cd viewinsar
pip install -e ".[test]"
pytest

MintPy itself is easiest to get from conda-forge; if you already have a MintPy environment, install viewinsar into it.

Requirements: Python ≥ 3.9, mintpy ≥ 1.5, numpy ≥ 1.20, matplotlib ≥ 3.5, pyproj, pyshp and shapely (all three already come with MintPy). Optional: pip install "viewinsar[vector]" adds pyogrio, so --fault reads every vector format GDAL knows, not only the common ones it reads by itself.


Quick start

# interactive - click 2 points on the map to draw the swath centre line
viewinsar swath geo_velocity_msk.h5 -w 15 --bin-x 0.5 --bin-y 1.5 --ylim -40 40

# non-interactive - give the line up front, write the figure + the .csv files
viewinsar swath geo_velocity.h5 \
    --start-lalo 30.125 129.988 --end-lalo 30.250 130.116 \
    -w 15 --save --nodisplay

# a coarse / multilooked raster: oversample the corridor so the profile fills in
viewinsar swath geo_velocity_ml10.h5 --nlook 10

# an elevation profile under the LOS panel, from a DEM in any format or CRS
viewinsar swath geo_velocity.h5 --topoxsect srtm1.dem

# fault traces on the map, and a dashed "Fault line" where a section crosses one
viewinsar swath geo_velocity.h5 -fault faults.shp
viewinsar swath geo_velocity.h5 -fault gem_active_faults.geojson -topoxsect dem.tif

# the point time series, in its own window (right-click a pixel on the map)
viewinsar swath geo_velocity.h5 --timeseries geo_timeseries_ERA5_demErr.h5

# vector output
viewinsar swath geo_velocity.h5 --topoxsect dem.tif --svg --save

# list what is inside a file
viewinsar list timeseries.h5

viewinsar FILE ... is a shortcut for viewinsar swath FILE ....

Mouse and keyboard

input action
left click ×2 set the start / end point of the current section's line
right click plot the time series of that pixel (needs --timeseries)
= or + start another section in a new window — A-A', B-B', C-C' …
n redraw the current section from scratch
e export the map (with every line) and each section

Keys work from any window.


Options

Anything viewinsar swath does not recognise is forwarded verbatim to view.py, so the whole MintPy display vocabulary keeps working:

viewinsar swath geo_velocity.h5 -c jet -v -3 3 -u cm -d srtm1.dem \
    --mask geo_maskTempCoh.h5 --sub-lat 30.0 30.5 --sub-lon 129.9 130.3 \
    --coastline --lalo-label --fontsize 12

The swath-specific options:

option default meaning
-w, --width, --buffer 15 half width of the buffer, in km
--bin-x 0.5 along-profile cell size of the density grid, in km
--bin-y auto value cell size, in the display unit (~55 bins over the Y range)
--ylim 0.5–99.5 % value range of the profile plot
--cmin / --cmax 1 / auto limits of the log density colour scale; --cmax defaults to the 98th percentile of the occupied cells
--pcmap viridis colormap of the density
--x-offset 0 shift the distances so a known feature sits at x = 0
--keep-zero off keep exactly-zero pixels (dropped by default, as in plot_transection.py)
--decimate 1 use every Nth pixel of the corridor
--nlook 1 oversample the corridor N× per axis (N² more samples). The cure for a sparse profile from multilooked data; inverse of --decimate
--topoxsect — DEM to profile under the LOS panel, any format / any CRS
--fault — fault trace file(s), any vector format / any CRS: drawn on the map, and a dashed vertical line + "Fault line" on every profile at each crossing
--fault-label / --fault-color / --fault-lw Fault line / k / 1.2 the annotation text ("" for none), the colour, and the map line width
--svg off write figures as vector .svg
--figsize-map auto size of the map window (--figsize sizes each section)
--timeseries — time-series file(s) for the 3rd panel
--start-yx / --end-yx — line end points in pixel numbers
--start-lalo / --end-lalo — line end points in lat/lon
--line-file — GMT-format lon lat file with the two end points
--save / --nodisplay / -o / --outdir — output control

-nlook, -topoxsect, -fault and -svg work with one dash or two. Run viewinsar swath -h for the full list.

Fault traces

-fault takes one or more vector files and reads .shp (with its .prj), .geojson, .gpkg, .kml/.kmz and GMT multi-segment text (.gmt, .lonlat, .xy) directly, without GDAL. Anything else - FileGDB, GML, FlatGeobuf, ... - goes through pyogrio, fiona or the GDAL bindings, whichever is installed. Lines and polygon outlines count as traces; points are ignored.

Every file is re-projected to the data's CRS, so a WGS84 GeoJSON on a UTM velocity map, or a UTM shapefile on a lat/lon one, just works. A file with no CRS at all is taken as lon/lat when its numbers fit, and as the data's own CRS otherwise (a UTM shapefile that lost its .prj).

A crossing is where the section's centre line meets a trace. Its distance along the profile, and its coordinates, are written to _info.txt. Every crossing gets its dashed line; when two are so close that their labels would overlap, only the first is labelled.


Output

Pressing e (or passing --save) writes four files per section, named after its label (swath_A_..., swath_B_...), plus one swath_map_ABC... figure of the map with every section line and fault trace.

swath_..._points.csv — one row per sample, the linear-referencing table:

column meaning
dist_km distance along the profile from the start point, minus --x-offset
perp_km distance from the centre line; + = left of the start→end direction
value the pixel value, in the display unit
row, col pixel coordinates in the full file
lat, lon pixel centre (geocoded files only)
file_idx which input file the row came from

swath_..._stats.csv — per along-profile bin: count, median, mean, std, q25, q75, plus the density-weighted median/q25/q75 that the figure draws, and elevation_median_m when --topoxsect is used. The plain statistics are exact and un-clipped; the density-weighted ones are clipped to the plotted Y range, exactly like the histogram.

swath_..._info.txt — everything needed to reproduce the profile, and with --fault one fault crossing : <km> km (dist_km), <lat/lon or N/E> line per crossing. swath_....png — the figure.

Referencing the profile to a fault, afterwards

By default x = 0 is the start of the line. To re-zero on a fault you already know the position of:

import pandas as pd

df = pd.read_csv('swath_A_Y300X150_Y300X750_w15km_points.csv')
df['dist_from_fault'] = df['dist_km'] - 27.5     # your fault position, in km
df['vel'] = df['value']                          # already in the display unit

With --fault, the position comes from _info.txt:

import re

info = open('swath_A_Y300X150_Y300X750_w15km_info.txt').read()
fault_km = float(re.search(r'fault crossing : (\S+) km', info).group(1))  # the 1st
df['dist_from_fault'] = df['dist_km'] - fault_km

or do it up front with --x-offset 27.5, which also puts a dashed marker at x = 0. The density grid always places a cell boundary at x = 0, so the bins never straddle the fault.


Python API

The numerical core has no MintPy or matplotlib dependency, so it is usable on its own:

import numpy as np
from viewinsar import swath_extract, swath_density

swath = swath_extract(data, atr, box=(0, 0, width, length),
                      start_yx=[300, 150], end_yx=[300, 750], half_width=15.)
den = swath_density(swath['dist'], swath['value'], bin_x=0.5, bin_y=1.5,
                    ylim=[-40, 40])

print(swath['dist'], swath['perp'], swath['value'])
print(den['x_centers'], den['median'], den['q25'], den['q75'])

The fault helpers work the same way:

from viewinsar import load_faults, profile_crossings

faults = load_faults(['faults.shp'], atr)          # traces in the data's CRS
dist_km, xy = profile_crossings(faults, atr, [300, 150], [300, 750], swath['length'])

viewinsar.swathProfileViewer is the interactive figure; it is imported lazily, so import viewinsar stays cheap.


Notes and caveats

  • Flat caps. The corridor is a rectangle, not a QGIS round buffer: pixels beyond either end point are excluded rather than clamped, so nothing piles up at the ends of the profile.
  • Coordinates. Geographic grids are converted to metres with a local equirectangular approximation about the profile's mid-latitude — the same one MintPy uses in transect_yx(). Fine over tens of km; for continental-scale profiles work in UTM.
  • Reading window. Data is read within the displayed window, so --sub-lat/--sub-lon bounds the memory. If the corridor pokes outside that window, the tool says so instead of silently biasing the density.
  • Zeros. Exactly-zero pixels are dropped by default, matching plot_transection.py. Use --keep-zero if zero is a real value in your data. The DEM behind --topoxsect always keeps zeros — 0 m is sea level.
  • --nlook interpolates, it does not invent information. It restores the sampling density a multilooked raster lost, which makes the density panel and the median readable again, but scatter that multilooking averaged away is gone for good. The median it produces is unbiased with respect to the full-resolution one.
  • Fault crossings follow the centre line. A trace that ends inside the corridor without reaching the centre line, or runs along it, is drawn on the map but not marked on the profile. Traces are re-projected vertex by vertex, so a long straight segment drawn in one CRS bends very slightly in another; digitised fault traces are dense enough for this not to matter.

License

GPL-3.0-or-later, following MintPy.

Metadata

Release files for viewinsar 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 viewinsar 0.2.0
File Size Uploaded Provenance Actions
viewinsar-0.2.0.tar.gz 80.1 kB Without provenance Details for viewinsar-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 136.2 kB

Release files / viewinsar-0.2.0.tar.gz

Download URL viewinsar-0.2.0.tar.gz
Size 80.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1adfdec6437a44c72e7b3e194b1bb4dafe7ba08f3cac349a640a45b8d43acfb0
BLAKE2b-256 checksum
How to use checksums
468971208dc21dad885571fbe644ea6d7763c3a32b16e10d9d72172380253d7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

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

Download URL viewinsar-0.2.0-py3-none-any.whl
Size 56.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9d321a3698c6087d92d604684bc59b6c7a424bcfea24cdcda989c26d6eefefd
BLAKE2b-256 checksum
How to use checksums
89f15f7c82d8396e7aa3933f4cb7e3ef1d00bde0f4744f52857c05db4bba1333
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.6

Security for viewinsar 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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