Skip to content

Commit 0e9390d

Browse files
committed
test lon regridding correctly
1 parent 423366e commit 0e9390d

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

test/regridders.jl

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ end
3131

3232
@testset "InterpolationsRegridder incorrect dimensions" begin
3333
lon, lat, z =
34-
collect(0.0:1:360), collect(-90.0:1:90), collect(0.0:1.0:100.0)
34+
collect(-180.0:1:180.0), collect(-90.0:1:90), collect(0.0:1.0:100.0)
3535
dimensions3D = (lon, lat, z)
3636
dimensions3D_reversed = (lon, reverse(lat), reverse(z))
3737
dimensions2D = (lon, lat)
@@ -141,7 +141,7 @@ end
141141
@testset "InterpolationsRegridder" begin
142142

143143
lon, lat, z =
144-
collect(0.0:1:360), collect(-90.0:1:90), collect(0.0:1.0:100.0)
144+
collect(-180.0:1:180.0), collect(-90.0:1:90), collect(0.0:1.0:100.0)
145145
dimensions2D = (lon, lat)
146146
dimensions3D = (lon, lat, z)
147147
size2D = (361, 181)
@@ -206,11 +206,26 @@ end
206206
coordinates = ClimaCore.Fields.coordinate_field(horzspace)
207207

208208
# Compute max err
209-
err_lat = coordinates.lat .- regridded_lat
210-
err_lon = coordinates.long .- regridded_lon
211-
209+
err_lat = abs.(coordinates.lat .- regridded_lat)
212210
@test maximum(err_lat) < 1e-5
213-
@test maximum(err_lon) < 1e-5
211+
212+
# Since lon uses periodic BCs, error is large at 180 degrees.
213+
# We check that the error is small at other indices, and that the values at -180 and 180 agree.
214+
# Note that for data that is actually periodic, the error at 180 degrees will also be small.
215+
inds_normal = findall(!=(180), parent(coordinates.long))
216+
err_lon = abs.(
217+
parent(coordinates.long)[inds_normal] .-
218+
parent(regridded_lon)[inds_normal],
219+
)
220+
@test maximum(err_lon) < 1e-4
221+
222+
inds_lon_180 = findall(==(180), parent(coordinates.long))
223+
inds_lon_neg180 = findall(==(-180), parent(coordinates.long))
224+
err_lon_180 = abs.(
225+
parent(regridded_lon)[inds_lon_180] .-
226+
parent(coordinates.long)[inds_lon_neg180],
227+
)
228+
@test maximum(err_lon_180) < 1e-5
214229

215230
# 3D space
216231
extrapolation_bc = (
@@ -257,13 +272,29 @@ end
257272
coordinates = ClimaCore.Fields.coordinate_field(hv_center_space)
258273

259274
# Compute max err
260-
err_lat = coordinates.lat .- regridded_lat
261-
err_lon = coordinates.long .- regridded_lon
262-
err_z = coordinates.z .- regridded_z
275+
err_lat = abs.(coordinates.lat .- regridded_lat)
276+
err_lon = abs.(coordinates.long .- regridded_lon)
277+
err_z = abs.(coordinates.z .- regridded_z)
263278

264279
@test maximum(err_lat) < 1e-5
265-
@test maximum(err_lon) < 1e-4
266280
@test maximum(err_z) < 1e-5
281+
282+
# Since lon uses periodic BCs but is not periodic itself, error is large at 180 degrees.
283+
# We check that the error is small at other indices, and that the values at -180 and 180 agree.
284+
inds_normal = findall(!=(180), parent(coordinates.long))
285+
err_lon = abs.(
286+
parent(coordinates.long)[inds_normal] .-
287+
parent(regridded_lon)[inds_normal],
288+
)
289+
@test maximum(err_lon) < 1e-4
290+
291+
inds_lon_180 = findall(==(180), parent(coordinates.long))
292+
inds_lon_neg180 = findall(==(-180), parent(coordinates.long))
293+
err_lon_180 = abs.(
294+
parent(regridded_lon)[inds_lon_180] .-
295+
parent(coordinates.long)[inds_lon_neg180],
296+
)
297+
@test maximum(err_lon_180) < 1e-5
267298
end
268299
end
269300

0 commit comments

Comments
 (0)