perrygeo / python-rasterstats

Summary statistics of geospatial raster datasets based on vector geometries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

differences with geotiff.io and negative minimum statistics

PA-Segura opened this issue · comments

Hello,
I would like to use rasterstats to quantify rainfall from weather radars.
I am trying to use a geojson polygon and a geotiff.

Comparing my result to a quantification done in geotiff.io I see that my calculation with rasterstats differs a little

| | rasterstats | geotiff.io |
| min | -0.94999 | 0.05 |
| max | 12.75 | 12.75 |
| median | 0.7684 | 0.81 |

Also rasterstats gives the warning:
... /anaconda3/envs/my_satpy_env/lib/python3.9/site-packages/rasterstats/io.py:313:
UserWarning: Setting nodata to -999; specify nodata explicitly
warnings.warn("Setting nodata to -999; specify nodata explicitly")

I tried using nodata=None and nodat=0, and the result is the same.

The negative value in the minimum rasterstats statistic makes me think that this result is wrong. Does anyone know what could be happening?

cheers,
Pedro

Screenshot_20211122_121103
Screenshot_20211122_120956

It worked out to remove the Geotiff negative values with a custom function..


[156]: def filter_where_negative(arr, k):
     ...:     return arr[np.where(arr > k)]
     ...: def mymean(x):
     ...:     #print(type(x))
     ...:     x2 = filter_where_negative(x,0)
     ...:     return np.ma.mean(x2)
     ...: 

In [157]: zonal_stats("./poligono_random_kbro.geojson", "NIDS_BRO_DSP_DSP_20211119_0942.tif",stats="cou
     ...: nt min mean max median nodata unique",add_stats={'mymean':mymean})
/home/smn/anaconda3/envs/my_satpy_env/lib/python3.9/site-packages/rasterstats/io.py:313: UserWarning: Setting nodata to -999; specify nodata explicitly
  warnings.warn("Setting nodata to -999; specify nodata explicitly")
Out[157]: 
[{'min': -0.949999988079071,
  'max': 12.75,
  'mean': 0.768426996584876,
  'count': 10642,
  'median': 0.550000011920929,
  'unique': 98,
  'nodata': 0.0,
  'mymean': 0.8153730300946037}]