kwcoco.util.lazy_frame_backends

Ducktyped interfaces for loading subregions of images with standard slice syntax

Module Contents

Classes

LazySpectralFrameFile

Potentially faster than GDAL for HDR formats.

LazyRasterIOFrameFile

fpath = '/home/joncrall/.cache/kwcoco/demo/large_hyperspectral/big_img_128.bsq'

LazyGDalFrameFile

Functions

_have_gdal()

_have_rasterio()

_have_spectral()

_demo_geoimg_with_nodata()

Example

_rectify_slice_dim(part, D)

_validate_nonzero_data(file)

Test to see if the image is all black.

_read_envi_header(file)

USAGE: hdr = _read_envi_header(file)

Attributes

profile

_GDAL_DTYPE_LUT

kwcoco.util.lazy_frame_backends.profile[source]
kwcoco.util.lazy_frame_backends._have_gdal()[source]
kwcoco.util.lazy_frame_backends._have_rasterio()[source]
kwcoco.util.lazy_frame_backends._have_spectral()[source]
kwcoco.util.lazy_frame_backends._GDAL_DTYPE_LUT[source]
class kwcoco.util.lazy_frame_backends.LazySpectralFrameFile(fpath)[source]

Bases: ubelt.NiceRepr

Potentially faster than GDAL for HDR formats.

_ds(self)[source]
classmethod available(self)[source]

Returns True if this backend is available

property ndim(self)[source]
property shape(self)[source]
property dtype(self)[source]
__nice__(self)[source]
__getitem__(self, index)[source]
class kwcoco.util.lazy_frame_backends.LazyRasterIOFrameFile(fpath)[source]

Bases: ubelt.NiceRepr

fpath = ‘/home/joncrall/.cache/kwcoco/demo/large_hyperspectral/big_img_128.bsq’ lazy_rio = LazyRasterIOFrameFile(fpath) ds = lazy_rio._ds

classmethod available(self)[source]

Returns True if this backend is available

_ds(self)[source]
property ndim(self)[source]
property shape(self)[source]
property dtype(self)[source]
__nice__(self)[source]
__getitem__(self, index)[source]
kwcoco.util.lazy_frame_backends._demo_geoimg_with_nodata()[source]

Example

from kwcoco.util.lazy_frame_backends import * # NOQA fpath = _demo_geoimg_with_nodata() self = LazyGDalFrameFile.demo()

class kwcoco.util.lazy_frame_backends.LazyGDalFrameFile(fpath, nodata=None)[source]

Bases: ubelt.NiceRepr

Todo

  • [ ] Move to its own backend module

  • [ ] When used with COCO, allow the image metadata to populate the

    height, width, and channels if possible.

Example

>>> # xdoctest: +REQUIRES(module:osgeo)
>>> self = LazyGDalFrameFile.demo()
>>> print('self = {!r}'.format(self))
>>> self[0:3, 0:3]
>>> self[:, :, 0]
>>> self[0]
>>> self[0, 3]
>>> # import kwplot
>>> # kwplot.imshow(self[:])
Parameters
  • nodata

  • masking_method

Example

>>> # See if we can reproduce the INTERLEAVE bug

data = np.random.rand(128, 128, 64) import kwimage import ubelt as ub from os.path import join dpath = ub.ensure_app_cache_dir(‘kwcoco/tests/reader’) fpath = join(dpath, ‘foo.tiff’) kwimage.imwrite(fpath, data, backend=’skimage’) recon1 = kwimage.imread(fpath) recon1.shape

self = LazyGDalFrameFile(fpath) self.shape self[:]

classmethod available(self)[source]

Returns True if this backend is available

_ds(self)[source]
classmethod demo(cls, key='astro', dsize=None)[source]
property ndim(self)[source]
property shape(self)[source]
property dtype(self)[source]
__nice__(self)[source]
__getitem__(self, index)[source]

References

https://gis.stackexchange.com/questions/162095/gdal-driver-create-typeerror

Example

>>> # Test nodata works correctly
>>> # xdoctest: +REQUIRES(module:osgeo)
>>> from kwcoco.util.lazy_frame_backends import *  # NOQA
>>> from kwcoco.util.lazy_frame_backends import _demo_geoimg_with_nodata
>>> fpath = _demo_geoimg_with_nodata()
>>> self = LazyGDalFrameFile(fpath, nodata='auto')
>>> imdata = self[:]
>>> # xdoctest: +REQUIRES(--show)
>>> import kwplot
>>> import kwarray
>>> kwplot.autompl()
>>> imdata = kwimage.normalize_intensity(imdata)
>>> imdata = np.nan_to_num(imdata)
>>> kwplot.imshow(imdata)
__array__(self)[source]

Allow this object to be passed to np.asarray

References

https://numpy.org/doc/stable/user/basics.dispatch.html

kwcoco.util.lazy_frame_backends._rectify_slice_dim(part, D)[source]
kwcoco.util.lazy_frame_backends._validate_nonzero_data(file)[source]

Test to see if the image is all black.

May fail on all-black images

Example

>>> # xdoctest: +REQUIRES(module:osgeo)
>>> import kwimage
>>> gpath = kwimage.grab_test_image_fpath()
>>> file = LazyGDalFrameFile(gpath)
>>> _validate_nonzero_data(file)
kwcoco.util.lazy_frame_backends._read_envi_header(file)[source]

USAGE: hdr = _read_envi_header(file)

Reads an ENVI “.hdr” file header and returns the parameters in a dictionary as strings. Header field names are treated as case insensitive and all keys in the dictionary are lowercase.

Modified from spectral/io/envi.py

References

https://github.com/spectralpython/spectral