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

AQUA notebook and docs #71

Merged
merged 5 commits into from
Oct 30, 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
4 changes: 4 additions & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ println("ROOT_DIR = $ROOT_DIR")
RAD_DIR = abspath(ENV["RAD_DIR"])
println("RAD_DIR = $RAD_DIR")

# Get socrates version
SOC_VER = readchomp(joinpath(RAD_DIR,"version"))
println("SOC_VER = $SOC_VER")

# Generate wrappers
println("Generate wrappers")
wrap = joinpath(RAD_DIR, "julia/src/generate_wrappers.jl")
Expand Down
7 changes: 6 additions & 1 deletion docs/src/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Follow the steps below in order to setup the code.
3. Change directory: `cd AGNI`
4. Setup SOCRATES by doing either **ONE** of the following...
- Follow the instructions on the [SOCRATES GitHub](https://github.com/nichollsh/SOCRATES) page
- Run `source get_socrates.sh`
- Run `source src/get_socrates.sh`
5. `julia -e 'using Pkg; Pkg.activate("."); Pkg.build()'`
AGNI is now installed as a package into a Julia environment in the AGNI
directory. This will also have downloaded some basic input data.
Expand All @@ -36,6 +36,11 @@ julia ./test/runtests.jl
```
This will print information on whether tests passed or failed.

## Coupling with FastChem
This can be enabled using the configuration file parameter `composition.chem_type`. Of
course, it is first necessary to setup FastChem, which can be done by running
`source src/get_fastchem.sh` and then setting the `FC_DIR` environment variable.

## Using the code
See [Running the model](@ref) for information on using the code.
See [Troubleshooting](@ref) for troubleshooting advice.
14 changes: 10 additions & 4 deletions docs/src/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ official website.
## Cannot find SOCRATES
Check the installation instructions. Have you set `RAD_DIR`? Try running
`l_run_cdf` in the terminal; if this fails, then SOCRATES has not compiled
or you haven't added it to your `PATH`.
or you haven't added it to your `PATH`. It is necessary to set the `RAD_DIR` variable
for the environment in which you are running AGNI, so it is best to add it to your shell's
rc file permanently.


## Spectral file does not exist
Check the path in the configuration file. Download additional spectral files using the
`get_data` script in the AGNI root directory. For example, for additional pure-steam
spectral files you would run
`get_data` script. For example, for additional pure-steam spectral files you would run
```bash
./src/get_data.sh steam
```

## Cannot find FastChem
You need to install FastChem. This can be done by running the command:
```bash
./src/get_fastchem.sh
```
and then adding `FC_DIR` to your shell rc file.

## Finally...
If you are still stuck, or feel that there is a problem with the code, then
you can contact the authors using the information on the main page.


6 changes: 3 additions & 3 deletions docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ If you require more data, such as additional stellar spectra or opacities, then
also be easily obtained using the `get_data` script in the AGNI root directory. To see how
to use this script, run it without arguments like so:
```bash
./get_data.sh
./src/get_data.sh
```

## Tutorials
Expand All @@ -17,8 +17,8 @@ of the repository.

## General execution
The environment variable `RAD_DIR` must point to the SOCRATES installation
directory. This is required for AGNI to find the SOCRATES libraries, and can be
done by running `source path/to/socrates/set_rad_env` in your terminal.
directory. This is required for AGNI to find the SOCRATES libraries. The best way to do
this is to add `RAD_DIR=path/to/socrates/folder/` to your shell rc file (e.g. `~/.bashrc`).

Then to use the model, simply run `./agni.jl [cfg]` where `[cfg]` is the path
to the required configuration file. If `[cfg]` is not passed, then the default
Expand Down
4,773 changes: 75 additions & 4,698 deletions misc/aqua.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/AGNI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module AGNI
# Include system libraries
using LoggingExtras
using Printf
using TOML
import TOML:parsefile

# Include local jl files (order matters)
include("phys.jl")
Expand Down Expand Up @@ -132,7 +132,7 @@ module AGNI
function open_config(cfg_path::String)::Dict

# open file
cfg_dict = TOML.parsefile(cfg_path)
cfg_dict = parsefile(cfg_path)

# check headers
headers = ["plots", "planet", "files", "execution", "title"]
Expand Down
21 changes: 14 additions & 7 deletions src/atmosphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ module atmosphere

# System libraries
using Printf
using DelimitedFiles
using PCHIPInterpolation
using LinearAlgebra
using Statistics
using Logging
using LoopVectorization
# import Statistics
import PCHIPInterpolation:Interpolator
import DelimitedFiles:readdlm

# Local files
include(joinpath(ENV["RAD_DIR"],"julia/src/SOCRATES.jl"))
Expand Down Expand Up @@ -323,6 +323,8 @@ module atmosphere
mkdir(OUT_DIR)
end

@info "Setting-up a new atmosphere struct"

# Code versions
atmos.AGNI_VERSION = "0.10.0"
atmos.SOCRATES_VERSION = readchomp(joinpath(ENV["RAD_DIR"],"version"))
Expand Down Expand Up @@ -467,7 +469,7 @@ module atmosphere

# Dict input case
if mf_source == 0
@info "Composition set by dict"
@debug "Composition set by dict"
for (key, value) in mf_dict # store as arrays
gas_valid = strip(key, [' ','\t','\n'])

Expand All @@ -492,7 +494,7 @@ module atmosphere
@error "Could not read VMR file '$mf_path'"
return false
end
@info "Composition set by file"
@debug "Composition set by file"

# get header
mf_head::String = readline(abspath(mf_path))
Expand Down Expand Up @@ -669,13 +671,15 @@ module atmosphere
atmos.FC_DIR = abspath(ENV["FC_DIR"])
if !isdir(atmos.FC_DIR)
@error "Could not find fastchem folder at '$(atmos.FC_DIR)'"
@error "Install FastChem with `\$ ./src/get_fastchem.sh`"
return false
end

# check executable
atmos.fastchem_flag = isfile(joinpath(atmos.FC_DIR,"fastchem"))
if !atmos.fastchem_flag
@error "Could not find fastchem executable inside '$(atmos.FC_DIR)' "
@error "Could not find fastchem executable inside '$(atmos.FC_DIR)'"
@error "Install FastChem with `\$ ./src/get_fastchem.sh`"
return false
else
@info "Found FastChem executable"
Expand Down Expand Up @@ -926,6 +930,7 @@ module atmosphere
# Validate files
if !isfile(atmos.spectral_file)
@error "Spectral file '$(atmos.spectral_file)' does not exist"
@error "Try running `\$ ./src/get_data.sh`"
return false
end

Expand All @@ -939,6 +944,7 @@ module atmosphere

if !isfile(stellar_spectrum)
@error "Stellar spectrum file '$(stellar_spectrum)' does not exist"
@error "Try running `\$ ./src/get_data.sh stellar`"
return false
end

Expand Down Expand Up @@ -1201,7 +1207,7 @@ module atmosphere
# For now, they are just stored inside the atmos struct

# Print info on the gases
@info "Allocated atmosphere with composition:"
@info "Allocating atmosphere with composition:"
gas_flags::String = ""
g::String = ""
for i in 1:atmos.gas_num
Expand Down Expand Up @@ -1313,6 +1319,7 @@ module atmosphere
atmos.surface_material = abspath(atmos.surface_material)
if !isfile(atmos.surface_material)
@error "Could not find surface albedo file '$(atmos.surface_material)'"
@error "Get these data with `\$ ./src/get_data.sh surfaces`"
return false
end

Expand Down
6 changes: 4 additions & 2 deletions src/energy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,15 @@ module energy
# Normalised contribution function (only LW stream contributes)
fill!(atmos.contfunc_norm,0.0)
if calc_cf
cf_max::Float64 = maximum(atmos.radout.contrib_funcf_band[1,:,:])
bw_nm::Float64 = 0.0
for ba in 1:atmos.dimen.nd_channel
bw_nm = atmos.bands_wid[ba] * 1e9
for lv in 1:atmos.nlev_c
atmos.contfunc_norm[lv,ba] =
atmos.radout.contrib_funcf_band[1,lv,ba]/cf_max
atmos.radout.contrib_funcf_band[1,lv,ba]/bw_nm
end
end
atmos.contfunc_norm /= maximum(atmos.contfunc_norm)
end
atmos.is_out_lw = true

Expand Down
8 changes: 3 additions & 5 deletions src/get_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ help_surfaces="Get a collection of surface single-scattering albedos"
help_realgas="Get a real-gas EOS coefficients and lookup tables"
help_thermo="Get lookup data for thermodynamics (heat capacities, etc.)"
help="\
Helper script used to download and unpack data used to run the model.
Download and unpack data used to run the model.

Call structure:
./get_data [TARGET]
$ get_data.sh [TARGET]

Where [TARGET] can be any of the following:
basic
Expand All @@ -57,7 +57,7 @@ Where [TARGET] can be any of the following:
realgas
$help_realgas
thermodynamics
$help_thermo
$help_thermo\
"

# Generic OSF downloader function
Expand Down Expand Up @@ -194,6 +194,4 @@ function handle_request {

handle_request $1

echo "Done!"

exit 0
9 changes: 7 additions & 2 deletions src/get_fastchem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ cd build
cmake ".."
make

cd ..
export FC_DIR="$(realpath $fcpath)"
cd $root
export FC_DIR=$fcpath

echo "FastChem has been installed"
echo "It is recommended that you add the following line to your shell rc file"
echo "export FC_DIR='$fcpath'"
exit 0
2 changes: 1 addition & 1 deletion src/get_socrates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cd "$socpath"

# Environment
export RAD_DIR=$socpath
cd ..
cd $root

# Inform user
echo "SOCRATES has been installed"
Expand Down
2 changes: 1 addition & 1 deletion src/phys.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ end
module phys

using NCDatasets
using PCHIPInterpolation
using LoggingExtras
import PCHIPInterpolation:Interpolator

# Sources:
# - Pierrehumbert (2010)
Expand Down
2 changes: 1 addition & 1 deletion src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module plotting
# Import stuff
using Plots
using LaTeXStrings
using Glob
using Printf
using FFMPEG
import Glob:glob

import ..atmosphere
import ..phys
Expand Down
2 changes: 1 addition & 1 deletion src/realgas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module realgas

using ScatteredInterpolation # 2D interpolation
using LoggingExtras
using DelimitedFiles
import DelimitedFiles:readdlm

mutable struct Aqua_t

Expand Down
2 changes: 1 addition & 1 deletion src/setpt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module setpt
import ..phys
import ..atmosphere

using PCHIPInterpolation
using NCDatasets
using LoggingExtras
import PCHIPInterpolation:Interpolator

# Read atmosphere T(p) from a CSV file (does not overwrite p_boa and p_toa)
function fromcsv!(atmos::atmosphere.Atmos_t, fpath::String)
Expand Down
4 changes: 2 additions & 2 deletions src/spectrum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module spectrum

using LoggingExtras
using Printf
using PCHIPInterpolation
using DelimitedFiles
using LinearAlgebra
import PCHIPInterpolation:Interpolator
import DelimitedFiles:readdlm

"""
**Validate spectral file.**
Expand Down