PoisotLab / SimpleSDMLayers.jl

Simple layers for species distribution modeling and bioclimatic data
https://docs.ecojulia.org/SimpleSDMLayers.jl/stable/
MIT License
19 stars 2 forks source link

findmin and findmax do not work as expected 🐛 #144

Closed gottacatchenall closed 2 years ago

gottacatchenall commented 2 years ago

Contact Details

No response

What happened?

Here's a demo of the bug using SimpleSDMLayers v0.8.3 on Julia 1.8

bbox = (left=-83.0, bottom=46.4, right=-55.2, top=63.7);
temp = convert(Float32, SimpleSDMPredictor(WorldClim, BioClim, 7; bbox...))

tempmin, tempmax = extrema(temp)
> (1.0f0, 51.8575f0)

findmax(temp)
> ([-55.25, 52.083333333333336] => 28.3f0, [-55.25, 52.083333333333336])

findmin(temp)
> ([-82.91666666666667, 46.416666666666664] => 40.6895f0, [-82.91666666666667, 46.416666666666664])

So clearly something is off here, as the value returns by findmin is greater than that returned by findmax, and neither align with the extrema call

Stacktrace

No response

tpoisot commented 2 years ago

Yeah I tried with a simple layer and it Works on My Machine ™️ , but I'll build an actual test and report back.

tpoisot commented 2 years ago

So I tracked down what is happening -- essentially, findmax works on the iterable structure of the layer, which returns pairs (from points to values), and the isless operation is applied to this.

tpoisot commented 2 years ago

This has probably an easy fix, I'll work on this today.

tpoisot commented 2 years ago

See #146 which adds findmin and findmax + findall, findfirst, findlast