Topics

Why does shape not return the number of channels


himat15@...
 


I was pretty surprised when I realized that my bug was due to ds.shape not showing the number of channels in its shape
i.e.

    with rio.open(f, 'r') as ds:
        
        ds_arr = ds.read()
        print(ds.profile) # {'driver': 'GTiff', 'dtype': 'float32', 'nodata': 0.0, 'width': 890, 'height': 3080, 'count': 3, 'crs': CRS.from_epsg(32629), 'transform': Affine(15.0, 0.0, 232060.0,
       0.0, -15.0, 1438430.0), 'tiled': False, 'interleave': 'pixel'}
        print(ds.shape) # (3080, 890)
        print(ds_arr.shape) # (3, 3080, 890)

I assume this is the expected behavior, but was just taken aback by this.


Sean Gillies
 

Correct, the dataset's shape is not the same as the shape of dataset.read().

On Thu, Apr 16, 2020 at 1:38 PM himat15 via groups.io <himat15=yahoo.com@groups.io> wrote:

I was pretty surprised when I realized that my bug was due to ds.shape not showing the number of channels in its shape
i.e.

    with rio.open(f, 'r') as ds:
        
        ds_arr = ds.read()
        print(ds.profile) # {'driver': 'GTiff', 'dtype': 'float32', 'nodata': 0.0, 'width': 890, 'height': 3080, 'count': 3, 'crs': CRS.from_epsg(32629), 'transform': Affine(15.0, 0.0, 232060.0,
       0.0, -15.0, 1438430.0), 'tiled': False, 'interleave': 'pixel'}
        print(ds.shape) # (3080, 890)
        print(ds_arr.shape) # (3, 3080, 890)

I assume this is the expected behavior, but was just taken aback by this.



--
Sean Gillies