From 124e220efce6e2fa5d06e5752bd45904f20cd270 Mon Sep 17 00:00:00 2001 From: Maarten Pronk <8655030+evetion@users.noreply.github.com> Date: Sun, 7 Jan 2024 19:57:50 +0100 Subject: [PATCH] Move GeoStatsBase into an ext. (#153) --- CHANGELOG.md | 10 +++++++++- Project.toml | 14 +++++++++++--- docs/Project.toml | 1 + docs/make.jl | 2 +- ext/GeoArraysStatsExt.jl | 28 ++++++++++++++++++++++++++++ src/geoarray.jl | 2 +- src/interpolate.jl | 24 ++++-------------------- 7 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 ext/GeoArraysStatsExt.jl diff --git a/CHANGELOG.md b/CHANGELOG.md index ccaa290..f2c67be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.8.3] - 2023-10-14 +## [0.8.5] - 2024-01-07 +- Fix small bug in metadata +- Move GeoStatsBase into an extension + +## [0.8.4] - 2024-01-07 +- Fix crop returning too small an array - Update GeoStatsBase compat bounds and fix interpolation + +## [0.8.3] - 2023-10-14 +- Correct roundoff errors in ranges - Drop Julia 1.6 (LTS), now requires 1.9 ## [0.8.2] - 2023-05-10 diff --git a/Project.toml b/Project.toml index 9f14b44..54d5c32 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,16 @@ name = "GeoArrays" uuid = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab" authors = ["Maarten Pronk "] -version = "0.8.4" +version = "0.8.5" + +[weakdeps] +GeoStatsBase = "323cb8eb-fbf6-51c0-afd0-f8fba70507b2" + +[extensions] +# name of extension to the left +# extension dependencies required to load the extension to the right +# use a list for multiple extension dependencies +GeoArraysStatsExt = "GeoStatsBase" [deps] ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3" @@ -10,7 +19,6 @@ DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910" GeoFormatTypes = "68eda718-8dee-11e9-39e7-89f7f65f511f" GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f" -GeoStatsBase = "323cb8eb-fbf6-51c0-afd0-f8fba70507b2" IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e" PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" @@ -23,7 +31,7 @@ DataAPI = "1" Extents = "0.1" GeoFormatTypes = "0.4" GeoInterface = "1" -GeoStatsBase = "0.37, 0.38, 0.39" +GeoStatsBase = "0.37 - 0.43" IterTools = "1" PrecompileTools = "1" RecipesBase = "0.7, 0.8, 1.0" diff --git a/docs/Project.toml b/docs/Project.toml index 0860c37..6b6abfa 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,3 +1,4 @@ [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" GeoArrays = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab" +GeoStatsBase = "323cb8eb-fbf6-51c0-afd0-f8fba70507b2" diff --git a/docs/make.jl b/docs/make.jl index 91ea75b..7cc65ba 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,5 +1,5 @@ push!(LOAD_PATH, "../src/") -using Documenter, GeoArrays +using Documenter, GeoArrays, GeoStatsBase cl = joinpath(@__DIR__, "src/CHANGELOG.md") isfile(cl) || cp(joinpath(@__DIR__, "../CHANGELOG.md"), cl) diff --git a/ext/GeoArraysStatsExt.jl b/ext/GeoArraysStatsExt.jl new file mode 100644 index 0000000..ae9b634 --- /dev/null +++ b/ext/GeoArraysStatsExt.jl @@ -0,0 +1,28 @@ +module GeoArraysStatsExt + +using GeoArrays, GeoStatsBase + +""" + fill!(ga::GeoArray, solver::EstimationSolver, band=1) + +Replace missing values in GeoArray `ga` using `solver` from the GeoStats ecosystem. +""" +function GeoArrays.fill!(ga::GeoArray, solver::T, band=1) where {T<:EstimationSolver} + 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) + + data[m] .= getproperty(solution, :band) + ga +end + +@deprecate interpolate!(ga::GeoArray, solver::T, band=1) where {T<:EstimationSolver} fill!(ga, solver, band) + +end diff --git a/src/geoarray.jl b/src/geoarray.jl index 4bd02e6..334d7b4 100644 --- a/src/geoarray.jl +++ b/src/geoarray.jl @@ -259,7 +259,7 @@ function DataAPI.metadata(ga::GeoArray; style=false) end function DataAPI.metadata!(ga::GeoArray, key::AbstractString, value::AbstractString; style::Symbol=:default, domain::Union{Nothing,AbstractString}=nothing) d = isnothing(domain) ? "ROOT" : domain - metadata(ga)[d][k] = value + metadata(ga)[d][key] = value end function DataAPI.emptymetadata!(ga::GeoArray) ga.metadata = Dict{String,Any}() diff --git a/src/interpolate.jl b/src/interpolate.jl index cb3954b..5a8ee7a 100644 --- a/src/interpolate.jl +++ b/src/interpolate.jl @@ -1,24 +1,8 @@ -using GeoStatsBase - """ - fill!(ga::GeoArray, solver::EstimationSolver, band=1) + fill!(ga::GeoArray, solver, band=1) -Replace missing values in GeoArray `ga` using `solver` from the GeoStats ecosystem. +Replace missing values in GeoArray `ga` using `solver`. """ -function fill!(ga::GeoArray, solver::T, band=1) where {T<:EstimationSolver} - 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) - - data[m] .= getproperty(solution, :band) - ga +function fill!(::GeoArray, solver, band) + error("fill! using $solver is not implemented yet. Please use an `EstimationSolver` from the GeoStats.jl ecosystem.") end - -@deprecate interpolate!(ga::GeoArray, solver::T, band=1) where {T<:EstimationSolver} fill!(ga, solver, band)