Skip to content

Commit 09d0a10

Browse files
Fix a small bug in bathymetry (#378)
* fix a small bug * add test * add comment * fix comment * fix tests
1 parent 34b1f0c commit 09d0a10

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/Bathymetry.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ function regrid_bathymetry(target_grid;
151151
Nyn = length(φ_data)
152152
Nzn = 1
153153

154-
155154
native_grid = LatitudeLongitudeGrid(arch, Float32;
156155
size = (Nxn, Nyn, Nzn),
157156
latitude = (φ₁_data, φ₂_data),
@@ -195,15 +194,15 @@ function interpolate_bathymetry_in_passes(native_z, target_grid;
195194
resxn = minimum_xspacing(native_z.grid)
196195
resyn = minimum_yspacing(native_z.grid)
197196

198-
# Check whether we are coarsening the grid in any directions.
199-
# If so, skip interpolation passes.
200-
if resxt > resxn || resyt > resyn
197+
# Check whether we are refining the grid in any directions.
198+
# If so, skip interpolation passes, as they are not needed.
199+
if resxt < resxn || resyt < resyn
201200
target_z = Field{Center, Center, Nothing}(target_grid)
202201
interpolate!(target_z, native_z)
203202
@info string("Skipping passes for interpolating bathymetry of size $Nn ", '\n',
204203
"to target grid of size $Nt. Interpolation passes may only ", '\n',
205-
"be used to refine bathymetry and require that the bathymetry ", '\n',
206-
"is larger than the target grid in both horizontal directions.")
204+
"be used to coarsen bathymetry and require that the bathymetry ", '\n',
205+
"is finer than the target grid in both horizontal directions.")
207206
return target_z
208207
end
209208

test/test_bathymetry.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,25 @@ using ClimaOcean.Bathymetry: remove_minor_basins!
5151
grid = LatitudeLongitudeGrid(arch;
5252
size = (200, 200, 10),
5353
longitude = (0, 2),
54-
latitude = (-10, 50),
54+
latitude = (-0.1, 0.1),
5555
z = (-6000, 0))
5656

5757
control_bottom_height = regrid_bathymetry(grid)
5858
interpolated_bottom_height = regrid_bathymetry(grid; interpolation_passes=100)
5959

6060
# Testing that multiple passes do not change the solution when refining the grid
6161
@test parent(control_bottom_height) == parent(interpolated_bottom_height)
62+
63+
grid = LatitudeLongitudeGrid(arch;
64+
size = (200, 200, 10),
65+
longitude = (0, 100),
66+
latitude = (-10, 50),
67+
z = (-6000, 0))
68+
69+
control_bottom_height = regrid_bathymetry(grid)
70+
interpolated_bottom_height = regrid_bathymetry(grid; interpolation_passes=10)
71+
72+
# Testing that multiple passes _do_ change the solution when coarsening the grid
73+
@test parent(control_bottom_height) != parent(interpolated_bottom_height)
6274
end
6375
end

0 commit comments

Comments
 (0)