Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include bucket diagnostics #978

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ClimaCoupler.jl Release Notes
============================

`main`
-------

### ClimaEarth features

### Sea-surface temperature and sea ice concentration data can now be automatically downloaded

Sea-surface temperature and sea ice concentration require external files. Now, a
low-resolution version of such files is automatically downloaded when a
higher-resolution version is not available. Please, refer to
[ClimaArtifacts](https://github.com/CliMA/ClimaArtifacts) for more information.

2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ authors = ["CliMA Contributors <clima-software@caltech.edu>"]
version = "0.1.1"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"
ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
ClimaCoreTempestRemap = "d934ef94-cdd4-4710-83d6-720549644b70"
Expand All @@ -17,6 +18,7 @@ SurfaceFluxes = "49b00bb7-8bd4-4f2b-b78c-51cd0450215f"
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"

[compat]
Artifacts = "1"
ClimaComms = "0.5.6, 0.6"
ClimaCore = "0.14.6"
ClimaCoreTempestRemap = "0.3"
Expand Down
9 changes: 8 additions & 1 deletion experiments/ClimaEarth/Artifacts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ git-tree-sha1 = "7486bf32e9352493f69364aead26f01eaf90d2af"
git-tree-sha1 = "945e31f8028a581f7e8435cb691462124484567a"

[historical_sst_sic]
git-tree-sha1 = "c4f82cd33fb26513ee45bff78330c6b606630fa5"
git-tree-sha1 = "0d30d71a6f9b6548fe7395ca647e853ec36d1699"

[historical_sst_sic_lowres]
git-tree-sha1 = "7f7b6d4ae6055c4c2b6a6dfba5be8b4e6ca1b0be"

[[historical_sst_sic_lowres.download]]
sha256 = "b68c0ce6ea682c38e29cb87c9c6ced6736ecac32d0d32dbaba78beb66046a06c"
url = "https://caltech.box.com/shared/static/ufnesb00zkvlc3sxzhnnmqc3zbatxkb9.gz"
8 changes: 4 additions & 4 deletions experiments/ClimaEarth/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.5"
manifest_format = "2.0"
project_hash = "3f041ae318abcda7361d1017b4769284277fd054"
project_hash = "068d169322176676d4a2ff1e87cafb47cc58b76b"

[[deps.ADTypes]]
git-tree-sha1 = "5a5eafb8344b81b8c2237f8a6f6b3602b3f6180e"
Expand Down Expand Up @@ -334,16 +334,16 @@ uuid = "d934ef94-cdd4-4710-83d6-720549644b70"
version = "0.3.17"

[[deps.ClimaCoupler]]
deps = ["ClimaComms", "ClimaCore", "ClimaCoreTempestRemap", "Dates", "JLD2", "NCDatasets", "SciMLBase", "StaticArrays", "SurfaceFluxes", "Thermodynamics"]
deps = ["Artifacts", "ClimaComms", "ClimaCore", "ClimaCoreTempestRemap", "Dates", "JLD2", "Logging", "NCDatasets", "SciMLBase", "StaticArrays", "SurfaceFluxes", "Thermodynamics"]
path = "../.."
uuid = "4ade58fe-a8da-486c-bd89-46df092ec0c7"
version = "0.1.1"

[[deps.ClimaDiagnostics]]
deps = ["Accessors", "ClimaComms", "ClimaCore", "Dates", "NCDatasets", "SciMLBase"]
git-tree-sha1 = "9526b91533254b043e860e17568555d21d1d041e"
git-tree-sha1 = "ae8854e55028856675294f744ca7a6a3a3bd75bc"
uuid = "1ecacbb8-0713-4841-9a07-eb5aa8a2d53f"
version = "0.2.6"
version = "0.2.7"

[[deps.ClimaLand]]
deps = ["ArtifactWrappers", "ClimaComms", "ClimaCore", "ClimaDiagnostics", "ClimaUtilities", "Dates", "DocStringExtensions", "Insolation", "Interpolations", "LazyArtifacts", "LinearAlgebra", "NCDatasets", "SciMLBase", "StaticArrays", "SurfaceFluxes", "Thermodynamics"]
Expand Down
1 change: 1 addition & 0 deletions experiments/ClimaEarth/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"
ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
ClimaCorePlots = "cf7c7e5a-b407-4c48-9047-11a94a308626"
ClimaCoupler = "4ade58fe-a8da-486c-bd89-46df092ec0c7"
ClimaDiagnostics = "1ecacbb8-0713-4841-9a07-eb5aa8a2d53f"
ClimaLand = "08f4d4ce-cf43-44bb-ad95-9d2d5f413532"
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
ClimaTimeSteppers = "595c0a79-7f3d-439a-bc5a-b232dc3bde79"
Expand Down
22 changes: 21 additions & 1 deletion experiments/ClimaEarth/components/land/climaland_bucket.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ClimaParams
import Thermodynamics as TD
import ClimaLand as CL
import ClimaLand.Parameters as LP
import ClimaDiagnostics as CD
import ClimaCoupler: Checkpointer, FluxCalculator, Interfacer

###
Expand Down Expand Up @@ -69,6 +70,9 @@ function bucket_init(
@assert config == "sphere"
end

regrid_dirpath = dir_paths.regrid
artifacts_dir = dir_paths.artifacts

α_snow = FT(0.8) # snow albedo
if albedo_type == "map_static" # Read in albedo from static data file (default type)
# By default, this uses a file containing bareground albedo without a time component. Snow albedo is specified separately.
Expand Down Expand Up @@ -136,7 +140,23 @@ function bucket_init(
ode_algo = CTS.ExplicitAlgorithm(stepper)
bucket_ode_function = CTS.ClimaODEFunction(T_exp! = exp_tendency!, dss! = CL.dss!)
prob = SciMLBase.ODEProblem(bucket_ode_function, Y, tspan, p)
integrator = SciMLBase.init(prob, ode_algo; dt = dt, saveat = saveat, adaptive = false)

# Add diagnostics
netcdf_writer = CD.Writers.NetCDFWriter(space, artifacts_dir)
scheduled_diagnostics = CL.default_diagnostics(model, date_ref, output_writer = netcdf_writer)

diagnostic_handler = CD.DiagnosticsHandler(scheduled_diagnostics, Y, p, t_start; dt = dt)
diag_cb = CD.DiagnosticsCallback(diagnostic_handler)
# TODO: after CD update, can use `integrator = CD.IntegratorWithDiagnostics(integrator, scheduled_diagnostics, state_name = :Y)`

integrator = SciMLBase.init(
prob,
ode_algo;
dt = dt,
saveat = saveat,
adaptive = false,
callback = SciMLBase.CallbackSet(diag_cb),
)

sim = BucketSimulation(model, Y, (; domain = domain, soil_depth = d_soil), integrator, area_fraction)

Expand Down
22 changes: 19 additions & 3 deletions experiments/ClimaEarth/run_amip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,24 @@ The data files are downloaded from the `ClimaCoupler` artifacts directory. If th
original sources.
=#
include(joinpath(pkgdir(ClimaCoupler), "artifacts", "artifact_funcs.jl"))
sst_data = joinpath(@clima_artifact("historical_sst_sic", comms_ctx), "MODEL.SST.HAD187001-198110.OI198111-202206.nc")
sic_data = joinpath(@clima_artifact("historical_sst_sic", comms_ctx), "MODEL.ICE.HAD187001-198110.OI198111-202206.nc")

if Utilities.artifact_exists("historical_sst_sic")
sst_data =
joinpath(@clima_artifact("historical_sst_sic", comms_ctx), "MODEL.SST.HAD187001-198110.OI198111-202206.nc")
sic_data =
joinpath(@clima_artifact("historical_sst_sic", comms_ctx), "MODEL.ICE.HAD187001-198110.OI198111-202206.nc")
else
ClimaComms.iamroot(comms_ctx) &&
@warn "Using lowres sst sic. If you want the higher resolution version, you have to obtain it from ClimaArtifacts"
sst_data = joinpath(
@clima_artifact("historical_sst_sic_lowres", comms_ctx),
"MODEL.SST.HAD187001-198110.OI198111-202206_lowres.nc",
)
sic_data = joinpath(
@clima_artifact("historical_sst_sic_lowres", comms_ctx),
"MODEL.ICE.HAD187001-198110.OI198111-202206_lowres.nc",
)
end
co2_data = joinpath(co2_dataset_path(), "mauna_loa_co2.nc")
land_mask_data = joinpath(mask_dataset_path(), "seamask.nc")

Expand Down Expand Up @@ -252,7 +268,7 @@ if mode_name == "amip"
config_dict["land_domain_type"],
config_dict["land_albedo_type"],
config_dict["land_temperature_anomaly"],
dir_paths.regrid;
dir_paths;
dt = Δt_cpl,
space = boundary_space,
saveat = saveat,
Expand Down
19 changes: 19 additions & 0 deletions src/Utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,31 @@ modules in the coupler.
"""
module Utilities

import Artifacts
import ClimaComms
import ClimaCore as CC
import Logging

export swap_space!

"""
artifact_exists(name)

Return whether the artifact with the given name exists and is available to use.
"""
function artifact_exists(name)
# There seems to be no easy way to determine if an artifact exists from the name
# only...
return try
# We need to macroexpand because we only want to resolve @artifact_str when
# we call this function
@macroexpand Artifacts.@artifact_str(name)
true
catch error
false
end
end

"""
swap_space!(space_out::CC.Spaces.AbstractSpace, field_in::CC.Fields.Field)

Expand Down
Loading