Skip to content

Commit

Permalink
Use artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed May 22, 2024
1 parent 4f8a838 commit e2fc12b
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 44 deletions.
7 changes: 7 additions & 0 deletions Artifacts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ git-tree-sha1 = "9da4af348af2606764e5e2c94d9439714221dff1"
[[aerosol2005.download]]
sha256 = "952d723b8462439c266dc0df79d0d4e71f774559edb941e03b7979e8ad743f56"
url = "https://caltech.box.com/shared/static/chmel1vdthfvfac0yl61ayw2jqnjzr2c.gz"

[atmos_held_suarez_obs]
git-tree-sha1 = "d93ff2958e12d6bba6e8343bfa73554390df52e4"

[[atmos_held_suarez_obs.download]]
sha256 = "f5d63df2bab849632bd2fcd5a4e3165465d1898e1a5fbee6e5fe07f5b3e57fc3"
url = "https://caltech.box.com/shared/static/sbn6afsgn2xzxi5n0ffs928otstshjvi.gz"
16 changes: 12 additions & 4 deletions calibration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ To run an experiment, open julia with the project in the experiment directory:
Then run the following code:

```julia
import ClimaCalibrate: calibrate, CaltechHPC, get_prior, kwargs
import ClimaCalibrate: calibrate, ExperimentConfig, CaltechHPC, get_prior, kwargs
using ClimaUtilities.ClimaArtifacts
import JLD2: load_object

experiment_dir = dirname(Base.active_project())
include(joinpath(experiment_dir, "observation_map.jl"))

slurm_kwargs = kwargs(time = 90, ntasks = 8, cpus_per_task = 16)
eki = calibrate(CaltechHPC, experiment_dir; slurm_kwargs, verbose=true)
artifact_path = @clima_artifact("atmos_held_suarez_obs")
observations = load_object(joinpath(artifact_path, "obs_mean.jld2"))
noise = load_object(joinpath(@clima_artifact("atmos_held_suarez_obs"), "obs_noise_cov.jld2"))
prior = get_prior(joinpath(experiment_dir, "prior.toml"))

experiment_config = ExperimentConfig(2, 10, observations, noise, prior, "output/sphere_held_suarez_rhoe_equilmoist", false)
slurm_kwargs = kwargs(time = 90, ntasks = 8)
eki = calibrate(CaltechHPC, experiment_config; slurm_kwargs, verbose=true)

include(joinpath(experiment_dir, "postprocessing.jl"))
convergence_plot(eki, get_prior(joinpath(experiment_dir, "prior.toml")))
convergence_plot(eki, prior)
scatter_plot(eki)
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.3"
manifest_format = "2.0"
project_hash = "194c921250be8966865640f3ff112d10d7f323fa"
project_hash = "662aeda187ef55e20754ee64b3bea95f814d7055"

[[deps.ADTypes]]
git-tree-sha1 = "9b3993053b87311e699ac9e1bcabec5ae7444f65"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
ClimaAnalysis = "29b5916a-a76c-4e73-9657-3c8fd22e65e6"
ClimaAtmos = "b2c96348-7fb7-4fe0-8da9-78d88439e717"
ClimaCalibrate = "4347a170-ebd6-470c-89d3-5c705c0cacc2"
ClimaUtilities = "b3f4f4ca-9299-4f7f-bd9b-81e1242a7513"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
EnsembleKalmanProcesses = "aa8a2aa5-91d8-4396-bcef-d4f2ec43552d"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
prior: prior.toml
ensemble_size: 10
n_iterations: 2
observations: obs_mean.jld2
noise: obs_noise_cov.jld2
observations: /groups/esm/ClimaArtifacts/artifacts/atmos_held_suarez_obs/obs_mean.jld2
noise: /groups/esm/ClimaArtifacts/artifacts/atmos_held_suarez_obs/obs_noise_cov.jld2
output_dir: output/sphere_held_suarez_rhoe_equilmoist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ forcing: held_suarez
precip_model: 0M
job_id: sphere_held_suarez_rhoe_equilmoist
output_dir: output/sphere_held_suarez_rhoe_equilmoist
restart_file: day200.0.hdf5
restart_file: /groups/esm/ClimaArtifacts/artifacts/atmos_held_suarez_obs/day200.0.hdf5
output_default_diagnostics: false
diagnostics:
- reduction_time: average
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ using Statistics
import YAML
import EnsembleKalmanProcesses: TOMLInterface
import JLD2
import ClimaCalibrate: observation_map, ExperimentConfig
import ClimaCalibrate: observation_map
using ClimaAnalysis
export observation_map

function observation_map(iteration)
configuration = ExperimentConfig(dirname(Base.active_project()))
(; ensemble_size, output_dir) = configuration

ensemble_size = 10
output_dir = joinpath("output", "sphere_held_suarez_rhoe_equilmoist")
dims = 1
G_ensemble = Array{Float64}(undef, dims..., ensemble_size)
for m in 1:ensemble_size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,21 @@ function convergence_plot(
Makie.save(joinpath(output, "convergence.png"), f)
end

function scatter_plot(eki, output = joinpath("output", "sphere_held_suarez_rhoe_equilmoist"))
function scatter_plot(
eki,
output = joinpath("output", "sphere_held_suarez_rhoe_equilmoist"),
)
# Define figure with explicit size
f = Makie.Figure(resolution = (800, 600))
a = Makie.Axis(f[1, 1], title = "60-Day Zonal Avg Temp at 242m versus Unconstrained Equator-Pole Temp Gradient", ylabel = "Parameter Value", xlabel = "Temperature (K)")
a = Makie.Axis(
f[1, 1],
title = "60-Day Zonal Avg Temp at 242m versus Unconstrained Equator-Pole Temp Gradient",
ylabel = "Parameter Value",
xlabel = "Temperature (K)",
)

g = vec.(EKP.get_g(eki; return_array=true))
u = vec.(EKP.get_u(eki; return_array=true))
g = vec.(EKP.get_g(eki; return_array = true))
u = vec.(EKP.get_u(eki; return_array = true))

for (gg, uu) in zip(g, u)
Makie.scatter!(a, gg, uu)
Expand Down
14 changes: 6 additions & 8 deletions calibration/model_interface.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ClimaAtmos as CA
import YAML
using ClimaUtilities.ClimaArtifacts

import ClimaCalibrate:
set_up_forward_model, run_forward_model, path_to_ensemble_member

Expand All @@ -11,15 +13,11 @@ If given an experiment id string, it will load the config from the corresponding
Turns off default diagnostics and sets the TOML parameter file to the member's path.
This assumes that the config dictionary has `output_dir` and `restart_file` keys.
"""
function set_up_forward_model(
member,
iteration,
experiment_dir::AbstractString,
)
function set_up_forward_model(member, iteration, experiment_dir::AbstractString)
config_dict = YAML.load_file(joinpath(experiment_dir, "model_config.yml"))
if haskey(config_dict, "restart_file")
config_dict["restart_file"] =
joinpath(experiment_dir, config_dict["restart_file"])
# If relative path, append experiment dir
if haskey(config_dict, "restart_file") && !isabspath(config_dict["restart_file"])
config_dict["restart_file"] = joinpath(experiment_dir, config_dict["restart_file"])
end
output_dir = config_dict["output_dir"]
member_path = path_to_ensemble_member(output_dir, iteration, member)
Expand Down
25 changes: 5 additions & 20 deletions test/calibration_interface.jl
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
# Tests for ensuring that the calibration/model interface sets AtmosConfig correctly.

# To run: julia --project=calibration/experiments/sphere_held_suarez_rhoe_equilmoist test/calibration_interface.jl
import ClimaCalibrate
using Test

experiment_id = "sphere_held_suarez_rhoe_equilmoist"
experiment_dir = dirname(Base.active_project())
include(joinpath("..", "calibration", "model_interface.jl"))

member_path = joinpath("test_output", "iteration_001", "member_001")
member_path = joinpath("output", "sphere_held_suarez_rhoe_equilmoist", "iteration_001", "member_001")
file_path = joinpath(member_path, "parameters.toml")
mkpath(dirname(file_path))
touch(file_path)

config_dict = Dict{Any, Any}(
"restart_file" => joinpath(
"..",
"calibration",
"experiments",
"sphere_held_suarez_rhoe_equilmoist",
"day200.0.hdf5",
),
"dt_save_to_disk" => "100days",
"moist" => "equil",
"forcing" => "held_suarez",
"output_dir" => "test_output",
)

physical_model = ClimaCalibrate.get_forward_model(Val(Symbol(experiment_id)))
atmos_config = ClimaCalibrate.get_config(physical_model, 1, 1, config_dict)
atmos_config = ClimaCalibrate.set_up_forward_model(1, 1, experiment_dir)
(; parsed_args) = atmos_config

@testset "Atmos Configuration" begin
@test parsed_args["moist"] == "equil"
@test parsed_args["toml"] == [file_path]
@test parsed_args["output_dir"] == member_path
@test parsed_args["restart_file"] == config_dict["restart_file"]
@test parsed_args["restart_file"] == "/groups/esm/ClimaArtifacts/artifacts/atmos_held_suarez_obs/day200.0.hdf5"
end

rm(file_path)

0 comments on commit e2fc12b

Please sign in to comment.