geowatch.tasks.tracking.from_heatmap module

Main tracker logic

SeeAlso:
  • ../../cli/run_tracker.py

class geowatch.tasks.tracking.from_heatmap.DataFrameFilter[source]

Bases: object

filter_dataframe(gdf)[source]
class geowatch.tasks.tracking.from_heatmap.TimePolygonFilter(threshold)[source]

Bases: DataFrameFilter

Cuts off start and end of each track based on min response.

filter_dataframe(gdf)[source]
class geowatch.tasks.tracking.from_heatmap.TimeSplitFilter(threshold, frame_buffer)[source]

Bases: DataFrameFilter

Splits tracks based on start and end of each subtracks min response.

filter_dataframe(gdf)[source]
class geowatch.tasks.tracking.from_heatmap.ResponsePolygonFilter(gdf, threshold)[source]

Bases: DataFrameFilter

Filters each track based on the average response of all tracks.

filter_dataframe(gdf, gids=None, threshold=None, cross=True)[source]
geowatch.tasks.tracking.from_heatmap.site_validation(sub_dset, thresh=0.25, span_steps=15)[source]

Example

>>> import geowatch
>>> from geowatch.tasks.tracking.from_heatmap import *  # NOQA
>>> coco_dset = geowatch.coerce_kwcoco(
>>>     'geowatch-msi', heatmap=True, geodata=True, dates=True)
>>> vid_id = coco_dset.videos()[0]
>>> sub_dset = coco_dset.subset(list(coco_dset.images(video_id=vid_id)))
>>> import numpy as np
>>> for ann in sub_dset.anns.values():
>>>     ann['score'] = float(np.random.rand())
>>> sub_dset.remove_annotations(sub_dset.index.trackid_to_aids[None])
>>> sub_dset = site_validation(sub_dset)
geowatch.tasks.tracking.from_heatmap.time_aggregated_polys(sub_dset, video_id, **kwargs)[source]

Polygon extraction and tracking function.

Aggregate heatmaps across time, threshold them to get polygons, and add one track per polygon.

Parameters:
  • sub_dset (kwcoco.CocoDataset) – a kwcoco dataset with exactly 1 video

  • video_id (int) – The video-id to track.

  • **kwargs – see TimeAggregatedPolysConfig and PolygonExtractConfig.

Example

>>> # test interpolation
>>> from geowatch.tasks.tracking.from_heatmap import time_aggregated_polys
>>> from geowatch.demo import demo_kwcoco_with_heatmaps
>>> import geowatch
>>> sub_dset = geowatch.coerce_kwcoco(
>>>     'geowatch-msi', num_videos=1, num_frames=5, image_size=(128, 128),
>>>     geodata=True, heatmap=True, dates=True)
>>> thresh = 0.01
>>> video_id = list(sub_dset.videos())[0]
>>> min_area_square_meters = None
>>> kwargs = dict(thresh=thresh, min_area_square_meters=min_area_square_meters, time_thresh=None)
>>> orig_track = time_aggregated_polys(sub_dset, video_id, **kwargs)
>>> # Test robustness to frames that are missing heatmaps
>>> skip_gids = [1,3]
>>> for gid in skip_gids:
>>>      sub_dset.imgs[gid]['auxiliary'].pop()
>>> inter_track = time_aggregated_polys(sub_dset, video_id, **kwargs)
>>> assert inter_track.iloc[0][('fg', -1)] == 0
>>> assert inter_track.iloc[1][('fg', -1)] > 0

Example

>>> # test interpolation
>>> from geowatch.tasks.tracking.from_heatmap import time_aggregated_polys
>>> from geowatch.demo import demo_kwcoco_with_heatmaps
>>> import geowatch
>>> sub_dset = geowatch.coerce_kwcoco(
>>>     'geowatch-msi', num_videos=1, num_frames=5, image_size=(128, 128),
>>>     geodata=True, heatmap=True, dates=True)
>>> video_id = list(sub_dset.videos())[0]
>>> thresh = 0.01
>>> min_area_square_meters = None
>>> kwargs = dict(thresh=thresh, min_area_square_meters=min_area_square_meters, time_thresh=None)
>>> orig_track = time_aggregated_polys(sub_dset, video_id, **kwargs)
>>> # Test robustness to frames that are missing heatmaps
>>> skip_gids = [1,3]
>>> for gid in skip_gids:
>>>      sub_dset.imgs[gid]['auxiliary'].pop()
>>> inter_track = time_aggregated_polys(sub_dset, video_id, **kwargs)
>>> assert inter_track.iloc[0][('fg', -1)] == 0
>>> assert inter_track.iloc[1][('fg', -1)] > 0
class geowatch.tasks.tracking.from_heatmap.TimeAggregatedPolysConfig(*args, **kwargs)[source]

Bases: PolygonExtractConfig

This is an intermediate config that we will use to transition between the current dataclass configuration and a new scriptconfig based one.

python -c “if 1:

from geowatch.tasks.tracking.from_heatmap import TimeAggregatedBAS TimeAggregatedBAS().argparse().print_help()

Valid options: []

Parameters:
  • *args – positional arguments for this data config

  • **kwargs – keyword arguments for this data config

default = {'agg_fn': <Value('probs')>, 'bg_key': <Value(None)>, 'dynamic_fixed_resolution': <Value(None)>, 'inner_agg_fn': <Value('mean')>, 'inner_window_size': <Value(None)>, 'key': <Value('salient')>, 'max_area_behavior': <Value('drop')>, 'max_area_square_meters': <Value(None)>, 'min_area_square_meters': <Value(None)>, 'modulate_post_construction': <Value(None)>, '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)>, 'response_thresh': <Value(None)>, 'thresh': <Value(0.0)>, 'thresh_hysteresis': <Value(None)>, 'time_split_frame_buffer': <Value(2)>, 'time_split_thresh': <Value(None)>, 'time_thresh': <Value(1)>, 'use_boundaries': <Value(False)>, 'viz_out_dir': <Value(None)>}
normalize()
class geowatch.tasks.tracking.from_heatmap.CommonTrackFn(*args, **kwargs)[source]

Bases: NewTrackFunction, TimeAggregatedPolysConfig

Valid options: []

Parameters:
  • *args – positional arguments for this data config

  • **kwargs – keyword arguments for this data config

default = {'agg_fn': <Value('probs')>, 'bg_key': <Value(None)>, 'dynamic_fixed_resolution': <Value(None)>, 'inner_agg_fn': <Value('mean')>, 'inner_window_size': <Value(None)>, 'key': <Value('salient')>, 'max_area_behavior': <Value('drop')>, 'max_area_square_meters': <Value(None)>, 'min_area_square_meters': <Value(None)>, 'modulate_post_construction': <Value(None)>, '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)>, 'response_thresh': <Value(None)>, 'thresh': <Value(0.0)>, 'thresh_hysteresis': <Value(None)>, 'time_split_frame_buffer': <Value(2)>, 'time_split_thresh': <Value(None)>, 'time_thresh': <Value(1)>, 'use_boundaries': <Value(False)>, 'viz_out_dir': <Value(None)>}
normalize()
class geowatch.tasks.tracking.from_heatmap.TrackFnWithSV(*args, **kwargs)[source]

Bases: CommonTrackFn

Valid options: []

Parameters:
  • *args – positional arguments for this data config

  • **kwargs – keyword arguments for this data config

site_validation: bool
site_validation_span_steps: int
site_validation_thresh: float
default = {'agg_fn': <Value('probs')>, 'bg_key': <Value(None)>, 'dynamic_fixed_resolution': <Value(None)>, 'inner_agg_fn': <Value('mean')>, 'inner_window_size': <Value(None)>, 'key': <Value('salient')>, 'max_area_behavior': <Value('drop')>, 'max_area_square_meters': <Value(None)>, 'min_area_square_meters': <Value(None)>, 'modulate_post_construction': <Value(None)>, '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)>, 'response_thresh': <Value(None)>, 'site_validation': False, 'site_validation_span_steps': 120, 'site_validation_thresh': 0.1, 'thresh': <Value(0.0)>, 'thresh_hysteresis': <Value(None)>, 'time_split_frame_buffer': <Value(2)>, 'time_split_thresh': <Value(None)>, 'time_thresh': <Value(1)>, 'use_boundaries': <Value(False)>, 'viz_out_dir': <Value(None)>}
class geowatch.tasks.tracking.from_heatmap.TimeAggregatedBAS(*args, **kwargs)[source]

Bases: TrackFnWithSV

Wrapper for BAS that looks for change heatmaps.

Valid options: []

Parameters:
  • *args – positional arguments for this data config

  • **kwargs – keyword arguments for this data config

thresh: float
key: str
agg_fn: str
create_tracks(sub_dset, video_id)[source]
add_tracks_to_dset(sub_dset, tracks)[source]
default = {'agg_fn': 'probs', 'bg_key': <Value(None)>, 'dynamic_fixed_resolution': <Value(None)>, 'inner_agg_fn': <Value('mean')>, 'inner_window_size': <Value(None)>, 'key': 'salient', 'max_area_behavior': <Value('drop')>, 'max_area_square_meters': <Value(None)>, 'min_area_square_meters': <Value(None)>, 'modulate_post_construction': <Value(None)>, '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)>, 'response_thresh': <Value(None)>, 'site_validation': False, 'site_validation_span_steps': 120, 'site_validation_thresh': 0.1, 'thresh': 0.2, 'thresh_hysteresis': <Value(None)>, 'time_split_frame_buffer': <Value(2)>, 'time_split_thresh': <Value(None)>, 'time_thresh': <Value(1)>, 'use_boundaries': <Value(False)>, 'viz_out_dir': <Value(None)>}
class geowatch.tasks.tracking.from_heatmap.TimeAggregatedSC(*args, **kwargs)[source]

Bases: TrackFnWithSV

Wrapper for Activity Characterization / Site Characterization that looks for phase heatmaps.

Alias: class_heatmaps

Note

This is a valid choice of track_fn in ../../cli/run_tracker.py

Valid options: []

Parameters:
  • *args – positional arguments for this data config

  • **kwargs – keyword arguments for this data config

thresh: float
key: Tuple[str]
bg_key: Tuple[str]
boundaries_as: Literal['bounds', 'polys', 'none']
create_tracks(sub_dset, video_id)[source]
boundaries_as: use for Site Boundary annots in coco_dsennjk

‘bounds’: generated polys will lie inside the boundaries ‘polys’: generated polys will be the boundaries ‘none’: generated polys will ignore the boundaries

add_tracks_to_dset(sub_dset, tracks, **kwargs)[source]
default = {'agg_fn': <Value('probs')>, 'bg_key': ('No Activity',), 'boundaries_as': 'bounds', 'dynamic_fixed_resolution': <Value(None)>, 'inner_agg_fn': <Value('mean')>, 'inner_window_size': <Value(None)>, 'key': ('Site Preparation', 'Active Construction', 'Post Construction', 'No Activity', 'ac_salient'), 'max_area_behavior': <Value('drop')>, 'max_area_square_meters': <Value(None)>, 'min_area_square_meters': <Value(None)>, 'modulate_post_construction': <Value(None)>, '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)>, 'response_thresh': <Value(None)>, 'site_validation': False, 'site_validation_span_steps': 120, 'site_validation_thresh': 0.1, 'thresh': 0.01, 'thresh_hysteresis': <Value(None)>, 'time_split_frame_buffer': <Value(2)>, 'time_split_thresh': <Value(None)>, 'time_thresh': None, 'use_boundaries': <Value(False)>, 'viz_out_dir': <Value(None)>}
class geowatch.tasks.tracking.from_heatmap.TimeAggregatedSV(*args, **kwargs)[source]

Bases: CommonTrackFn

Wrapper for Site Validation that looks for phase heatmaps.

Alias:

site_validation

Note

This is a valid choice of track_fn in ../../cli/run_tracker.py

Valid options: []

Parameters:
  • *args – positional arguments for this data config

  • **kwargs – keyword arguments for this data config

thresh: float
key: str
boundaries_as: Literal['bounds', 'polys', 'none']
span_steps: int
create_tracks(sub_dset, video_id)[source]
boundaries_as: use for Site Boundary annots in coco_dset

‘bounds’: generated polys will lie inside the boundaries ‘polys’: generated polys will be the boundaries ‘none’: generated polys will ignore the boundaries

add_tracks_to_dset(sub_dset, tracks, **kwargs)[source]
default = {'agg_fn': <Value('probs')>, 'bg_key': <Value(None)>, 'boundaries_as': 'polys', 'dynamic_fixed_resolution': <Value(None)>, 'inner_agg_fn': <Value('mean')>, 'inner_window_size': <Value(None)>, 'key': 'salient', 'max_area_behavior': <Value('drop')>, 'max_area_square_meters': <Value(None)>, 'min_area_square_meters': <Value(None)>, 'modulate_post_construction': <Value(None)>, '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)>, 'response_thresh': <Value(None)>, 'span_steps': 120, 'thresh': 0.1, 'thresh_hysteresis': <Value(None)>, 'time_split_frame_buffer': <Value(2)>, 'time_split_thresh': <Value(None)>, 'time_thresh': <Value(1)>, 'use_boundaries': <Value(False)>, 'viz_out_dir': <Value(None)>}