Giter Club home page Giter Club logo

neutrallandscapes.jl's People

Contributors

github-actions[bot] avatar gottacatchenall avatar mkborregaard avatar rafaqz avatar tpoisot avatar virgile-baudrot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

neutrallandscapes.jl's Issues

[RFC] adding methods for temporal change in neutral landscapes

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)

Problem with wavesurface

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))

wave_problem
The manual seems to have the right behaviour - a sine wave with three periods

`normalize` can't handle NaNs

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

Add voronoi grid

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])

image

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)

image

DiamondSquare warning?

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.

Euclidean Distance Transform

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.

MethodError: no method matching NearestNeighborCluster(::Float64)

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:

  • OS: MacOS 11.2.3 (20D91) (Big Sur)
  • Julia version: Version 1.5.4 (2021-03-11)
  • Other packages used in the example and their versions: using NeutralLandscapes, Plots

Tag?

When #39 is solved, do we want to tag the first release?

TagBot trigger issue

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!

NearestNeighborCluser is broken with :queen

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:

  • OS: Arch Linux
  • Julia version: 1.5
  • Other packages used in the example and their versions:

code organisation

Do we really need small files for every algorithm? Or would NeutralLandscapes.jl, utils.jl and algorithms.jl be clearer?

HaltonSequences is misbehaving

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?

Progress on landscape makers

The list below is for housekeeping, let's add PR / usernames after the ones that are left to do.

Done

  • planar gradient
  • edge gradient
  • no gradient
  • wave surface
  • distance gradient #13
  • random rectangular cluster #12
  • Perlin noise #18
  • random cluster nearest neighbor #41
  • diamond square and mpd #19
  • random element nearest neighbor #22

In progress

Todo

two abstract types of landscape makers

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.