Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
juliasloan25 committed Apr 9, 2024
1 parent 0a236d5 commit 11cc032
Show file tree
Hide file tree
Showing 36 changed files with 589 additions and 636 deletions.
8 changes: 0 additions & 8 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ authors = ["CliMA Contributors <clima-software@caltech.edu>"]
version = "0.0.1"

[deps]
ClimaAtmos = "b2c96348-7fb7-4fe0-8da9-78d88439e717"
ClimaComms = "3a4d1b5c-c61d-41fd-a00a-5873ba7a1b0d"
ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
ClimaCoreTempestRemap = "d934ef94-cdd4-4710-83d6-720549644b70"
ClimaLand = "08f4d4ce-cf43-44bb-ad95-9d2d5f413532"
ClimaParams = "5c42b081-d73a-476f-9059-fd94b934656c"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Insolation = "e98cc03f-d57e-4e3c-b70c-8d51efe9e0d8"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
NCDatasets = "85f8d34a-cbdd-5861-8df4-14fed0d494ab"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Expand All @@ -24,15 +20,11 @@ TempestRemap_jll = "8573a8c5-1df0-515e-a024-abad257ee284"
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"

[compat]
ClimaAtmos = "0.22"
ClimaComms = "0.5.6"
ClimaCore = "0.13"
ClimaCoreTempestRemap = "0.3"
ClimaLand = "0.11"
ClimaParams = "0.10"
Dates = "1"
DocStringExtensions = "0.8, 0.9"
Insolation = "0.9.2"
JLD2 = "0.4"
NCDatasets = "0.11, 0.12, 0.13, 0.14.2"
Plots = "1.39.0"
Expand Down
4 changes: 4 additions & 0 deletions experiments/AMIP/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ ArgParse = "1.1"
ArtifactWrappers = "0.2"
AtmosphericProfilesLibrary = "0.1"
ClimaAnalysis = "0.5"
ClimaAtmos = "0.22"
ClimaCorePlots = "0.2"
ClimaLand = "0.11"
ClimaParams = "0.10"
ClimaTimeSteppers = "0.7"
Colors = "0.12"
Dierckx = "0.5"
ForwardDiff = "0.10"
Glob = "1"
HDF5_jll = "1"
Insolation = "0.9.2"
IntervalSets = "0.5, 0.6, 0.7"
JSON = "0.21"
MPI = "0.20"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The `compute!` function is called at every atmos time step to compute the diagno
To output these variables, short_name needs to be specified under diagnostics in the required yml file.
"""

add_diagnostic_variable!(
CAD.add_diagnostic_variable!(
short_name = "mse",
long_name = "Moist static energy",
standard_name = "moist_static_energy",
Expand All @@ -32,7 +32,7 @@ add_diagnostic_variable!(
end,
)

add_diagnostic_variable!(
CAD.add_diagnostic_variable!(
short_name = "lr",
long_name = "Lapse rate",
standard_name = "lapse_rate",
Expand All @@ -52,7 +52,7 @@ add_diagnostic_variable!(
end,
)

add_diagnostic_variable!(
CAD.add_diagnostic_variable!(
short_name = "ediff",
long_name = "Eddy diffusivity",
standard_name = "eddy_diffusivity",
Expand Down
2 changes: 1 addition & 1 deletion experiments/AMIP/components/ocean/eisenman_seaice.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import ClimaCoupler.Interfacer: get_field, update_field!, step!, reinit!
Thermodynamic 0-layer, based on the Semtner 1979 model and later refined by
Eisenmen 2009 and Zhang et al 2021.
"""
struct EisenmanIceSimulation{P, Y, D, I} <: SeaIceModelSimulation
struct EisenmanIceSimulation{P, Y, D, I} <: Interfacer.SeaIceModelSimulation
params_ice::P
Y_init::Y
domain::D
Expand Down
17 changes: 8 additions & 9 deletions experiments/AMIP/user_io/debug_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import Plots
import Printf
import ClimaCore as CC
import ClimaCorePlots

using ClimaCoupler.Interfacer: ComponentModelSimulation, SurfaceModelSimulation
import ClimaCoupler: Interfacer

# plotting functions for the coupled simulation
"""
debug(cs::CoupledSimulation, dir = "debug", cs_fields_ref = nothing)
debug(cs::Interfacer.CoupledSimulation, dir = "debug", cs_fields_ref = nothing)
Plot the fields of a coupled simulation and save plots to a directory.
"""
function debug(cs::CoupledSimulation, dir = "debug", cs_fields_ref = nothing)
function debug(cs::Interfacer.CoupledSimulation, dir = "debug", cs_fields_ref = nothing)
mkpath(dir)
@info "plotting debug in " * dir
for sim in cs.model_sims
Expand Down Expand Up @@ -70,21 +69,21 @@ function debug(cs_fields::NamedTuple, dir, cs_fields_ref = nothing)
end

"""
debug(sim::ComponentModelSimulation, dir)
debug(sim::Interfacer.ComponentModelSimulation, dir)
Plot the fields of a component model simulation and save plots to a directory.
"""
function debug(sim::ComponentModelSimulation, dir)
function debug(sim::Interfacer.ComponentModelSimulation, dir)

field_names = plot_field_names(sim)

all_plots = []
for field_name in field_names
field = get_field(sim, Val(field_name))
field = Interfacer.get_field(sim, Val(field_name))
push!(all_plots, Plots.plot(field, title = string(field_name) * print_extrema(field)))
end
fig = Plots.plot(all_plots..., size = (1500, 800))
Plots.png(joinpath(dir, "debug_$(name(sim))"))
Plots.png(joinpath(dir, "debug_$(Interfacer.name(sim))"))

end

Expand Down Expand Up @@ -117,7 +116,7 @@ get_field(sim::BucketSimulation, ::Val{:Ws}) = sim.integrator.u.bucket.Ws
get_field(sim::BucketSimulation, ::Val{:W}) = sim.integrator.u.bucket.W

# currently selected plot fields
plot_field_names(sim::SurfaceModelSimulation) = (:area_fraction, :surface_temperature, :surface_humidity)
plot_field_names(sim::Interfacer.SurfaceModelSimulation) = (:area_fraction, :surface_temperature, :surface_humidity)
plot_field_names(sim::BucketSimulation) =
(:area_fraction, :surface_temperature, :surface_humidity, :air_density, :σS, :Ws, :W)
plot_field_names(sim::ClimaAtmosSimulation) = (:w, :ρq_tot, :ρe_tot, :liquid_precipitation, :snow_precipitation)
1 change: 1 addition & 0 deletions experiments/ClimaCore/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
ClimaParams = "0.10"
ClimaTimeSteppers = "0.7"
DifferentialEquations = "7.10"
FileIO = "1.16"
Expand Down
4 changes: 4 additions & 0 deletions perf/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
ArgParse = "1.1"
ArtifactWrappers = "0.2"
AtmosphericProfilesLibrary = "0.1"
ClimaAtmos = "0.22"
ClimaCorePlots = "0.2"
ClimaLand = "0.11"
ClimaParams = "0.10"
ClimaTimeSteppers = "0.7"
Colors = "0.12"
Dierckx = "0.5"
ForwardDiff = "0.10"
Glob = "1"
HDF5_jll = "1"
Insolation = "0.9.2"
IntervalSets = "0.5, 0.6, 0.7"
JSON = "0.21"
MPI = "0.20"
Expand Down
8 changes: 4 additions & 4 deletions src/Regridder.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,8 @@ function write_datafile_cc(datafile_cc, field, name)
space = axes(field)
# write data
NCD.NCDataset(datafile_cc, "c") do nc
def_space_coord(nc, space; type = "cgll")
nc_field = defVar(nc, name, Float64, space)
CCTR.def_space_coord(nc, space; type = "cgll")
nc_field = NCD.defVar(nc, name, Float64, space)
nc_field[:, 1] = field

nothing
Expand Down Expand Up @@ -486,7 +486,7 @@ function land_fraction(
ClimaComms.barrier(comms_ctx)
file_dates = JLD2.load(joinpath(REGRID_DIR, outfile_root * "_times.jld2"), "times")
fraction = read_from_hdf5(REGRID_DIR, outfile_root, file_dates[1], varname, comms_ctx)
fraction = swap_space!(zeros(boundary_space), fraction) # needed if we are reading from previous run
fraction = Utilities.swap_space!(zeros(boundary_space), fraction) # needed if we are reading from previous run
return mono ? fraction : binary_mask.(fraction, threshold)
end

Expand Down Expand Up @@ -629,7 +629,7 @@ Regrids a field from CGLL to an RLL array using TempestRemap. It can hanlde mult
"""
function cgll2latlonz(field; DIR = "cgll2latlonz_dir", nlat = 360, nlon = 720, clean_dir = true)
isdir(DIR) ? nothing : mkpath(DIR)
datafile_latlon = DIR * "/remapped_" * string(name) * ".nc"
datafile_latlon = DIR * "/remapped_" * string(Interfacer.name) * ".nc"
remap_field_cgll_to_rll(:var, field, DIR, datafile_latlon, nlat = nlat, nlon = nlon)
new_data, coords = read_remapped_field(:var, datafile_latlon)
clean_dir ? rm(DIR; recursive = true) : nothing
Expand Down
4 changes: 3 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ ClimaTimeSteppers = "595c0a79-7f3d-439a-bc5a-b232dc3bde79"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
Insolation = "e98cc03f-d57e-4e3c-b70c-8d51efe9e0d8"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -38,6 +37,9 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
[compat]
Aqua = "0.8"
ArtifactWrappers = "0.2"
ClimaAtmos = "0.22"
ClimaLand = "0.11"
ClimaParams = "0.10"
Dates = "1"
Downloads = "1"
IntervalSets = "0.5, 0.6, 0.7"
Expand Down
43 changes: 23 additions & 20 deletions test/TestHelper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ various files in the test folder.
=#
module TestHelper

using ClimaCore: Geometry, Meshes, Domains, Topologies, Spaces, Fields, InputOutput
using ClimaComms
using NCDatasets
import ClimaCore as CC
import ClimaComms
import NCDatasets as NCD

export create_space, gen_ncdata

Expand Down Expand Up @@ -36,25 +36,28 @@ function create_space(
polynomial_degree = 3,
nz = 1,
)
domain = Domains.SphereDomain(R)
mesh = Meshes.EquiangularCubedSphere(domain, ne)
domain = CC.Domains.SphereDomain(R)
mesh = CC.Meshes.EquiangularCubedSphere(domain, ne)

if comms_ctx isa ClimaComms.SingletonCommsContext
topology = Topologies.Topology2D(comms_ctx, mesh, Topologies.spacefillingcurve(mesh))
topology = CC.Topologies.Topology2D(comms_ctx, mesh, CC.Topologies.spacefillingcurve(mesh))
else
topology = Topologies.DistributedTopology2D(comms_ctx, mesh, Topologies.spacefillingcurve(mesh))
topology = CC.Topologies.DistributedTopology2D(comms_ctx, mesh, CC.Topologies.spacefillingcurve(mesh))
end

Nq = polynomial_degree + 1
quad = Spaces.Quadratures.GLL{Nq}()
sphere_space = Spaces.SpectralElementSpace2D(topology, quad)
quad = CC.Spaces.Quadratures.GLL{Nq}()
sphere_space = CC.Spaces.SpectralElementSpace2D(topology, quad)

if nz > 1
vertdomain =
Domains.IntervalDomain(Geometry.ZPoint{FT}(0), Geometry.ZPoint{FT}(100); boundary_names = (:bottom, :top))
vertmesh = Meshes.IntervalMesh(vertdomain, nelems = nz)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(vertmesh)
return Spaces.ExtrudedFiniteDifferenceSpace(sphere_space, vert_center_space)
vertdomain = CC.Domains.IntervalDomain(
CC.Geometry.ZPoint{FT}(0),
CC.Geometry.ZPoint{FT}(100);
boundary_names = (:bottom, :top),
)
vertmesh = CC.Meshes.IntervalMesh(vertdomain, nelems = nz)
vert_center_space = CC.Spaces.CenterFiniteDifferenceSpace(vertmesh)
return CC.Spaces.ExtrudedFiniteDifferenceSpace(sphere_space, vert_center_space)
else
return sphere_space
end
Expand All @@ -76,17 +79,17 @@ function gen_ncdata(FT, path, varname, val)
isfile(path) ? rm(path) : nothing

# Create dataset of all ones
nc = NCDataset(path, "c")
nc = NCD.NCDataset(path, "c")

# Define dataset information
defDim(nc, "lon", 64)
defDim(nc, "lat", 32)
NCD.defDim(nc, "lon", 64)
NCD.defDim(nc, "lat", 32)
nc.attrib["title"] = "this is an NCDataset containing all 1s on a lat/lon grid"

# Define variables
lon = defVar(nc, "lon", FT, ("lon",))
lat = defVar(nc, "lat", FT, ("lat",))
v = defVar(nc, varname, FT, ("lon", "lat"))
lon = NCD.defVar(nc, "lon", FT, ("lon",))
lat = NCD.defVar(nc, "lat", FT, ("lat",))
v = NCD.defVar(nc, varname, FT, ("lon", "lat"))

# Populate lon and lat
lon[:] = [i for i in 0.0:(360 / 64):(360 - (360 / 64))]
Expand Down
6 changes: 3 additions & 3 deletions test/aqua.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Test
using ClimaCoupler
using Aqua
import Test: @test, @testset
import ClimaCoupler
import Aqua

@testset "Aqua tests (performance)" begin
# This tests that we don't accidentally run into
Expand Down
Loading

0 comments on commit 11cc032

Please sign in to comment.