Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes and download stellar spectrum #34

Merged
merged 5 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## JANUS (temperature structure generator)
## JANUS (1D convective atmosphere model)

Generates a temperature profile using the generalised moist pseudoadiabat and a prescribed stratosphere. Calculates radiative fluxes using SOCRATES.

Expand Down Expand Up @@ -36,12 +36,13 @@ https://proteus-code.readthedocs.io
* `git clone [email protected]:FormingWorlds/JANUS.git`
* `cd JANUS`
* `pip install -e .`
3. Download spectral files from the [OSF repository](https://osf.io/vehxg/)
3. Download data 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`
* Run the following commands within a python environment (or script) to download all basic data
* `from janus.utils.data import *`
* `DownloadSpectralFiles()`
* `DownloadStellarSpectra()`
* Alternatively, you can specify which spectral data you want to download, and optionally the number of bands
* `DownloadSpectralFiles("/Frostflow", 4096)`

Expand Down
14 changes: 11 additions & 3 deletions examples/SocRadConv.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from importlib.resources import files

from janus.modules import RadConvEqm, plot_fluxes, plot_emission
from janus.utils import atmos, CleanOutputDir, DownloadSpectralFiles, plot_adiabats, ReadBandEdges, StellarSpectrum
from janus.utils import atmos, CleanOutputDir, DownloadSpectralFiles, DownloadStellarSpectra, plot_adiabats, ReadBandEdges, StellarSpectrum
import mors

####################################
Expand Down Expand Up @@ -70,13 +70,21 @@

#Download required spectral files
DownloadSpectralFiles("/Dayspring")
DownloadSpectralFiles("/stellar_spectra")
DownloadStellarSpectra()

# Read spectrum
spec = mors.Spectrum()
spec.LoadTSV(os.environ.get('FWL_DATA')+"/stellar_spectra/Named/sun.txt")

# Convert to SOCRATES format
socstar = os.path.join(dirs["output"], "socstar.txt")
StellarSpectrum.PrepareStellarSpectrum(spec.wl, spec.fl, socstar)

# 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",
socstar,
dirs["output"]
)

Expand Down
15 changes: 12 additions & 3 deletions examples/demo_instellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import numpy as np

from janus.modules import MCPA_CBL
from janus.utils import atmos, CleanOutputDir, DownloadSpectralFiles, ReadBandEdges, StellarSpectrum
from janus.utils import atmos, CleanOutputDir, DownloadSpectralFiles, DownloadStellarSpectra, ReadBandEdges, StellarSpectrum

import mors

Expand All @@ -37,13 +37,22 @@

#Download required spectral files
DownloadSpectralFiles("/Oak")
DownloadSpectralFiles("/stellar_spectra")
DownloadStellarSpectra()

# Read spectrum
spec = mors.Spectrum()
spec.LoadTSV(os.environ.get('FWL_DATA')+"/stellar_spectra/Named/sun.txt")

# Convert to SOCRATES format
socstar = os.path.join(dirs["output"], "socstar.txt")
StellarSpectrum.PrepareStellarSpectrum(spec.wl, spec.fl, socstar)


# Setup spectral file
print("Inserting stellar spectrum")
StellarSpectrum.InsertStellarSpectrum(
os.environ.get('FWL_DATA')+"/spectral_files/Oak/318/Oak.sf",
os.environ.get('FWL_DATA')+"/spectral_files/stellar_spectra/Sun_t4_4Ga_claire_12.txt",
socstar,
dirs["output"]
)
band_edges = ReadBandEdges(dirs["output"]+"star.sf")
Expand Down
15 changes: 12 additions & 3 deletions examples/demo_runaway_greenhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from importlib.resources import files

from janus.modules import RadConvEqm
from janus.utils import atmos, CleanOutputDir, DownloadSpectralFiles, ReadBandEdges, StellarSpectrum
from janus.utils import atmos, CleanOutputDir, DownloadSpectralFiles, DownloadStellarSpectra, ReadBandEdges, StellarSpectrum
import mors

if __name__=='__main__':
Expand All @@ -36,13 +36,22 @@

#Download required spectral files
DownloadSpectralFiles("/Oak")
DownloadSpectralFiles("/stellar_spectra")
DownloadStellarSpectra()

# Read spectrum
spec = mors.Spectrum()
spec.LoadTSV(os.environ.get('FWL_DATA')+"/stellar_spectra/Named/sun.txt")

# Convert to SOCRATES format
socstar = os.path.join(dirs["output"], "socstar.txt")
StellarSpectrum.PrepareStellarSpectrum(spec.wl, spec.fl, socstar)


# Setup spectral file
print("Inserting stellar spectrum")
StellarSpectrum.InsertStellarSpectrum(
os.environ.get('FWL_DATA')+"/spectral_files/Oak/318/Oak.sf",
os.environ.get('FWL_DATA')+"/spectral_files/stellar_spectra/Sun_t4_4Ga_claire_12.txt",
socstar,
dirs["output"]
)
print(" ")
Expand Down
14 changes: 7 additions & 7 deletions src/janus/data/tests/data_instellation.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# r [AU], S_0 [W m-2], OLR [W m-2], net [W m-2], ts [K], tr[K]
3.00000e-01,2.34296e+03,1.94531e+03,-7.41821e+01,3.00037e+03,4.19568e+02
4.83333e-01,9.02638e+02,8.44987e+02,6.70043e+01,2.99966e+03,3.30552e+02
6.66667e-01,4.74449e+02,5.02546e+02,9.36275e+01,2.99953e+03,2.81455e+02
8.50000e-01,2.91856e+02,4.21740e+02,1.70194e+02,2.99915e+03,2.49261e+02
1.03333e+00,1.97481e+02,4.17035e+02,2.46829e+02,2.99877e+03,2.26070e+02
1.21667e+00,1.42450e+02,4.16624e+02,2.93848e+02,2.99853e+03,2.08342e+02
1.40000e+00,1.07585e+02,4.16473e+02,3.23747e+02,2.99838e+03,1.94222e+02
3.00000e-01,2.34297e+03,1.94397e+03,-4.67185e+01,3.00023e+03,4.19568e+02
4.83333e-01,9.02641e+02,8.43916e+02,7.70272e+01,2.99961e+03,3.30552e+02
6.66667e-01,4.74451e+02,5.01731e+02,9.86425e+01,2.99951e+03,2.81454e+02
8.50000e-01,2.91857e+02,4.21028e+02,1.73069e+02,2.99913e+03,2.49260e+02
1.03333e+00,1.97482e+02,4.16319e+02,2.48540e+02,2.99876e+03,2.26070e+02
1.21667e+00,1.42451e+02,4.15915e+02,2.94890e+02,2.99853e+03,2.08342e+02
1.40000e+00,1.07585e+02,4.15768e+02,3.24365e+02,2.99838e+03,1.94222e+02
40 changes: 20 additions & 20 deletions src/janus/data/tests/data_runaway_greenhouse.csv
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# T_surf [K], OLR [W m-2]
200.00000000, 90.72589
336.84210526, 277.55026
473.68421053, 277.47986
610.52631579, 277.27164
747.36842105, 277.35020
884.21052632, 277.18277
1021.05263158, 277.37436
1157.89473684, 277.13092
1294.73684211, 277.14750
1431.57894737, 277.30030
1568.42105263, 277.64148
1705.26315789, 279.04703
1842.10526316, 285.55804
1978.94736842, 308.2808
2115.78947368, 375.7102
2252.63157895, 548.4764
2389.47368421, 954.2722
2526.31578947, 1821.3682
2663.15789474, 3517.7295
2800.00000000, 6636.2110
200.00000000,9.07314e+01
336.84210526,2.77416e+02
473.68421053,2.77349e+02
610.52631579,2.77138e+02
747.36842105,2.77217e+02
884.21052632,2.77049e+02
1021.05263158,2.77241e+02
1157.89473684,2.76997e+02
1294.73684211,2.77013e+02
1431.57894737,2.77166e+02
1568.42105263,2.77504e+02
1705.26315789,2.78884e+02
1842.10526316,2.85329e+02
1978.94736842,3.07788e+02
2115.78947368,3.74184e+02
2252.63157895,5.47014e+02
2389.47368421,9.50390e+02
2526.31578947,1.80287e+03
2663.15789474,3.49537e+03
2800.00000000,6.58174e+03
12 changes: 10 additions & 2 deletions src/janus/modules/plot_emission_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import janus.utils.phys as phys

def plot_emission(atm:atmos, filename:str='output/toa_emission.pdf',
level_idx:int=0, planck_surface:bool=True, show_bands:bool=False):
level_idx:int=0, planck_surface:bool=True,
incoming_solar:bool=True, show_bands:bool=False):

# Configure
planck_samps = 1000
Expand All @@ -34,6 +35,13 @@ def plot_emission(atm:atmos, filename:str='output/toa_emission.pdf',
# Make plot
fig,ax = plt.subplots(1,1, figsize=(8,4))

# Plot incoming stellar spectrum
if incoming_solar:
ysolar = atm.SW_spectral_flux_down.T[0] # W m-2
ysolar /= atm.band_widths
ysolar *= 1e3
ax.plot(x, ysolar, color="green", lw=lw, label="TOA stellar flux")

# Plot band edges
if show_bands:
for i in range(atm.nbands):
Expand Down Expand Up @@ -70,7 +78,7 @@ def plot_emission(atm:atmos, filename:str='output/toa_emission.pdf',
ax.set_xlim(max(xmin, np.amin(x)), min(xmax, np.amax(x)))
ax.set_xscale("log")

ax.set_ylabel("Upward flux [erg s$^{-1}$ cm$^{-2}$ nm$^{-1}$]")
ax.set_ylabel("Flux density [erg s$^{-1}$ cm$^{-2}$ nm$^{-1}$]")
ax.set_yscale("log")

ax.legend(loc="lower center")
Expand Down
Loading
Loading