From 8bd71edba459a87c2ae2d4483d49d4e0024b319f Mon Sep 17 00:00:00 2001 From: Kevin Phan <98072684+ph-kev@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:37:00 -0800 Subject: [PATCH] =?UTF-8?q?Add=20periodic=20boundary=20condition=20when=20?= =?UTF-8?q?lat=20is=20360=C2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the difference between the longitude dimension is exactly 360.0 degrees, then a periodic boundary condition is added. --- NEWS.md | 2 ++ src/Var.jl | 4 ++++ test/test_Var.jl | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/NEWS.md b/NEWS.md index a4da09e..683c37a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -45,6 +45,8 @@ var_reversed = ClimaAnalysis.reverse_dim(var, "pressure_level") -> P0 * exp(-z / H_EARTH), where P0 = 10000 and H_EARTH = 7000.0, following a simple hydrostatic model for the atmosphere. - `Var.dim_units` returns a string even if the type of the units is Unitful. +- Add periodic boundary condition when extrapolating on longitude dimension when it is + exactly 360 degrees v0.5.11 ------- diff --git a/src/Var.jl b/src/Var.jl index 9943eff..bcdc865 100644 --- a/src/Var.jl +++ b/src/Var.jl @@ -166,6 +166,10 @@ function _find_extp_bound_cond(dim_name, dim_array) _isequispaced(dim_array) && isapprox(dim_size + dsize, 360.0) ) && return Intp.Periodic() + ( + conventional_dim_name(dim_name) == "longitude" && + (dim_array[end] - dim_array[begin]) ≈ 360.0 + ) && return Intp.Periodic() ( conventional_dim_name(dim_name) == "latitude" && _isequispaced(dim_array) && diff --git a/test/test_Var.jl b/test/test_Var.jl index dc77918..498675e 100644 --- a/test/test_Var.jl +++ b/test/test_Var.jl @@ -121,6 +121,13 @@ end var = ClimaAnalysis.OutputVar(attribs, dims, dim_attribs, data) @test var.interpolant.et == (Intp.Throw(), Intp.Throw(), Intp.Throw()) + # Lon is exactly 360 degrees + lon = 0.0:1.0:360.0 |> collect + data = ones(length(lon)) + dims = OrderedDict(["lon" => lon]) + var = ClimaAnalysis.OutputVar(attribs, dims, dim_attribs, data) + @test var.interpolant.et == (Intp.Periodic(),) + # Dates for the time dimension lon = 0.5:1.0:359.5 |> collect lat = -89.5:1.0:89.5 |> collect