@@ -205,27 +205,29 @@ end
205
205
206
206
coordinates = ClimaCore. Fields. coordinate_field (horzspace)
207
207
208
+ # Since lon uses periodic BCs but is not periodic itself, error is large at 180 degrees.
209
+ # We check that the error is small at other indices, and that the values at -180 and 180 agree.
210
+ function check_lon_error (coords_lon, lon_regrid)
211
+ inds_normal = findall (!= (180 ), Array (parent (coords_lon)))
212
+ err_lon = abs .(
213
+ Array (parent (coords_lon))[inds_normal] .-
214
+ Array (parent (lon_regrid))[inds_normal],
215
+ )
216
+ @test maximum (err_lon) < 1e-4
217
+
218
+ inds_lon_180 = findall (== (180 ), Array (parent (coords_lon)))
219
+ inds_lon_neg180 = findall (== (- 180 ), Array (parent (coords_lon)))
220
+ err_lon_180 = abs .(
221
+ Array (parent (lon_regrid))[inds_lon_180] .-
222
+ Array (parent (coords_lon))[inds_lon_neg180],
223
+ )
224
+ @test maximum (err_lon_180) < 1e-5
225
+ end
226
+
208
227
# Compute max err
209
228
err_lat = abs .(coordinates. lat .- regridded_lat)
210
229
@test maximum (err_lat) < 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
230
+ check_lon_error (coordinates. long, regridded_lon)
229
231
230
232
# 3D space
231
233
extrapolation_bc = (
@@ -273,28 +275,47 @@ end
273
275
274
276
# Compute max err
275
277
err_lat = abs .(coordinates. lat .- regridded_lat)
276
- err_lon = abs .(coordinates. long .- regridded_lon)
277
278
err_z = abs .(coordinates. z .- regridded_z)
278
279
279
280
@test maximum (err_lat) < 1e-5
280
281
@test maximum (err_z) < 1e-5
282
+ check_lon_error (coordinates. long, regridded_lon)
281
283
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],
284
+ # 2D space with LatLongZ coordinates
285
+ surface_space = ClimaCore. Spaces. level (hv_center_space, 1 ) # SpectralElementSpace2D with LatLongZPoint coordinates
286
+ coordinates = ClimaCore. Fields. coordinate_field (surface_space)
287
+ @assert ! (
288
+ surface_space isa ClimaCore. Spaces. ExtrudedFiniteDifferenceSpace
288
289
)
289
- @test maximum (err_lon ) < 1e-4
290
+ @assert eltype (coordinates ) <: ClimaCore.Geometry.LatLongZPoint
290
291
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
292
+ # 3D data
293
+ reg_2d = Regridders. InterpolationsRegridder (surface_space)
294
+
295
+ regridded_lat_3d = Regridders. regrid (reg_2d, data_lat3D, dimensions3D)
296
+ regridded_lon_3d = Regridders. regrid (reg_2d, data_lon3D, dimensions3D)
297
+
298
+ # Compute max err
299
+ err_lat = abs .(coordinates. lat .- regridded_lat_3d)
300
+ @test maximum (err_lat) < 1e-5
301
+ check_lon_error (coordinates. long, regridded_lon_3d)
302
+
303
+ # 2D data
304
+ @test_logs (
305
+ :warn ,
306
+ " Regridding 2D data onto a 2D space with LatLongZ coordinates." ,
307
+ ) Regridders. regrid (reg_2d, data_lat2D, dimensions2D)
308
+ @test_logs (
309
+ :warn ,
310
+ " Regridding 2D data onto a 2D space with LatLongZ coordinates." ,
311
+ ) Regridders. regrid (reg_2d, data_lon2D, dimensions2D)
312
+
313
+ regridded_lat_2d = Regridders. regrid (reg_2d, data_lat2D, dimensions2D)
314
+ regridded_lon_2d = Regridders. regrid (reg_2d, data_lon2D, dimensions2D)
315
+
316
+ err_lat = abs .(coordinates. lat .- regridded_lat_2d)
317
+ @test maximum (err_lat) < 1e-5
318
+ check_lon_error (coordinates. long, regridded_lon_2d)
298
319
end
299
320
end
300
321
0 commit comments