Inverted axis in numpy


gabriel@...
 

Hi everyone. I started using rasterio a few days ago to read some DSM/DTM and process them using numba.

I was trying to debug some weird behaviour in my numba function and i realized that the "read" function in Rasterio actually flips the axis of my dataset.
The file I am opening is a Geotiff, with EPSG:3003 projection.

This how i reproduced this behaviour:

dataset = rasterio.open("raster.tif")
band = dataset.read(1)
print(dataset.width)    -> 84
print(dataset.heigth)  -> 44
print(band.shape)   -> (44,84)


Is this behaviour normal? I don't understand why my data are being flipped in this way.

Thanks, Gabriel


 

Hi Gabriel, 

I am not sure if I understood what you meant!!
Were you expecting to have the width in the first axis? 
I think this behaviour (height first) is normal in rasterio and in many libraries used to manipulate images!!

But if you really wanna change the axis you can use something like numpy.transpose (recommended) or numpy.rollaxis

Good luck!!!



De: main@rasterio.groups.io <main@rasterio.groups.io> em nome de gabriel@... <gabriel@...>
Enviado: 11 de abril de 2020 22:11
Para: main@rasterio.groups.io <main@rasterio.groups.io>
Assunto: [rasterio] Inverted axis in numpy
 

Hi everyone. I started using rasterio a few days ago to read some DSM/DTM and process them using numba.

I was trying to debug some weird behaviour in my numba function and i realized that the "read" function in Rasterio actually flips the axis of my dataset.
The file I am opening is a Geotiff, with EPSG:3003 projection.

This how i reproduced this behaviour:

dataset = rasterio.open("raster.tif")
band = dataset.read(1)
print(dataset.width)    -> 84
print(dataset.heigth)  -> 44
print(band.shape)   -> (44,84)


Is this behaviour normal? I don't understand why my data are being flipped in this way.

Thanks, Gabriel