Skip to content

Commit

Permalink
Merge branch 'main' into column-selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv authored Sep 29, 2023
2 parents e7a2783 + 419bb5c commit ba9046f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GeoStatsTransforms"
uuid = "725d9659-360f-4996-9c94-5f19c7e4a8a6"
authors = ["Júlio Hoffimann <julio.hoffimann@gmail.com> and contributors"]
version = "0.1.5"
version = "0.1.7"

[deps]
ArnoldiMethod = "ec485272-7323-5ecc-a04f-4719b315124d"
Expand Down
13 changes: 13 additions & 0 deletions src/feature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ end

# --------------------------------------------------

function applymeta(::DropExtrema, dom::Domain, prep)
ftrans, fprep = prep
newmeta, fmcache = applymeta(ftrans, dom, fprep)
newmeta, (ftrans, fmcache)
end

function revertmeta(::DropExtrema, newdom::Domain, mcache)
ftrans, fmcache = mcache
revertmeta(ftrans, newdom, fmcache)
end

# --------------------------------------------------

function applymeta(::Sample, dom::Domain, prep)
sinds, rinds = prep

Expand Down
12 changes: 9 additions & 3 deletions src/interpneighbors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

"""
InterpolateNeighbors(domain, vars₁ => model₁, ..., varsₙ => modelₙ; [parameters])
InterpolateNeighbors([g₁, g₂, ..., gₙ], vars₁ => model₁, ..., varsₙ => modelₙ; [parameters])
Interpolate geospatial data on given `domain` using geostatistical models
`model₁`, ..., `modelₙ` for variables `vars₁`, ..., `varsₙ`.
Interpolate geospatial data on given `domain` or set of geometries `g₁`, `g₂`, ..., `gₙ`,
using geostatistical models `model₁`, ..., `modelₙ` for variables `vars₁`, ..., `varsₙ`.
InterpolateNeighbors(domain, model=IDW(); [parameters])
InterpolateNeighbors([g₁, g₂, ..., gₙ], model=IDW(); [parameters])
Interpolate geospatial data on given `domain` using geostatistical `model` for all variables.
Interpolate geospatial data on given `domain` or set of geometries `g₁`, `g₂`, ..., `gₙ`,
using geostatistical `model` for all variables.
Unlike [`Interpolate`](@ref), this transform uses neighbor search methods to
fit geostatistical models at each interpolation location with a reduced number
Expand Down Expand Up @@ -73,6 +76,9 @@ InterpolateNeighbors(
prob
)

InterpolateNeighbors(geoms::AbstractVector{<:Geometry}, selectors, models; kwargs...) =
InterpolateNeighbors(GeometrySet(geoms), selectors, models; kwargs...)

InterpolateNeighbors(domain::Domain, model::GeoStatsModel=IDW(); kwargs...) =
InterpolateNeighbors(domain, [AllSelector()], [model]; kwargs...)

Expand Down
12 changes: 9 additions & 3 deletions src/interpolate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

"""
Interpolate(domain, vars₁ => model₁, ..., varsₙ => modelₙ; [parameters])
Interpolate([g₁, g₂, ..., gₙ], vars₁ => model₁, ..., varsₙ => modelₙ; [parameters])
Interpolate geospatial data on given `domain` using geostatistical models
`model₁`, ..., `modelₙ` for variables `vars₁`, ..., `varsₙ`.
Interpolate geospatial data on given `domain` or set of geometries `g₁`, `g₂`, ..., `gₙ`,
using geostatistical models `model₁`, ..., `modelₙ` for variables `vars₁`, ..., `varsₙ`.
Interpolate(domain, model=IDW(); [parameters])
Interpolate([g₁, g₂, ..., gₙ], model=IDW(); [parameters])
Interpolate geospatial data on given `domain` using geostatistical `model` for all variables.
Interpolate geospatial data on given `domain` or set of geometries `g₁`, `g₂`, ..., `gₙ`,
using geostatistical `model` for all variables.
## Parameters
Expand All @@ -30,6 +33,9 @@ end
Interpolate(domain::Domain, selectors, models; point=true, prob=false) =
Interpolate(domain, collect(ColumnSelector, selectors), collect(GeoStatsModel, models), point, prob)

Interpolate(geoms::AbstractVector{<:Geometry}, selectors, models; kwargs...) =
Interpolate(GeometrySet(geoms), selectors, models; kwargs...)

Interpolate(domain::Domain, model::GeoStatsModel=IDW(); kwargs...) =
Interpolate(domain, [AllSelector()], [model]; kwargs...)

Expand Down
1 change: 1 addition & 0 deletions test/feature.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Sample(10),
Filter(x -> true),
DropMissing(),
DropExtrema(:z),
Replace(1.0 => 2.0),
Coalesce(value=0.0),
Coerce(:z => Continuous),
Expand Down
12 changes: 6 additions & 6 deletions test/interpneighbors.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@testset "InterpolateNeighbors" begin
@test !isrevertible(InterpolateNeighbors(CartesianGrid(2, 2)))

pset = PointSet(rand(Point2, 3))
gtb = georef((a=[1, 2, 3], b=[4, 5, 6]), pset)
ngtb = gtb |> InterpolateNeighbors(pset, IDW(), maxneighbors=3)
points = rand(Point2, 3)
gtb = georef((a=[1, 2, 3], b=[4, 5, 6]), points)
ngtb = gtb |> InterpolateNeighbors(points, IDW(), maxneighbors=3)
@test ngtb.a == gtb.a
@test ngtb.b == gtb.b
@test ngtb.geometry == pset
@test ngtb.geometry == gtb.geometry

gtb = georef((; z=[1.0, 0.0, 1.0]), [(25.0, 25.0), (50.0, 75.0), (75.0, 50.0)])
grid = CartesianGrid((100, 100), (0.5, 0.5), (1.0, 1.0))
Expand All @@ -32,13 +32,13 @@
@test isapprox(ngtb.z[linds[75, 50]], 1.0, atol=1e-3)

# units
gtb = georef((; T=[1.0, 0.0, 1.0] * u"K"), pset)
gtb = georef((; T=[1.0, 0.0, 1.0] * u"K"), points)
grid = CartesianGrid(5, 5)
ngtb = gtb |> InterpolateNeighbors(grid)
@test GeoStatsTransforms.elunit(ngtb.T) == u"K"

# affine units
gtb = georef((; T=[-272.15, -273.15, -272.15] * u"°C"), pset)
gtb = georef((; T=[-272.15, -273.15, -272.15] * u"°C"), points)
ngtb = gtb |> InterpolateNeighbors(grid)
@test GeoStatsTransforms.elunit(ngtb.T) == u"K"
end
12 changes: 6 additions & 6 deletions test/interpolate.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@testset "Interpolate" begin
@test !isrevertible(Interpolate(CartesianGrid(2, 2)))

pset = PointSet(rand(Point2, 3))
gtb = georef((a=[1, 2, 3], b=[4, 5, 6]), pset)
ngtb = gtb |> Interpolate(pset, IDW())
points = rand(Point2, 3)
gtb = georef((a=[1, 2, 3], b=[4, 5, 6]), points)
ngtb = gtb |> Interpolate(points, IDW())
@test ngtb.a == gtb.a
@test ngtb.b == gtb.b
@test ngtb.geometry == pset
@test ngtb.geometry == gtb.geometry

gtb = georef((; z=[1.0, 0.0, 1.0]), [(25.0, 25.0), (50.0, 75.0), (75.0, 50.0)])
grid = CartesianGrid((100, 100), (0.5, 0.5), (1.0, 1.0))
Expand All @@ -20,13 +20,13 @@
@test isapprox(ngtb.z[linds[75, 50]], 1.0, atol=1e-3)

# units
gtb = georef((; T=[1.0, 0.0, 1.0] * u"K"), pset)
gtb = georef((; T=[1.0, 0.0, 1.0] * u"K"), points)
grid = CartesianGrid(5, 5)
ngtb = gtb |> Interpolate(grid)
@test GeoStatsTransforms.elunit(ngtb.T) == u"K"

# affine units
gtb = georef((; T=[-272.15, -273.15, -272.15] * u"°C"), pset)
gtb = georef((; T=[-272.15, -273.15, -272.15] * u"°C"), points)
ngtb = gtb |> Interpolate(grid)
@test GeoStatsTransforms.elunit(ngtb.T) == u"K"
end

0 comments on commit ba9046f

Please sign in to comment.