geowatch.cli.coco_reformat_channels module

class geowatch.cli.coco_reformat_channels.CocoReformatChannels(*args, **kwargs)[source]

Bases: DataConfig

Helper to remove channels from a coco file and reformat predictions from float32 to int16.

Valid options: []

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

  • **kwargs – keyword arguments for this data config

default = {'nodata': <Value(-9999)>, 'quantize': <Value(None)>, 'remove': <Value(None)>, 'src': <Value(None)>, 'workers': <Value(0)>}
geowatch.cli.coco_reformat_channels.main(cmdline=False, **kwargs)[source]

Example

>>> from geowatch.cli.coco_reformat_channels import *  # NOQA
>>> import kwcoco
>>> import kwarray
>>> import shutil
>>> # Make a dataset we can modify inplace
>>> orig_dset = kwcoco.CocoDataset.demo('vidshapes1-msi')
>>> orig_dset.reroot(absolute=False)
>>> orig_bundle = ub.Path(orig_dset.bundle_dpath)
>>> new_bundle = ub.Path.appdir('kwcoco/tests/test_reformat_channels')
>>> new_bundle.delete().ensuredir()
>>> shutil.copytree(orig_bundle, new_bundle, dirs_exist_ok=True)
>>> new_fpath = new_bundle / 'data.kwcoco.json'
>>> orig_dset.dump(new_fpath)
>>> new_dset = kwcoco.CocoDataset(new_fpath)
>>> gid = 1
>>> coco_img = new_dset.coco_image(gid)
>>> rng = kwarray.ensure_rng(432)
>>> imdata = rng.rand(128, 128)
>>> coco_img.add_auxiliary_item('test_prediction.tif', channels='salient', imdata=imdata, imwrite=True)
>>> new_dset.dump(new_dset.fpath)
>>> # now reformat this new dataset
>>> orig_pred = coco_img.imdelay('salient').finalize()
>>> kwargs = {
>>>     'src': new_dset.fpath,
>>>     'quantize': 'salient',
>>>     #'remove': 'B11',
>>> }
>>> cmdline = False
>>> main(cmdline=False, **kwargs)
>>> reformatted_dset = kwcoco.CocoDataset(new_fpath)
>>> assert 'quantization' in reformatted_dset.imgs[1]['auxiliary'][-1]
>>> new_coco_img = reformatted_dset.coco_image(gid)
>>> import numpy as np
>>> new_pred1 = np.nan_to_num(new_coco_img.imdelay('salient').finalize())
>>> #assert np.allclose(new_pred1, new_pred2)
>>> #new_pred2 = new_coco_img.imdelay('salient').finalize(dequantize=False)
>>> #assert new_pred2.dtype.kind == 'i'
geowatch.cli.coco_reformat_channels.reformat_obj(obj, bundle_dpath, has_remove, has_quantize)[source]
geowatch.cli.coco_reformat_channels.schedule_quantization()[source]