I have created this loop in order to find a temperature, change in albedo and latitude ice reaches after 100 iterations of the code.
import numpy as np
import matplotlib.pyplot as plt
#define constants
L = 1280
albedo = 0.15
nIters = 100
LRange = [1200, 1600] #W/m2
Episilon = 1 #no units
Sigma = 5.67E-08 #Wm-2K-4
Ice_Lat_m = 1.5
Ice_lat_c = -322.5
Alb_m = -0.01
Alb_c = 2.8
plotType = "iterDown" #"L", "iterUp", "iterDown"
x = []
y = []
while (L > LRange[0] - 1):
for iter in range(nIters):
T = ((L * ( 1- albedo)) / 4) / Sigma
T = T ** (1/4)
albedo = Alb_m * T + Alb_c
albedo = min(albedo, 0.65)
albedo = max(albedo, 0.15)
lat_ice = Ice_Lat_m * T + Ice_lat_c
lat_ice = min(lat_ice, 90)
lat_ice = max(lat_ice, 0)
if plotType is "iter" or plotType is "iterDown":
x.append(iter)
y.append(T)
if plotType is "iter" or plotType is "iterDown":
x.append(np.nan)
y.append(np.nan)
if plotType is "L":
x.append(L)
y.append(T)
L = L - 10
while (L < LRange[1] + 1):
for iter in range(nIters):
T = ((L * ( 1- albedo)) / 4) / Sigma
T = T ** (1/4)
albedo = Alb_m * T + Alb_c
albedo = min(albedo, 0.65)
albedo = max(albedo, 0.15)
lat_ice = Ice_Lat_m * T + Ice_lat_c
lat_ice = min(lat_ice, 90)
lat_ice = max(lat_ice, 0)
if plotType is "iter" or plotType is "iterDown":
x.append(iter)
y.append(T)
if plotType is "iter" or plotType is "iterDown":
x.append(np.nan)
y.append(np.nan)
if plotType is "L":
x.append(L)
y.append(T)
L = L + 10
plt.plot(x, y)
plt.show()
print(T, albedo, lat_ice)
The output from this code is:
278.2748546226214 0.15 90
This tells me that the code is using the variable "LRange[1]" as the input into the loop rather than the variable "L" when it is within the range defined "LRange".
Desired output should be:
255.45242794389384 0.24547572056106137
Could anyone explain to me why this is happening? It would be greatly appreciated!