Let’s have some fun! So I went to my graphic design software and made some simple daisies. I was really lame about making them, at least according to my 14-year old at home.



Here is some code I added to the fun model.
from scipy.ndimage import gaussian_filter1d
from PIL import Image
BlackDaisyPic = 'BlackdaisyR.jpg'
WhiteDaisyPic = 'WhitedaisyR.jpg'
So if you want to run this code you are going to make sure to save those daisies as those file names. And put those files in the same folder as the python code.
Then you have to open the daisies in python and make them small so you can see a bunch of them on the earth.
BlackDaisyHan = Image.open(BlackDaisyPic)
WhiteDaisyHan = Image.open(WhiteDaisyPic)
BlackDaisyHan = BlackDaisyHan.resize((50,50))
WhiteDaisyHan = WhiteDaisyHan.resize((50,50))
At the end of the code I want to put daisies on my planet. So do that you have to create a new image and put each daisy, one at a time, at each location. It looks like this.
#Display the daisy
picture = Image.new('RGB',(50*yLength,50*xLength),(250,250,250))
for yy in range(yLength):
for xx in range(xLength):
if Daisy[yy,xx] < 0:
picture.paste (WhiteDaisyHan, (50*xx,50*yy))
if Daisy[yy,xx] > 0:
picture.paste (BlackDaisyHan, (50*xx,50*yy))
[discussion question 14] How am I putting each daisy at a time in this plot?
I am not going to lie to you, this sucked. It wasn’t easy. There were lots of four letter words. I tried three or four things to get it right. Animation is always tricky. And there are about 10 different ways to solve this problem, but this is the one I choose.
Here is the final code.
#implement daisy model for one point on earth
import matplotlib.pyplot as plt
import numpy as np
from scipy.ndimage import gaussian_filter1d
from PIL import Image
BlackDaisyPic = 'BlackdaisyR.jpg'
WhiteDaisyPic = 'WhitedaisyR.jpg'
p_k = 1/(17.5)**2 # K - parameter
p_Topt = 295.5 # optimal daisy growth
p_q = 2.1e9 # q factor in model
p_SL0 = 917 #solar output factor
p_sig = 5.67e-8 #Stefan-Boltzmann constant
p_q = 2.1e9 # q factor in model
p_aw = 0.75 #albeto for white daisy
p_ab = 0.25 #albeto for black daisy
p_ag = 0.50 #albeto for ground
p_GrowRate = 1
p_DeathRate = 0.05
xLength = 10
yLength = 10
numTimes = 200
time = np.arange(0,numTimes)
SL = p_SL0 * (1 + 0.2 * np.cos(time/20))
Daisy = np.zeros((yLength,xLength))
Temp = np.zeros((yLength,xLength))
EarthTemp = np.zeros(numTimes)
BlackDaisyHan = Image.open(BlackDaisyPic)
WhiteDaisyHan = Image.open(WhiteDaisyPic)
BlackDaisyHan = BlackDaisyHan.resize((50,50))
WhiteDaisyHan = WhiteDaisyHan.resize((50,50))
# Get the probability of growing a daisy of a certain type.
def Get_Daisy_Prob (aA, aTemperature):
#White Daisy Factor
TLocW = (p_q * (aA-p_aw) + aTemperature**4)**0.25
WhiteProb = 1 - p_k * (TLocW-p_Topt)**2
if WhiteProb < 0:
WhiteProb = 0
NoWhitePRob = 1 - WhiteProb
#Black Daisy Factor
TLocB = (p_q * (aA-p_ab) + aTemperature**4)**0.25
BlackProb = 1 - p_k * (TLocB-p_Topt)**2
if BlackProb < 0:
BlackProb = 0
NoBlackPRob = 1 - BlackProb
GroundProb = NoWhitePRob * NoBlackPRob
#Normalize Daisy Growth prob
mag = np.sqrt(WhiteProb**2 + BlackProb**2) + .0001
WP = WhiteProb/mag / np.sqrt(2)
BP = BlackProb/mag / np.sqrt(2)
ratio = WP / (WP + BP)
Prob = np.array([ratio, GroundProb])
return Prob
def getDaisySitutation (aA, Temp, daisy):
#flag for seeing if daisy should be recalculated
GrowNewDaisy = 0
#Is there a daisy alive?
if daisy == 0:
GrowNewDaisy = 1
#Now there is a daisy, but does it die?
else:
#Does Daisy die?
pickNum = np.random.rand()
if pickNum < p_DeathRate:
GrowNewDaisy = 1
#Grow New Daisy
if GrowNewDaisy:
daisy = 0
BWGrowRates = Get_Daisy_Prob (aA, Temp)
pickNum = np.random.rand()
if pickNum > BWGrowRates[1]:
pickNum = np.random.rand()
if pickNum < BWGrowRates[0]:
daisy = -1
else:
daisy = +1
return daisy
def getSmoothedArray (Y):
sY = gaussian_filter1d(Y,3)
return sY
for tt in range(numTimes):
TLat = np.zeros(yLength)
Albeto = np.zeros(yLength)
for yy in range(yLength):
#Dtermine the Albeto for each lat.
white = 0
black = 0
ground = 0
SolarRad = (0.5*(1 - (2*np.abs(yy - yLength/2))**2 / yLength**2) + 0.5) * SL[tt]
for xx in range(xLength):
if Daisy[yy,xx] < 0:
white = white + 1
elif Daisy[yy,xx] > 0:
black = black + 1
else:
ground = ground + 1
Albeto[yy] = white/xLength * p_aw + black/xLength * p_ab + ground/xLength * p_ag
#EarthTemperature note power to the fourth
TLat[yy] = (SolarRad * (1-Albeto[yy]) / p_sig)**0.25
#Albeto = getSmoothedArray(Albeto)
TLat = getSmoothedArray(TLat)
for yy in range(yLength):
for xx in range(xLength):
Temp[yy,xx] = TLat[yy]
Daisy[yy,xx] = getDaisySitutation (Albeto[yy], TLat[yy], Daisy[yy,xx])
#plt.imshow(Daisy)
#plt.show()
EarthTemp[tt] = np.mean(Temp)
#plt.plot(TLat)
#Display the daisy
picture = Image.new('RGB',(50*yLength,50*xLength),(250,250,250))
for yy in range(yLength):
for xx in range(xLength):
if Daisy[yy,xx] < 0:
picture.paste (WhiteDaisyHan, (50*xx,50*yy))
if Daisy[yy,xx] > 0:
picture.paste (BlackDaisyHan, (50*xx,50*yy))
plt.subplot(121)
plt.plot (tt,EarthTemp[tt],'ok')
plt.axis ([0, numTimes, 260, 320])
plt.xlabel ('Time')
plt.ylabel ('Temperature (K)')
plt.subplot(122)
picPlot = np.array(picture)
plt.xticks([])
plt.yticks([])
plt.imshow(picPlot)
plt.savefig('A' + str(tt) + '.png')
plt.show()
This is the result! There are still so many issues. Like why does python insist on replacing my plot each time I show a picture?

[discussion question 15] What do you think about this result and this project?

