Skip to content

Commit

Permalink
Add tests for TempestRegridder and nc_common
Browse files Browse the repository at this point in the history
Add very simple TempestRegridder test

Add test for read_available_dates
  • Loading branch information
imreddyTeja committed Dec 17, 2024
1 parent e11bc59 commit aa1f1bc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
22 changes: 22 additions & 0 deletions test/file_readers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,25 @@ end
@test isempty(open_ncfiles)
end
end

@testset "read_available_dates" begin
read_dates_func =
Base.get_extension(
ClimaUtilities,
:ClimaUtilitiesNCDatasetsExt,
).NCFileReaderExt.read_available_dates

data_dir = mktempdir()
NCDataset(joinpath(data_dir, "test_time_1.nc"), "c") do nc
defDim(nc, "time", 2)
times = [DateTime(2022), DateTime(2023)]
defVar(nc, "time", times, ("time",))
@test read_dates_func(nc) == times
end
NCDataset(joinpath(data_dir, "test_date_1.nc"), "c") do nc
defDim(nc, "date", 2)
times = [20220101, 20230101]
defVar(nc, "date", times, ("date",))
@test read_dates_func(nc) == DateTime.(string.(times), "yyyymmdd")
end
end
32 changes: 31 additions & 1 deletion test/regridders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Test

import ClimaUtilities
import ClimaUtilities: Regridders

import NCDatasets
import ClimaCore
import ClimaComms
@static pkgversion(ClimaComms) >= v"0.6" && ClimaComms.@import_required_backends
Expand Down Expand Up @@ -214,3 +214,33 @@ end
@test maximum(err_z) < 1e-5
end
end

@testset "TempestRegridder" begin
for FT in (Float32, Float64)
data_path = joinpath(@__DIR__, "test_data", "era5_1979_1.0x1.0_lai.nc")
ds = NCDatasets.NCDataset(data_path, "r")
original_max = maximum(ds["lai_lv"][:, :, 1])
original_min = minimum(ds["lai_lv"][:, :, 1])
test_time = ds["time"][1]
close(ds)
test_space = make_spherical_space(FT; context).horizontal
regrid_dir = nothing
if ClimaComms.iamroot(context)
regrid_dir = mktempdir()
end
regrid_dir = ClimaComms.bcast(context, regrid_dir)
ClimaComms.barrier(context)
regridder = Regridders.TempestRegridder(
test_space,
"lai_lv",
data_path;
regrid_dir,
)
ClimaComms.barrier(context)
regridded_field = Regridders.regrid(regridder, test_time)
regridded_max = maximum(regridded_field)
regridded_min = minimum(regridded_field)
@test original_max >= regridded_max
@test original_min <= regridded_min
end
end

0 comments on commit aa1f1bc

Please sign in to comment.