Skip to content

Commit

Permalink
Merge pull request #33 from FormingWorlds/baraffe
Browse files Browse the repository at this point in the history
Baraffe
  • Loading branch information
lsoucasse authored Jul 12, 2024
2 parents 3b8260d + f525968 commit be2a52d
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 3,532 deletions.
23 changes: 8 additions & 15 deletions examples/SocRadConv.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,9 @@
import numpy as np
from importlib.resources import files

from janus.modules.stellar_luminosity import InterpolateStellarLuminosity
from janus.modules.solve_pt import RadConvEqm
from janus.modules.solve_pt import *
from janus.modules.plot_flux_balance import plot_fluxes
from janus.modules.plot_emission_spectrum import plot_emission
from janus.utils.socrates import CleanOutputDir

import janus.utils.GeneralAdiabat as ga # Moist adiabat with multiple condensibles
from janus.utils.atmosphere_column import atmos
import janus.utils.StellarSpectrum as StellarSpectrum
from janus.utils.ReadSpectralFile import ReadBandEdges
from janus.utils.data import DownloadSpectralFiles
from janus.modules import RadConvEqm, plot_fluxes, plot_emission
from janus.utils import atmos, CleanOutputDir, DownloadSpectralFiles, plot_adiabats, ReadBandEdges, StellarSpectrum
import mors

####################################
##### Stand-alone initial conditions
Expand All @@ -44,7 +35,7 @@
if os.environ.get('RAD_DIR') == None:
raise Exception("Socrates environment variables not set! Have you installed Socrates and sourced set_rad_env?")
if os.environ.get('FWL_DATA') == None:
raise Exception("The FWL_DATA environment variable where spectral data will be downloaded needs to be set up!")
raise Exception("The FWL_DATA environment variable where spectral and evolution tracks data will be downloaded needs to be set up!")
dirs = {
"janus": str(files("janus"))+"/",
"output": os.path.abspath(os.getcwd())+"/output/"
Expand Down Expand Up @@ -98,7 +89,9 @@
if cfg['star']['stellar_heating'] == False:
atm.instellation = 0.
else:
atm.instellation = InterpolateStellarLuminosity(star_mass, time, mean_distance)
mors.DownloadEvolutionTracks("/Baraffe")
baraffe = mors.BaraffeTrack(star_mass)
atm.instellation = baraffe.BaraffeSolarConstant(time['star'], mean_distance)
print("Instellation:", round(atm.instellation), "W/m^2")

# Set up atmosphere with general adiabat
Expand All @@ -118,7 +111,7 @@
)

# Plot abundances w/ TP structure
ga.plot_adiabats(atm,filename= dirs["output"]+"moist_ga.png")
plot_adiabats(atm,filename= dirs["output"]+"moist_ga.png")
atm.write_PT(filename= dirs["output"]+"moist_pt.tsv")
atm.write_ncdf( dirs["output"]+"moist_atm.nc")
plot_fluxes(atm,filename= dirs["output"]+"moist_fluxes.png")
Expand Down
20 changes: 9 additions & 11 deletions examples/demo_instellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
import os, shutil, toml
import numpy as np

from janus.modules.stellar_luminosity import InterpolateStellarLuminosity
from janus.modules.solve_pt import *
from janus.utils.socrates import CleanOutputDir
from janus.utils.atmosphere_column import atmos
import janus.utils.StellarSpectrum as StellarSpectrum
import janus.utils.phys as phys
from janus.utils.ReadSpectralFile import ReadBandEdges
from janus.utils.data import DownloadSpectralFiles
from janus.modules import MCPA_CBL
from janus.utils import atmos, CleanOutputDir, DownloadSpectralFiles, ReadBandEdges, StellarSpectrum

import mors

if __name__=='__main__':

Expand All @@ -28,7 +24,7 @@
if os.environ.get('RAD_DIR') == None:
raise Exception("Socrates environment variables not set! Have you installed Socrates and sourced set_rad_env?")
if os.environ.get('FWL_DATA') == None:
raise Exception("The FWL_DATA environment variable where spectral data will be downloaded needs to be set up!")
raise Exception("The FWL_DATA environment variable where spectral and evolution tracks data will be downloaded needs to be set up!")
dirs = {
"janus": str(files("janus"))+"/",
"output": os.path.abspath(os.getcwd())+"/output/"
Expand Down Expand Up @@ -57,9 +53,11 @@
with open(cfg_file, 'r') as f:
cfg = toml.load(f)

# Planet
# Star luminosity
time = { "planet": cfg['planet']['time'], "star": cfg['star']['time']}
star_mass = cfg['star']['star_mass']
mors.DownloadEvolutionTracks("/Baraffe")
baraffe = mors.BaraffeTrack(star_mass)

# Define volatiles by mole fractions
vol_mixing = {
Expand Down Expand Up @@ -88,7 +86,7 @@
for i in range(7):
print("Orbital separation = %.2f AU" % r_arr[i])

atm.instellation = InterpolateStellarLuminosity(star_mass, time, r_arr[i])
atm.instellation = baraffe.BaraffeSolarConstant(time['star'], r_arr[i])
atmos.setTropopauseTemperature(atm)

atm = MCPA_CBL(dirs, atm, False, rscatter = True, T_surf_max=9.0e99, T_surf_guess = atm.trppT+100)
Expand Down
17 changes: 7 additions & 10 deletions examples/demo_runaway_greenhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@
from matplotlib.ticker import MultipleLocator
from importlib.resources import files

from janus.modules.stellar_luminosity import InterpolateStellarLuminosity
from janus.modules.solve_pt import RadConvEqm
from janus.utils.socrates import CleanOutputDir

from janus.utils.atmosphere_column import atmos
import janus.utils.StellarSpectrum as StellarSpectrum
from janus.utils.ReadSpectralFile import ReadBandEdges
from janus.utils.data import DownloadSpectralFiles
from janus.modules import RadConvEqm
from janus.utils import atmos, CleanOutputDir, DownloadSpectralFiles, ReadBandEdges, StellarSpectrum
import mors

if __name__=='__main__':

Expand All @@ -28,7 +23,7 @@
if os.environ.get('RAD_DIR') == None:
raise Exception("Socrates environment variables not set! Have you installed Socrates and sourced set_rad_env?")
if os.environ.get('FWL_DATA') == None:
raise Exception("The FWL_DATA environment variable where spectral data will be downloaded needs to be set up!")
raise Exception("The FWL_DATA environment variable where spectral and evolution tracks data will be downloaded needs to be set up!")
dirs = {
"janus": str(files("janus"))+"/",
"output": os.path.abspath(os.getcwd())+"/output/"
Expand Down Expand Up @@ -72,7 +67,9 @@
atm = atmos.from_file(cfg_file, band_edges, vol_mixing=vol_mixing, vol_partial={})

# Compute stellar heating
atm.instellation = InterpolateStellarLuminosity(star_mass, time, mean_distance)
mors.DownloadEvolutionTracks("/Baraffe")
baraffe = mors.BaraffeTrack(star_mass)
atm.instellation = baraffe.BaraffeSolarConstant(time['star'], mean_distance)

#Run Janus

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ dependencies = [
'seaborn',
'toml',
'tomlkit',
'f90nml'
'f90nml',
'fwl-mors'
]

[project.urls]
Expand Down
Loading

0 comments on commit be2a52d

Please sign in to comment.