1

I would like to reclassify a raster with the following code:

#RBR reclassification to USGS burn severity values

arr = np.array(RBR_MultiplyBy1000_Int)

level1 = (arr >= -500) & (arr <= -251) #-2 Enhanced Regrowth, high (post-fire)
level2 = (arr >= -250) & (arr <= -101) #-1 Enhanced Regrowth, low (post-fire)
level3 = (arr >= -100) & (arr <= 99) #0 Unburned
level4 = (arr >= 100) & (arr <= 269) #1 Low Severity
level5 = (arr >= 270) & (arr <= 439) #2 Moderate-low Severity
level6 = (arr >= 440) & (arr <= 659) #3 Moderate-high Severity
level7 = (arr >= 660) & (arr <= 1300) #4 High Severity

levels = [level2, level3, level4, level5, level6, level7]
reclass_values = [-1, 0, 1, 2, 3, 4]

RBR_reclassed_arr = np.where(level1,-2, arr)
for level, val in zip(levels, reclass_values):
  RBR_reclassed_arr = np.where(level, val, RBR_reclassed_arr)

But when the reclassification is finished, I get the following raster values:

enter image description here

It seems to me that some values are not reclassified because I have the min value of -650, normally should be -2 the min value.

2
  • What is RBR_MultiplyBy1000_Int – BERA Apr 30 '20 at 12:08
  • Is my raster array with integer raster cell values. – DanielKovacs Apr 30 '20 at 12:11
1

Well, this should be posted as comment rather than answer because your question is not really clear, but let me try (sadly I have no privilege to add comments yet):

1) I do assume that your question is related to numpy rather than gdal

2) Assuming that you have -650 as minimal value in your raster (which from our point of view is numpy variable called arr) - there is no level which contains values as low as -650 (level 1 reassigns values starting from -500 and higher), so it remains unclassified

Corrected code would look like this:

import numpy as np

#fake data as we don't have access to your raster/array
arr=np.array([[-650,-400,200],[300,500,900]]) 

level1 = (arr >= -650) & (arr <= -251) #-2 Enhanced Regrowth, high (post-fire)
#level1 changed to include -650

level2 = (arr >= -250) & (arr <= -101) #-1 Enhanced Regrowth, low (post-fire)
level3 = (arr >= -100) & (arr <= 99) #0 Unburned
level4 = (arr >= 100) & (arr <= 269) #1 Low Severity
level5 = (arr >= 270) & (arr <= 439) #2 Moderate-low Severity
level6 = (arr >= 440) & (arr <= 659) #3 Moderate-high Severity
level7 = (arr >= 660) & (arr <= 1300) #4 High Severity


#levels adjusted, so they contain level1.
#this is not strictly problem in previous version of code, but better for clarity
levels = [level1, level2, level3, level4, level5, level6, level7]
#reclass values also adjusted    
reclass_values = [-2,-1, 0, 1, 2, 3, 4]

RBR_reclassed_arr = arr
for level, val in zip(levels, reclass_values):
    RBR_reclassed_arr = np.where(level, val, RBR_reclassed_arr)

Output:

array([[-2, -2,  1],
       [ 2,  3,  4]])
1
  • Thank you very much for your time. Really, the problem was with the outlier values that were not included in the first class. I strictly implemented the USGS recommended classification and this led me into trouble. – DanielKovacs Apr 30 '20 at 13:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.