diff --git a/test/file_readers.jl b/test/file_readers.jl index f7ded753..26d90499 100644 --- a/test/file_readers.jl +++ b/test/file_readers.jl @@ -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 diff --git a/test/regridders.jl b/test/regridders.jl index 3a01206f..c4a81a13 100644 --- a/test/regridders.jl +++ b/test/regridders.jl @@ -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 @@ -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