lib.malib module

Functions involving masked arrays

Some functions are general array operations, others involve geospatial information

class pygeotools.lib.malib.DEMStack(fn_list=[], stack_fn=None, outdir=None, res=None, extent=None, srs=None, trend=True, robust=False, med=False, stats=True, save=True, sort=True, datestack=True, mask_geom=None, min_dt_ptp=<Mock id='140637716128528'>, n_thresh=2, n_cpu=None)[source]
compute_dt_stats()[source]
compute_stats()[source]
compute_trend()[source]
finish()[source]
get_date_list()[source]
get_ds()[source]
get_extent()[source]
get_fn_list()[source]
get_res()[source]
get_sortorder()[source]
get_stack_fn()[source]
linreg(rsq=False, conf_test=False)[source]
loadstack()[source]
make_datestack()[source]
makestack()[source]
mean_hillshade()[source]
savestack()[source]
sort_in_place(sort_idx)[source]
write_datestack()[source]
write_stats()[source]
write_trend()[source]
pygeotools.lib.malib.apply_edgemask(a, trim=False)[source]
pygeotools.lib.malib.bin_stats(x, y, stat='median', nbins=128, bin_range=None)[source]
pygeotools.lib.malib.bin_x_by_z(x, z, bin_width=10.0)[source]
pygeotools.lib.malib.block_view(A, block=(3, 3))[source]
pygeotools.lib.malib.calcperc(b, perc=(0.1, 99.9))[source]

Calculate values at specified percentiles

pygeotools.lib.malib.calcperc_sym(b, perc=(0.1, 99.9))[source]

Get symmetrical percentile values Useful for determining clim centered on 0 for difference maps

pygeotools.lib.malib.checkma(a, fix=False)[source]
pygeotools.lib.malib.common_mask(ma_list, apply=False)[source]
pygeotools.lib.malib.contour_edges(a)[source]
pygeotools.lib.malib.do_robust_linreg(arg)[source]
pygeotools.lib.malib.edgefind2(a, intround=True)[source]
pygeotools.lib.malib.edgefind_loop(a)[source]
pygeotools.lib.malib.fast_median(a)[source]

Fast median operation for masked array using 50th-percentile

pygeotools.lib.malib.get_2dhist(x, y, xlim=None, ylim=None, xint=None, yint=None, nbins=(128, 128))[source]
pygeotools.lib.malib.get_bins(x, bin_width=100.0, bin_range=None)[source]
pygeotools.lib.malib.get_edgemask(a, edge_env=False, convex=False, dilate=False)[source]
pygeotools.lib.malib.get_edges(a, convex=False)[source]
pygeotools.lib.malib.get_stack_subset(s_orig, idx, out_stack_fn=None, copy=True, save=False)[source]

Create a new stack object as a subset of an exising stack object

pygeotools.lib.malib.get_stats(a, full=False)[source]

Compute and print statistics for input array

Needs to be cleaned up, return a stats object

pygeotools.lib.malib.get_stats_dict(a_in, full=True)[source]

Compute and print statistics for input array

pygeotools.lib.malib.get_xyz(a)[source]
pygeotools.lib.malib.iqr(b, perc=(25, 75))[source]

Inter-quartile range

pygeotools.lib.malib.iv(b, **kwargs)[source]

Quick access to imview for interactive sessions

pygeotools.lib.malib.ma_interp(a, method='cubic', newmask=None)[source]
pygeotools.lib.malib.ma_linreg(ma_stack, dt_list, n_thresh=2, model='linear', dt_stack_ptp=None, min_dt_ptp=None, smooth=False, rsq=False, conf_test=False, parallel=True, n_cpu=None, remove_outliers=False)[source]

Compute per-pixel linear regression for stack object

pygeotools.lib.malib.mad(a, axis=None, c=1.4826, return_med=False)[source]

Compute normalized median absolute difference

Can also return median array, as this can be expensive, and often we want both med and nmad

Note: 1.4826 = 1/0.6745

pygeotools.lib.malib.mask_dilate(a, iterations=1, erode=False)[source]
pygeotools.lib.malib.mask_erode(a, iterations=1, erode=False)[source]
pygeotools.lib.malib.mask_islands(a, iterations=3)[source]
pygeotools.lib.malib.maskfill(a, iterations=1, erode=False)[source]
pygeotools.lib.malib.maskfill_edgeinclude(a, iterations=1, erode=False)[source]
pygeotools.lib.malib.masktrim(a)[source]
pygeotools.lib.malib.nanfill(a, f_a, *args, **kwargs)[source]

Fill masked areas with np.nan

Wrapper for functions that can’t handle ma (e.g. scipy.ndimage)

This will force filters to ignore nan, but causes adjacent pixels to be set to nan as well: http://projects.scipy.org/scipy/ticket/1155

pygeotools.lib.malib.ndv_trim(a)[source]
pygeotools.lib.malib.norm_shape(shape)[source]

Normalize numpy array shapes so they’re always expressed as a tuple, even for one-dimensional shapes.

Parameters
shape - an int, or a tuple of ints
Returns
a shape tuple
pygeotools.lib.malib.print_stats(a, full=False)[source]
pygeotools.lib.malib.randomfill(a)[source]

Fill masked areas with random noise

This is needed for any fft-based operations

pygeotools.lib.malib.rmse(a)[source]
pygeotools.lib.malib.robust_linreg(x, y, model='theilsen')[source]
pygeotools.lib.malib.robust_spread(b, perc=(16, 84))[source]
pygeotools.lib.malib.robust_spread_fltr(b, sigma=3)[source]
pygeotools.lib.malib.robust_spread_idx(b, sigma=3)[source]
pygeotools.lib.malib.rolling_window(a, window)[source]
pygeotools.lib.malib.sliding_window(a, ws, ss=None, flatten=True)[source]
pygeotools.lib.malib.sliding_window_padded(a, ws, ss=(1, 1), flatten=True)[source]
pygeotools.lib.malib.stack_clip(s_orig, extent, out_stack_fn=None, copy=True, save=False)[source]

Create a new stack object with limited extent from an exising stack object

pygeotools.lib.malib.stack_merge(s1, s2, out_stack_fn=None, sort=True, save=False)[source]

Merge two stack objects

pygeotools.lib.malib.stack_smooth(s_orig, size=7, save=False)[source]

Run Gaussian smoothing filter on exising stack object