From 8d005ab34686f6d9021242ec5914a9d46ea07e7d Mon Sep 17 00:00:00 2001 From: nefrathenrici Date: Fri, 20 Oct 2023 11:43:21 -0700 Subject: [PATCH] Use PrettyTables for Available Diagnostics docs --- .gitignore | 3 --- docs/make.jl | 1 - docs/make_diagnostic_table.jl | 32 ------------------------------- docs/src/available_diagnostics.md | 6 ++++++ docs/src/make_diagnostic_table.jl | 27 ++++++++++++++++++++++++++ 5 files changed, 33 insertions(+), 36 deletions(-) delete mode 100644 docs/make_diagnostic_table.jl create mode 100644 docs/src/available_diagnostics.md create mode 100644 docs/src/make_diagnostic_table.jl diff --git a/.gitignore b/.gitignore index 5de6569e9c..d59f15fdb9 100644 --- a/.gitignore +++ b/.gitignore @@ -22,9 +22,6 @@ deps/src/ docs/build/ docs/site/ -# File generated by make_available_diagnostics.jl -docs/src/available_diagnostics.md - # File generated by Pkg, the package manager, based on a corresponding Project.toml # It records a fixed state of all packages used by the project. As such, it should not be # committed for packages, but should be committed for applications that require a static diff --git a/docs/make.jl b/docs/make.jl index 1d32681b03..c044c61b27 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -10,7 +10,6 @@ bib = CitationBibliography(joinpath(@__DIR__, "bibliography.bib")) doctest(ClimaAtmos; plugins = [bib]) disable_logging(Base.CoreLogging.BelowMinLevel) # Re-enable all logging -include("make_diagnostic_table.jl") makedocs(; plugins = [bib], modules = [ClimaAtmos], diff --git a/docs/make_diagnostic_table.jl b/docs/make_diagnostic_table.jl deleted file mode 100644 index ee6d007ae7..0000000000 --- a/docs/make_diagnostic_table.jl +++ /dev/null @@ -1,32 +0,0 @@ -import ClimaAtmos as CA - -# Read all the diagnostics we know how to compute, and print them into a -# markdown table that is later compiled into the docs - -# basename(pwd()) if the code is run from inside the docs folder. If we don't -# have that, we will assume that we are running from the project root. If this -# code is run from anywhere but these two places, mkdocs will fail to find -# availbale_diagnostics.md -prefix = basename(pwd()) == "docs" ? "" : "docs/" - -out_path = "$(prefix)src/available_diagnostics.md" - -open(out_path, "w") do file - - write(file, "# Available diagnostic variables\n\n") - - write( - file, - "| Short name | Long name | Standard name | Units | Comments |\n", - ) - write(file, "|---|---|---|---|---|\n") - - for d in values(CA.Diagnostics.ALL_DIAGNOSTICS) - write(file, "| `$(d.short_name)` ") - write(file, "| $(d.long_name) ") - write(file, "| `$(d.standard_name)` ") - write(file, "| $(d.units) ") - write(file, "| $(d.comments)|\n") - end -end -@info "Written $out_path" diff --git a/docs/src/available_diagnostics.md b/docs/src/available_diagnostics.md new file mode 100644 index 0000000000..3642907644 --- /dev/null +++ b/docs/src/available_diagnostics.md @@ -0,0 +1,6 @@ +# Available diagnostic variables + +Autogenerate table of available diagnostics: +```@example +include("make_diagnostic_table.jl") +``` diff --git a/docs/src/make_diagnostic_table.jl b/docs/src/make_diagnostic_table.jl new file mode 100644 index 0000000000..f1ecba38e6 --- /dev/null +++ b/docs/src/make_diagnostic_table.jl @@ -0,0 +1,27 @@ +import ClimaAtmos as CA +using PrettyTables + +# Print all available diagnostics to an ASCII table + +short_names = [] +long_names = [] +units = [] +comments = [] +standard_names = [] +for d in values(CA.Diagnostics.ALL_DIAGNOSTICS) + push!(short_names, d.short_name) + push!(long_names, d.long_name) + push!(units, d.units) + push!(comments, d.comments) + push!(standard_names, d.standard_name) +end +data = hcat(short_names, long_names, units, comments, standard_names) +pretty_table( + data; + autowrap = true, + linebreaks = true, + columns_width = [10, 15, 8, 32, 15], # Width = 80 + body_hlines = collect(1:size(data)[1]), + header = ["Short name", "Long name", "Units", "Comments", "Standard name"], + alignment = :l, +)