Skip to content

Commit

Permalink
Add support for reading input maps
Browse files Browse the repository at this point in the history
Okay, this is a massive commit (and I feel bad about it).

This commit splits PrescribedDataStatic and PrescibedDataTemporal in
multiple independent modules.

Before, PrescribedData was:
- reading files
- regridding
- discovering dates available
- interpolating
- taking care of edge cases (e.g., what to do when reading outside of
where the date is outside of the definition range)

This commit splits all the different functions in different independent
modules so that they can be more easily maintained and upgraded.

This will soon be needed to efficiently support reading and buffering
reads for GPU runs.
  • Loading branch information
Sbozzolo committed Mar 14, 2024
1 parent 1775977 commit 44d1a3f
Show file tree
Hide file tree
Showing 23 changed files with 1,265 additions and 1,588 deletions.
18 changes: 9 additions & 9 deletions docs/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.10.1"
julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "5f713b750235cf07465e21e92a6bd2f152ad3358"

Expand Down Expand Up @@ -273,9 +273,9 @@ version = "0.5.7"

[[deps.ClimaCore]]
deps = ["Adapt", "BandedMatrices", "BlockArrays", "CUDA", "ClimaComms", "CubedSphere", "DataStructures", "DocStringExtensions", "ForwardDiff", "GaussQuadrature", "GilbertCurves", "HDF5", "InteractiveUtils", "IntervalSets", "KrylovKit", "LinearAlgebra", "PkgVersion", "RecursiveArrayTools", "RootSolvers", "SparseArrays", "Static", "StaticArrays", "Statistics", "Unrolled"]
git-tree-sha1 = "bc6a0154e3bcc1657d3a75f697e216fb70121969"
git-tree-sha1 = "844afbd6a7c4f112f974e0031ebf4fb13d0b4157"
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
version = "0.13.2"
version = "0.13.1"
weakdeps = ["Krylov"]

[deps.ClimaCore.extensions]
Expand All @@ -299,9 +299,9 @@ weakdeps = ["ClimaParams"]

[[deps.ClimaParams]]
deps = ["DocStringExtensions", "TOML", "Test"]
git-tree-sha1 = "ec67949db856e01df4cbf7d6ddafefeda02f93ee"
git-tree-sha1 = "323dd6c5423caf31f0da81bb9c288683cbdafb01"
uuid = "5c42b081-d73a-476f-9059-fd94b934656c"
version = "0.10.3"
version = "0.10.2"

[[deps.ClimaTimeSteppers]]
deps = ["ClimaComms", "Colors", "DataStructures", "DiffEqBase", "DiffEqCallbacks", "KernelAbstractions", "Krylov", "LinearAlgebra", "LinearOperators", "NVTX", "SciMLBase", "StaticArrays"]
Expand Down Expand Up @@ -379,7 +379,7 @@ weakdeps = ["Dates", "LinearAlgebra"]
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.1.0+0"
version = "1.0.5+1"

[[deps.CompositionsBase]]
git-tree-sha1 = "802bb88cd69dfd1509f6670416bd4434015693ad"
Expand All @@ -394,9 +394,9 @@ version = "0.1.2"

[[deps.ConcurrentUtilities]]
deps = ["Serialization", "Sockets"]
git-tree-sha1 = "6cbbd4d241d7e6579ab354737f4dd95ca43946e1"
git-tree-sha1 = "9c4708e3ed2b799e6124b5673a712dda0b596a9b"
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
version = "2.4.1"
version = "2.3.1"

[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
Expand Down Expand Up @@ -1495,7 +1495,7 @@ version = "0.3.24+0"
[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.23+4"
version = "0.3.23+2"

[[deps.OpenLibm_jll]]
deps = ["Artifacts", "Libdl"]
Expand Down
6 changes: 3 additions & 3 deletions docs/src/APIs/Regridder.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Bucket

```@meta
CurrentModule = ClimaLand.Regridder
CurrentModule = ClimaLand.Regridders
```

## Functions

```@docs
ClimaLand.Regridder.hdwrite_regridfile_rll_to_cgll
ClimaLand.Regridder.swap_space
ClimaLand.Regridders.hdwrite_regridfile_rll_to_cgll
ClimaLand.Regridders.swap_space
```
18 changes: 9 additions & 9 deletions experiments/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.10.1"
julia_version = "1.10.0"
manifest_format = "2.0"
project_hash = "960bdc0a1ed4b3f2aee66ed2e0c02065769614a9"

Expand Down Expand Up @@ -330,9 +330,9 @@ version = "0.5.7"

[[deps.ClimaCore]]
deps = ["Adapt", "BandedMatrices", "BlockArrays", "CUDA", "ClimaComms", "CubedSphere", "DataStructures", "DocStringExtensions", "ForwardDiff", "GaussQuadrature", "GilbertCurves", "HDF5", "InteractiveUtils", "IntervalSets", "KrylovKit", "LinearAlgebra", "PkgVersion", "RecursiveArrayTools", "RootSolvers", "SparseArrays", "Static", "StaticArrays", "Statistics", "Unrolled"]
git-tree-sha1 = "bc6a0154e3bcc1657d3a75f697e216fb70121969"
git-tree-sha1 = "844afbd6a7c4f112f974e0031ebf4fb13d0b4157"
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
version = "0.13.2"
version = "0.13.1"
weakdeps = ["Krylov"]

[deps.ClimaCore.extensions]
Expand All @@ -356,9 +356,9 @@ weakdeps = ["ClimaParams"]

[[deps.ClimaParams]]
deps = ["DocStringExtensions", "TOML", "Test"]
git-tree-sha1 = "ec67949db856e01df4cbf7d6ddafefeda02f93ee"
git-tree-sha1 = "323dd6c5423caf31f0da81bb9c288683cbdafb01"
uuid = "5c42b081-d73a-476f-9059-fd94b934656c"
version = "0.10.3"
version = "0.10.2"

[[deps.ClimaTimeSteppers]]
deps = ["ClimaComms", "Colors", "DataStructures", "DiffEqBase", "DiffEqCallbacks", "KernelAbstractions", "Krylov", "LinearAlgebra", "LinearOperators", "NVTX", "SciMLBase", "StaticArrays"]
Expand Down Expand Up @@ -453,7 +453,7 @@ weakdeps = ["Dates", "LinearAlgebra"]
[[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.1.0+0"
version = "1.0.5+1"

[[deps.CompositionsBase]]
git-tree-sha1 = "802bb88cd69dfd1509f6670416bd4434015693ad"
Expand All @@ -468,9 +468,9 @@ version = "0.1.2"

[[deps.ConcurrentUtilities]]
deps = ["Serialization", "Sockets"]
git-tree-sha1 = "6cbbd4d241d7e6579ab354737f4dd95ca43946e1"
git-tree-sha1 = "9c4708e3ed2b799e6124b5673a712dda0b596a9b"
uuid = "f0e56b4a-5159-44fe-b623-3e5288b988bb"
version = "2.4.1"
version = "2.3.1"

[[deps.ConstructionBase]]
deps = ["LinearAlgebra"]
Expand Down Expand Up @@ -1793,7 +1793,7 @@ version = "0.3.24+0"
[[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.23+4"
version = "0.3.23+2"

[[deps.OpenEXR]]
deps = ["Colors", "FileIO", "OpenEXR_jll"]
Expand Down
17 changes: 4 additions & 13 deletions experiments/standalone/Bucket/global_bucket_staticmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,9 @@ tf = 7 * 86400;
Δt = 3600.0;

# Construct albedo parameter object using static map
# Use separate regridding directory for CPU and GPU runs to avoid race condition
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
regrid_dir = joinpath(
pkgdir(ClimaLand),
"experiments/standalone/Bucket/$device_suffix/regrid-static/",
)
!ispath(regrid_dir) && mkpath(regrid_dir)
surface_space = bucket_domain.space.surface
α_snow = FT(0.8)
albedo = PrescribedBaregroundAlbedo{FT}(α_snow, regrid_dir, surface_space);
albedo = PrescribedBaregroundAlbedo{FT}(α_snow, surface_space);

bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc);

Expand Down Expand Up @@ -213,6 +204,9 @@ F_sfc = [
];

# save prognostic state to CSV - for comparison between GPU and CPU output
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
open(joinpath(outdir, "tf_state_$device_suffix.txt"), "w") do io
writedlm(io, hcat(T_sfc[end][:], W[end][:], Ws[end][:], σS[end][:]), ',')
end;
Expand Down Expand Up @@ -261,6 +255,3 @@ for (i, (field_ts, field_name)) in enumerate(
end
outfile = joinpath(outdir, string("ts_$device_suffix.png"))
CairoMakie.save(outfile, fig_ts)

# delete regrid directory
rm(regrid_dir, recursive = true)
19 changes: 5 additions & 14 deletions experiments/standalone/Bucket/global_bucket_temporalmap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ bucket_domain = ClimaLand.Domains.SphericalShell(;
npolynomial = 1,
dz_tuple = FT.((1.0, 0.05)),
);
ref_time = DateTime(2005);
ref_time = DateTime(2005, 01, 15, 12);

# Initialize parameters
σS_c = FT(0.2);
Expand All @@ -86,17 +86,8 @@ tf = 50 * 86400;
Δt = 3600.0;

# Construct albedo parameter object using temporal map
# Use separate regridding directory for CPU and GPU runs to avoid race condition
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
regrid_dir = joinpath(
pkgdir(ClimaLand),
"experiments/standalone/Bucket/$device_suffix/regrid-temporal/",
)
!ispath(regrid_dir) && mkpath(regrid_dir)
surface_space = bucket_domain.space.surface
albedo = PrescribedSurfaceAlbedo{FT}(regrid_dir, ref_time, t0, surface_space);
albedo = PrescribedSurfaceAlbedo{FT}(ref_time, t0, surface_space);

bucket_parameters = BucketModelParameters(FT; albedo, z_0m, z_0b, τc);

Expand Down Expand Up @@ -211,6 +202,9 @@ F_sfc = [
];

# save prognostic state to CSV - for comparison between GPU and CPU output
device_suffix =
typeof(ClimaComms.context().device) <: ClimaComms.CPUSingleThreaded ?
"cpu" : "gpu"
open(joinpath(outdir, "tf_state_$device_suffix.txt"), "w") do io
writedlm(io, hcat(T_sfc[end][:], W[end][:], Ws[end][:], σS[end][:]), ',')
end;
Expand Down Expand Up @@ -259,6 +253,3 @@ for (i, (field_ts, field_name)) in enumerate(
end
outfile = joinpath(outdir, string("ts_$device_suffix.png"))
CairoMakie.save(outfile, fig_ts)

# delete regrid directory
rm(regrid_dir, recursive = true)
7 changes: 4 additions & 3 deletions src/ClimaLand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ include("shared_utilities/Parameters.jl")
import .Parameters as LP

include("shared_utilities/general_utils.jl")
include("shared_utilities/Domains.jl")
include("shared_utilities/FileReaders.jl")
include("shared_utilities/Regridders.jl")
include("shared_utilities/DataHandling.jl")
include("shared_utilities/TimeVaryingInputs.jl")
using .TimeVaryingInputs
export TimeVaryingInput, evaluate!
include("shared_utilities/Regridder.jl")
include("shared_utilities/Domains.jl")
include("shared_utilities/FileReader.jl")
include("shared_utilities/SpaceVaryingInputs.jl")
using .SpaceVaryingInputs
export SpaceVaryingInput
Expand Down
Loading

0 comments on commit 44d1a3f

Please sign in to comment.