Sample of Work Code

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Objective

Develop an algorithm in Jupyter to show the effects of planetary temperature variations due to the
solar heat flux, planetary composition, and distance from the host star. This will include a base
model of Earth’s temperature and seasonal variations. I will use this information summarize and
compare Earth to Mars to see the differences with living on Earth to Mars. An overview of Earth,
including the solar heat flux, radiation levels, and water cycle will conclude the importance of
planetary health and why Earth is habitable. The temperature differences with Earth due to polar ice
cap melting will also be compared.

By Kassandra Gurule

Base Model of Earth


In [1]:

# Load needed modules for Earth Base Models and Mars Model
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp

%matplotlib inline
In [2]:

# Earth's physical constants needed for calculations of Earth Base Model


R_e = 6.371E6 # Radius of Earth (meters)
sigma = 5.67E-8 # Stephan Boltzmann constant (W / m^2 / K^4)
c_h2o = 4000 # water heat capacity (J /kg / K)
rho_h2o = 1000 # water density (kg/m^3)
c_sil = 712 # Silicon-rock heat capacity (J /kg / K)
rho_sil = 2329 # Silicon-rock density (kg/m^3)
S_0 = 1361 # solar insolation/flux of Earth (W m-2)

#conversions needed for calculations for Earth Base Model


deg2rad = np.pi/180.0 # conversion factor - degrees to radians
days_e = 24*3600 # Number of seconds per Earth day
yrs_sec = 365.25*24*3600 # Number of seconds in one Earth year

# Base Model of Earth’s parameters


depth = 100 # Earth's land and active layer/ocean and water mixe
d layer depth – currently at 100 meters
earth_emm = 0.82 # Earth's emissivity
alpha = 0.32 # Earth's albedo with Polar Ice Caps
In [3]:

# Calculation for Earth's heat capacity at 100 meters deep - 71% ocean and 29
% silicate land
volume = 4 * np.pi * R_e**2 * depth # Earth’s volume - top 100 meters
HC_earth = 0.71 * (c_h2o * volume * rho_h2o) + 0.29 * (c_sil * volume * rho_s
il ) # Earth's heat capacity (J K-1)
HC_bar = HC_earth/(4*np.pi*R_e**2) # Earth's heat capacity per unit
area (J m-2 K-1)
In [4]:

# Earth’s time integration parameters


time_end = 100*yrs_sec # Integration end time (100 years
in seconds)
d_t = 10*days_e # Step size maximum for time inte
gration (10-day timestep in seconds)
out_pt = 30*days_e # Time between the plots (30 days
in seconds)
timesteps = np.arange(0,time_end,out_pt) # Output array of timesteps

# Needed diffusion coefficient for Earth


D_0 = 0.9
In [5]:

# Set the initial conditions and create data for the needed plot
n = 300 # Number of segments for plot
y_inter = np.linspace(-1,1,n+1) # Position of interfaces for plot
y_mid = (y_inter[0:n]+y_inter[1:n+1])/2 # Position of midpoints for plot
d_y = y_inter[1]-y_inter[0] # Segment length for plot
model_latitude = np.arcsin(y_mid)/deg2rad # Latitude of Earth at segment ce
nters for plot

# Set initial conditions – Earth Base Model


T_0 = 288 + 0*y_mid # Using the constant average temperature of Earth
In [6]:

#Solar Flux Functions Needed for latitudinal varying solar radiation of Earth
def solar_y(y):
s_1=1.241-0.723*y**2
return(s_1)

# Solar Radiation Calculations for Latitudes and Seasons on Earth


def solar_y_seasonal(t,time_end,y):
time_days = t/days_e # converts t (in seconds) to days
julian_day = np.mod(time_days,365) # Julian Day subtracts the number of w
hole years from t
delta_1 = 23.45*np.cos(2*np.pi*(julian_day-172)/365) # Calculate declinat
ion angle for JD on Earth at 23.5 degree axis tilt (starts on January 1)
# The declination angle is the angle at which the Sun is directly over
head for any given Julian day
delta_array_1 = np.repeat(delta_1,n)
value = -np.tan(delta_array_1*deg2rad)*np.tan(model_latitude*deg2rad)
value = np.where((value<-1.0),-1.0,value)
value = np.where((value>1.0),1.0,value)
Hr_0=np.arccos(value)
Q_0 = (S_0/np.pi)*(Hr_0*np.sin(model_latitude*deg2rad)*np.sin(delta_array
_1*deg2rad) + np.cos(model_latitude*deg2rad)*np.cos(delta_array_1*deg2rad)*np
.sin(Hr_0))
return(Q_0)
In [7]:

# Create Functions to Calculate the Albedo of Earth - Earth changing albedo b


y the Latitude calculated
def albedo_earth(y):
P_1 = 1/2* (3*y**2-1)
albedo = alpha + 0.25*P_1
return(albedo)

# Albedo function to vary the time over 100 Earth years


def albedo_1(t,time_end,y):
a_0=albedo_earth(y)
for i in range(n):
if (t>=40*yrs_sec) and (t<=60*yrs_sec):
M = (a_0[i]- 0.985*a_0[i])/(100*yrs_sec)
B = a_0[i]-60*yrs_sec*M
a_0[i] = M*t+B
return a_0

# Temperature and time dependent albedo that changes by Latitude over 100 Ear
th years
def alpha_time(t,time_end,y,T,option=1):
if option==3:
a_0 = albedo_1(t,time_end,y)
else:
a_0 = albedo_earth(y)
for i in range(n):
if T[i] <=(273.15-25):
a_0[i]=0.55
else:
a_0[i]=a_0[i]
type(a_0)
return a_0
In [8]:

# Solar radiation over all latitudes at a given timestep (30-day periods)


plt.figure()
plt.plot(model_latitude,solar_y_seasonal(timesteps[3],time_end,y_mid), color=
'red')
plt.xlabel("Latitude", color='black')
plt.ylabel("Solar Radiation (W m^-2)", color='black')
plt.title("Earth Base Model: Incoming Solar Radiation Over Every Latitude",fo
ntsize=15, color='black')
plt.savefig('base_model_Earth_solar_radiation_lat.jpg')
plt.show()

In [9]:

# Calculations needed to look at the surface temperature vs latitude for Eart


h
def earth_latitude_temp_time(t,T):
# Calculate the energy flux at each interface needed for each of Earth's
latitudes
F_1 = np.zeros(n+1)
F_1[1:n] = -D_0*(1-y_mid[1:n]**2)*(T[1:n]-T[0:n-1])/d_y
F_1[0] = 0
F_1[n] = 0
# Calculate the diffusion term at the segment centers for Earth
diffusion_earth = -(F_1[1:n+1]-F_1[0:n])/d_y
# Compute the right side of the equation needed for graph of Earth Temper
ature variations over 100 Earth years
heat_diffusion = diffusion_earth/HC_bar
earth_albedo_temp_time = (solar_y_seasonal(t,time_end,y_mid))*(1-alpha_ti
me(t,time_end,y_mid,T))/HC_bar # with albedo and solar parameterization inclu
ded for the declination angle of each latitude
lat_range = (1-(earth_emm/2))*sigma*T**4/HC_bar
right_eq = earth_albedo_temp_time - lat_range + heat_diffusion
return right_eq

# Call the time integrator to solve the equation numerically for the graph
solution_1 = solve_ivp(earth_latitude_temp_time, (0,time_end), T_0, "Radau",
timesteps, max_step=d_t)

# Extract time and temperature fields from the solution needed for the graph
time_latitude_temp_time = solution_1.t
temp_latitude_temp_time = solution_1.y
In [10]:

# Plot final temperature vs latitude graph of Earth Base Model


figure = plt.figure(figsize=(10,5))
plt.plot(model_latitude, temp_latitude_temp_time[:,-1],label='Temperature of
Earth per Latitude');
plt.xlabel('Earth Latitude')
plt.ylabel('Earth Temperature')
plt.title('Earth Base Model of Surface Temperature vs Latitude')
plt.legend()
plt.savefig('base_model_Earth_surface_temperature_vs_lat.jpg')
plt.show()
In [11]:

# Plot temperature vs time for one latitude of Earth Base Model


fig = plt.figure(figsize=(20,10))
plt.plot(time_latitude_temp_time/yrs_sec, temp_latitude_temp_time[-90,:],labe
l='Albedo Based on Temperature, Time, and Earth Latitude');
# Can pick a specific latitude here. The Latitude chosen is the equator
plt.xlabel('Time (years)')
plt.ylabel('Temperature')
plt.title('Earth Base Model of Surface Temperature for the Equator')
plt.show()

# Plot temperature vs time for several latitudes of Earth Base Model


fig = plt.figure(figsize=(30,15))
plt.plot(time_latitude_temp_time/yrs_sec, temp_latitude_temp_time[150,:],colo
r='red',linewidth=4,label='Equator') # 0 deg N, band 150
plt.plot(time_latitude_temp_time/yrs_sec, temp_latitude_temp_time[188,:],colo
r='orange',linewidth=4,label='Tropics') # 23 deg N, band 188
plt.plot(time_latitude_temp_time/yrs_sec, temp_latitude_temp_time[225,:],colo
r='green',linewidth=4,label='Mid Latitudes') # 45 deg N, band 225
plt.plot(time_latitude_temp_time/yrs_sec, temp_latitude_temp_time[260,:],colo
r='blue',linewidth=4,label='High Latitudes') # 66 def N, band 260
plt.xlabel('Time (years)',fontsize=25)
xticks=np.arange(0,101,5)
plt.xticks(xticks,fontsize=25)
plt.ylabel('Temperature (K)',fontsize=25)
yticks = np.arange(260,310,5)
plt.yticks(yticks,fontsize=25)
plt.title('Base Model of Earth: Surface Temperature over 100 Years',fontsize=
30)
plt.legend(loc='lower right',fontsize=25)
plt.savefig('base_model_Earth_surface_temperature_100.jpg')
plt.show()
Temperature and Incoming Solar Radiation of Earth if the
Polar Ice Caps Melt
In [12]:

# Earth's physical constants needed for calculations of Earth Model with no P


olar Ice Caps
R_e = 6.371E6 # Radius of Earth (meters)
sigma = 5.67E-8 # Stephan Boltzmann constant (W / m^2 / K^4)
c_h2o = 4000 # water heat capacity (J /kg / K)
rho_h2o = 1000 # water density (kg/m^3)
c_sil = 712 # Silicon-rock heat capacity (J /kg / K)
rho_sil = 2329 # Silicon-rock density (kg/m^3)
S_0 = 1361 # solar insolation/flux of Earth (W m-2)

#conversions needed for calculations for Earth Model with no Polar Ice Caps
deg2rad = np.pi/180.0 # converstion factor - degrees to radians
days_e = 24*3600 # Number of seconds per Earth day
yrs_sec = 365.25*24*3600 # Time - number of seconds in one year

# Earth Model – no Polar Ice Caps for - Earth parameters


depth_2 = 100 # Earth's land and active layer/ocean and water mi
xed layer depth (meters)
earth_emm = 0.82 # Earth's Emissivity

# Calculation for Earth's heat capacity at 100 meters deep – No Polar Ice Caps

#alp_ic_1 = .32 # Current albedo of Earth


#alp_ic_2 = (alp_ic_1 * 100) * (.10 * .84) # current albedo of Earth with ice
caps covering 10% and if Earth were covered 100% in Ice the albedo would be .
84
#alpha = (alp_ic_1 - .02) - (alp_ic_2 / 100) # Earth's albedo if
ice caps melted. Lowest albedo now is .3 and the Ice caps make 10% of Earth's
surface and albedo would be .84 if Earth were 100% covered in ice
alpha = .27
In [13]:

# Calculation for Earth's heat capacity at 72.7% ocean (1.7% increase from Po
lar Ice Caps completely melting) and 27.3% silicate land at 100 meter depth f
or the heat capacity of the oceans
volume_2 = 4 * np.pi * R_e**2 * depth_2 # Top 100 meters of earth volume
(depth)
HC_earth_2 = 0.71 * (c_h2o * volume_2 * rho_h2o) + 0.29 * (c_sil * volume_2 *
rho_sil ) # Earth's heat capacity (J K-1)
HC_bar_2 = HC_earth_2/(4*np.pi*R_e**2) # Earth's heat capacity – no Po
lar Ice Caps - per unit area (J m-2 K-1)
In [14]:

# Time integration parameters for Earth with no Polar Ice Caps


time_end = 100*yrs_sec # Integration end time (100 Earth y
ears in seconds)
d_t = 10*days_e # Step size maximum for time integra
tion (10 day step in seconds)
out_pt = 30*days_e # Time between the plots (30 days in
seconds)
timesteps = np.arange(0,time_end,out_pt) # Output array of timesteps for g
raph

# Needed diffusion coefficient for Earth – no Polar Ice Caps


D_0 = 0.9 # diffusion coefficient
In [15]:

# Set the initial conditions and create data for needed plot
n = 300 # Number of segments for plot
y_inter = np.linspace(-1,1,n+1) # Position of interfaces for plot
y_mid = (y_inter[0:n]+y_inter[1:n+1])/2 # Position of midpoints for plot
d_y = y_inter[1]-y_inter[0] # Segment length for plot
model_latitude = np.arcsin(y_mid)/deg2rad # Latitude of Earth at segme
nt centers for plot

# Set initial conditions for the model of Earth with no Polar Ice Caps
T_0 = 288 + 0*y_mid # Using the constant initial temperat
ure of Earth
In [16]:

# Solar Flux Functions Needed for Latitudinal varying solar radiation for Ear
th Model
def solar_y(y):
s_1=1.241-0.723*y**2
return(s_1)

# Solar Radiation Calculations for Latitudes and Seasons on Earth with no Pol
ar Ice Caps
def solar_y_seasonal(t,time_end,y):
time_days = t/days_e # t is in seconds, this converts t to Earth days
julian_day = np.mod(time_days,365) # subtracts the number of whole Earth
years from t
delta_1 = 23.45*np.cos(2*np.pi*(julian_day-172)/365) # Calculate declinat
ion angle for JD on Earth at 23.5 degree axis tilt (starts on January 1)
# The declination angle is the angle at which the Sun is directly overhead fo
r any given Julian day
delta_array_1 = np.repeat(delta_1,n)
value = -np.tan(delta_array_1*deg2rad)*np.tan(model_latitude*deg2rad)
value = np.where((value<-1.0),-1.0,value)
value = np.where((value>1.0),1.0,value)
Hr_0=np.arccos(value) # hour angle
Q_0 = (S_0/np.pi)*(Hr_0*np.sin(model_latitude*deg2rad)*np.sin(delta_array
_1*deg2rad) + np.cos(model_latitude*deg2rad)*np.cos(delta_array_1*deg2rad)*np
.sin(Hr_0))
return(Q_0)
In [17]:

# Create Functions to Calculate the Albedo of Earth with no Polar Ice Caps -
Earth changing albedo by the Latitude calculated
def albedo_earth(y):
P_1 = 1/2* (3*y**2-1)
albedo = alpha + 0.25*P_1
return(albedo)

# Albedo function to vary the time over 100 years


def albedo_1(t,time_end,y):
a_0=albedo_earth(y)
for i in range(n):
if (t>=40*yrs_sec) and (t<=60*yrs_sec):
M = (a_0[i]- 0.985*a_0[i])/(100*yrs_sec)
B = a_0[i]-60*yrs_sec*M
a_0[i] = M*t+B
return a_0

# Temperature and time dependent albedo that changes by Latitude for Earth wi
th no Polar Ice Caps
def alpha_time(t,time_end,y,T,option=1):
if option==3:
a_0 = albedo_1(t,time_end,y)
else:
a_0 = albedo_earth(y)
for i in range(n):
if T[i] <=(273.15-25):
a_0[i]=0.55
else:
a_0[i]=a_0[i]
type(a_0)
return a_0
In [18]:

# Solar radiation over all latitudes at a given timestep (30-day periods)


plt.figure()
plt.plot(model_latitude,solar_y_seasonal(timesteps[3],time_end,y_mid), color=
'red')
plt.xlabel("Latitude", color='black')
plt.ylabel("Solar Radiation (W m^-2)", color='black')
plt.title("Earth Base Model: Incoming Solar Radiation Over Every Latitude - N
o Polar Ice Caps",fontsize=15, color='black')
plt.savefig('base_model_Earth_solar_radiation_NPI.jpg')
plt.show()

In [19]:

# Compute the right side of the equation needed for graph of Earth Temperatur
e variations over 100 Earth years with no Polar Ice Caps
def earth_latitude_temp_time_2(t,T):

# Calculate the energy flux at each interface needed for each of Earth's
latitudes
F_1 = np.zeros(n+1)
F_1[1:n] = -D_0*(1-y_mid[1:n]**2)*(T[1:n]-T[0:n-1])/d_y
F_1[0] = 0
F_1[n] = 0
# Calculate the diffusion term at the segment centers - NPI
diffusion_earth = -(F_1[1:n+1]-F_1[0:n])/d_y
# Compute the right side of the equation needed for graph of Earth Temper
ature variations over 100 Earth years
heat_diffusion_2 = diffusion_earth/HC_bar_2
earth_albedo_temp_time_2 = (solar_y_seasonal(t,time_end,y_mid))*(1-alpha_time
(t,time_end,y_mid,T))/HC_bar_2 # with albedo and solar parameterization inclu
ded for the declination angle of each latitude - NPI
lat_range_2 = (1-(earth_emm/2))*sigma*T**4/HC_bar
right_eq_2 = earth_albedo_temp_time_2 - lat_range_2 + heat_diffusion_2
return right_eq_2

# Call the time integrator to solve the equation numerically for the graph
solution_2 = solve_ivp(earth_latitude_temp_time_2, (0,time_end), T_0, "Radau"
, timesteps, max_step=d_t)

# Extract time and temperature fields from the solution needed for the graph
time_latitude_temp_time_2 = solution_2.t
temp_latitude_temp_time_2 = solution_2.y
In [20]:

# Plot final temperature vs latitude for Earth with melted Polar Ice Caps
figure = plt.figure(figsize=(10,5))
plt.plot(model_latitude, temp_latitude_temp_time_2[:,-1],label='Temperature o
f Earth per Latitude - No Ice Polar Caps');
plt.xlabel('Earth Latitude')
plt.ylabel('Earth Temperature')
plt.title('Earth Base Model of Surface Temperature vs Latitude - No Polar Ice
Caps')
plt.legend()
plt.savefig('earth_base_model_surface_temperature_vs_latitude_100 - NPI.jpg')
plt.show()
In [21]:

# Plot temperature vs time for one latitude of Earth Model with no Polar Ice
Caps
fig = plt.figure(figsize=(20,10))
plt.plot(time_latitude_temp_time_2/yrs_sec, temp_latitude_temp_time_2[-90,:],
label='Temperature at Earth Equator: Based on No Polar Ice Caps');
plt.xlabel('Time (years)')
plt.ylabel('Temperature')
plt.title('Base Model of Earth: Surface Temperature for the Equator Over 100
Years - No Polar Ice Caps')
plt.legend()
plt.savefig('earth_base_model_surface_temperature_for_the_equator_100 - NPI.j
pg')
plt.show()

# Plot temperature vs time for several latitudes of Earth Model with no Polar
Ice Caps
fig = plt.figure(figsize=(30,15))
plt.plot(time_latitude_temp_time_2/yrs_sec, temp_latitude_temp_time_2[150,:],
color='red',linewidth=4,label='Equator') # 0 deg N, band 150
plt.plot(time_latitude_temp_time_2/yrs_sec, temp_latitude_temp_time_2[188,:],
color='orange',linewidth=4,label='Tropics') # 23 deg N, band 188
plt.plot(time_latitude_temp_time_2/yrs_sec, temp_latitude_temp_time_2[225,:],
color='green',linewidth=4,label='Mid Latitudes') # 45 deg N, band 225
plt.plot(time_latitude_temp_time_2/yrs_sec, temp_latitude_temp_time_2[260,:],
color='blue',linewidth=4,label='High Latitudes') # 66 def N, band 260
plt.xlabel('Time (years)',fontsize=25)
xticks=np.arange(0,101,5)
plt.xticks(xticks,fontsize=25)
plt.ylabel('Temperature (K)',fontsize=25)
yticks = np.arange(270,320,5)
plt.yticks(yticks,fontsize=25)
plt.title('Base Model of Earth: Surface Temperature over 100 Years - No Polar
Ice Caps',fontsize=30)
plt.legend(loc='lower right',fontsize=25)
plt.savefig('earth_base_model_surface_temperature_for_latitudes_100 - NPI.jpg
')
plt.show()
Model for Mars
In [22]:

# Mars's physical constants needed for calculations


R_mars = 3.3895E6 # Radius of Mars (meters)
sigma = 5.67E-8 # Stephan Boltzmann constant (W / m^2 / K^4)
c_bas = 840 # Basalt-rock heat capacity (J /kg / K)
rho_bas = 2900 # Basalt-rock density (kg/m^3)
S_mars = 590 # solar insolation/flux of Mars (W m-2)
c_sil = 712 # Silicon-rock heat capacity (J /kg / K)
rho_sil = 2329 # Silicon-rock density (kg/m^3)

# Conversions needed for calculations


deg2rad = np.pi/180.0 # converstion factor - degrees to radians
days_mars = 25*3600 # Number of seconds per Mars day
yrs_sec_mars = 687*25*3600 # Time - number of seconds in one year on Mars

# Base Model of Mars parameters


depth_mars = 700 # Mars's top crust minimum layer depth of 6 mete
rs
mars_emm = 0.82 # Mars's Emissivity
alpha_mars = 0.16 # Mars's albedo
In [23]:

# Calculation for Mars's heat capacity at 60% silicate and 40% basalt rock
volume_3 = 4 * np.pi * R_mars**2 * depth_mars
# Top 70 meters of Mars's volume (depth)
HC_mars = .40 * (c_bas * volume_3 * rho_bas) + 0.60 * (c_sil * volume_3 * rho
_sil ) # Mars's heat capacity (J K-1)
HC_bar_mars = HC_mars/(4*np.pi*R_mars**2) # Mars's heat capacity per uni
t area (J m-2 K-1)
In [24]:

# Time integration parameters for Mars


time_end_mars = 20*yrs_sec_mars # Integration end time (20 Mars years i
n seconds)
d_t_mars = 10*days_mars # Step size maximum for time integratio
n (10 day step in seconds)
out_pt_mars = 30*days_mars # Time between the plots (30 days in se
conds)
timesteps_mars = np.arange(0,time_end_mars,out_pt_mars) # Output array of
timesteps for graph of Mars

# Needed diffusion coefficient for Mars


D_1 = 0.1 # diffusion coefficient (previously 0.9 for Earth Base Mod
el)
In [25]:

# Set the initial conditions and create data for plot for Mars
n = 300 # Number of segments
y_inter = np.linspace(-1,1,n+1) # Position of interfaces
y_mid = (y_inter[0:n]+y_inter[1:n+1])/2 # Position of midpoints
d_y = y_inter[1]-y_inter[0] # Segment length
model_latitude = np.arcsin(y_mid)/deg2rad # Latitude of Mars at segment cen
ters

# Set initial conditions for the base model of Mars


T_1 = 215 + 0*y_mid # Using the constant black body s
urface temperature of Mars
In [26]:

# Solar Flux Functions Needed for Mars Model with latitudinal varying solar r
adiation
def solar_mars(y):
s_2=1.241-0.723*y**2
return(s_2)

# Solar Radiation Calculations for Latitudes and Seasons on Mars


def solar_mars_seasonal(t,time_end_mars,y):
time_days_mars = t/days_mars # t is in seconds, this converts t to days
julian_day_mars = np.mod(time_days_mars,687) # Julian Day subtracts the n
umber of whole years from t
delta_2 = 25*np.cos(2*np.pi*(julian_day_mars-323)/687) # Calculate declin
ation angle for JD on Mars at 25 degree axis tilt (starts on January 1)
# The declination angle is the angle at which the Sun is directly overhead fo
r any given Julian day
delta_array_2 = np.repeat(delta_2,n)
value_1 = -np.tan(delta_array_2*deg2rad)*np.tan(model_latitude*deg2rad)
value_1 = np.where((value_1<-1.0),-1.0,value_1)
value_1 = np.where((value_1>1.0),1.0,value_1)
Hr_1=np.arccos(value_1)
Q_1 = (S_mars/np.pi)*(Hr_1*np.sin(model_latitude*deg2rad)*np.sin(delta_ar
ray_2*deg2rad) + np.cos(model_latitude*deg2rad)*np.cos(delta_array_2*deg2rad)
*np.sin(Hr_1))
return(Q_1)
In [27]:

# Create Functions to Calculate the Albedo of Mars – Mars changing albedo by


the Latitude calculated
def albedo_mars(y):
P_2 = 1/2* (3*y**2-1)
albedo_1 = alpha_mars + 0.25*P_2
return(albedo_1)

# Albedo function to vary the time for Mars over 20 years


def albedo_2(t,time_end_mars,y):
a_1=albedo_mars(y)
for i in range(n):
if (t>=40*yrs_sec_mars) and (t<=60*yrs_sec_mars):
M_1 = (a_1[i]- 0.985*a_1[i])/(20*yrs_sec_mars)
B_1 = a_1[i]-60*yrs_sec_mars*M_1
a_1[i] = M_1*t+B_1
return a_1

# Temperature and time dependent albedo that changes by Latitude for Mars
def alpha_time_mars(t,time_end_mars,y,T_1,option=1):
if option==3:
a_1 = albedo_2(t,time_end_mars,y)
else:
a_1 = albedo_mars(y)
for i in range(n):
if T_1[i] <=(215-15):
a_1[i]=0.55
else:
a_1[i]=a_1[i]
type(a_1)
return a_1
In [28]:

# Solar radiation over all latitudes at a given timestep (30-day periods)


plt.figure()
plt.plot(model_latitude,solar_mars_seasonal(timesteps_mars[3],time_end_mars,y
_mid), color='red')
plt.xlabel("Latitude", color='black')
plt.ylabel("Solar Radiation (W m^-2)", color='black')
plt.title("Mars Model: Incoming Solar Radiation Over All Latitudes",fontsize=
15, color='black')
plt.savefig('Mars_Model_Radiation.jpg')
plt.show()

In [29]:

# Compute the right side of the equation needed for graph of Mars Temperature
variations over 100 Earth years
def mars_latitude_temp_time(t,T):
# Calculate the energy flux at each interface needed for each of Mars’s l
atitudes
F_m = np.zeros(n+1)
F_m[1:n] = -D_1*(1-y_mid[1:n]**2)*(T[1:n]-T[0:n-1])/d_y
F_m[0] = 0
F_m[n] = 0
# Calculate the diffusion term at the segment centers - Mars
diffusion_mars = -(F_m[1:n+1]-F_m[0:n])/d_y
# Compute the right side of the equation needed for graph of Mars Tempera
ture variations over 20 Mars years
heat_diffusion_m = diffusion_mars/HC_bar_mars
mars_albedo_temp_time = (solar_mars_seasonal(t,time_end_mars,y_mid))*(1-a
lpha_time_mars(t,time_end_mars,y_mid,T))/HC_bar_mars # with albedo and solar
parameterization included for the declination angle of each latitude - Mars
lat_range_m = (1-(mars_emm/2))*sigma*T_1**4/HC_bar_mars
right_eq_m = mars_albedo_temp_time - lat_range_m + heat_diffusion_m
return right_eq_m

# Call the time integrator to solve the equation numerically for the graph
solution_m = solve_ivp(mars_latitude_temp_time, (0,time_end_mars), T_1, "Rada
u", timesteps_mars, max_step=d_t)

# Extract time and temperature fields from the solution needed for the graph
time_latitude_temp_time_m = solution_m.t
temp_latitude_temp_time_m = solution_m.y
In [30]:

# Plot temperature vs time for the Equator of the Mars Model


figure = plt.figure(figsize=(10,5))
plt.plot(model_latitude, temp_latitude_temp_time_m[:,-1],label='Temperature b
ased on Latitude at Equator');
plt.xlabel('Mars Latitude')
plt.ylabel('Mars Temperature')
plt.title('Mars Model of Surface Temperature vs Latitude at the Equator')
plt.legend()
plt.savefig('Mars_base_temp_lat.jpg')
plt.show()

You might also like