Skip to content

moraine.cli in Python

import moraine.cli as mc gives the file based functions: the same operations as the commands, called from Python with the same arguments (mc.amp_disp('raw/rslc.zarr', 'ps/ras_adi.zarr', cuda=True)), plus the viewer and a few helpers that are not commands.

import moraine.cli as mc
logger = mc.get_logger()                       # the log lines the command line prints
mc.amp_disp('raw/rslc.zarr', 'ps/ras_adi.zarr', cuda=True)
mc.view('ps/ras_adi_pyramid', label='amplitude dispersion index', clim=(0, 1))

view

view

view(data, x=None, y=None, show=None, dates=None, series=None, polygons: str = None, cmap=None, clim: tuple = None, opacity: float = 1.0, label: str = None, size: tuple = None, terrain=None, bounds: tuple = None, resolution: float = None, image_pairs: str = None, sliders: dict = None, crs: str = None)

View a raster or point cloud: an interactive map in a notebook (the last expression of a cell) or a PNG (.png(path)); a * b overlays views on one map, a + b shows maps side by side with linked zoom and pan and shared sliders.

On the map: zoom and pan read only what is on screen; sliders choose the image of a stack; the cursor shows the values of all layers; click a pixel or point to plot its time series, double click one to make it the reference of the time series; draw polygons with the polygon button. In Python, .selected, .reference, .polygons and .index (slider values) follow the map. Point clouds are drawn as individual points when zoomed in; web mercator coordinates are drawn north up over a base map, or over the terrain in 3D with terrain.

Parameters:

Name Type Description Default
data str or ndarray

a pyramid directory made by ras_pyramid or pc_pyramid; a raster, (nlines, width[, n[, m]]), as array or zarr path (read into memory, at most 512 MiB); or point data, (n_points[, n[, m]]), with x and y

required
x str or ndarray

x coordinate (range or web mercator x) of point data that is not a pyramid, (n_points,)

None
y str or ndarray

y coordinate (azimuth or web mercator y) of point data that is not a pyramid, (n_points,)

None
show str or callable

what to show of a stack: 'phase', 'intf_0' (interferograms with the first image), 'intf_seq' (sequential interferograms), 'intf_all' (any pair, sliders ref and sec), 'coh' / 'coh_abs' (phase / magnitude of compressed coherence (..., n_pairs), sliders ref and sec), or a function f(v, *sliders) of the visible stack v (index it like a numpy array, e.g. v[..., ref]) whose other arguments are sliders named like them, e.g. lambda v, ref, sec: np.angle(v[..., ref] * np.conj(v[..., sec])); the phase for complex data, the values otherwise by default

None
dates list or str

date of each image, or a toml file with dates (e.g. of load_gamma_metadata), shown with the sliders and on the time axis

None
series str or ndarray

time series plotted for a clicked pixel or point: (nlines, width, n) for rasters, (n_points, n) in the order of the points; the stack itself by default

None
polygons str

GeoJSON file of the polygons drawn on the map: read if it exists, written on every change; use it with polygon_mask

None
cmap str or list

matplotlib colour map name or list of colours; cyclic for phases, viridis otherwise by default

None
clim tuple

(min, max) of the colours; (-pi, pi) for phases, the 1 % - 99 % range otherwise by default

None
opacity float

opacity of the layer, 0 - 1

1.0
label str

name of the layer; the pyramid directory name by default

None
size tuple

(width, height) of the map in screen pixels; by default the map takes the width of the notebook (at most 700 pixels high) with the aspect of the scene (at most 1:4). Drag the lower right corner of a map to resize it

None
terrain bool or str

3D view over the terrain in a notebook, web mercator layers only: True for the public elevation tiles (AWS Terrain Tiles: SRTM, EU-DEM, 3DEP, ... heights of about 30 m, zoom levels up to 15, fetched by the browser like the base map), or the URL template 'https://.../{z}/{x}/{y}.png' of another service of Terrarium encoded tiles. The layers and the satellite base map are draped over the terrain; the right mouse button (or ctrl + drag) tilts and rotates the view, which zooms two levels further than the 2D map. Polygons are shown but drawn in 2D views; .png stays the 2D image

None
bounds tuple

raster only: (x0, y0, xm, ym), coordinates of the centres of the first and the last pixel; pixel (i, j) at range j, azimuth i by default

None
resolution float

point data only: cell size of the rasterized points; 1 for integer coordinates

None
image_pairs str

image pair file (image_pairs) of compressed coherence for 'coh' / 'coh_abs'; all pairs by default

None
sliders dict

number of values of each slider of a show function, e.g. {'ref': 17, 'sec': 17}; from the stack shape or dates by default

None
crs str

'grid' (radar grid, azimuth down) or 'web_mercator' (metres, north up); from the coordinates by default

None

Returns:

Type Description
layer

displayed in a notebook; combine with * and +; .png(path) saves an image

The map widget behind view is moraine.cli.TileView (anywidget and Leaflet; the tiles are rendered by the kernel and sent through the notebook channel, so no server or port forwarding is needed, decision 0018). moraine view PYRAMID ... -o view.ipynb writes a notebook of such views.

get_logger

get_logger

get_logger(logfile: str = None)

get logger for decorrelation cli application

Parameters:

Name Type Description Default
logfile str

logfile, optional. default: no logfile

None

zarr and dask helpers

moraine.cli.dask_ has the parallel zarr readers and writers the commands use: dask_from_zarr(path, chunks) and dask_from_zarr_overlap(...) make dask arrays of a zarr array (optionally with halos), dask_to_zarr(darr, path, chunks) writes one, parallel_read_zarr / parallel_write_zarr read and write whole arrays with threads, and ZarrDir iterates a directory of per chunk zarrs (docs/contracts/data.md). Errors of the parallel reads and writes are raised.