Skip to content

Commit

Permalink
Merge branch 'master' into compathelper/new_version/2024-04-28-00-42-…
Browse files Browse the repository at this point in the history
…48-988-00171841129
  • Loading branch information
Alexander-Barth authored May 28, 2024
2 parents 4d372e9 + 3d67cd7 commit 9cca2c3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ jobs:
- uses: codecov/codecov-action@v4
with:
file: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
CodecZlib = "0.6, 0.7"
GeoInterface = "0.4, 0.5, 1.0"
RemoteFiles = "0.3, 0.4, 0.5"
Shapefile = "0.6, 0.7, 0.8, 0.10, 0.11, 0.13"
Shapefile = "0.6, 0.7, 0.8, 0.10, 0.11, 0.12, 0.13"
ZipFile = "0.8, 0.9, 0.10"
julia = "1"

Expand Down
14 changes: 11 additions & 3 deletions src/land_sea_mask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,17 @@ is_land(mask::LandSeaMask, lat::Real, lon::Real) = nearest_point(mask, lat, lon)
is_land(mask::LandSeaMask, (lat, lon)::Tuple{Real, Real}) = is_land(mask, lat, lon)

function nearest_point(mask::LandSeaMask, lat::Real, lon::Real)
return mask.data[nearest_point_idx(mask.lon, lon), nearest_point_idx(mask.lat, lat)]
i = nearest_point_idx_periodic(mask.lon, lon)
j = nearest_point_idx(mask.lat, lat)
return mask.data[i,j]
end

function nearest_point_idx(xs::StepRangeLen, x::Real)
return convert(Int, floor((x - first(xs)) / (last(xs) - first(xs)) * length(xs)))
function nearest_point_idx(xs::AbstractRange, x::Real)
idx = 1 + round(Int,(x - first(xs)) / step(xs))
return idx
end

function nearest_point_idx_periodic(xs::AbstractRange, x::Real)
idx = nearest_point_idx(xs, x)
return mod1(idx,length(xs))
end
16 changes: 16 additions & 0 deletions test/land_sea_mask.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
using Test
using GeoDatasets

@testset "land_sea_mask" begin
lon,lat,data = GeoDatasets.landseamask(;resolution='c',grid=5)
@test size(data,1) == length(lon)
Expand All @@ -7,6 +10,19 @@
@test_throws ErrorException GeoDatasets.landseamask(;resolution='g',grid=5)

mask = GeoDatasets.LandSeaMask()

@test GeoDatasets.is_land(mask, 52.200475, 0.1138)
@test !GeoDatasets.is_land(mask, 56.615841, 3.39206)

# check finding the index of the nearest point
xs = 12.:34.:567.;
i = 11
@test GeoDatasets.nearest_point_idx(xs, xs[i]) == i
@test GeoDatasets.nearest_point_idx(xs, xs[i]+step(xs)/4) == i
@test GeoDatasets.nearest_point_idx(xs, xs[i]-step(xs)/4) == i

# wrapping in longitude
for lon = 90 .* (-4:4)
GeoDatasets.is_land(mask, 0.0, lon) == GeoDatasets.is_land(mask, 0.0, lon + 360)
end
end

0 comments on commit 9cca2c3

Please sign in to comment.