ecojulia / neutrallandscapes.jl Goto Github PK
View Code? Open in Web Editor NEWGeneration of neutral landscapes in Julia.
Home Page: https://ecojulia.github.io/NeutralLandscapes.jl/dev/
License: MIT License
Generation of neutral landscapes in Julia.
Home Page: https://ecojulia.github.io/NeutralLandscapes.jl/dev/
License: MIT License
As part of an ongoing project, I need a way to simulate species occurrence as a function of the environment, where the environment changes in a neutral way (see this issue). I can imagine adding methods for various types of environmental change (whether is be directional change or random fluctuations around the mean) could be useful in many contexts
Describe the solution you'd like
A clear and concise description of what you want to happen.
using NeutralLandscapes
# this already exists
env = rand(MidpointDisplacement(0.5), 250, 250)
# new stuff
rate = 5
change = Directional(rate, θ = 90)
update!(env, change)
When #39 is solved, do we want to tag the first release?
We (me + @TanyaS08 and @Beasley015) have been running into issues with NeutralLandscapes
using julia 1.9 in different projects, on different OS. I can install the package just fine on its own, but with additional project dependencies, it sometimes chokes because there's an issue with HaltonSequences
and its Primes
dependency.
I started the bug/HaltonSequences1dot9
branch to see what's up, but maybe @gottacatchenall has encountered the same?
The following lines provide a simple way to make grid landscape using voronoi tesselation. It's working but need to be reframe to fit package requirement.
Computing the voronoi is done using VoronoiCells.jl and then the rasterization is by using ArchGDAL.jl.
Digging into both dependencies, I should be able to make things clearer.
using VoronoiCells
using GeometryBasics
using ArchGDAL
using Distributions
using Plots
const VC=VoronoiCells
const GB=GeometryBasics
const AG=ArchGDAL
const DB=Distributions
I created 3 functions. The 2 first create the set of polygones
function voronoitess(min_x, max_x, min_y, max_y, nCell::Int)
rect = VC.Rectangle(GB.Point2(min_x, min_y), GB.Point2(max_x, max_y))
points = [GB.Point2(rand(DB.Uniform(min_x, max_x)), rand(DB.Uniform(min_y, max_y))) for _ in 1:nCell]
return (tess=VC.voronoicells(points, rect),rect,points)
end
vortess = voronoitess(0, 1, 0, 1, 100)
function polygonset(tess)
tc = tess.tess.Cells
poly = [ArchGDAL.createpolygon([(tc[i][j][1], tc[i][j][2]) for j in vcat(1:length(tc[i]),1)])
for i in 1:length(tc)]
return (poly, tess.rect, tess.points)
end
polyset = polygonset(vortess)
plot(polyset[1])
And the last is making a rasterization providing some features:
# Create a grid over the map
function rasterize(polygonset, nrow, ncol,feature)
w = rect.UpperRight[1] - rect.LowerLeft[1]
h = rect.UpperRight[2] - rect.LowerLeft[2]
gridcell_x=w/ncol
gridcell_y=h/nrow
gridX=(rect.LowerLeft[1]:gridcell_x:(rect.UpperRight[1]-gridcell_x)) .+ (gridcell_x/2)
gridY=(rect.LowerLeft[2]:gridcell_y:(rect.UpperRight[2]-gridcell_y)) .+ (gridcell_y/2)
gridX_seq=repeat(gridX,inner=nrow)
gridY_seq=repeat(gridY,outer=ncol)
gridCell = fill(0,nrow,ncol)
for j in 1:length(gridCell)
for i in 1:length(polygonset[1])
if AG.contains(polygonset[1][i],
AG.createpoint((gridX_seq[j], gridY_seq[j]))
)
gridCell[j] = feature[i]
end
end
end
return gridCell
end
feature = rand(0:3,length(polyset[1]))
nrow, ncol = 200, 10
gridCell = rasterize(polyset, nrow, ncol, feature)
Plots.heatmap(gridCell)
julia> rand(PerlinNoise(), 10, 10);
julia> rand(PerlinNoise(), 10, 12);
ERROR: DimensionMismatch("array could not be broadcast to match destination")
What to do?
I think we need a ContinuousNeutralLandscapeMaker and a DiscreteNeutralLandscapeMaker
Why?
Because the discrete ("classed") landscapes shouldn't be 0-1 rescaled by rand
Any ideas how?
ez
When checking the extrema of either methods, the minimum is rarely 0.
DIstance gradients (#13) and a bunch of other are using the Euclidean Distance Transform from numpy (which is actually from Matlab). The two implementations in Julia that I found are in SignedDistanceFields
(but it doesn't do what we want) and Images
(but that's a lot of dependencies to add).
The solution is likely to write our own edt.
Describe the bug
following error generated when I try to execute
Fig1i = rand(NearestNeighborCluster(0.4), siz)
ERROR: MethodError: no method matching NearestNeighborCluster(::Float64)
Environment:
I'd suggest having the readme show the code (and result) of repeating Fig 1 of the paper here: https://besjournals.onlinelibrary.wiley.com/doi/full/10.1111/2041-210X.12308
The Python code for doing it is here: https://besjournals.onlinelibrary.wiley.com/action/downloadSupplement?doi=10.1111%2F2041-210X.12308&file=mee312308-sup-0002-dataS2.py
And then maybe below our planned benchmarking exercise.
Do we really need small files for every algorithm? Or would NeutralLandscapes.jl, utils.jl and algorithms.jl be clearer?
This warning for DiamondSquare is a bit odd:
Warning: DiamondSquare(0.5) cannot be run on the input dimensions (50 x 200),
│ and will instead run on the next smallest valid size (257 x 257).
│ This can slow performance as it involves additional memory allocation.
└ @ NeutralLandscapes ~/julia/NeutralLandscapes/src/algorithms/diamondsquare.jl:75
The same size problem exists in other rules, at least PerlinNoise
- which is essentially based around making larger grids than the output grid - and we should be consistent.
I think it would make more sense to have a warning once allocations are larger than a certain size, or not have one at all and warn in the docs. Because warning for small arrays like the above isn't necessary, and once you get the warning, you're already allocating the memory.
Describe the bug
The wavesurface code seems not to work correctly. I also had this issue yesterday with my code. I can't really locate what the issue is, as doing it manually seems to work fine.
To Reproduce
using NeutralLandscapes, Plots
wv_auto = rand(WaveSurface(110, 3), (50, 50));
wv_manual = NeutralLandscapes._rescale!(sin.(rand(PlanarGradient(110), (50, 50)) * 2π * 3));
plot(heatmap(wv_auto), heatmap(wv_manual), size = (750, 300))
The manual seems to have the right behaviour - a sine wave with three periods
Describe the bug
julia> rand(NearestNeighborCluster(; n=:queen), 100, 100)
ERROR: InexactError: Int64(-0.8399155691543502)
Stacktrace:
[1] Int64(::Float64) at ./float.jl:710
[2] label(::Array{Float64,2}, ::Symbol) at /home/raf/julia/NeutralLandscapes/src/classify.jl:118
[3] _landscape!(::Array{Float64,2}, ::NearestNeighborCluster) at /home/raf/julia/NeutralLandscapes/src/algorithms/nncluster.jl:25
[4] #rand!#3 at /home/raf/julia/NeutralLandscapes/src/landscape.jl:32 [inlined]
[5] #rand#1 at /home/raf/julia/NeutralLandscapes/src/landscape.jl:20 [inlined]
[6] #rand#2 at /home/raf/julia/NeutralLandscapes/src/landscape.jl:22 [inlined]
[7] rand(::NearestNeighborCluster, ::Int64, ::Int64) at /home/raf/julia/NeutralLandscapes/src/landscape.jl:22
[8] top-level scope at REPL[2]:1
Environment:
This issue is used to trigger TagBot; feel free to unsubscribe.
If you haven't already, you should update your TagBot.yml
to include issue comment triggers.
Please see this post on Discourse for instructions and more details.
If you'd like for me to do this for you, comment TagBot fix
on this issue.
I'll open a PR within a few hours, please be patient!
The list below is for housekeeping, let's add PR / usernames after the ones that are left to do.
Describe the bug
If you call normalize
on an initial landscape with NaNs, some numbers get turned into nans
To Reproduce
using Plots
using SimpleSDMLayers
using Distributions
ENV["SDMLAYERS_PATH"] = "/home/michael/data/"
quebec = SimpleSDMPredictor(WorldClim, BioClim; left=-90., right=-55., top=60., bottom=45.)
qcmask = fill(true, size(quebec))
qcmask[findall(isnothing, quebec.grid)] .= false
init = rand(PerlinNoise((2,2)), size(quebec), mask=qcmask)
svu = SpatiotemporallyAutocorrelatedUpdater(
rate = 0.01,
variability = 0.01,
spatialupdater = PlanarGradient(90)
)
seq = normalize(update(svu, init, 30))
Expected behavior
Should leave NaNs in place but not convert numbers to NaNs
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.