multiplying rasters range problem

219
8
01-27-2021 02:27 PM
Labels (1)
arcgisarcgipro_6
New Contributor

Hello 

I multiply 5 different rasters in raster calculator. However, I can not get the minimum and maximum range as it expected mathematically from the output raster layer. I would appreciate if you post the solution here. 

Thanks,

Gigi

0 Kudos
8 Replies
DavidPike
MVP Frequent Contributor

You need to supply a lot more info on your input data, the expression you've used currently etc. 

Also very unsure of what you're asking.

0 Kudos
arcgisarcgipro_6
New Contributor

I am using raster layers including values from 1 to 5 and counts.  I have 5 of those raster layers. When I use Raster Calculator (Spatial Analyst) tool the outcome raster layer's range is expected to become sth from 1 (1^5) to 3125(5^5) however it is not. so I am asking where does this problem stem? I am using Arcgis Pro 2.7.0 by the way.

0 Kudos
DavidPike
MVP Frequent Contributor

ah ok.  That range is probably expected but not a certainty surely? Only if all 5 rasters have at least one coincident cell all with values of 1, and the same again where a coincident cell has value 5 across all rasters.

What range are you getting?, and can you do an easy manual check to see if there cells where that is true across the 5 rasters? 

Only other thing I can suggest is a projection issue. Are they in the same projection (which projection) and do you have the same cell sizes?  If you have different cell sizes, the coincidence is also only true where the cell size overlaps the cell centre of another cell I believe.

Also a simple explanation might be an error in the raster calculator expression.

0 Kudos
DanPatterson
MVP Esteemed Contributor

What is the exact raster calculation you are using? and are all combinations possible?


... sort of retired...
0 Kudos
arcgisarcgipro_6
New Contributor

I am using Raster Calculator (Special Analyst Tools) and I am putting into this tool the raster layers with multiplication (*)  between them. I am not sure what you meant in your second question but I attached the pic of the attribute table that I got. hope that is the answer to your question.

0 Kudos
DanPatterson
MVP Esteemed Contributor

It has to do with possible "combinations", specifically "combinations with replacement" 

You indicate you have 5 rasters which can have a value of 1, 2, 3, 4, or 5 (unless that is wrong)

You then multiply each raster (leave nodata out of the question for now).

That means any cell can have the possible combinations of the aforementioned numbers.

For posterity

 from itertools import combinations_with_replacement
comb = combinations_with_replacement([1, 2, 3, 4, 5], 5)

for i in list(comb):
    print("combination {}, product {}".format(i, np.prod(i)))
    
combination (1, 1, 1, 1, 1), product 1
combination (1, 1, 1, 1, 2), product 2
combination (1, 1, 1, 1, 3), product 3
combination (1, 1, 1, 1, 4), product 4
combination (1, 1, 1, 1, 5), product 5
combination (1, 1, 1, 2, 2), product 4
combination (1, 1, 1, 2, 3), product 6
combination (1, 1, 1, 2, 4), product 8
combination (1, 1, 1, 2, 5), product 10
combination (1, 1, 1, 3, 3), product 9
combination (1, 1, 1, 3, 4), product 12
combination (1, 1, 1, 3, 5), product 15
combination (1, 1, 1, 4, 4), product 16
combination (1, 1, 1, 4, 5), product 20
combination (1, 1, 1, 5, 5), product 25
combination (1, 1, 2, 2, 2), product 8
combination (1, 1, 2, 2, 3), product 12
combination (1, 1, 2, 2, 4), product 16
combination (1, 1, 2, 2, 5), product 20
combination (1, 1, 2, 3, 3), product 18
combination (1, 1, 2, 3, 4), product 24
combination (1, 1, 2, 3, 5), product 30
combination (1, 1, 2, 4, 4), product 32
combination (1, 1, 2, 4, 5), product 40
combination (1, 1, 2, 5, 5), product 50
combination (1, 1, 3, 3, 3), product 27
combination (1, 1, 3, 3, 4), product 36
combination (1, 1, 3, 3, 5), product 45
combination (1, 1, 3, 4, 4), product 48
combination (1, 1, 3, 4, 5), product 60
combination (1, 1, 3, 5, 5), product 75
combination (1, 1, 4, 4, 4), product 64
combination (1, 1, 4, 4, 5), product 80
combination (1, 1, 4, 5, 5), product 100
combination (1, 1, 5, 5, 5), product 125
combination (1, 2, 2, 2, 2), product 16
combination (1, 2, 2, 2, 3), product 24
combination (1, 2, 2, 2, 4), product 32
combination (1, 2, 2, 2, 5), product 40
combination (1, 2, 2, 3, 3), product 36
combination (1, 2, 2, 3, 4), product 48
combination (1, 2, 2, 3, 5), product 60
combination (1, 2, 2, 4, 4), product 64
combination (1, 2, 2, 4, 5), product 80
combination (1, 2, 2, 5, 5), product 100
combination (1, 2, 3, 3, 3), product 54
combination (1, 2, 3, 3, 4), product 72
combination (1, 2, 3, 3, 5), product 90
combination (1, 2, 3, 4, 4), product 96
combination (1, 2, 3, 4, 5), product 120
combination (1, 2, 3, 5, 5), product 150
combination (1, 2, 4, 4, 4), product 128
combination (1, 2, 4, 4, 5), product 160
combination (1, 2, 4, 5, 5), product 200
combination (1, 2, 5, 5, 5), product 250
combination (1, 3, 3, 3, 3), product 81
combination (1, 3, 3, 3, 4), product 108
combination (1, 3, 3, 3, 5), product 135
combination (1, 3, 3, 4, 4), product 144
combination (1, 3, 3, 4, 5), product 180
combination (1, 3, 3, 5, 5), product 225
combination (1, 3, 4, 4, 4), product 192
combination (1, 3, 4, 4, 5), product 240
combination (1, 3, 4, 5, 5), product 300
combination (1, 3, 5, 5, 5), product 375
combination (1, 4, 4, 4, 4), product 256
combination (1, 4, 4, 4, 5), product 320
combination (1, 4, 4, 5, 5), product 400
combination (1, 4, 5, 5, 5), product 500
combination (1, 5, 5, 5, 5), product 625
combination (2, 2, 2, 2, 2), product 32
combination (2, 2, 2, 2, 3), product 48
combination (2, 2, 2, 2, 4), product 64
combination (2, 2, 2, 2, 5), product 80
combination (2, 2, 2, 3, 3), product 72
combination (2, 2, 2, 3, 4), product 96
combination (2, 2, 2, 3, 5), product 120
combination (2, 2, 2, 4, 4), product 128
combination (2, 2, 2, 4, 5), product 160
combination (2, 2, 2, 5, 5), product 200
combination (2, 2, 3, 3, 3), product 108
combination (2, 2, 3, 3, 4), product 144
combination (2, 2, 3, 3, 5), product 180
combination (2, 2, 3, 4, 4), product 192
combination (2, 2, 3, 4, 5), product 240
combination (2, 2, 3, 5, 5), product 300
combination (2, 2, 4, 4, 4), product 256
combination (2, 2, 4, 4, 5), product 320
combination (2, 2, 4, 5, 5), product 400
combination (2, 2, 5, 5, 5), product 500
combination (2, 3, 3, 3, 3), product 162
combination (2, 3, 3, 3, 4), product 216
combination (2, 3, 3, 3, 5), product 270
combination (2, 3, 3, 4, 4), product 288
combination (2, 3, 3, 4, 5), product 360
combination (2, 3, 3, 5, 5), product 450
combination (2, 3, 4, 4, 4), product 384
combination (2, 3, 4, 4, 5), product 480
combination (2, 3, 4, 5, 5), product 600
combination (2, 3, 5, 5, 5), product 750
combination (2, 4, 4, 4, 4), product 512
combination (2, 4, 4, 4, 5), product 640
combination (2, 4, 4, 5, 5), product 800
combination (2, 4, 5, 5, 5), product 1000
combination (2, 5, 5, 5, 5), product 1250
combination (3, 3, 3, 3, 3), product 243
combination (3, 3, 3, 3, 4), product 324
combination (3, 3, 3, 3, 5), product 405
combination (3, 3, 3, 4, 4), product 432
combination (3, 3, 3, 4, 5), product 540
combination (3, 3, 3, 5, 5), product 675
combination (3, 3, 4, 4, 4), product 576
combination (3, 3, 4, 4, 5), product 720
combination (3, 3, 4, 5, 5), product 900
combination (3, 3, 5, 5, 5), product 1125
combination (3, 4, 4, 4, 4), product 768
combination (3, 4, 4, 4, 5), product 960
combination (3, 4, 4, 5, 5), product 1200
combination (3, 4, 5, 5, 5), product 1500
combination (3, 5, 5, 5, 5), product 1875
combination (4, 4, 4, 4, 4), product 1024
combination (4, 4, 4, 4, 5), product 1280
combination (4, 4, 4, 5, 5), product 1600
combination (4, 4, 5, 5, 5), product 2000
combination (4, 5, 5, 5, 5), product 2500
combination (5, 5, 5, 5, 5), product 3125

 


... sort of retired...
0 Kudos
arcgisarcgipro_6
New Contributor

the problem is new raster layer does not include the minimum and maximum product.

0 Kudos
DanPatterson
MVP Esteemed Contributor

That is because no location/cell (ie in your stack of 5 rasters) has a combination of 5, 5, 5, 5, 5

In order to get 3125 all the stacked rasters have to have a value of 5 at one location

a = np.array([[0, 1, 2], [3, 4, 5]])  # ---- one raster
a5 = np.vstack([a, a, a, a, a]).reshape(5, 2, 3)  # 5 identical stacked rasters
a
array([[0, 1, 2],
       [3, 4, 5]])

a5
array([[[0, 1, 2],
        [3, 4, 5]],
       [[0, 1, 2],
        [3, 4, 5]],
       [[0, 1, 2],
        [3, 4, 5]],
       [[0, 1, 2],
        [3, 4, 5]],
       [[0, 1, 2],
        [3, 4, 5]]])

np.cumprod(a5, axis=0)  # ---- their product looking down through a "cell"

array([[[   0,    1,    2],
        [   3,    4,    5]],

       [[   0,    1,    4],
        [   9,   16,   25]],

       [[   0,    1,    8],
        [  27,   64,  125]],

       [[   0,    1,   16],
        [  81,  256,  625]],

       [[   0,    1,   32],
        [ 243, 1024, 3125]]], dtype=int32)

... sort of retired...
0 Kudos