geowatch.cli.coco_spectra module¶
Compute intensity histograms of the underlying images in this dataset.
Todo
[ ] Migrate to kwcoco proper
[ ] Fix accumulation of floating point values
[ ] Handle nodata
[x] Rename to coco_spectra
CommandLine
geowatch spectra --src special:geowatch-msi --show=True --stat=density
geowatch spectra --src special:photos --show=True --fill=False
geowatch spectra --src special:shapes8 --show=True --stat=count --cumulative=True --multiple=stack
DVC_DATA_DPATH=$(geowatch_dvc --tags='phase2_data' --hardware='auto')
geowatch spectra --src $DVC_DATA_DPATH/Drop6/data.kwcoco.zip --channels='red|green|blue|nir' --workers=11
DVC_DPATH=$HOME/data/dvc-repos/smart_watch_dvc
KWCOCO_FPATH=$DVC_DPATH/Drop2-Aligned-TA1-2022-01/combo_L_nowv_vali.kwcoco.json
geowatch spectra --src $KWCOCO_FPATH --show=True --show=True --include_channels="forest|water|bare_ground"
- class geowatch.cli.coco_spectra.CocoSpectraConfig(*args, **kwargs)[source]¶
Bases:
DataConfig
Plot the spectrum of band intensities in a kwcoco file.
Valid options: []
- Parameters:
*args – positional arguments for this data config
**kwargs – keyword arguments for this data config
- default = {'bins': <Value('auto')>, 'cache_dpath': <Value(None)>, 'cumulative': <Value(False)>, 'draw': <Value(True)>, 'dst': <Value(None)>, 'element': <Value('step')>, 'exclude_channels': <Value(None)>, 'exclude_sensors': <Value(None)>, 'fill': <Value(True)>, 'include_channels': <Value(None)>, 'include_sensors': <Value(None)>, 'kde': <Value(True)>, 'max_images': <Value(None)>, 'mode': <Value('process')>, 'multiple': <Value('layer')>, 'select_images': <Value(None)>, 'select_videos': <Value(None)>, 'show': <Value(False)>, 'src': <Value('data.kwcoco.json')>, 'stat': <Value('probability')>, 'title': <Value(None)>, 'valid_range': <Value(None)>, 'workers': <Value(0)>}¶
- geowatch.cli.coco_spectra.main(cmdline=True, **kwargs)[source]¶
CommandLine
XDEV_PROFILE=1 xdoctest -m geowatch.cli.coco_spectra main
Example
>>> from geowatch.cli.coco_spectra import * # NOQA >>> import kwcoco >>> test_dpath = ub.Path.appdir('geowatch/tests/cli/spectra').ensuredir() >>> image_fpath = test_dpath + '/intensityhist_demo.jpg' >>> coco_dset = kwcoco.CocoDataset.demo('vidshapes-msi-multisensor-videos1-frames2-gsize8') >>> kwargs = {'src': coco_dset, 'dst': image_fpath, 'mode': 'thread'} >>> kwargs['multiple'] = 'layer' >>> kwargs['element'] = 'step' >>> kwargs['workers'] = 'avail' >>> kwargs['show'] = False >>> kwargs['draw'] = False >>> main(cmdline=False, **kwargs)
Example
>>> # xdoctest: +REQUIRES(--slow) >>> from geowatch.cli.coco_spectra import * # NOQA >>> import kwcoco >>> import geowatch >>> test_dpath = ub.Path.appdir('geowatch/tests/cli/spectra').ensuredir() >>> image_fpath = test_dpath + '/intensityhist_demo2.jpg' >>> coco_dset = geowatch.coerce_kwcoco('geowatch-msi') >>> kwargs = { >>> 'src': coco_dset, >>> 'dst': image_fpath, >>> 'mode': 'thread', >>> 'valid_range': '10:2000', >>> 'workers': 'avail', >>> } >>> kwargs['multiple'] = 'layer' >>> kwargs['element'] = 'step' >>> main(cmdline=False, **kwargs)
- geowatch.cli.coco_spectra.single_persensor_table(full_df)[source]¶
Like sensor_stats_tables, but only used for intermediate stats
- geowatch.cli.coco_spectra.ensure_intensity_sidecar(fpath, cache_dpath=None, bundle_dpath=None, recompute=False)[source]¶
Write statistics next to the image
- Parameters:
fpath (str | PathLike) – the path to the image to compute spectra for
cache_dpath (str | PathLike | None) – if specified, write cache files here instead of next to the input file.
bundle_dpath (str | PathLike | None) – if cache_dpath is specified and this is specified, this is considered the “root” of the image, which allows the cache to use specific parent folders, but not the entire filesystem. Specifying this allows portablity of the cache.
recompute (bool) – if True, force recomputation.
Example
>>> from geowatch.cli.coco_spectra import * # NOQA >>> import kwimage >>> import ubelt as ub >>> dpath = ub.Path.appdir('geowatch/tests/intensity_sidecar').ensuredir() >>> dpath.delete().ensuredir() >>> img = kwimage.grab_test_image(dsize=(16, 16)) >>> img01 = kwimage.ensure_float01(img) >>> img255 = kwimage.ensure_uint255(img) >>> fpath1 = dpath / 'img01.tif' >>> fpath2 = dpath / 'img255.tif' >>> kwimage.imwrite(fpath1, img01) >>> kwimage.imwrite(fpath2, img255) >>> fpath = fpath1 >>> stats_fpath1 = ensure_intensity_sidecar(fpath1) >>> fpath = fpath2 >>> stats_fpath2 = ensure_intensity_sidecar(fpath1) >>> import pickle >>> pickle.loads(stats_fpath1.read_bytes()) >>> pickle.loads(stats_fpath2.read_bytes())
Example
>>> from geowatch.cli.coco_spectra import * # NOQA >>> import kwimage >>> import ubelt as ub >>> dpath = ub.Path.appdir('geowatch/tests/intensity_sidecar2').ensuredir() >>> dpath.delete().ensuredir() >>> cache_dpath = dpath / 'cache' >>> bundle_dpath = None >>> img = kwimage.grab_test_image(dsize=(16, 16)) >>> img255 = kwimage.ensure_uint255(img) >>> fpath = dpath / 'img255.tif' >>> kwimage.imwrite(fpath, img255) >>> stats_fpath = ensure_intensity_sidecar(fpath, cache_dpath=cache_dpath) >>> import pickle >>> pickle.loads(stats_fpath.read_bytes())