Skip to content

Commit

Permalink
Use astype for casting numpy data
Browse files Browse the repository at this point in the history
In [2]: numpy.array([[0, -128], [-100, 100], [37, -80], [255, 0]], numpy.int8)
   ...:
<ipython-input-2-a2ef1427d77a>: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).
  • Loading branch information
ghislainv committed Jun 17, 2024
1 parent ea3025f commit 9fbd0f7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion forestatrisk/project/deforest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).astype(np.int8)
for_data = np.ones(shape=prob_data.shape).astype(int)
for_data = for_data * 255 # nodata
for_data[prob_data != 0] = 1
for_data[deforpix] = 0
Expand Down

0 comments on commit 9fbd0f7

Please sign in to comment.