Closed emuise closed 3 years ago
Hello @emuise,
thank you for reporting this. I can imagine where the problem comes from. In any case, I suppose that if you could send me the files, the debugging would probably be easier - but otherwise I can try solving it anyway.
Best, Martí
Hello @emuise,
did you manage to bypass the error? In any case, would it be possible to get access to your file (e.g., by mail) so that I can add a fix for this in the next release?
Thank you. Best, Martí
Hi @martibosch, I sent an email with a zip of the files. Not too large this time, but let me know if it doesn't go through. Evan
Hello again @emuise,
I could find two issues. The first is with pylandstats and it should be fixed in 6ba529a. The second is that (unless I am mistaken) your raster file does not have an assigned nodata value, so even after the fix, the following:
import pylandstats as pls
landscape_filepath = 'path/to/InkaneepPark_PACE-2015-HMM.tif'
zones_filepath = 'path/to/InkaneepPark_PACE_dissolved.shp'
za = pls.ZonalAnalysis(landscape_filepath, masks=zones_filepath, masks_index_col='ppa_gpe')
will raise:
Truncated Traceback (Use C-c C-$ to view full TB):
~/libraries/pylandstats/pylandstats/zonal.py in <listcomp>(.0)
198 landscapes = [
199 pls_landscape.Landscape(
--> 200 np.where(mask_arr, landscape_arr, landscape.nodata).astype(
201 landscape.landscape_arr.dtype),
202 res=(landscape.cell_width, landscape.cell_height),
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
because of landscape.nodata
being None
. If instead, we first do:
gdal_translate -of GTiff -a_nodata 0 path/to/InkaneepPark_PACE-2015-HMM.tif path/to/fix-nodata.tif
(or any other way to assign a nodata value to the raster) and then:
za = pls.ZonalAnalysis('path/to/fix-nodata.tif', masks=zones_filepath, masks_index_col='ppa_gpe')
you will have the proper ZonalAnalysis
instance.
The fix will be included in the next release, which will hopefully be this or next week. In the meantime, you can install the development version of pylandstats following these instructions - just note that you will net to run git checkout develop
before pip install -e .
so that you install pylandstats from the source of the develop
branch.
I am closing this, but feel free to reopen if you encounter any further problems related to this. Thank you again for reporting this. Best, Martí
FYI, the fix is included in the new release v2.3.0. Best, Martí
Description
Run zonal statistics on a region with two zones. It works for many of my cases doing the exact same thing, but when a zone contains only one class in the raster it throws this error. More than happy to send you the files, as well as files generated in the same way with multiple rasters in the class.
What I Did