Skip to content

Commit fee25cd

Browse files
committed
Deal with longitude periodicity when determining grid topology
1 parent 767ff62 commit fee25cd

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "OceanTransportMatrixBuilder"
22
uuid = "c2b4a04e-6049-4fc4-aa6a-5508a29a1e1c"
3-
version = "0.8.1"
3+
version = "0.8.2"
44
authors = ["Benoit Pasquier <briochemc@gmail.com> and contributors"]
55

66
[deps]

src/gridtopology.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ struct UnknownGridTopology <: AbstractGridTopology
1515
nz::Int64
1616
end
1717

18+
"""
19+
isapprox_lon(a, b)
20+
21+
Approximate equality for longitudes, taking into account the periodicity.
22+
"""
23+
function isapprox_lon(a, b)
24+
Δ = @. mod(a - b + 180, 360) - 180
25+
return isapprox(Δ, zeros(size(Δ)), atol = eps(180.0))
26+
end
27+
1828
"""
1929
getgridtopology(lon_vertices, lat_vertices, lev)
2030
@@ -31,7 +41,7 @@ function getgridtopology(lon_vertices, lat_vertices, lev)
3141
if all(NPlat .== 90)
3242
return BipolarGridTopology(nx, ny, nz)
3343
# Otherwise check if the north pole is split in two
34-
elseif isapprox(NPlon, rot180(NPlon)) && isapprox(NPlat, rot180(NPlat))
44+
elseif isapprox_lon(NPlon, rot180(NPlon)) && isapprox(NPlat, rot180(NPlat))
3545
return TripolarGridTopology(nx, ny, nz)
3646
else
3747
return UnknownGridTopology(nx, ny, nz)

0 commit comments

Comments
 (0)