1

I am trying to reclassify a continuous raster(Int32) using GDAL Python/NumPy, by giving values greater than a number (in this case 60 minutes) 0, and less than/equal to the number 1. It's working for the most part, but some pixels are not changing to 1 in spite of their value being equal to the number. In other cases pixels equal to the number are 1.

I think the culprit line is:

 cum_cost_array_bin = np.where(cum_cost_array_cont < (num_hours*60), 1, 0)

I have also tried:

cum_cost_array_bin = np.where(cum_cost_array_cont <= (num_hours*60), 1, 0)

The image shows the output, with the blue pixels <= 60 minutes, and the red > 60 in the continuous. I've reclassified the raster using ArcMap, and the yellow polygon represents that output, which is correct. Any ideas as to why NumPy is not changing the values based on the conditional? enter image description here

  • Hard to debug without seeing the input data, but have you tried simply doing cum_cost_array_bin = cum_cost_array_cont <= (num_hours*60) ? That should return a boolean numpy array. – mikewatt Mar 21 '18 at 19:54
  • Thanks for the idea. I've just tried it, but get the same result. The input raster is a continuous raster with values between 0-2882, read into a NumPy array. Is there any other information that I can give you? – David Mar 21 '18 at 20:08
  • 1
    I'm curious what the value of cum_cost_array_cont is for pixels where the Arc and numpy methods differ. Can you click around on a few pixels that are 0 in the numpy version, but included in the arc_bin layer. Could it be a decimal precision problem? – jdbcode Mar 21 '18 at 20:47
  • Thanks @jdbcode, that seems to be the problem. cum_cost_array_cont was a float datatype. I was reclassifying that, and then the raster that I used to create the arc_bin was an int32 dtype, which was created later in the script. Solution: Before I reclassified the NumPy array, I changed the dtype by cum_cost_array_cont = cum_cost_array_cont.astype(np.int32) Thanks again for your help. – David Mar 22 '18 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.