Skip to content

Commit

Permalink
Refactor start_proteus.py and move config to toml (#142)
Browse files Browse the repository at this point in the history
* Set up boilerplate for cli

* Move code away from start_proteus.py to Proteus class

* Change cfg to toml and set up tests

* Tweak documentation

* Refactor dirs/options loader in cpl_*

* Add test

* Fix tomllib dependency

* Fix crash

* Fix test issues

* Fix version check

* Fix toml 3.10 compatibility

* Source PROTEUS.env

* Add FWL_DATA to workflow

* Add RAD_DIR env var

* Fix lint issues

* Fix docs

* Fix whitespace issues
  • Loading branch information
stefsmeets authored Aug 26, 2024
1 parent a7cf9e2 commit 851fc7c
Show file tree
Hide file tree
Showing 43 changed files with 1,070 additions and 1,150 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,17 @@ jobs:
run: |
python -m pip install -e .[develop]
- uses: actions/cache@v3
id: cache-fwl-data
with:
path: /home/runner/work/fwl_data
key: fwl-data-1

- name: Test with pytest
run: |
source PROTEUS.env
export FWL_DATA="/home/runner/work/fwl_data"
export RAD_DIR="./SOCRATES"
coverage run -m pytest
- name: Report coverage
Expand Down
8 changes: 3 additions & 5 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
You can directly run PROTEUS using the Python command:

```console
python start_proteus.py --cfg [cfgfile]
proteus start --config [cfgfile]
```

Where `[cfgfile]` is the path to the required configuration file. If
`--cfg [cfgfile]` is not provided, then the default configuration
located at `input/default.cfg` will be used. Pass the flag `--resume` in
order to resume the simulation from the disk.
Where `[cfgfile]` is the path to the required configuration file.
Pass the flag `--resume` in to resume the simulation from the disk.

You can also run PROTEUS inside a Screen session using:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

star_model = 0 # Evolution model to use for star (0: Spada, 1: Baraffe)
star_mass = 1 # M_sun, mass of star
star_radius_modern = 1 # R_sun, radius of star (TODAY)
star_radius_modern = 1 # R_sun, radius of star (TODAY)
star_temperature_modern = 5772.0 # K, temperature of star (TODAY)
star_luminosity_modern = 1 # L_sun, luminosity of star (TODAY) used for Baraffe model
star_age_modern = 4.567e9 # yr, age of star (TODAY)
star_rot_pctle = 50.0
star_spectrum = stellar_spectra/Named/sun.txt # Stellar spectrum file at 1 AU (TODAY)
star_spectrum = 'stellar_spectra/Named/sun.txt' # Stellar spectrum file at 1 AU (TODAY)

##### Planet configuration
mean_distance = 1 # AU, star-planet distance
Expand All @@ -26,24 +26,24 @@ P_top = 1.0e-6 # bar, Pressure at TOA
##### PROTEUS settings

iter_max = 9000
log_level = DEBUG
log_level = 'DEBUG'

# Output subdirectory name (relative to output folder)
dir_output = dummy
dir_output = 'dummy'

# Choose times
time_star = 100.0e6 # yr, time since star formation
time_target = 4.567e+9 # yr, target time for MO evolution

# SOCRATES spectral file to use (relative to FWL_DATA folder)
spectral_file = spectral_files/Frostflow/48/Frostflow.sf
spectral_file = 'spectral_files/Frostflow/48/Frostflow.sf'

# Stellar heating toggle, 0: disabled | 1: enabled
stellar_heating = 1

# Time-stepping stuff
plot_iterfreq = 1 # Plotting frequency, 0: wait until completion | n: every n iterations
plot_format = png # Plotting image file format
plot_format = 'png' # Plotting image file format
sspec_dt_update = 1e9 # Time intervals at which to re-calculate the stellar spectrum
sinst_dt_update = 1e1 # Time intervals at which to re-calculate the instellation
dt_maximum = 3e7 # Maximum time-step
Expand Down Expand Up @@ -74,7 +74,7 @@ steady_dprel = 1.0e-9 # Percentage change in melt fraction ov
emit_stop = 0 # Enable this break condition
F_crit = 0.2 # Model will terminate when |F_atm| < F_crit

# Atmospheric escape
# Atmospheric escape
escape_model = 2 # Escape model to be used, 0: None | 1: ZEPHYRUS | 2: Dummy
escape_stop = 3e-4 # Terminate when atm mass drops below this fraction of its initial mass
escape_dummy_rate = 2e7 # Bulk escape rate for dummy escape model [kg s-1]
Expand All @@ -87,8 +87,8 @@ atmosphere_surf_state = 1 # Atmosphere bottom edge boundary conditi
atmosphere_nlev = 40

# Temperature limits throughout atmosphere [K]
min_temperature = 0.5
max_temperature = 5000.0
min_temperature = 0.5
max_temperature = 5000.0

# Clouds
water_cloud = 0 # enable water cloud radiative effects? (1: yes, 0: no)
Expand All @@ -98,10 +98,10 @@ alpha_cloud = 0.0 # condensate retention fraction (1 -> fu
tropopause = 0

# Rayleigh scattering, 0: Disabled | 1: Enabled
rayleigh = 1
rayleigh = 1

# Atmospheric chemistry, 0: Disabled | 1: Equilibrium | 2: Kinetics
atmosphere_chemistry = 0
atmosphere_chemistry = 0

##### SPIDER-specific settings

Expand All @@ -115,7 +115,7 @@ mixing_length = 2
solver_tolerance = 1.0e-10

# Maximum absolute surface temperature change [K]
tsurf_poststep_change = 30.0
tsurf_poststep_change = 30.0

# Maximum fractional surface temperature change [fraction]
tsurf_poststep_change_frac = 0.02
Expand Down Expand Up @@ -168,4 +168,3 @@ CH4_initial_bar = 0.0

CO_included = 1
CO_initial_bar = 0.0

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

star_model = 0 # Evolution model to use for star (0: Spada, 1: Baraffe)
star_mass = 1 # M_sun, mass of star
star_radius_modern = 1 # R_sun, radius of star (TODAY)
star_radius_modern = 1 # R_sun, radius of star (TODAY)
star_temperature_modern = 5772.0 # K, temperature of star (TODAY)
star_luminosity_modern = 1 # L_sun, luminosity of star (TODAY) used for Baraffe model
star_age_modern = 4.567e9 # yr, age of star (TODAY)
star_rot_pctle = 50.0
star_spectrum = stellar_spectra/Named/sun.txt # Stellar spectrum file at 1 AU (TODAY)
star_spectrum = 'stellar_spectra/Named/sun.txt' # Stellar spectrum file at 1 AU (TODAY)

##### Planet configuration
mean_distance = 1 # AU, star-planet distance
Expand All @@ -26,24 +26,24 @@ P_top = 1.0e-5 # bar, Pressure at TOA
##### PROTEUS settings

iter_max = 9000
log_level = INFO
log_level = 'INFO'

# Output subdirectory name (relative to output folder)
dir_output = earth_demo
dir_output = 'earth_demo'

# Choose times
time_star = 100.0e6 # yr, time since star formation
time_target = 4.567e+9 # yr, target time for MO evolution

# SOCRATES spectral file to use (relative to FWL_DATA folder)
spectral_file = spectral_files/Frostflow/256/Frostflow.sf
spectral_file = 'spectral_files/Frostflow/256/Frostflow.sf'

# Stellar heating toggle, 0: disabled | 1: enabled
stellar_heating = 1

# Time-stepping stuff
plot_iterfreq = 1 # Plotting frequency, 0: wait until completion | n: every n iterations
plot_format = pdf # Plotting image file format
plot_format = 'pdf' # Plotting image file format
sspec_dt_update = 1e9 # Time intervals at which to re-calculate the stellar spectrum
sinst_dt_update = 1e2 # Time intervals at which to re-calculate the instellation
dt_maximum = 3e7 # Maximum time-step
Expand Down Expand Up @@ -74,7 +74,7 @@ steady_dprel = 1.0e-9 # Percentage change in melt fraction over
emit_stop = 1 # Enable this break condition
F_crit = 0.2 # Critical flux, below which the model will terminate

# Atmospheric escape
# Atmospheric escape
escape_model = 0 # Escape model to be used, 0: None | 1: ZEPHYRUS | 2: Dummy
escape_stop = 3e-4 # Terminate when atm mass drops below this fraction of its initial mass
escape_dummy_rate = 0.0 # Bulk escape rate for dummy escape model [kg s-1]
Expand All @@ -87,8 +87,8 @@ atmosphere_surf_state = 2 # Atmosphere bottom edge boundary condit
atmosphere_nlev = 250

# Temperature limits throughout atmosphere [K]
min_temperature = 0.5
max_temperature = 5000.0
min_temperature = 0.5
max_temperature = 5000.0

# Tropopause type, 0: none | 1: skin temperature | 2: dynamic
tropopause = 1
Expand All @@ -98,10 +98,10 @@ water_cloud = 0 # enable water cloud radiative effects?
alpha_cloud = 0.0 # condensate retention fraction (1 -> fully retained)

# Rayleigh scattering, 0: Disabled | 1: Enabled
rayleigh = 1
rayleigh = 1

# Atmospheric chemistry, 0: Disabled | 1: Equilibrium | 2: Kinetics
atmosphere_chemistry = 0
atmosphere_chemistry = 0

##### SPIDER-specific settings

Expand All @@ -115,10 +115,10 @@ mixing_length = 2
solver_tolerance = 1.0e-10

# Maximum absolute surface temperature change [K]
tsurf_poststep_change = 20.0
tsurf_poststep_change = 20.0

# Maximum fractional surface temperature change [fraction]
tsurf_poststep_change_frac = 0.01
tsurf_poststep_change_frac = 0.01

# Fractional core radius
planet_coresize = 0.55
Expand Down Expand Up @@ -168,4 +168,3 @@ CH4_initial_bar = 0.0

CO_included = 0
CO_initial_bar = 0.0

27 changes: 13 additions & 14 deletions input/default.cfg → input/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

star_model = 0 # Evolution model to use for star (0: Spada, 1: Baraffe)
star_mass = 1 # M_sun, mass of star
star_radius_modern = 1 # R_sun, radius of star (TODAY)
star_radius_modern = 1 # R_sun, radius of star (TODAY)
star_temperature_modern = 5772.0 # K, temperature of star (TODAY)
star_luminosity_modern = 1 # L_sun, luminosity of star (TODAY) used for Baraffe model
star_age_modern = 4.567e9 # yr, age of star (TODAY)
star_rot_pctle = 50.0
star_spectrum = stellar_spectra/Named/sun.txt # Stellar spectrum file at 1 AU (TODAY)
star_spectrum = 'stellar_spectra/Named/sun.txt' # Stellar spectrum file at 1 AU (TODAY)

##### Planet configuration
mean_distance = 1 # AU, star-planet distance
Expand All @@ -26,24 +26,24 @@ P_top = 1.0e-5 # bar, Pressure at TOA
##### PROTEUS settings

iter_max = 9000
log_level = INFO
log_level = 'INFO'

# Output subdirectory name (relative to output folder)
dir_output = earth_demo
dir_output = 'earth_demo'

# Choose times
time_star = 100.0e6 # yr, time since star formation
time_target = 4.567e+9 # yr, target time for MO evolution

# SOCRATES spectral file to use (relative to FWL_DATA folder)
spectral_file = spectral_files/Frostflow/256/Frostflow.sf
spectral_file = 'spectral_files/Frostflow/256/Frostflow.sf'

# Stellar heating toggle, 0: disabled | 1: enabled
stellar_heating = 1

# Time-stepping stuff
plot_iterfreq = 1 # Plotting frequency, 0: wait until completion | n: every n iterations
plot_format = pdf # Plotting image file format
plot_format = 'pdf' # Plotting image file format
sspec_dt_update = 1e9 # Time intervals at which to re-calculate the stellar spectrum
sinst_dt_update = 1e2 # Time intervals at which to re-calculate the instellation
dt_maximum = 3e7 # Maximum time-step
Expand Down Expand Up @@ -74,7 +74,7 @@ steady_dprel = 1.0e-9 # Percentage change in melt fraction over
emit_stop = 1 # Enable this break condition
F_crit = 0.2 # Critical flux, below which the model will terminate

# Atmospheric escape
# Atmospheric escape
escape_model = 0 # Escape model to be used, 0: None | 1: ZEPHYRUS | 2: Dummy
escape_stop = 3e-4 # Terminate when atm mass drops below this fraction of its initial mass
escape_dummy_rate = 0.0 # Bulk escape rate for dummy escape model [kg s-1]
Expand All @@ -87,8 +87,8 @@ atmosphere_surf_state = 2 # Atmosphere bottom edge boundary condit
atmosphere_nlev = 250

# Temperature limits throughout atmosphere [K]
min_temperature = 0.5
max_temperature = 5000.0
min_temperature = 0.5
max_temperature = 5000.0

# Tropopause type, 0: none | 1: skin temperature | 2: dynamic
tropopause = 1
Expand All @@ -98,10 +98,10 @@ water_cloud = 0 # enable water cloud radiative effects?
alpha_cloud = 0.0 # condensate retention fraction (1 -> fully retained)

# Rayleigh scattering, 0: Disabled | 1: Enabled
rayleigh = 1
rayleigh = 1

# Atmospheric chemistry, 0: Disabled | 1: Equilibrium | 2: Kinetics
atmosphere_chemistry = 0
atmosphere_chemistry = 0

##### SPIDER-specific settings

Expand All @@ -115,10 +115,10 @@ mixing_length = 2
solver_tolerance = 1.0e-10

# Maximum absolute surface temperature change [K]
tsurf_poststep_change = 20.0
tsurf_poststep_change = 20.0

# Maximum fractional surface temperature change [fraction]
tsurf_poststep_change_frac = 0.01
tsurf_poststep_change_frac = 0.01

# Fractional core radius
planet_coresize = 0.55
Expand Down Expand Up @@ -168,4 +168,3 @@ CH4_initial_bar = 0.0

CO_included = 0
CO_initial_bar = 0.0

Loading

0 comments on commit 851fc7c

Please sign in to comment.