Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.

Commit c801f96

Browse files
committed
Refactor PointPattern
1 parent 4439258 commit c801f96

File tree

5 files changed

+26
-46
lines changed

5 files changed

+26
-46
lines changed

Project.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ version = "0.1.0"
77
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
88
GeoStatsBase = "323cb8eb-fbf6-51c0-afd0-f8fba70507b2"
99
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
10-
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1110

1211
[compat]
1312
Distributions = "0.21"
1413
GeoStatsBase = "0.7"
1514
RecipesBase = "0.7"
16-
StaticArrays = "0.12"
1715
julia = "1"
1816

1917
[extras]

src/PointPatterns.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ module PointPatterns
66

77
using GeoStatsBase
88

9-
using Distributions: Uniform, Poisson, product_distribution
10-
using StaticArrays: SVector, MVector
9+
using Distributions
1110
using RecipesBase
1211

13-
import GeoStatsBase: npoints, coordinates, coordinates!
12+
import GeoStatsBase: npoints, coordinates
1413

1514
include("pattern.jl")
1615
include("processes.jl")
@@ -24,7 +23,6 @@ export
2423
PointPattern,
2524
npoints,
2625
coordinates,
27-
coordinates!,
2826

2927
# point processes
3028
PointProcess,

src/pattern.jl

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,60 +20,27 @@ PointPattern(coords::AbstractMatrix{T}) where {T} =
2020
PointPattern(coords::AbstractVector{NTuple{N,T}}) where {N,T} =
2121
PointPattern([c[i] for i in 1:N, c in coords])
2222

23-
npoints(pp::PointPattern) = size(pp.coords, 2)
24-
2523
"""
26-
coordinates(pp, ind)
24+
npoints(pp)
2725
28-
Return the coordinates of the `ind`-th point in the point pattern `pp`.
26+
Return number of points in spatial point pattern `pp`.
2927
"""
30-
function coordinates(pp::PointPattern{T,N}, ind::Int) where {N,T}
31-
x = MVector{N,T}(undef)
32-
coordinates!(x, pp, ind)
33-
x
34-
end
28+
npoints(pp::PointPattern) = size(pp.coords, 2)
3529

3630
"""
3731
coordinates(pp, inds)
3832
39-
Return the coordinates of the points `inds` in the point pattern `pp`.
33+
Return the coordinates of the points at indices `inds` in
34+
the point pattern `pp`.
4035
"""
41-
function coordinates(pp::PointPattern{T,N}, inds::AbstractVector{Int}) where {N,T}
42-
X = Matrix{T}(undef, N, length(inds))
43-
coordinates!(X, pp, inds)
44-
X
45-
end
36+
coordinates(pp::PointPattern{T,N}, inds) where {N,T} = view(pp.coords, :, inds)
4637

4738
"""
4839
coordinates(pp)
4940
5041
Return the coordinates of all points in point pattern `pp`.
5142
"""
52-
coordinates(pp::PointPattern) = coordinates(pp, 1:npoints(pp))
53-
54-
"""
55-
coordinates!(buff, pp, inds)
56-
57-
Non-allocating version of [`coordinates`](@ref)
58-
"""
59-
function coordinates!(buff::AbstractMatrix, pp::PointPattern,
60-
inds::AbstractVector{Int})
61-
for j in 1:length(inds)
62-
coordinates!(view(buff,:,j), pp, inds[j])
63-
end
64-
end
65-
66-
"""
67-
coordinates!(buff, pp, ind)
68-
69-
Non-allocating version of [`coordinates`](@ref).
70-
"""
71-
function coordinates!(buff::AbstractVector{T}, pp::PointPattern{T,N},
72-
ind::Int) where {N,T}
73-
for i in 1:N
74-
@inbounds buff[i] = pp.coords[i,ind]
75-
end
76-
end
43+
coordinates(pp::PointPattern) = pp.coords
7744

7845
# ------------
7946
# IO methods

src/thinning.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ Thin spatial point process `p` with thinning method `t`.
1616
"""
1717
thin(p::PointProcess, t::AbstractThinning) = @error "not implemented"
1818

19+
"""
20+
thin(pp, t)
21+
22+
Thin spatial point pattern `pp` with thinning method `t`.
23+
"""
24+
thin(pp::PointPattern, t::AbstractThinning) = @error "not implemented"
25+
1926
#-----------------
2027
# IMPLEMENTATIONS
2128
#-----------------

src/thinning/random.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ struct RandomThinning{P<:Union{Real,Function}} <: AbstractThinning
1111
p::P
1212
end
1313

14+
# -----------------------
15+
# thinning point process
16+
# -----------------------
1417
thin(p::PoissonProcess{<:Real}, t::RandomThinning{<:Real}) =
1518
PoissonProcess(t.p * p.λ)
1619

@@ -22,3 +25,10 @@ thin(p::PoissonProcess{<:Real}, t::RandomThinning{<:Function}) =
2225

2326
thin(p::PoissonProcess{<:Function}, t::RandomThinning{<:Real}) =
2427
PoissonProcess(u -> t.p * p.λ(u))
28+
29+
# -----------------------
30+
# thinning point pattern
31+
# -----------------------
32+
function thin(pp::PointPattern{T,N}, t::RandomThinning{<:Real}) where {N,T}
33+
# TODO
34+
end

0 commit comments

Comments
 (0)