Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Julia states my habitat file is empty #366

Closed
merijnvdb opened this issue Sep 20, 2022 · 7 comments
Closed

Julia states my habitat file is empty #366

merijnvdb opened this issue Sep 20, 2022 · 7 comments
Assignees

Comments

@merijnvdb
Copy link

merijnvdb commented Sep 20, 2022

See below my error, I will also attach the content of my .ini file. My resistance raster is 23MB (and thus not empty)

[Circuitscape Mode]
data_type = raster
scenario = pairwise

[Version]
version = 5.11.2

[Habitat raster or graph]
habitat_file = D:\Merijn\Desktop\circuitch2\resraster_new.tif
habitat_map_is_resistances = true

[Connection Scheme for raster habitat data]
connect_four_neighbors_only = false
connect_using_avg_resistances = false

[Short circuit regions (aka polygons)]
use_polygons = false
polygon_file = False

[Options for advanced mode]
ground_file_is_resistances = true
source_file = (Browse for a current source file)
remove_src_or_gnd = keepall
ground_file = (Browse for a ground point file)
use_unit_currents = false
use_direct_grounds = false

[Mask file]
use_mask = false
mask_file = None

[Options for one-to-all and all-to-one modes]
use_variable_source_strengths = false
variable_source_file = None

[Options for pairwise and one-to-all and all-to-one modes]
included_pairs_file = (Browse for a file with pairs to include or exclude)
use_included_pairs = false
point_file = D:\Merijn\Desktop\circuitch2\new_nodes.tif

[Calculation options]
solver = cg+amg
parallelize = true
max_parallel = 3

[Output options]
write_cum_cur_map_only = true
log_transform_maps = false
output_file = D:\Merijn\Desktop\circuitch2\settings
write_max_cur_maps = false
write_volt_maps = false
set_null_currents_to_nodata = false
set_null_voltages_to_nodata = false
compress_grids = false
write_cur_maps = true

julia> compute("D:\Merijn\Desktop\circuitch2\newest.ini")
I need to do double backslash to avoid an error: syntax:invalid escape sequence
[ Info: 2022-09-19 20:59:00 : Precision used: Double
[ Info: 2022-09-19 20:59:01 : Starting up Circuitscape to use 3 processes in parallel
[ Info: 2022-09-19 20:59:17 : Reading maps
ERROR: "Error: zero resistance values are not currently supported for habitat maps. Use a short-circuit region file instead."
Stacktrace:
[1] read_cellmap(habitat_file::String, is_res::Bool, #unused#::Type{Float64})
@ Circuitscape C:\Users\merij.julia\packages\Circuitscape\XpftG\src\io.jl:89
[2] load_raster_data(T::Type, V::Type, cfg::Dict{String, String})
@ Circuitscape C:\Users\merij.julia\packages\Circuitscape\XpftG\src\io.jl:429
[3] raster_pairwise(T::Type, V::Type, cfg::Dict{String, String})
@ Circuitscape C:\Users\merij.julia\packages\Circuitscape\XpftG\src\raster\pairwise.jl:18
[4] _compute(T::Type, V::Type, cfg::Dict{String, String})
@ Circuitscape C:\Users\merij.julia\packages\Circuitscape\XpftG\src\run.jl:43
[5] macro expansion
@ .\timing.jl:287 [inlined]
[6] compute(path::String)
@ Circuitscape C:\Users\merij.julia\packages\Circuitscape\XpftG\src\run.jl:31
[7] top-level scope
@ REPL[4]:1

@merijnvdb
Copy link
Author

In case it helps, here are my raster files (for nodes + habitat map) and .ini file
https://we.tl/t-fGP0sIR2N9

@ranjanan ranjanan self-assigned this Oct 20, 2022
@ranjanan
Copy link
Member

ranjanan commented Oct 21, 2022

Your habitat file is not empty, but does contain zeros. At least according to how Circuitscape is reading it:

x = Circuitscape.read_raster("resraster_new.tif", Float64)
count(iszero, x)

returns

16539

We don't support rasters like that currently because that would result in a conductance matrix with Inf in them. Can you replace the zeros with values that are small relative to the rest of your parametrization?

@merijnvdb
Copy link
Author

merijnvdb commented Oct 21, 2022

It still isn't working after changing all zeros in the raster to a different value.
I will attach a link to the new files, and please see below the error.

Wetransfer file: https://we.tl/t-Nr0wCHbGZh

ERROR: MethodError: Cannot `convert` an object of type Nothing to an object of type Float32
Closest candidates are:
  convert(::Type{T}, ::T) where T<:Number at number.jl:6
  convert(::Type{T}, ::Number) where T<:Number at number.jl:7
  convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at twiceprecision.jl:250
  ...
Stacktrace:
  [1] (::Circuitscape.var"#70#71"{DataType})(raw::ArchGDAL.Dataset)
    @ Circuitscape C:\Users\mvandenbosch\.julia\packages\Circuitscape\QbA2E\src\io.jl:511
  [2] read(f::Circuitscape.var"#70#71"{DataType}, args::String; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ ArchGDAL C:\Users\mvandenbosch\.julia\packages\ArchGDAL\zkx2f\src\context.jl:267
  [3] read(f::Function, args::String)
    @ ArchGDAL C:\Users\mvandenbosch\.julia\packages\ArchGDAL\zkx2f\src\context.jl:265
  [4] read_raster
    @ C:\Users\mvandenbosch\.julia\packages\Circuitscape\QbA2E\src\io.jl:492 [inlined]
  [5] _grid_reader(T::Type, file::String)
    @ Circuitscape C:\Users\mvandenbosch\.julia\packages\Circuitscape\QbA2E\src\io.jl:106
  [6] read_cellmap(habitat_file::String, is_res::Bool, #unused#::Type{Float64})
    @ Circuitscape C:\Users\mvandenbosch\.julia\packages\Circuitscape\QbA2E\src\io.jl:83
  [7] load_raster_data(T::Type, V::Type, cfg::Dict{String, String})
    @ Circuitscape C:\Users\mvandenbosch\.julia\packages\Circuitscape\QbA2E\src\io.jl:429
  [8] raster_pairwise(T::Type, V::Type, cfg::Dict{String, String})
    @ Circuitscape C:\Users\mvandenbosch\.julia\packages\Circuitscape\QbA2E\src\raster\pairwise.jl:18
  [9] _compute(T::Type, V::Type, cfg::Dict{String, String})
    @ Circuitscape C:\Users\mvandenbosch\.julia\packages\Circuitscape\QbA2E\src\run.jl:43
 [10] macro expansion
    @ .\timing.jl:287 [inlined]
 [11] compute(path::String)
    @ Circuitscape C:\Users\mvandenbosch\.julia\packages\Circuitscape\QbA2E\src\run.jl:31
 [12] top-level scope
    @ REPL[6]:1

@ranjanan
Copy link
Member

Looks like you set your nodata value to nothing? Could you set it to something like -9999? The

julia> f = Circuitscape.ArchGDAL.read("wetransfer_untitled-transfer_2022-10-21_2337\\newraster\\nozeroraster.tif")
GDAL Dataset (Driver: GTiff/GeoTIFF)
File(s):
  wetransfer_untitled-transfer_2022-10-21_2337\newraster\nozeroraster.tif
  wetransfer_untitled-transfer_2022-10-21_2337\newraster\nozeroraster.tif.ovr
  wetransfer_untitled-transfer_2022-10-21_2337\newraster\nozeroraster.tif.aux.xml

Dataset (width x height): 7007 x 3878 (pixels)
Number of raster bands: 1
  [GA_ReadOnly] Band 1 (Gray): 7007 x 3878 (Float32)


julia> band = Circuitscape.ArchGDAL.getband(f, 1)
[GA_ReadOnly] Band 1 (Gray): 7007 x 3878 (Float32)
    blocksize: 128×128, nodata: nothing, units: 1.0px + 0.0
    overviews: (0) 3504x1939 (1) 1752x970 (2) 876x485
               (3) 438x243

In the previous file you set it to something like

julia> f2 = Circuitscape.ArchGDAL.read("resraster_new.tif")
GDAL Dataset (Driver: GTiff/GeoTIFF)
File(s):
  resraster_new.tif

Dataset (width x height): 7007 x 3878 (pixels)
Number of raster bands: 1
  [GA_ReadOnly] Band 1 (Gray): 7007 x 3878 (Float32)

julia> band2 = Circuitscape.ArchGDAL.getband(f2, 1)
[GA_ReadOnly] Band 1 (Gray): 7007 x 3878 (Float32)
    blocksize: 128×128, nodata: 3.3999999521443642e38, units: 1.0px + 0.0
    overviews:

@merijnvdb
Copy link
Author

merijnvdb commented Oct 24, 2022 via email

@merijnvdb
Copy link
Author

merijnvdb commented Oct 24, 2022 via email

@ranjanan
Copy link
Member

Closing this due to inactivity, and a subsequent email chain. Please reopen if this is a problem with the latest versions, which have many updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants