geowatch.tasks.tracking.old_polygon_extraction module¶
Note: even though this is called old-polygon-extraction, it was never fully refactored out of the critical path. Due to funding cuts we arent investing effort in changing this. A refactor is needed, but for now that will just have to add to our our technical dept.
The original heatmap -> polygon extraction code.
- exception geowatch.tasks.tracking.old_polygon_extraction.FoundNothing[source]¶
Bases:
Exception
Error to help short-circuit the part where we return an empty list
- class geowatch.tasks.tracking.old_polygon_extraction.PolygonExtractConfig(*args, **kwargs)[source]¶
Bases:
DataConfig
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'agg_fn': <Value('probs')>, 'dynamic_fixed_resolution': <Value(None)>, 'inner_agg_fn': <Value('mean')>, 'inner_window_size': <Value(None)>, 'key': <Value('salient')>, 'morph_kernel': <Value(3)>, 'moving_window_size': <Value(None)>, 'new_algo': <Value(None)>, 'norm_ord': <Value(1)>, 'poly_merge_method': <Value('v1')>, 'polygon_simplify_tolerance': <Value(None)>, 'resolution': <Value(None)>, 'thresh': <Value(0.0)>, 'thresh_hysteresis': <Value(None)>, 'use_boundaries': <Value(False)>, 'viz_out_dir': <Value(None)>}¶
- geowatch.tasks.tracking.old_polygon_extraction.heatmaps_to_polys(heatmaps, track_bounds, heatmap_dates=None, config=None)[source]¶
Use parameters: agg_fn, thresh, morph_kernel, thresh_hysteresis, norm_ord
- Parameters:
heatmaps (ndarray) – A [T, H, W] heatmap
track_bounds (kwimage.MultiPolygon | None) – a valid region in the heatmaps where new polygons can be extracted.
heatmap_dates (List[datetime] | None) – dates corresponding with each heatmap time dimension
config (PolygonExtractConfig) – polygon extraction config
Example
>>> from geowatch.tasks.tracking.old_polygon_extraction import * # NOQA >>> import kwimage >>> from kwutil import util_time >>> import numpy as np >>> from geowatch.tasks.tracking.old_polygon_extraction import PolygonExtractConfig # NOQA >>> config = PolygonExtractConfig() >>> heatmaps = np.zeros((7, 64, 64)) >>> heatmaps[2, 20:40, 20:40] = 1 >>> heatmaps[5, 30:50, 30:50] = 1 >>> heatmap_dates = [util_time.coerce_datetime(x) for x in [ >>> '2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01', >>> '2020-05-01', '2020-06-01', '2020-07-01', ]] >>> track_bounds = kwimage.Polygon.random(rng=0).scale((64, 64)) >>> # V1 merges everything together across all time >>> config.poly_merge_method = 'v1' >>> polygons_final = heatmaps_to_polys(heatmaps, track_bounds, heatmap_dates=heatmap_dates, config=config) >>> # V3 does some time separation >>> config.poly_merge_method = 'v3' >>> polygons_final = heatmaps_to_polys(heatmaps, track_bounds, heatmap_dates=heatmap_dates, config=config)