-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
121 changed files
with
941 additions
and
14,079,582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
name: Publish on PyPI | ||
|
||
on: | ||
release: | ||
types: [published] | ||
workflow_dispatch: | ||
|
||
|
||
jobs: | ||
fix_release_deps: | ||
permissions: write-all | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip pip-tools setuptools | ||
- name: Set configuration | ||
run: | | ||
git config --global user.name "${GITHUB_ACTOR}" | ||
git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | ||
- name: Create requirements files | ||
run: | | ||
python tools/generate_requirements_txt.py | ||
pip-compile -o requirements_full.txt pyproject.toml | ||
git add requirements_full.txt requirements.txt | ||
git commit -m "Updated requirements.txt files" || true | ||
- name: Bump version to new tag | ||
run: | | ||
python -m pip install bump-my-version | ||
bump-my-version bump --new-version $GITHUB_REF_NAME patch | ||
git commit -am "Bump version to: $GITHUB_REF_NAME" | ||
- name: Push back changes to master and tag | ||
run: | | ||
git tag --force $GITHUB_REF_NAME HEAD | ||
git push --force --tags | ||
git switch -C master | ||
git push --set-upstream -f origin master | ||
deploy: | ||
needs: fix_release_deps | ||
runs-on: ubuntu-latest | ||
environment: release | ||
permissions: | ||
# IMPORTANT: this permission is mandatory for trusted publishing | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.ref_name }} | ||
|
||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.12' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install build setuptools>=61.2 wheel | ||
python -m build --no-isolation | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@release/v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Tests for JANUS | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.10', '3.11', '3.12'] | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Get SOCRATES | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: 'FormingWorlds/SOCRATES' | ||
path: 'SOCRATES' | ||
|
||
- name: Setup system | ||
run: | | ||
sudo apt update | ||
sudo apt-get install libnetcdff-dev netcdf-bin gfortran gcc | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Build SOCRATES | ||
run: | | ||
export LD_LIBRARY_PATH="" | ||
cd SOCRATES | ||
./configure | ||
./build_code | ||
source set_rad_env | ||
cd .. | ||
- name: Build JANUS | ||
run: | | ||
pip install -e . | ||
- name: Test with pytest | ||
run: | | ||
pip install pytest | ||
export FWL_DATA="./fwl_data" | ||
source SOCRATES/set_rad_env | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,17 +17,12 @@ https://proteus-code.readthedocs.io | |
* LS - Laurent Soucasse ([email protected]) | ||
|
||
### Repository structure | ||
* `README.md` - This file | ||
* `JANUS.env` - Sets environment flags to run the code | ||
* `src/janus/SocRadConv.py` - Main JANUS Python script | ||
* `src/janus/data/luminosity_tracks/` - Stellar evolution data | ||
* `src/janus/data/spectral_files/` - Spectral files for SOCRATES | ||
* `src/janus/modules/` - Utility python scripts | ||
* `src/janus/plotting_tools/` - Plotting scripts | ||
* `src/janus/utils/` - Utility python scripts | ||
* `tests/demo_runaway_greenhouse.py` - Demonstrate pure-steam runaway greenhouse OLR curve | ||
* `tests/demo_instellation.py` - Calculate fluxes (and temperatures) for different instellations | ||
* `tools/` - Useful tools | ||
* `README.md` - This file | ||
* `src/janus/data/` - Janus data files | ||
* `src/janus/modules/` - Utility python scripts | ||
* `src/janus/utils/` - Utility python scripts | ||
* `examples/` - Typical use scripts | ||
* `tools/` - Useful tools | ||
|
||
### Developer installation instructions | ||
1. Download and install Socrates | ||
|
@@ -36,14 +31,19 @@ https://proteus-code.readthedocs.io | |
* `./configure` | ||
* `./build-code` | ||
* `source set_rad_env` | ||
* `cd ..` | ||
2. Download and install Janus | ||
* `git clone [email protected]:FormingWorlds/JANUS.git` | ||
* `cd JANUS` | ||
* `pip install -e .` | ||
3. Download spectral files from the [OSF repository](https://osf.io/vehxg/) | ||
* Set the environment variable FWL_DATA to define where the spectral data files will be stored | ||
* `export FWL_DATA=...` | ||
* Run the following commands within a python environment (or script) to download all basic spectral files | ||
* `from janus.utils.data import DownloadSpectralFiles` | ||
* `DownloadSpectralFiles()` | ||
* Alternatively, you can specify which spectral data you want to download, and optionally the number of bands | ||
* `DownloadSpectralFiles("/Frostflow", 4096)` | ||
|
||
### Run instructions | ||
Only attempt to run JANUS after you have followed all of the instructions in INSTALL.md | ||
If using a fresh shell, it is necessary to perform the following steps: | ||
1. `source JANUS.env` | ||
2. `conda activate janus` | ||
Then you can run the code by running: `python SocRadConv.py` | ||
In the examples folder you can find python scripts showing typical usecases/workflows of atmosphere modelling with Janus. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Mon Jan 23 12:20:27 2023 | ||
@authors: | ||
Mark Hammond (MH) | ||
Tim Lichtenberg (TL) | ||
Ryan Boukrouche (RB) | ||
Harrison Nicholls (HN) | ||
JANUS radiative-convective model, using SOCRATES for radiative-transfer. | ||
""" | ||
|
||
import matplotlib as mpl | ||
mpl.use('Agg') | ||
|
||
import time as t | ||
import os, shutil, toml | ||
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 | ||
|
||
#################################### | ||
##### Stand-alone initial conditions | ||
#################################### | ||
if __name__ == "__main__": | ||
|
||
print("Start JANUS") | ||
|
||
# Set up dirs | ||
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!") | ||
dirs = { | ||
"janus": str(files("janus"))+"/", | ||
"output": os.path.abspath(os.getcwd())+"/output/" | ||
} | ||
|
||
start = t.time() | ||
##### Settings | ||
cfg_file = dirs["janus"]+"data/tests/config_janus.toml" | ||
with open(cfg_file, 'r'): | ||
cfg = toml.load(cfg_file) | ||
|
||
# Planet | ||
time = { "planet": cfg['planet']['time'], "star": cfg['star']['time']} | ||
star_mass = cfg['star']['star_mass'] | ||
mean_distance = cfg['star']['mean_distance'] | ||
|
||
# Define volatiles by partial pressures | ||
vol_mixing = {} | ||
vol_partial = { | ||
"H2O" : 9.0e5, | ||
"CO2" : 2.0e5, | ||
"CH4" : 3.0e5, | ||
"CO" : 5.0e5, | ||
"N2" : 4.0e5, | ||
"H2" : 1.0e5, | ||
} | ||
|
||
# Tidy directory | ||
if os.path.exists(dirs["output"]): | ||
shutil.rmtree(dirs["output"]) | ||
os.mkdir(dirs["output"]) | ||
|
||
#Download required spectral files | ||
DownloadSpectralFiles("/Dayspring") | ||
DownloadSpectralFiles("/stellar_spectra") | ||
|
||
# Move/prepare spectral file | ||
print("Inserting stellar spectrum") | ||
StellarSpectrum.InsertStellarSpectrum( | ||
os.environ.get('FWL_DATA')+"/spectral_files/Dayspring/256/Dayspring.sf", | ||
os.environ.get('FWL_DATA')+"/spectral_files/stellar_spectra/Sun_t4_4Ga_claire_12.txt", | ||
dirs["output"] | ||
) | ||
|
||
band_edges = ReadBandEdges(dirs["output"]+"star.sf") | ||
|
||
# Create atmosphere object | ||
atm = atmos.from_file(cfg_file, band_edges, vol_mixing=vol_mixing, vol_partial=vol_partial) | ||
|
||
# Set stellar heating on or off | ||
if cfg['star']['stellar_heating'] == False: | ||
atm.instellation = 0. | ||
else: | ||
atm.instellation = InterpolateStellarLuminosity(star_mass, time, mean_distance) | ||
print("Instellation:", round(atm.instellation), "W/m^2") | ||
|
||
# Set up atmosphere with general adiabat | ||
atm_dry, atm = RadConvEqm(dirs, | ||
time, | ||
atm, | ||
standalone=True, | ||
cp_dry=False, | ||
trppD=False, # Calculate dynamically? | ||
rscatter=False, # Rayleigh scattering on/off | ||
pure_steam_adj=False, # Pure steam convective adjustment | ||
surf_dt=False, # Surface temperature time-stepping | ||
# Options activated by surf_dt | ||
cp_surf=1e5, # Heat capacity of the ground [J.kg^-1.K^-1], | ||
mix_coeff_atmos=1e6, # mixing coefficient of the atmosphere [s] | ||
mix_coeff_surf=1e6 # mixing coefficient at the surface [s] | ||
) | ||
|
||
# Plot abundances w/ TP structure | ||
ga.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") | ||
plot_emission(atm, dirs["output"]+"toa_emission.png", planck_surface=True, show_bands=True) | ||
|
||
# Tidy | ||
CleanOutputDir(os.getcwd()) | ||
CleanOutputDir(dirs['output']) | ||
|
||
end = t.time() | ||
print("Runtime:", round(end - start,2), "s") | ||
|
Oops, something went wrong.