跳转至

Python 里的 moraine.cli

import moraine.cli as mc 给出基于文件的函数:与命令相同的操作,在 Python 里以相同的参数调用 (mc.amp_disp('raw/rslc.zarr', 'ps/ras_adi.zarr', cuda=True)),外加查看器和几个不是命令的辅助函数。

import moraine.cli as mc
logger = mc.get_logger()                       # 命令行打印的那些日志
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

view 背后的地图部件是 moraine.cli.TileView(anywidget 加 Leaflet;瓦片由内核渲染,通过 notebook 通道发送, 所以不需要服务器或端口转发,决策 0018)。moraine view PYRAMID ... -o view.ipynb 生成一个由这种视图组成的 notebook。

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 与 dask 辅助函数

moraine.cli.dask_ 里是命令使用的并行 zarr 读写:dask_from_zarr(path, chunks) 和 dask_from_zarr_overlap(...) 把 zarr 数组变成 dask 数组(后者带 halo),dask_to_zarr(darr, path, chunks) 写回,parallel_read_zarr / parallel_write_zarr 用线程读写整个数组,ZarrDir 遍历按块存放的 zarr 目录(docs/contracts/data.md)。并行读写 的错误会被抛出。