Circuitscape / Circuitscape.jl

Algorithms from circuit theory to predict connectivity in heterogeneous landscapes
https://circuitscape.org
MIT License
128 stars 35 forks source link

InexactError while parsing nodata values #239

Closed VLucet closed 4 years ago

VLucet commented 4 years ago

I am running Julia 1.3.1 and circuitscape dev (adding my project and manifest file along with the ini and raster files). The patches file only contains 1 pair. I will also add that the rasters were generated with GRASS GIS 7.6.

The ini file, the rasters and the toml files: https://drive.google.com/drive/folders/1X_JmaWdS5OHvdNzyEcvv19VybhuMv74Z?usp=sharing

The error is:

julia> compute("sce_38_it_1_ts_0_BLBR_with_buffer_EW.ini")
[ Info: 2020-06-09 12:52:36 : Precision used: Double
[ Info: 2020-06-09 12:52:43 : Reading maps
ERROR: InexactError: UInt8(-1.0e10)
Stacktrace:
 [1] UInt8 at ./float.jl:688 [inlined]
 [2] convert(::Type{UInt8}, ::Float64) at ./number.jl:7
 [3] read_raster(::String, ::Type) at /opt/julia/dev/Circuitscape/src/io.jl:455
 [4] _grid_reader(::Type, ::String) at /opt/julia/dev/Circuitscape/src/io.jl:93
 [5] read_cellmap(::String, ::Bool, ::Type{Float64}) at /opt/julia/dev/Circuitscape/src/io.jl:70
 [6] load_raster_data(::Type, ::Type, ::Dict{String,String}) at /opt/julia/dev/Circuitscape/src/io.jl:384
 [7] raster_pairwise(::Type, ::Type, ::Dict{String,String}) at /opt/julia/dev/Circuitscape/src/raster/pairwise.jl:18
 [8] _compute(::Type, ::Type, ::Dict{String,String}) at /opt/julia/dev/Circuitscape/src/run.jl:42
 [9] macro expansion at ./util.jl:212 [inlined]
 [10] compute(::String) at /opt/julia/dev/Circuitscape/src/run.jl:31
 [11] top-level scope at REPL[17]:1
vlandau commented 4 years ago

I know what's going on here. Basically -9999 isn't supported by UInt8 (and many other Int types), so I need to convert Integer rasters to something like Int64 right away. Will have this fixed today.

VLucet commented 4 years ago

@vlandau thanks for your explanation. Does that mean it would work if the values in the input rasters were not integer but float?

vlandau commented 4 years ago

Yep! If you need it to work immediately it should be fine if you convert your input rasters to Float32 for now.

VLucet commented 4 years ago

Not that much in a rush - was just eager to understand. Thanks again.

vlandau commented 4 years ago

The pull request linked above should fix it. Tests take about 30 minutes to complete, and once they do, I'll merge with master and you should be good to go. Thanks for testing out the new .tif reading capabilities and discovering this issue!

ViralBShah commented 4 years ago

Should we make a new release?

vlandau commented 4 years ago

It looks like we haven't released a version with tif reading at all yet, so anyone installing from the Julia registry won't face this bug (but also won't have tif reading supported). @ranjanan and I were talking about doing a new minor release though.

VLucet commented 4 years ago

BTW, i've installed from your latest commit on your PR and it works fine now. I believe this can be closed.

vlandau commented 4 years ago

I'm going to wait to close until I finalize the PR.