Skip to content

Commit

Permalink
This commit adds a diagnostics test for ALL_DIAGNOSTICS
Browse files Browse the repository at this point in the history
In this commit, we check if ALL_DIAGNOSTICS isa Dict, check if its
length is 0. Then we add a diagnostic variable, and check if its new
length is 1.
  • Loading branch information
AlexisRenchon committed Aug 30, 2024
1 parent 2954b39 commit cc7b705
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/src/diagnostics/developers_diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Note that you can also use the @diagnostic\_compute macro to do the same thing:
@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

Expand Down
25 changes: 25 additions & 0 deletions docs/src/diagnostics/users_diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

16 changes: 16 additions & 0 deletions test/diagnostics/diagnostics_tests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Test
using ClimaLand
using ClimaLand.Diagnostics: @with_error

@test isdefined(ClimaLand.Diagnostics, :compute_albedo!)

Expand All @@ -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
Expand Down

0 comments on commit cc7b705

Please sign in to comment.