Skip to content

Commit

Permalink
Do not allow mismatch between dims and bcs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sbozzolo committed Jul 23, 2024
1 parent 6b8f4f2 commit 5ebbd64
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 11 additions & 1 deletion ext/InterpolationsRegridderExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ function Regridders.InterpolationsRegridder(
)
coordinates = ClimaCore.Fields.coordinate_field(target_space)

num_dimensions = length(propertynames(coordinates))

if isnothing(extrapolation_bc)
extrapolation_bc = ()
if eltype(coordinates) <: ClimaCore.Geometry.LatLongPoint
Expand All @@ -69,7 +71,15 @@ function Regridders.InterpolationsRegridder(
end
end

return InterpolationsRegridder(target_space, coordinates, extrapolation_bc)
num_dimensions == length(extrapolation_bc) || error(
"Number of boundary conditions does not match the number of dimensions",
)

return InterpolationsRegridder(
target_space,
coordinates,
extrapolation_bc
)
end

"""
Expand Down
7 changes: 2 additions & 5 deletions test/data_handling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,10 @@ ClimaComms.init(context)
target_space;
regridder_type = :InterpolationsRegridder,
file_reader_kwargs = (; preprocess_func = (data) -> 0.0 * data),
regridder_kwargs = (;
extrapolation_bc = (Intp.Flat(), Intp.Flat(), Intp.Flat())
),
regridder_kwargs = (; extrapolation_bc = (Intp.Flat(), Intp.Flat())),
)

@test data_handler.regridder.extrapolation_bc ==
(Intp.Flat(), Intp.Flat(), Intp.Flat())
@test data_handler.regridder.extrapolation_bc == (Intp.Flat(), Intp.Flat())
field = DataHandling.regridded_snapshot(data_handler)
@test extrema(field) == (0.0, 0.0)
end
Expand Down
11 changes: 11 additions & 0 deletions test/regridders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ end
extrapolation_bc,
)

# Test num_dimensions != length(extrapolation_bc)
@test_throws ErrorException Regridders.InterpolationsRegridder(
hv_center_space;
extrapolation_bc = (
Interpolations.Periodic(),
Interpolations.Flat(),
Interpolations.Flat(),
Interpolations.Flat(),
),
)

regridded_lat = Regridders.regrid(reg_hv, data_lat3D, dimensions3D)
regridded_lon = Regridders.regrid(reg_hv, data_lon3D, dimensions3D)
regridded_z = Regridders.regrid(reg_hv, data_z3D, dimensions3D)
Expand Down

0 comments on commit 5ebbd64

Please sign in to comment.