Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Land Mask Issue Near -180 degrees #38

Closed
naufalwx opened this issue May 24, 2024 · 2 comments
Closed

Land Mask Issue Near -180 degrees #38

naufalwx opened this issue May 24, 2024 · 2 comments

Comments

@naufalwx
Copy link

naufalwx commented May 24, 2024

Hi,

I'd love to use the land mask to identify if various points are over water or over land. But I ran into an issue. I'm a terrible coder, so I may just be doing something wrong or I'm just not fully understanding what is happening. But here's a MWE of the issue I ran into.

using GeoDatasets

mask = GeoDatasets.LandSeaMask(; resolution='f')

GeoDatasets.is_land(mask, 0.0, 180.0)     # This would give me an answer

GeoDatasets.is_land(mask, 0.0, -179.87)   # This would also give me an answer

GeoDatasets.is_land(mask, 0.0, -179.88)   # This would give me the error below

ERROR: BoundsError: attempt to access 4320×2160 Matrix{UInt8} at index [0, 1080]
Stacktrace:
 [1] getindex
   @ ./array.jl:862 [inlined]
 [2] nearest_point
   @ ~/.julia/packages/GeoDatasets/8HX2S/src/land_sea_mask.jl:74 [inlined]
 [3] is_land(mask::GeoDatasets.LandSeaMask{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Matrix{UInt8}}, lat::Int64, lon::Float64)
   @ GeoDatasets ~/.julia/packages/GeoDatasets/8HX2S/src/land_sea_mask.jl:70
 [4] top-level scope
   @ REPL[25]:1

It seems like any value below -179.87501 (i.e., -179.87502; pardon the excessive decimals, I was experimenting) would produce the error above. And for the line in the error message: ERROR: BoundsError: attempt to access 4320×2160 Matrix{UInt8} at index [0, 1080], the first index can be 0 or -1 depending on how close the longitude is to -180.

Is this expected behavior? Am I doing anything wrong? Or is this a bug?

I'm using Julia 1.7.1 and GeoDataset 0.1.8

Thanks!

Alexander-Barth added a commit that referenced this issue May 28, 2024
Alexander-Barth added a commit that referenced this issue May 28, 2024
@Alexander-Barth
Copy link
Member

Thank you for your time to report this issue and to provide a reproducible example!

This should be fixed by commit 529bbe3

@naufalwx
Copy link
Author

Thank your for looking into this so quickly! The commit works for my purposes.

I decided to do a check on the range of possible lats/lons and I ran into a similar issue when the latitude value is exactly 90 or -90. It doesn't affect me, since I don't deal with values at the poles. But I figured I would let you know.

using GeoDatasets

mask = GeoDatasets.LandSeaMask(; resolution='f')

GeoDatasets.is_land(mask, 89.99999, 0.0)     # This would give me an answer

GeoDatasets.is_land(mask, 90.0, 0.0)         # This would give me the error below

BoundsError: attempt to access 4320×2160 Matrix{UInt8} at index [2161, 2161]

Stacktrace:
 [1] getindex
   @ ./essentials.jl:14 [inlined]
 [2] nearest_point(mask::GeoDatasets.LandSeaMask{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Matrix{UInt8}}, lat::Float64, lon::Float64)
   @ GeoDatasets ~/.julia/packages/GeoDatasets/gJpgj/src/land_sea_mask.jl:76
 [3] is_land(mask::GeoDatasets.LandSeaMask{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}, Matrix{UInt8}}, lat::Float64, lon::Float64)
   @ GeoDatasets ~/.julia/packages/GeoDatasets/gJpgj/src/land_sea_mask.jl:70
 [4] top-level scope
   @ In[28]:1

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants