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:
DataConfigPlot 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')>, '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.ensure_intensity_sidecar(fpath, recompute=False)[source]¶
Write statistics next to the image
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())