# reclassify items in list based values in dictionary

Question asked by lpalao on Jun 1, 2015
Latest reply on Jun 1, 2015 by sephefox

Dear ArcPy/Python Users,

I am working on four MODIS datasets on the same tile. I reclassified the map into boolean (1 and 0) based on some criteria. My objective is to have a reclassified map which contains some values based on the combination of values for each pixel from my four MODIS dataset. For instance, each pixel of my four rasters would contain one of the possible combinations, i.e., (1,1,0,0) the values are based on the sequence of my rasters -- (pixel value raster 1, pixel value raster 2, ...).

How can I convert this to 1100?

Another example would be:

>>> a = np.array([1,2,3,4])

>>> b = np.array([5,6,7,8])

>>> c = np.array([9,10,11,12])

>>> d = np.array([4,7,8,9])

>>> x

array([[[ 1,  5,  9,  4],

[ 2,  6, 10,  7],

[ 3,  7, 11,  8],

[ 4,  8, 12,  9]]])

convert the items to 1594, 26107, 37118, 48129

then for instance 1594 will be reclassified to say 2120

The reason is that, I have a dictionary variable (see below) which will reclassify the values for each possible combination. So in the end I will have an array of, i.e., from 1100 to 2120.

The corresponding values are representative on the number of occurrence and the sequence of that event. For instance the 1100 will be reclassified into 2120 -- this means the event of interest occurred twice in week 1 and week 2.

{1000:1100,

0100:1200,

0010:0130,

0001:1400,

1001:2140,

1100:2120,

0110:2230,

0011:2340,

1011:3134,

1101:3124,

1110:3123,

0111:3234,

1111:4111,

0000:1

255,255,255,255 = 0}

Here is the code that I am trying to complete and run but I am stuck now:

```# import arcpy module of arcgis
import arcpy, os, sys
from arcpy import env

# import spatial extension
from arcpy.sa import *
arcpy.env.overwriteOutput = True

# activate spatial extension
arcpy.CheckOutExtension("Spatial")

# environment settings
arcpy.env.extent = "MAXOF"

# workspace
arcpy.env.workspace = r'raster\directory'
rasters = arcpy.ListRasters("*", "tif")

# output workspace
out_ws = 'output/workspace/'

rastersCount = len(rasters)

counter = 0 # starting index

pixReclass = {1000:1100,
0100:1200,
0010:0130,
0001:1400,
1001:2140,
1100:2120,
0110:2230,
0011:2340,
1011:3134,
1101:3124,
1110:3123,
0111:3234,
1111:4111,
0000:0}

# compute dekad rasters
while counter < 4: # I am processing/testing only the first four rasters in my list
rast = []
rastMon = []

for i in range(counter,counter+4):
#print rasters[i]
rast.append(rasters[i])
print "rasters:{}".format(rast)
print len(rast)

for r in rast:
name, ext = r.split(".")
crit_Out = out_ws + name + "_reclass.tif"

criteria = Raster(r) >= 0001
criteria.save(crit_Out)
print criteria

vRast = arcpy.RasterToNumPyArray(crit_Out)
rastMon.append(vRast)
print "number of array:{}".format(len(rastMon))

zipped = np.dstack((rastMon, rastMon, rastMon, rastMon))

counter += 4
```

Hope that I made my query clear.

Thanks for any advice and suggestion.

-Leo

Message was edited by: Leo Kris Palao