diff --git a/docs/src/diagnostics/developers_diagnostics.md b/docs/src/diagnostics/developers_diagnostics.md index 133c8826fa..a1ed75c1f1 100644 --- a/docs/src/diagnostics/developers_diagnostics.md +++ b/docs/src/diagnostics/developers_diagnostics.md @@ -40,10 +40,10 @@ It defines how to access your diagnostic (here, p.bucket.α\_sfc) with the land\ Note that you can also use the @diagnostic\_compute macro to do the same thing: ```Julia -@diagnostic\_compute "albedo" BucketModel p.bucket.α\_sfc +@diagnostic_compute "albedo" BucketModel p.bucket.α\_sfc ``` -The @with\_error macro define helper functions returning error messages if a user tries to compute a diagnostic variable that doesn't exist in their model type. +The `@with_error` macro define helper functions returning error messages if a user tries to compute a diagnostic variable that doesn't exist in their model type. # Define diagnostics diff --git a/docs/src/diagnostics/users_diagnostics.md b/docs/src/diagnostics/users_diagnostics.md index c61c4da2a4..143ca80922 100644 --- a/docs/src/diagnostics/users_diagnostics.md +++ b/docs/src/diagnostics/users_diagnostics.md @@ -137,3 +137,28 @@ my_custom_diagnostics = ["lhf", "bor"] diags = seasonal_maxs(my_custom_diagnostics...; output_writer, t_start) ``` +### Analyze your simulation output + +Once you've run your simulation and created an output folder (e.g., output\_dir) with diagnostics, you can use [ClimaAnalysis](https://github.com/CliMA/ClimaAnalysis.jl) +to access and analyze your data. For in depth documentation about ClimaAnalysis, see its [documentation](https://clima.github.io/ClimaAnalysis.jl/stable/). + +Here is an example of how to plot a variable: + +```Julia +import ClimaAnalysis + +import ClimaAnalysis.Visualize as viz + +import CairoMakie # the plotting package used by ClimaAnalysis + +simdir = ClimaAnalysis.SimDir(output_dir) # where output_dir is where you saved your diagnostics. + +var = get(simdir; "lhf") # assuming lhf, latent_heat_flux used as an example above, is one of your diagnostics variables. + +fig = CairoMakie.Figure() # creates an empty figure object + +viz.plot!(fig, var) # creates an axis inside fig, and plot your var in it. + +CairoMakie.save(fig) # saves the figure in current working directory +``` + diff --git a/test/diagnostics/diagnostics_tests.jl b/test/diagnostics/diagnostics_tests.jl index 29ff4acdb6..35eb2b5e89 100644 --- a/test/diagnostics/diagnostics_tests.jl +++ b/test/diagnostics/diagnostics_tests.jl @@ -1,5 +1,6 @@ using Test using ClimaLand +using ClimaLand.Diagnostics: @with_error @test isdefined(ClimaLand.Diagnostics, :compute_albedo!) @@ -9,7 +10,22 @@ using ClimaLand ) # Define some diagnostics for a DummyModel + +@test ClimaLand.Diagnostics.ALL_DIAGNOSTICS isa Dict +@test length(ClimaLand.Diagnostics.ALL_DIAGNOSTICS) == 0 struct DummyModel end +ClimaLand.Diagnostics.@diagnostic_compute "albedo" DummyModel p.foo.bar + +ClimaLand.Diagnostics.add_diagnostic_variable!( + short_name = "alpha", + long_name = "Albedo", + standard_name = "albedo", + units = "", + compute! = (out, Y, p, t) -> compute_albedo!(out, Y, p, t, land_model), +) + +@test length(ClimaLand.Diagnostics.ALL_DIAGNOSTICS) == 1 + ClimaLand.Diagnostics.define_diagnostics!(DummyModel()) # Just to trigger the error