|
31 | 31 |
|
32 | 32 | @testset "InterpolationsRegridder incorrect dimensions" begin
|
33 | 33 | 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) |
35 | 35 | dimensions3D = (lon, lat, z)
|
36 | 36 | dimensions3D_reversed = (lon, reverse(lat), reverse(z))
|
37 | 37 | dimensions2D = (lon, lat)
|
|
141 | 141 | @testset "InterpolationsRegridder" begin
|
142 | 142 |
|
143 | 143 | 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) |
145 | 145 | dimensions2D = (lon, lat)
|
146 | 146 | dimensions3D = (lon, lat, z)
|
147 | 147 | size2D = (361, 181)
|
@@ -206,11 +206,26 @@ end
|
206 | 206 | coordinates = ClimaCore.Fields.coordinate_field(horzspace)
|
207 | 207 |
|
208 | 208 | # 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) |
212 | 210 | @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 |
214 | 229 |
|
215 | 230 | # 3D space
|
216 | 231 | extrapolation_bc = (
|
@@ -257,13 +272,29 @@ end
|
257 | 272 | coordinates = ClimaCore.Fields.coordinate_field(hv_center_space)
|
258 | 273 |
|
259 | 274 | # 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) |
263 | 278 |
|
264 | 279 | @test maximum(err_lat) < 1e-5
|
265 |
| - @test maximum(err_lon) < 1e-4 |
266 | 280 | @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 |
267 | 298 | end
|
268 | 299 | end
|
269 | 300 |
|
|
0 commit comments