import numpy as np
import matplotlib.pyplot as plt
import astropy.constants as const
import Bell_EBM as ebm
from Bell_EBM import pretty_plotting # Makes the plots look much nicer!
# WASP-12b
# Periods are in units of days
# All other units are in SI (m, kg, s, K, J, Pa, etc.)
# All angles are in degrees
planet = ebm.Planet('bell2018', rad=1.900*const.R_jup.value, mass=1.470*const.M_jup.value,
Porb=1.09142030, a=0.02340*const.au.value, inc=83.37, vWind=5e3)
# WASP-12
# Radius and mass are in solar units
# Temperatures are always in K
star = ebm.Star(teff=6300., rad=1.59, mass=1.20)
# Load the star and planet into a system
system = ebm.System(star, planet)
fig = planet.orbit.plot_orbit()
plt.show()
# Run initial burn-in - try guessing the equilibrium temperature to begin with
Teq = system.get_teq()
T0 = np.ones_like(system.planet.map.values)*Teq
t0 = 0.
t1 = t0+system.planet.Porb*2
dt = system.planet.Porb/1000.
times, maps = system.run_model(T0, t0, t1, dt, verbose=False)
fig = system.planet.plot_map()
plt.show()
fig = system.planet.plot_H2_dissociation()
plt.show()
# Plot the lightcurves - by default it will use one planetary orbit
fig = system.plot_lightcurve()
plt.show()
# Plot the temperature curves
fig = system.plot_tempcurve()
plt.show()
# We can also specify a rotation rate for the planet: we'll say it somehow isn't
# tidally locked yet. We also don't have to specify the planet's orbital period:
# it will be calculated using Kepler's equations
planet = ebm.Planet('rock', rad=const.R_earth.value, mass=const.M_earth.value,
a=0.05*const.au.value, e=0.4, argp=45.)
# The default values are the sun's values already
star = ebm.Star()
# Load everything into the system: this is when the orbital period is calculated
system = ebm.System(star, planet)
# Now that we know the orbital period, we can set the planet's rotation period
system.planet.Prot = system.planet.Porb*(2./3.)
# The plotted dots have equal spacing in time, so the get scruntched up near apastron
fig = planet.orbit.plot_orbit()
plt.show()
# Run initial burn-in - try guessing the median irradiation temperature to begin with
Teq = np.median(system.get_teq(np.linspace(0.,system.planet.Porb,1000, endpoint=False)))
T0 = Teq*np.ones_like(system.planet.map.values)
t0 = 0.
t1 = t0+system.planet.Porb*10
dt = system.planet.Porb/1000.
times, maps = system.run_model(T0, t0, t1, dt, verbose=False)
# Run a production run with intermediates=True to get the times and maps at each time step
T0 = maps[-1]
t0 = times[-1]
t1 = t0+system.planet.Porb
dt = system.planet.Porb/1000.
times, maps = system.run_model(T0, t0, t1, dt, verbose=False, intermediates=True)
phases = system.get_phase(times)
phasePeri = system.get_phase_periastron()
indexPeri = np.argmin(np.abs(phases-phasePeri))
fig = system.planet.plot_map(maps[indexPeri], times[indexPeri])
plt.show()
# Plot the lightcurves
fig = system.plot_lightcurve(times, maps, bolo=False, wav=4.5e-6)
plt.show()
# Plot the temperature curves
fig = system.plot_tempcurve(times, maps, bolo=False, wav=4.5e-6)
plt.show()
# The Earth's atmosphere is mostly N2, so we'll change the heat capacity
# of the gas from H2 (the default) to N2
cp_N2 = 1.039e3 # J/(kg K)
# We'll pretend the whole atmosphere absorbs and radiates
P0 = const.atm.value
a = const.au.value # AU
Rp = const.R_earth.value # m
Mp = const.M_earth.value # kg
Prot = 1. # days
albedo = 0.30
e = 0.0167
obliquity = 23.5 # degrees
# We'll assume that the Earth transits during the northern hemisphere's summer solstice
argp = -90.
t0 = 0.
planet = ebm.Planet('gas', rad=Rp, mass=Mp, Prot=Prot, a=a, e=e, obliq=obliquity,
argp=argp, t0=t0, cp=cp_N2, mlDepth=P0, albedo=albedo,
useHealpix=True)
# The default values are the sun's values already
star = ebm.Star()
# Load everything into the system
system = ebm.System(star, planet)
# Run initial burn-in - try guessing the median irradiation temperature to begin with
# Run for two full-orbits to work out seasonal variations
T0 = system.get_teq()*np.ones_like(system.planet.map.values)
t0 = planet.t0
t1 = t0+system.planet.Porb*2.-system.planet.Prot
dt = system.planet.Prot/10.
times, maps = system.run_model(T0, t0, t1, dt, verbose=False)
# Run one day at high-rez to get good temperatures around the planet
T0 = maps[-1]
t0 = times[-1]
t1 = t0+system.planet.Prot
dt = system.planet.Prot/100.
times, maps = system.run_model(T0, t0, t1, dt, verbose=False)
T0 = maps[-1]
t0 = times[-1]
t1 = t0+system.planet.Porb
# We'll use a small time step to make sure we're doing a good job
dt = system.planet.Prot/10.
times, maps = system.run_model(T0, t0, t1, dt, verbose=False, intermediates=True)
# Then we'll cut down on the number of points, since our full-orbit phasecurves
# don't need that high of a time resolution. Just daily outputs are fine
times = times[::10]
maps = maps[::10]
lc_reflected = system.lightcurve(times, maps, bolo=False, wav=0.5e-6,
allowThermal=False, allowReflect=True)
lc_thermal = system.lightcurve(times, maps, bolo=False, wav=0.5e-6,
allowThermal=True, allowReflect=False)
x = times.flatten()
x = (x-planet.Porb*int(np.median(x/planet.Porb)))
fig = plt.figure(figsize=(12,4))
plt.plot(x, lc_reflected*1e9, c='b', label=r'$\rm Reflected~Flux$')
plt.plot(x, lc_thermal*1e9, c='r', label=r'$\rm Thermal~Flux$')
plt.ylabel(r'$F_p/F_* \rm ~(ppb)$')
plt.xlabel(r'$\rm Time~from~Transit~(days)$')
plt.xlim(0, 365)
plt.legend(loc='best')
plt.show()
plt.close(fig)
lc_reflected = system.lightcurve(times, maps, bolo=False, wav=10e-6,
allowThermal=False, allowReflect=True)
lc_thermal = system.lightcurve(times, maps, bolo=False, wav=10e-6,
allowThermal=True, allowReflect=False)
x = times.flatten()
x = (x-planet.Porb*int(np.median(x/planet.Porb)))
fig = plt.figure(figsize=(12,4))
plt.plot(x, lc_reflected*1e9, c='b', label=r'$\rm Reflected~Flux$')
plt.plot(x, lc_thermal*1e9, c='r', label=r'$\rm Thermal~Flux$')
plt.ylabel(r'$F_p/F_* \rm ~(ppb)$')
plt.xlabel(r'$\rm Time~from~Transit~(days)$')
plt.xlim(0, 365)
plt.legend(loc='best')
plt.show()
plt.close(fig)
fig = system.planet.plot_map()
plt.show()
meanMap = np.mean(maps, axis=0)
EPTD = np.max(meanMap)-np.min(meanMap) # Average Equator-to-pole temperature difference
print('Average equator-to-pole temperature difference is ~'+str(int(np.rint(EPTD)))+'°C.')