From ea3025fc6180f7ad2a7f24acfada1c37f776b9e4 Mon Sep 17 00:00:00 2001 From: Ghislain Vieilledent Date: Mon, 17 Jun 2024 12:30:13 +1200 Subject: [PATCH] Use astype for casting numpy data In [2]: numpy.array([[0, -128], [-100, 100], [37, -80], [255, 0]], numpy.int8) ...: :1: DeprecationWarning: NumPy will stop allowing conversion of out-of-bound Python integers to integer arrays. The conversion of 255 to int8 will fail in the future. For the old behavior, usually: np.array(value).astype(dtype) will give the desired result (the cast overflows). --- forestatrisk/project/deforest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forestatrisk/project/deforest.py b/forestatrisk/project/deforest.py index 5ffcb58..07aa9a0 100644 --- a/forestatrisk/project/deforest.py +++ b/forestatrisk/project/deforest.py @@ -168,7 +168,7 @@ def deforest(input_raster, hectares, output_file="output/fcc.tif", blk_rows=128) # Number of pixels that are really deforested deforpix = np.nonzero(prob_data >= threshold) # Forest-cover change - for_data = np.ones(shape=prob_data.shape, dtype=np.int8) + for_data = np.ones(shape=prob_data.shape).astype(np.int8) for_data = for_data * 255 # nodata for_data[prob_data != 0] = 1 for_data[deforpix] = 0