0

I am using Gtif files for raster calculations in python. I want to apply the formula:

Aridity index = precipitation/(Temperature + 10).

When I use this for Gtiff I get the following error: "TypeError: unsupported operand type(s) for /: 'DatasetReader' and 'DatasetReader".

I am new to python. Thank you

Here is my code:

tmp_tif= rasterio.open('temp.tif')
pcp_tif = rasterio.open('pcp.tif')

AI_DM = pcp_tif/tmp_tif + 10
alex
  • 10,900
  • 15
  • 70
  • 100
Nishita
  • 37
  • 1
  • 3
  • [Docs say](https://rasterio.readthedocs.io/en/latest/topics/reading.html) you should `read()` the `DatasetReader` to get the array. Then you can perform operations on it. – alex Apr 14 '22 at 10:57

1 Answers1

0

As @alex points out (see comments), you should read the contents of the DatasetReaders first (see Documentation)

Therefore, what you want to do is this:

tmp_tif= rasterio.open('temp.tif').read()
pcp_tif = rasterio.open('pcp.tif').read()

AI_DM = pcp_tif/tmp_tif + 10
nTerior
  • 159
  • 1
  • 9