Linear regression between every 3×3 pixels of two rasters

510
3
08-07-2020 12:16 AM
BennyIstanto
New Contributor II

I have two raster with same resolution and dimension: rainfall (mm) and water-occurrence (%). I want to create a new raster of SLOPE (a) and INTERCEPT (b) by performing linear regression between every 3×3 pixels of the two rasters (rainfall and water-occurrence), such that each pixel of the SLOPE and INTERCEPT will hold the regression slope and intercept value obtained from linear regression of the corresponding 3×3 pixels in rainfall and water-occurrence that surround that pixel.

Is there any example solution using ArcGIS or python/arcpy related above problem?

Example data in the attachment.

0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

how about covariance

https://numpy.org/doc/stable/reference/generated/numpy.cov.html 

will give you some

or

scipy.stats.linregress — SciPy v1.5.2 Reference Guide 

perhaps if implemented through a sliding/rolling windows approach using a 3x3 kernel.

What would the purpose be for such an analysis given `n` is extremely small?


... sort of retired...
BennyIstanto
New Contributor II

Hi Dan, 

For the final output, I am would like to have a raster with information on SLOPE, INTERCEPT, and Maximum rainfall threshold that could trigger a flood.

So if I have rainfall forecast in a raster, then I could use above mentioned data to calculate the probability if each pixel will flooded or not.

Now, I am still preparing all the data requirement for that, in the question above I have attached example data (rainfall and percent of water occurrence). As the pixel size is 0.05 deg ~ to 5.6km/pixels and by doing 3x3 or 5x5 group of cells, in my opinion is enough to see the correlation between both data.

Most of extreme rainfall followed by flood event are occurred locally, then 3x3 ~ 282.24 sqkm or 5x5 ~ 784 sqkm is a good start to analyse it.

Do you have any script that ready to use?

I also review some script related to regression written by you and/or Xander Bakker‌ in other thread, but doesn't consider 3x3 or 5x5 neighbour value.

I found similar problem that already answered using R approach: https://gis.stackexchange.com/questions/278979/linear-regression-between-every-3×3-pixels-between-tw...

0 Kudos
DanPatterson
MVP Esteemed Contributor

Pro can use R if you have the distribution installed


... sort of retired...
0 Kudos