Skip to content

Commit

Permalink
Merge pull request #114 from FormingWorlds/observational
Browse files Browse the repository at this point in the history
Some observational quantities
  • Loading branch information
nichollsh committed Jul 24, 2024
2 parents 9565213 + 495aad2 commit 3ac786f
Show file tree
Hide file tree
Showing 23 changed files with 2,877 additions and 3,220 deletions.
Binary file added examples/dummy_atmosphere/plot_observables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
425 changes: 213 additions & 212 deletions examples/dummy_atmosphere/proteus_00.log

Large diffs are not rendered by default.

160 changes: 80 additions & 80 deletions examples/dummy_atmosphere/runtime_helpfile.csv

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions examples/earth_demo/init_coupler.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ dt_initial = 1e4 # Inital step size
# Flux convergence scheme and tolerances for surface equilibration
shallow_ocean_layer = 0 # 0: off | 1: on
F_atm_bc = 0 # Boundary condition choice for F_atm, 0: TOA | 1: Surface
F_eps = 1.0 # W m-2
F_diff = 0.1 # flux fraction
RF_crit = 0.01 # depth fraction
dTs_atm = 30 # K
skin_d = 0.01 # m
skin_k = 2.0 # W m-1 K-1
prevent_warming = 1 # Require that the planet only cool down over time, 0: disabled | 1: enabled
Expand Down
Binary file modified examples/earth_demo/plot_atmosphere.pdf
Binary file not shown.
Binary file modified examples/earth_demo/plot_fluxes_atmosphere.pdf
Binary file not shown.
Binary file modified examples/earth_demo/plot_fluxes_global.pdf
Binary file not shown.
Binary file modified examples/earth_demo/plot_global_lin.pdf
Binary file not shown.
Binary file modified examples/earth_demo/plot_global_log.pdf
Binary file not shown.
Binary file modified examples/earth_demo/plot_interior.pdf
Binary file not shown.
Binary file modified examples/earth_demo/plot_interior_cmesh.pdf
Binary file not shown.
Binary file added examples/earth_demo/plot_observables.pdf
Binary file not shown.
Binary file modified examples/earth_demo/plot_sflux.pdf
Binary file not shown.
Binary file modified examples/earth_demo/plot_stacked.pdf
Binary file not shown.
5,145 changes: 2,360 additions & 2,785 deletions examples/earth_demo/proteus_00.log

Large diffs are not rendered by default.

255 changes: 124 additions & 131 deletions examples/earth_demo/runtime_helpfile.csv

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions input/rce_mixed.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ star_age_modern = 4.567e9 # yr, age of star (TODAY)
star_spectrum = stellar_spectra/Named/sun.txt # Stellar spectrum file at 1 AU (TODAY)

##### Planet configuration
mean_distance = 1.0 # AU, star-planet distance
mean_distance = 0.4 # AU, star-planet distance
mass = 5.972e24 # kg, planet mass--original mass of the Earth
radius = 6.371e6 # m, planet surface radius

Expand Down Expand Up @@ -124,7 +124,7 @@ tsurf_poststep_change_frac = 0.01
planet_coresize = 0.55

# Initial entropy conditions for interior
ic_adiabat_entropy = 2650.0
ic_adiabat_entropy = 2750.0
ic_dsdr = -4.698e-06

# Atmosphere heat flux start guess, adjusted during runtime [W/m^2]
Expand All @@ -137,7 +137,7 @@ fO2_shift_IW = 0
solvevol_use_params = 1

# Parameters used to solve for initial partial pressures (when solvepp_use_params = 1)
T_magma = 2300 # Surface temperature initial guess [K]
T_magma = 3000 # Surface temperature initial guess [K]
Phi_global = 1.0 # Mantle melt fraction initial guess
CH_ratio = 1.0 # C/H ratio
hydrogen_earth_oceans = 10.0 # Hydrogen inventory in units of equivalent Earth oceans
Expand Down
70 changes: 70 additions & 0 deletions plot/cpl_observables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3

from utils.modules_ext import *
from utils.plot import *

log = logging.getLogger("PROTEUS")

def plot_observables( output_dir, plot_format="pdf", t0=100.0):

log.info("Plot observables")

hf_all = pd.read_csv(output_dir+"/runtime_helpfile.csv", sep=r"\s+")

time = np.array(hf_all["Time"] )
if len(time) < 3:
log.warning("Cannot make plot with less than 3 samples")
return

# make plot
lw = 1.2
scale = 1.1
fig,axl = plt.subplots(1,1, figsize=(7*scale,4*scale))

# left axis
axl.plot(time, hf_all["transit_depth"]*1e6, lw=lw, color='k')
axl.set_ylabel("Transit depth [ppm]")

# right axis
axr = axl.twinx()
color = "tab:red"
axr.plot(time, hf_all["contrast_ratio"]*1e9, lw=lw, color=color)
axr.set_ylabel("Contrast ratio [ppb]")
axr.yaxis.label.set_color(color)
axr.tick_params(axis='y', colors=color)

# x-axis
axl.set_xlabel("Time [yr]")
axl.set_xscale("log")
axl.set_xlim(left=t0, right=np.amax(time))
axl.grid(alpha=0.2)

plt.close()
plt.ioff()

fpath = os.path.join(output_dir, "plot_observables.%s"%plot_format)
fig.savefig(fpath, dpi=200, bbox_inches='tight')

#====================================================================
def main():

if len(sys.argv) == 2:
cfg = sys.argv[1]
else:
cfg = 'init_coupler.cfg'

# Read in COUPLER input file
log.info("Read cfg file")
from utils.coupler import ReadInitFile, SetDirectories
COUPLER_options, time_dict = ReadInitFile( cfg )

# Set directories dictionary
dirs = SetDirectories(COUPLER_options)

plot_observables( output_dir=dirs["output"], plot_format=COUPLER_options["plot_format"] )

#====================================================================

if __name__ == "__main__":

main()
11 changes: 7 additions & 4 deletions proteus.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from utils.coupler import *
from utils.spider import RunSPIDER
from utils.surface_gases import *
from utils.logs import SetupLogger, GetLogfilePath, GetCurrentLogfileIndex
from utils.logs import SetupLogger, GetLogfilePath, GetCurrentLogfileIndex, StreamToLogger

from janus.utils.StellarSpectrum import PrepareStellarSpectrum,InsertStellarSpectrum
from janus.utils import DownloadSpectralFiles, DownloadStellarSpectra
Expand Down Expand Up @@ -404,7 +404,6 @@ def main():
hf_row[k] = solvevol_result[k]
############### / OUTGASSING



############### UPDATE TIME

Expand Down Expand Up @@ -450,13 +449,17 @@ def main():


# Store atmosphere module output variables
hf_row["z_obs"] = atm_output["z_obs"]
hf_row["F_atm"] = atm_output["F_atm"]
hf_row["F_olr"] = atm_output["F_olr"]
hf_row["F_sct"] = atm_output["F_sct"]
hf_row["T_surf"] = atm_output["T_surf"]
hf_row["F_net"] = hf_row["F_int"] - hf_row["F_atm"]

############### / ATMOSPHERE SUB-LOOP

# Calculate observables (measured at infinite distance)
hf_row["transit_depth"] = (hf_row["z_obs"] / hf_row["R_star"])**2.0
hf_row["contrast_ratio"] = ((hf_row["F_olr"]+hf_row["F_sct"])/hf_row["F_ins"]) * \
(hf_row["z_obs"] / (COUPLER_options["mean_distance"]*AU))**2.0

# Update full helpfile
if loop_counter["total"]>1:
Expand Down
8 changes: 8 additions & 0 deletions utils/agni.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,9 @@ def RunAGNI(loops_total:int, dirs:dict, COUPLER_options:dict, hf_row:dict):
net_flux = np.array(ds.variables["fl_N"][:])
LW_flux_up = np.array(ds.variables["fl_U_LW"][:])
SW_flux_up = np.array(ds.variables["fl_U_SW"][:])
arr_p = np.array(ds.variables["p"][:])
arr_z = np.array(ds.variables["z"][:])
radius = float(ds.variables["planet_radius"][:])
T_surf = float(ds.variables["tmp_surf"][:])
ds.close()

Expand All @@ -348,11 +351,16 @@ def RunAGNI(loops_total:int, dirs:dict, COUPLER_options:dict, hf_row:dict):
log.info("SOCRATES fluxes (net@BOA, net@TOA, OLR): %.3f, %.3f, %.3f W/m^2" %
(net_flux[-1], net_flux[0] ,LW_flux_up[0]))

# find 1 mbar level
idx = find_nearest(arr_p*1e5, 1e-3)[1]
z_obs = arr_z[idx]

output = {}
output["F_atm"] = F_atm_new
output["F_olr"] = LW_flux_up[0]
output["F_sct"] = SW_flux_up[0]
output["T_surf"] = T_surf
output["z_obs"] = z_obs + radius

return output

8 changes: 6 additions & 2 deletions utils/coupler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import plot.cpl_fluxes_global as cpl_fluxes_global
import plot.cpl_fluxes_atmosphere as cpl_fluxes_atmosphere
import plot.cpl_interior_cmesh as cpl_interior_cmesh
import plot.cpl_observables as cpl_observables

def GitRevision(dir:str) -> str:
'''
Expand Down Expand Up @@ -86,8 +87,7 @@ def CreateLockFile(output_dir:str):
keepalive_file = os.path.join(output_dir,"keepalive")
safe_rm(keepalive_file)
with open(keepalive_file, 'w') as fp:
fp.write("Removing this file will be interpreted by PROTEUS as a \
request to stop the simulation loop\n")
fp.write("Removing this file will be interpreted by PROTEUS as a request to stop the simulation loop\n")
return keepalive_file

def GetHelpfileKeys():
Expand All @@ -113,6 +113,9 @@ def GetHelpfileKeys():
# Stellar
"R_star", "age_star",

# Observational
"z_obs", "transit_depth", "contrast_ratio", # observed from infinity

# Surface composition
"P_surf", "atm_kg_per_mol", # more keys are added below

Expand Down Expand Up @@ -415,6 +418,7 @@ def UpdatePlots( output_dir, COUPLER_options, end=False, num_snapshots=7):
cpl_sflux.plot_sflux(output_dir, plot_format=COUPLER_options["plot_format"])
cpl_sflux_cross.plot_sflux_cross(output_dir, plot_format=COUPLER_options["plot_format"])
cpl_fluxes_global.plot_fluxes_global(output_dir, COUPLER_options)
cpl_observables.plot_observables(output_dir, plot_format=COUPLER_options["plot_format"])

# Close all figures
plt.close()
Expand Down
1 change: 1 addition & 0 deletions utils/dummy_atmosphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ def _resid(x):
output["F_atm"] = F_atm_lim # Net flux at TOA
output["F_olr"] = fluxes["fl_U_LW"] # OLR
output["F_sct"] = fluxes["fl_U_SW"] # Scattered SW flux
output["z_obs"] = COUPLER_options["radius"]

return output
5 changes: 5 additions & 0 deletions utils/janus.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,16 @@ def RunJANUS( atm, time:float, dirs:dict, COUPLER_options:dict, hf_all:pd.DataFr

# Restore stdout
sys.stdout , sys.stderr = old_stdout , old_stderr

# find 1 mbar level
idx = find_nearest(atm.p*1e5, 1e-3)[1]
z_obs = atm.z[idx]

output["T_surf"] = atm.ts # Surface temperature [K]
output["F_atm"] = F_atm_lim # Net flux at TOA
output["F_olr"] = atm.LW_flux_up[0] # OLR
output["F_sct"] = atm.SW_flux_up[0] # Scattered SW flux
output["z_obs"] = z_obs + atm.planet_radius

return output

0 comments on commit 3ac786f

Please sign in to comment.