Skip to content

Commit

Permalink
Fixed convolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Paytonco committed Jan 29, 2022
1 parent 87a8670 commit 22a0cf6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
23 changes: 15 additions & 8 deletions model.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import matplotlib
import numpy as np
from scipy.ndimage import convolve
import util

'''features to add:
basic functionality
'''


#initialState: initial fire state matrix
#tempHigh: vector of high temperatures over the next 14 days
#tempLow: vector of low temperatures over the next 14 days
#precipVec: vector of precipitation values (decimal) over the next 14 days
#windVec: vector of wind speeds over the next 14 days (all northwesternly)
#windVec: vector of wind speeds over the next 14 days (all southeasternly)
#humidVec: vector of humidity values over the next 14 days
#density: tree density
#r: side length of partitions in km
Expand All @@ -36,13 +35,21 @@ def __init__(self, initialState, tempHigh, tempLow, precip, wind, humid, density
self.temp = tempLow[0] #figure this out in more detail later
self.humid = humid[0]
self.precip = precip[0]
self.mask = np.ones(initialState.shape)
def fireSpread(self):
kernel = util.findKernel(self.state, self.wind, self.humid, self.precip)
self.state = convolve(self.state, kernel, mode='constant')
kernel = util.findKernel(self.state, self.wind, self.humid, self.precip) #calculate kernel for convolution
self.state = util.maskConvolve(self.state, kernel, self.mask) #convolve but skipping burnt out cells
self.burnout() #check if any regions are over 100% burned

#iterate over all matrix entries, randomly determine spread according to temperature, density, humiditiy, wind
#need to add sensitivity to wind, humidity, and preciptiation

def burnout(self):
for i in range(self.state.shape[0]):
for j in range(self.state.shape[1]):
if self.state[i,j] >= 1:
self.state[i,j] = 0
self.mask[i,j] = 0

def timeStep(self):
#fireSpread and fireGrow; increment t
pass
self.fireSpread()
self.t += 1
7 changes: 4 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import model
import time

initialState = np.zeros((5,5))
initialState[2,0] = 0.1
initialState = np.zeros((36,88))
initialState[18,44] = 0.1

tempHigh = np.array([94,87,86,97,98,89,92,96,98,99,103,103,97,91])
tempLow = np.array([60,56,55,59,61,61,57,58,59,64,65,64,62,57])
Expand All @@ -18,7 +18,8 @@
plt.imshow(testModel.state, cmap=plt.get_cmap('inferno'))
plt.show
for i in range(7):
testModel.fireSpread()
testModel.timeStep()
#print(testModel.state)

plt.figure(i+2)
plt.imshow(testModel.state, cmap=plt.get_cmap('inferno'))
Expand Down
10 changes: 8 additions & 2 deletions util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import numpy as np
from scipy.ndimage import convolve

def findKernel(state,wind,humidity,precip):
return np.ones((3,3))
def findKernel(state,wind,humidity,precip):
kernel = np.ones((3,3))
return kernel

def maskConvolve(state,kernel,mask):
conv = convolve(state, kernel, mode='constant')
return np.where(mask, conv, state)

0 comments on commit 22a0cf6

Please sign in to comment.