Skip to content

Commit

Permalink
Fix GeoStats compat (#171)
Browse files Browse the repository at this point in the history
* Added Makie plotting extension.

* Fixed GeoStats compat..

* Fix tests.

* Some more fixes..

* Docs fix.
  • Loading branch information
evetion authored Dec 8, 2024
1 parent eafff43 commit 8fe698c
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 41 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.9.2] - 2024-12-8

### Fixed
- Fixed GeoStats compatability, now depends on GeoStatsModels and GeoStatsTransforms

## [0.9.1] - 2024-12-5

### Added
Expand Down
11 changes: 7 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name = "GeoArrays"
uuid = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab"
authors = ["Maarten Pronk <[email protected]>"]
version = "0.9.1"
version = "0.9.2"


[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Expand All @@ -16,12 +17,13 @@ RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[weakdeps]
GeoStatsBase = "323cb8eb-fbf6-51c0-afd0-f8fba70507b2"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
GeoStatsModels = "ad987403-13c5-47b5-afee-0a48f6ac4f12"
GeoStatsTransforms = "725d9659-360f-4996-9c94-5f19c7e4a8a6"

[extensions]
GeoArraysMakieExt = "Makie"
GeoArraysStatsExt = "GeoStatsBase"
GeoArraysStatsExt = ["GeoStatsModels", "GeoStatsTransforms"]

[compat]
ArchGDAL = "0.7 - 0.9, 0.10"
Expand All @@ -30,7 +32,8 @@ DataAPI = "1"
Extents = "0.1"
GeoFormatTypes = "0.4"
GeoInterface = "1"
GeoStatsBase = "0.37 - 0.43"
GeoStatsModels = "0.6"
GeoStatsTransforms = "0.9"
IterTools = "1"
PrecompileTools = "1"
RecipesBase = "0.7, 0.8, 1.0"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ga2 = GeoArrays.warp(ga, Dict("t_srs" => "EPSG:4326+3855"))
GeoArrays with missing data can be filled with the [`fill!`](@ref) function.
```julia
julia> using GeoStatsSolvers # or any estimation solver from the GeoStats ecosystem
julia> using GeoStats # or any estimation solver from the GeoStats ecosystem
julia> ga = GeoArray(Array{Union{Missing, Float64}}(rand(5, 1)))
julia> ga.A[2,1] = missing
[:, :, 1] =
Expand All @@ -174,7 +174,7 @@ julia> ga.A[2,1] = missing
0.852882193026649
0.7137410453351622
0.5949409082233854
julia> GeoArrays.fill!(ga, IDW(:band => (neighbors=3,))) # band is the hardcoded variable
julia> GeoArrays.fill!(ga, IDW(2), maxneighbors=10)
[:, :, 1] =
0.6760718768442127
0.7543298370153771
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GeoArrays = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab"
GeoStatsBase = "323cb8eb-fbf6-51c0-afd0-f8fba70507b2"
GeoStatsModels = "ad987403-13c5-47b5-afee-0a48f6ac4f12"
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
push!(LOAD_PATH, "../src/")
using Documenter, GeoArrays, GeoStatsBase
using Documenter, GeoArrays, GeoStatsModels

cl = joinpath(@__DIR__, "src/CHANGELOG.md")
isfile(cl) || cp(joinpath(@__DIR__, "../CHANGELOG.md"), cl)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ ga2 = GeoArrays.warp(ga, Dict("t_srs" => "EPSG:4326+3855"))
GeoArrays with missing data can be filled with the [`fill!`](@ref) function.
```julia
julia> using GeoStatsSolvers # or any estimation solver from the GeoStats ecosystem
julia> using GeoStats # or any estimation solver from the GeoStats ecosystem
julia> ga = GeoArray(Array{Union{Missing, Float64}}(rand(5, 1)))
julia> ga.A[2,1] = missing
[:, :, 1] =
Expand All @@ -161,7 +161,7 @@ julia> ga.A[2,1] = missing
0.852882193026649
0.7137410453351622
0.5949409082233854
julia> GeoArrays.fill!(ga, IDW(:band => (neighbors=3,))) # band is the hardcoded variable
julia> GeoArrays.fill!(ga, IDW(2), maxneighbors=10)
[:, :, 1] =
0.6760718768442127
0.7543298370153771
Expand Down
25 changes: 11 additions & 14 deletions ext/GeoArraysStatsExt.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
module GeoArraysStatsExt

using GeoArrays, GeoStatsBase
using GeoArrays, GeoStatsModels, GeoStatsTransforms

"""
fill!(ga::GeoArray, solver::EstimationSolver, band=1)
fill!(ga::GeoArray, solver::GeoStatsModels.GeoStatsModel, band=1, kwargs...)
Replace missing values in GeoArray `ga` using `solver` from the GeoStats ecosystem.
"""
function GeoArrays.fill!(ga::GeoArray, solver::T, band=1) where {T<:EstimationSolver}
function GeoArrays.fill!(ga::GeoArray, solver::T, band=1; kwargs...) where {T<:GeoStatsModels.GeoStatsModel}
GeoArrays.is_rotated(ga) && error("Can't interpolate rotated GeoArrays yet. Please make an issue.")

data = @view ga.A[:, :, band]
m = ismissing.(data)
sum(m) == 0 && return ga
cds = collect(coords(ga))
problemdata = GeoStatsBase.georef(
(; band=@view data[.!m]),
@view cds[.!m]
)
problem = EstimationProblem(problemdata, GeoStatsBase.PointSet(cds[m]), :band)
solution = solve(problem, solver)
any(ismissing, data) || return ga

data[m] .= getproperty(solution, :band)
domain = GeoStatsModels.CartesianGrid(size(ga)[1:2], Tuple(ga.f.translation), (abs(ga.f.linear[1]), abs(ga.f.linear[4])))
problemdata = GeoStatsModels.georef((; z=vec(data)), domain)
interp = problemdata |> GeoStatsTransforms.InterpolateMissing(:z => solver; kwargs...)
data .= reshape(getproperty(interp, :z), size(data))
ga
end

@deprecate interpolate!(ga::GeoArray, solver::T, band=1) where {T<:EstimationSolver} fill!(ga, solver, band)
@deprecate interpolate!(ga::GeoArray, solver::T, band=1; kwargs...) where {T<:GeoStatsModels.GeoStatsModel} fill!(ga, solver, band; kwargs...)

end
2 changes: 1 addition & 1 deletion src/geoarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ julia> ga[2:3,2:3,1]
```
"""
function Base.getindex(ga::GeoArray{T,N}, i::AbstractRange, j::AbstractRange, k::Union{Colon,AbstractRange,Integer}=Colon()) where {T,N}
A = N == 2 ? getindex(ga.A, i, j) : getindex(ga.A, i, j, k)
A = N == 2 ? getindex(parent(ga), i, j) : getindex(parent(ga), i, j, k)
x, y = first(i) - 1, first(j) - 1
t = ga.f(SVector(x, y))
l = ga.f.linear * SMatrix{2,2}([step(i) 0; 0 step(j)])
Expand Down
4 changes: 2 additions & 2 deletions src/interpolate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
Replace missing values in GeoArray `ga` using `solver`.
"""
function fill!(::GeoArray, solver, band)
error("fill! using $solver is not implemented yet. Please use an `EstimationSolver` from the GeoStats.jl ecosystem.")
function fill!(::GeoArray, solver, band=1; kwargs...)
error("fill! using $solver is not implemented yet. Please use an `GeoStatsModel` from the GeoStats.jl ecosystem.")
end
5 changes: 4 additions & 1 deletion src/operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ function warp(ga::GeoArray, options::Dict{String}, dest="/vsimem/$(gensym())")
noptions = Dict{String,Any}()
warpdefaults!(noptions)
merge!(noptions, options)
ArchGDAL.gdalwarp([dataset], warpstringlist(options); dest
ds = [dataset]
nga = ArchGDAL.gdalwarp(ds, warpstringlist(options); dest
) do warped
GeoArray(warped)
end
ArchGDAL.destroy(dataset)
return nga
end

function warp(ga::GeoArray, like::GeoArray, options::Dict{String}=Dict{String,Any}(), dest="/vsimem/$(gensym())")
Expand Down
4 changes: 2 additions & 2 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
GeoArrays = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab"
GeoFormatTypes = "68eda718-8dee-11e9-39e7-89f7f65f511f"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
GeoStatsBase = "323cb8eb-fbf6-51c0-afd0-f8fba70507b2"
GeoStatsSolvers = "50e95529-e670-4fa6-84ad-e28f686cc091"
GeoStatsModels = "ad987403-13c5-47b5-afee-0a48f6ac4f12"
GeoStatsTransforms = "725d9659-360f-4996-9c94-5f19c7e4a8a6"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2 changes: 1 addition & 1 deletion test/test_crs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const GFT = GeoFormatTypes

@testset "Check projection of file" begin
ga = GeoArrays.read(joinpath(testdatadir, "gdalworkshop/world.tif"))
@test GFT.val(crs(ga)) == wgs84_wkt
@test GFT.val(GeoInterface.crs(ga)) == wgs84_wkt
end

end
23 changes: 13 additions & 10 deletions test/test_interpolate.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
using StaticArrays
using GeoStatsSolvers
using GeoStatsTransforms
using GeoStatsModels


@testset "Interpolating rasters" begin
@testset "Regular Grid interpolation" begin
ga = GeoArray(Array{Union{Missing,Float64}}(rand(10, 10, 1)), GeoArrays.geotransform_to_affine(SVector(0.0, 1.0, 0.0, 0.0, 0.0, 1.0)), "")
ga.A[2, 2, 1] = missing
@test count(ismissing, ga.A) == 1
GeoArrays.fill!(ga, KrigingSolver())
GeoArrays.fill!(ga, IDW())
@test count(ismissing, ga.A) == 0
end
@testset "Regular Grid interpolation with negative spacing" begin
ga = GeoArray(Array{Union{Missing,Float64}}(rand(10, 10, 1)), GeoArrays.geotransform_to_affine(SVector(0.0, 1.0, 0.0, 0.0, 0.0, -1.0)), "")
ga.A[2, 2, 1] = missing
@test count(ismissing, ga.A) == 1
GeoArrays.fill!(ga, KrigingSolver())
@test count(ismissing, ga.A) == 0
end
@testset "Irregular Grid interpolation" begin
ga = GeoArray(Array{Union{Missing,Float64}}(rand(10, 10, 1)), GeoArrays.geotransform_to_affine(SVector(0.0, 1.0, 1.0, 0.0, 0.0, 1.0)), "")
ga.A[2, 2, 1] = missing
@test count(ismissing, ga.A) == 1
GeoArrays.fill!(ga, IDWSolver())
GeoArrays.fill!(ga, IDW())
@test count(ismissing, ga.A) == 0
end
# TODO Currently broken
# @testset "Irregular Grid interpolation" begin
# ga = GeoArray(Array{Union{Missing,Float64}}(rand(10, 10, 1)), GeoArrays.geotransform_to_affine(SVector(0.0, 1.0, 1.0, 0.0, 0.0, 1.0)), "")
# ga.A[2, 2, 1] = missing
# @test count(ismissing, ga.A) == 1
# GeoArrays.fill!(ga, IDW(2), maxneighbors=5)
# @test count(ismissing, ga.A) == 0
# end
end

2 comments on commit 8fe698c

@evetion
Copy link
Owner Author

@evetion evetion commented on 8fe698c Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/121004

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.2 -m "<description of version>" 8fe698cca8f4d2ed9212c8227b559bb022ab3cfd
git push origin v0.9.2

Please sign in to comment.