Skip to content

Commit

Permalink
Add graph
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum committed Jul 19, 2023
1 parent 5f74200 commit 992f6c5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install Julia
uses: julia-actions/setup-julia@v1
with:
version: 1.5
version: 1.9
# NOTE
# The steps below ensure that NodeJS and Franklin are loaded then it
# installs highlight.js which is needed for the prerendering step
Expand Down
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand All @@ -7,8 +8,10 @@ EarthSciData = "a293c155-435f-439d-9c11-a083b6b47337"
EarthSciMLBase = "e53f1632-a13c-4728-9402-0c66d48804b0"
Franklin = "713c75ef-9fc9-4b05-94a9-213340da978e"
GasChem = "58070593-4751-4c87-a5d1-63807d11d76c"
GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377"
MethodOfLines = "94925ecb-adb7-4558-8ed8-f975c56a0bf4"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
NodeJS = "2bd173c7-0d6d-553b-b6af-13a54713934c"
Expand Down
40 changes: 27 additions & 13 deletions tutorials/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ tags = ["syntax", "code"]
using EarthSciData, EarthSciMLBase, GasChem,
DomainSets, ModelingToolkit, MethodOfLines,
DifferentialEquations, Dates, Distributions,
Latexify, Plots, SciMLBase
Latexify, Plots, SciMLBase,
CairoMakie, GraphMakie, MetaGraphsNext
@parameters t lev lon lat
model = SuperFast(t)
ls = latexify(model.rxn_sys) # TODO: Change to model.rxn_sys
print(replace(ls.s, "\require{mhchem}" => "")) # hide
print(replace(ls.s, raw"\require{mhchem}" => "")) # hide
```

This is what `ls` looks like:
Expand All @@ -46,11 +47,13 @@ prob = ODEProblem(structural_simplify(get_mtk(model_ode)), [], (start, finish),
sol = solve(prob, TRBDF2(), saveat=1800.0)
# Plot result.
ticks = Dates.datetime2unix.([Dates.DateTime(2022, 5, 1), Dates.DateTime(2022, 5, 2), Dates.DateTime(2022, 5, 3)])
ticks = Dates.datetime2unix.([Dates.DateTime(2022, 5, 1), Dates.DateTime(2022, 5, 2),
Dates.DateTime(2022, 5, 3)])
tickstrings = Dates.format.(Dates.unix2datetime.(ticks), "m-d-yy")
plot(sol,ylims=(0,15),xlabel="Date", ylabel="Concentration (ppb)", ylabelfontsize=9, xlabelfontsize=9,
Plots.plot(sol,ylims=(0,30),xlabel="Date", ylabel="Concentration (ppb)",
ylabelfontsize=9, xlabelfontsize=9,
xticks=(ticks, tickstrings), legend=:outertopright, size=(500, 310))
savefig(joinpath(@OUTPUT, "ode.svg")) # hide
Plots.savefig(joinpath(@OUTPUT, "ode.svg")) # hide
```

\textoutput{./code/ex2}
Expand Down Expand Up @@ -94,7 +97,7 @@ SciMLBase.observed(sol::SciMLBase.AbstractTimeseriesSolution, sym, i::Colon) = z
\textoutput{./code/ex4}

## Figure 4
```julia:./code/ex5
```julia:./code/ex5a
domain = DomainInfo(
partialderivatives_lonlat2xymeters,
constIC(1.0f0, t ∈ Interval(start, finish)),
Expand All @@ -105,12 +108,23 @@ geos = GEOSFP("0.25x0.3125_NA", t; coord_defaults = Dict(:lat => 34.0, :lev => 1
model = SuperFast(t) + FastJX(t) + domain +
Emissions(t, -118.2, 0.2)+ Advection() + geos
g = graph(model)
f, ax, p = graphplot(g; ilabels=labels(g))
hidedecorations!(ax); hidespines!(ax); ax.aspect = DataAspect()
save(joinpath(@OUTPUT, "graph.svg"), f) # hide
```
\output{./code/ex5a}
\fig{graph}

```julia:./code/ex5b
discretization = MOLFiniteDifference([lon => 50], t, approx_order=2)
prob = discretize(get_mtk(model), discretization)
sol = solve(prob, TRBDF2(), saveat=3600.0)
```

\textoutput{./code/ex5}
\output{./code/ex5b}

## Supplemental plotting code
```julia:./code/ex6
Expand All @@ -124,20 +138,20 @@ sol_no = sol[superfast₊NO(t, lon)]
sol_no2 = sol[superfast₊NO2(t, lon)]
using LaTeXStrings
plot(
heatmap(discrete_t, discrete_lon[1:end], sol_isop[:, 1:end]',
Plots.plot(
Plots.heatmap(discrete_t, discrete_lon[1:end], sol_isop[:, 1:end]',
xticks=(ticks, tickstrings),
ylabel="Longitude (°)", title="Isoprene", titlefontsize=12,
margin=0Plots.mm,
size=(600, 400), dpi=300),
heatmap(discrete_t, discrete_lon[1:end], sol_no[:, 1:end]',
Plots.heatmap(discrete_t, discrete_lon[1:end], sol_no[:, 1:end]',
xticks=(ticks, tickstrings), title="NO", titlefontsize=12),
heatmap(discrete_t, discrete_lon[1:end], sol_no2[:, 1:end]',
Plots.heatmap(discrete_t, discrete_lon[1:end], sol_no2[:, 1:end]',
xticks=(ticks, tickstrings), xlabel="Date", title=L"\textrm{NO_2}"),
heatmap(discrete_t, discrete_lon[1:end], sol_o3[:, 1:end]',colorbar_title="Concentration (ppb)",
Plots.heatmap(discrete_t, discrete_lon[1:end], sol_o3[:, 1:end]',colorbar_title="Concentration (ppb)",
xticks=(ticks, tickstrings), title=L"\textrm{O_3}", titlefontsize=12),
)
savefig(joinpath(@OUTPUT, "pde.svg"))
Plots.savefig(joinpath(@OUTPUT, "pde.svg"))
```

\textoutput{./code/ex6}
Expand Down

0 comments on commit 992f6c5

Please sign in to comment.