-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
33 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,23 @@ | ||
""" | ||
wombling(layer::T; convert_to::Type=Float64) where {T <: SimpleSDMLayer} | ||
wombling(layer::SDMLayer; convert_to::Type=Float64) | ||
Performs a lattice wombling on a `SimpleSDMLayer`. | ||
""" | ||
function wombling(layer::T; convert_to::Type = Float64) where {T <: SimpleSDMLayer} | ||
try | ||
global nan = convert(convert_to, NaN) | ||
catch | ||
throw(ArgumentError("The type given as `convert_to` must have a `NaN` value.")) | ||
end | ||
|
||
function wombling(layer::SDMLayer) | ||
|
||
# Get the values for x and y | ||
y = collect(SimpleSDMLayers.longitudes(layer)) | ||
x = collect(SimpleSDMLayers.latitudes(layer)) | ||
y = collect(SimpleSDMLayers.eastings(layer)) | ||
x = collect(SimpleSDMLayers.northings(layer)) | ||
|
||
# Get the grid | ||
z = convert(Matrix{Union{Nothing, convert_to}}, layer.grid) | ||
replace!(z, nothing => nan) | ||
return wombling(x, y, convert(Matrix{convert_to}, z)) | ||
end | ||
z = convert(Matrix{Float64}, layer.grid) | ||
z[findall(!, layer.indices)] .= NaN | ||
|
||
# We want to make sure that the layers are returned without NaN values, and | ||
# adding this method makes the code easier to write | ||
Base.isnan(::Nothing) = false | ||
|
||
function SimpleSDMLayers.SimpleSDMPredictor(W::T) where {T <: LatticeWomble} | ||
rate = SimpleSDMLayers.SimpleSDMPredictor(W.m, extrema(W.y)..., extrema(W.x)...) | ||
direction = SimpleSDMLayers.SimpleSDMPredictor(W.θ, extrema(W.y)..., extrema(W.x)...) | ||
rate.grid[findall(isnan, rate.grid)] .= nothing | ||
direction.grid[findall(isnan, direction.grid)] .= nothing | ||
return (rate, direction) | ||
end | ||
# Womble | ||
W = wombling(Float64.(x), Float64.(y), z) | ||
|
||
function SimpleSDMLayers.SimpleSDMResponse(W::T) where {T <: LatticeWomble} | ||
return convert.(SimpleSDMLayers.SimpleSDMResponse, SimpleSDMLayers.SimpleSDMPredictor(W)) | ||
# Prepare to return | ||
rate = SimpleSDMLayers.SDMLayer(W.m, (!isnan).(W.m), extrema(W.y), extrema(W.x), layer.crs) | ||
direction = SimpleSDMLayers.SDMLayer(W.θ, (!isnan).(W.m), extrema(W.y), extrema(W.x), layer.crs) | ||
return (; rate, direction) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters