From 8aa8fbf992effefa9f4d68cf1d62ce9c30beb62f Mon Sep 17 00:00:00 2001 From: ranjanan Date: Sat, 5 Jan 2019 19:07:40 -0500 Subject: [PATCH 01/11] Fix file type and included pairs reading --- src/consts.jl | 12 +++++++ src/io.jl | 86 +++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 85 insertions(+), 13 deletions(-) diff --git a/src/consts.jl b/src/consts.jl index d6fbd1d9..04756365 100644 --- a/src/consts.jl +++ b/src/consts.jl @@ -19,6 +19,18 @@ const PAIRS_AAGRID = 4 const PAIRS_LIST = 5 const TRUELIST = ["True", "true", "1"] +const FILE_TYPE_NPY = 1 +const FILE_TYPE_AAGRID = 2 +const FILE_TYPE_TXTLIST = 3 +const FILE_TYPE_INCL_PAIRS_AAGRID = 4 +const FILE_TYPE_INCL_PAIRS = 5 + +const FILE_HDR_GZIP = "\x1f\x8b\x08" +const FILE_HDR_NPY = "\x93NUMPY" +const FILE_HDR_AAGRID = "ncols" +const FILE_HDR_INCL_PAIRS_AAGRID = "min" +const FILE_HDR_INCL_PAIRS = "mode" + # Constants for logging const NONE = ["NONE", "None", "none"] const INFO = ["INFO", "info", "Info"] diff --git a/src/io.jl b/src/io.jl index 0822abba..6db51002 100644 --- a/src/io.jl +++ b/src/io.jl @@ -121,7 +121,7 @@ function _ascii_grid_read_header(habitat_file, f) RasterMeta(ncols, nrows, xllcorner, yllcorner, cellsize, nodata, file_type) end -function _guess_file_type(filename, f) +#=function _guess_file_type(filename, f) s = readline(f) seek(f, 0) @@ -137,6 +137,26 @@ function _guess_file_type(filename, f) throw("Check file format") end +end=# + +function _guess_file_type(filename, f) + + hdr = readline(f) + seek(f, 0) + + if startswith(hdr, FILE_HDR_NPY) + filetype = FILE_TYPE_NPY + elseif startswith(lowercase(hdr), FILE_HDR_AAGRID) + filetype = FILE_TYPE_AAGRID + elseif startswith(hdr, FILE_HDR_INCL_PAIRS_AAGRID) + filetype = FILE_TYPE_INCL_PAIRS_AAGRID + elseif startswith(hdr, FILE_HDR_INCL_PAIRS) + filetype = FILE_TYPE_INCL_PAIRS + else + filetype = FILE_TYPE_TXTLIST + end + + return filetype end function read_polymap(T, file::String, habitatmeta; @@ -173,13 +193,13 @@ function read_point_map(V, file, habitatmeta) f = endswith(file, ".gz") ? GZip.open(file, "r") : open(file, "r") filetype = _guess_file_type(file, f) - _points_rc = filetype == TXTLIST ? readdlm(file) : + _points_rc = filetype == FILE_TYPE_TXTLIST ? readdlm(file) : read_polymap(V, file, habitatmeta) i = V[] j = V[] v = V[] - if filetype == TXTLIST + if filetype == FILE_TYPE_TXTLIST I = _points_rc[:,2] J = _points_rc[:,3] v = _points_rc[:,1] @@ -228,7 +248,7 @@ function read_source_and_ground_maps(T, V, source_file, ground_file, habitatmeta f = endswith(ground_file, "gz") ? Gzip.open(ground_file, "r") : open(ground_file, "r") filetype = _guess_file_type(ground_file, f) - if filetype == AAGRID + if filetype == FILE_TYPE_AAGRID ground_map = read_polymap(T, ground_file, habitatmeta; nodata_as = -1) ground_map = map(T, ground_map) else @@ -240,7 +260,7 @@ function read_source_and_ground_maps(T, V, source_file, ground_file, habitatmeta f = endswith(source_file, "gz") ? Gzip.open(source_file, "r") : open(source_file, "r") filetype = _guess_file_type(source_file, f) - if filetype == AAGRID + if filetype == FILE_TYPE_AAGRID source_map = read_polymap(T, source_file, habitatmeta) source_map = map(T, source_map) else @@ -261,16 +281,16 @@ function read_source_and_ground_maps(T, V, source_file, ground_file, habitatmeta source_map, ground_map end -function read_included_pairs(V, file) +function read_included_pairs(V, filename) - f = endswith(file, "gz") ? Gzip.open(file, "r") : open(file, "r") - filetype = _guess_file_type(file, f) + f = endswith(filename, "gz") ? Gzip.open(filename, "r") : open(filename, "r") + filetype = _guess_file_type(filename, f) minval = 0 maxval = 0 mode = :undef - if filetype == PAIRS_AAGRID - open(file, "r") do f + #=if filetype == PAIRS_AAGRID + open(file, "r") do fV minval = parse(Float64, split(readline(f))[2]) maxval = parse(Float64, split(readline(f))[2]) end @@ -288,7 +308,7 @@ function read_included_pairs(V, file) mode = Symbol(split(readline(f))[2]) end included_pairs = readdlm(file, skipstart = 1) - point_ids = V.(sort!(unique(included_pairs))) + #=point_ids = V.(sort!(unique(included_pairs))) if point_ids[1] == 0 deleteat!(point_ids, 1) end @@ -300,11 +320,51 @@ function read_included_pairs(V, file) idx2 = findfirst(x -> x == included_pairs[i, 2], point_ids) if idx1 != nothing && idx2 != nothing mat[idx1,idx2] = 1 - mat[idx2,idx1] = 1 + # mat[idx2,idx1] = 1 end - end + end=# + + IncludeExcludePairs(mode, point_ids, mat) + end=# + + if filetype == FILE_TYPE_INCL_PAIRS_AAGRID + + open(filename, "r") do f + minval = parse(Float64, split(readline(f))[2]) + maxval = parse(Float64, split(readline(f))[2]) + end + included_pairs = readdlm(file, skipstart=2) + point_ids = V.(included_pairs[:,1]) + deleteat!(point_ids, 1) + included_pairs = included_pairs[2:end, 2:end] + map!(x -> x > maxval ? 0 : x, included_pairs, included_pairs) + idx = findall(x -> x >= minval, included_pairs) + mode = :include + bin = map(x -> x >= minval ? V(1) : V(0), included_pairs) + + elseif filetype == FILE_TYPE_INCL_PAIRS + + open(filename, "r") do f + mode = Symbol(split(readline(f))[2]) + end + pair_list = readdlm(filename, V, skipstart=1,) + point_ids = unique(pair_list) + if size(pair_list, 1) == 1 + pl = zeros(V, 1,2) + pl[1,:] = pair_list + pair_list = pl + end + end + I = pair_list[:,1] .+ 1 + J = pair_list[:,2] .+ 1 + V = ones(V, size(pair_list, 1)) + max_node = maximum(pair_list) + 1 + included_pairs = sparse(I, J, V, max_node, max_node) + + IncludeExcludePairs(mode, point_ids, Matrix(included_pairs)) + end function get_network_data(T, V, cfg)::NetworkData{T,V} From bf3c09144e2ec36dd1cc7c91721d1706db89b61d Mon Sep 17 00:00:00 2001 From: ranjanan Date: Sun, 6 Jan 2019 14:12:37 -0500 Subject: [PATCH 02/11] Tests to pass --- src/io.jl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/io.jl b/src/io.jl index 6db51002..08a81bda 100644 --- a/src/io.jl +++ b/src/io.jl @@ -334,7 +334,7 @@ function read_included_pairs(V, filename) minval = parse(Float64, split(readline(f))[2]) maxval = parse(Float64, split(readline(f))[2]) end - included_pairs = readdlm(file, skipstart=2) + included_pairs = readdlm(filename, skipstart=2) point_ids = V.(included_pairs[:,1]) deleteat!(point_ids, 1) included_pairs = included_pairs[2:end, 2:end] @@ -342,9 +342,9 @@ function read_included_pairs(V, filename) idx = findall(x -> x >= minval, included_pairs) mode = :include bin = map(x -> x >= minval ? V(1) : V(0), included_pairs) + return IncludeExcludePairs(mode, point_ids, bin) elseif filetype == FILE_TYPE_INCL_PAIRS - open(filename, "r") do f mode = Symbol(split(readline(f))[2]) end @@ -356,14 +356,14 @@ function read_included_pairs(V, filename) pair_list = pl end - end - I = pair_list[:,1] .+ 1 - J = pair_list[:,2] .+ 1 - V = ones(V, size(pair_list, 1)) - max_node = maximum(pair_list) + 1 - included_pairs = sparse(I, J, V, max_node, max_node) + I = pair_list[:,1] .+ 1 + J = pair_list[:,2] .+ 1 + V = ones(V, size(pair_list, 1)) + max_node = maximum(pair_list) + 1 + included_pairs = sparse(I, J, V, max_node, max_node) - IncludeExcludePairs(mode, point_ids, Matrix(included_pairs)) + return IncludeExcludePairs(mode, point_ids, Matrix(included_pairs)) + end end From 91c57ae670bc16c206633f0bc19702c4230ade81 Mon Sep 17 00:00:00 2001 From: ranjanan Date: Tue, 8 Jan 2019 16:16:22 -0500 Subject: [PATCH 03/11] Get cholmod to work --- src/core.jl | 32 +++++++++++++++++++------------- src/io.jl | 4 ++-- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/core.jl b/src/core.jl index 8da09931..0636dbfc 100644 --- a/src/core.jl +++ b/src/core.jl @@ -105,7 +105,8 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where get_shortcut_resistances = false if is_raster && !write_volt_maps && !write_cur_maps && - !write_cum_cur_map_only && !write_max_cur_maps + !write_cum_cur_map_only && !write_max_cur_maps && + isempty(exclude) get_shortcut_resistances = true csinfo("Triggering resistance calculation shortcut") num, d = get_num_pairs_shortcut(cc, points, exclude) @@ -201,14 +202,16 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where # Return resistance value for c_i in I, c_j in J - push!(ret, (c_i, c_j, r)) - if get_shortcut_resistances - resistances[c_i, c_j] = r - resistances[c_j, c_i] = r + if !((c_i, c_j) in exclude) + push!(ret, (c_i, c_j, r)) + if get_shortcut_resistances + resistances[c_i, c_j] = r + resistances[c_j, c_i] = r + end + output = Output(points, v, (orig_pts[c_i], orig_pts[c_j]), + (comp_i, comp_j), r, V(c_j), cum) + postprocess(output, component_data, flags, shortcut, cfg) end - output = Output(points, v, (orig_pts[c_i], orig_pts[c_j]), - (comp_i, comp_j), r, V(c_j), cum) - postprocess(output, component_data, flags, shortcut, cfg) end end @@ -306,7 +309,8 @@ function _cholmod_solver_path(data::GraphData{T,V}, flags, get_shortcut_resistances = false if is_raster && !write_volt_maps && !write_cur_maps && - !write_cum_cur_map_only && !write_max_cur_maps + !write_cum_cur_map_only && !write_max_cur_maps && + isempty(exclude) get_shortcut_resistances = true csinfo("Triggering resistance calculation shortcut") num, d = get_num_pairs_shortcut(cc, points, exclude) @@ -360,22 +364,24 @@ function _cholmod_solver_path(data::GraphData{T,V}, flags, J = findall(x -> x == pj, points) # Forget excluded pairs - ex = false + #=ex = false for c_i in I, c_j in J if (c_i, c_j) in exclude ex = true break end end - ex && continue + ex && continue=# if pi == pj continue end for c_i in I, c_j in J - push!(cholmod_batch, - CholmodNode((comp_i, comp_j), (V(c_i), V(c_j)))) + if !((c_i, c_j) in exclude) + push!(cholmod_batch, + CholmodNode((comp_i, comp_j), (V(c_i), V(c_j)))) + end end end end diff --git a/src/io.jl b/src/io.jl index 08a81bda..61c03518 100644 --- a/src/io.jl +++ b/src/io.jl @@ -356,8 +356,8 @@ function read_included_pairs(V, filename) pair_list = pl end - I = pair_list[:,1] .+ 1 - J = pair_list[:,2] .+ 1 + I = pair_list[:,1] + J = pair_list[:,2] V = ones(V, size(pair_list, 1)) max_node = maximum(pair_list) + 1 included_pairs = sparse(I, J, V, max_node, max_node) From f289cad3303b3c5685f4e001fbb60c8fe3fd1863 Mon Sep 17 00:00:00 2001 From: ranjanan Date: Tue, 8 Jan 2019 21:49:58 -0500 Subject: [PATCH 04/11] Have the included pairs be displauyed but also ignore repeat point --- src/core.jl | 44 ++++++++++++++++++++++++------------------ src/io.jl | 2 +- src/raster/pairwise.jl | 14 ++++++++++---- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/core.jl b/src/core.jl index 0636dbfc..2e208d57 100644 --- a/src/core.jl +++ b/src/core.jl @@ -75,6 +75,7 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where orig_pts = data.user_points hbmeta = data.hbmeta cellmap = data.cellmap + @show exclude # Flags outputflags = flags.outputflags @@ -113,6 +114,7 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where csinfo("Total number of pair solves has been reduced to $num ") end shortcut = Shortcut(get_shortcut_resistances, voltmatrix, shortcut_res) + @show points for (cid, comp) in enumerate(cc) @@ -156,6 +158,7 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where # Iteration space through all possible pairs rng = i+1:size(csub, 1) + @show i,rng if nprocs() > 1 for j in rng pj = csub[j] @@ -170,13 +173,17 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where comp_j = something(findfirst(isequal(pj), comp), 0) comp_j = V(comp_j) J = findall(x -> x == pj, points) + @show I,J # Forget excluded pairs ex = false - for c_i in I, c_j in J - if (c_i, c_j) in exclude - ex = true - break + for c_i in I + for c_j in J + if (c_i, c_j) in exclude + ex = true + @show ex, c_i,c_j + break + end end end ex && continue @@ -200,18 +207,19 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where # Calculate resistance r = v[comp_j] - v[comp_i] + @show "second", I,J + # Return resistance value for c_i in I, c_j in J - if !((c_i, c_j) in exclude) - push!(ret, (c_i, c_j, r)) - if get_shortcut_resistances - resistances[c_i, c_j] = r - resistances[c_j, c_i] = r - end - output = Output(points, v, (orig_pts[c_i], orig_pts[c_j]), - (comp_i, comp_j), r, V(c_j), cum) - postprocess(output, component_data, flags, shortcut, cfg) + @show "inside", c_i, c_j + push!(ret, (c_i, c_j, r)) + if get_shortcut_resistances + resistances[c_i, c_j] = r + resistances[c_j, c_i] = r end + output = Output(points, v, (orig_pts[c_i], orig_pts[c_j]), + (comp_i, comp_j), r, V(c_j), cum) + postprocess(output, component_data, flags, shortcut, cfg) end end @@ -364,24 +372,22 @@ function _cholmod_solver_path(data::GraphData{T,V}, flags, J = findall(x -> x == pj, points) # Forget excluded pairs - #=ex = false + ex = false for c_i in I, c_j in J if (c_i, c_j) in exclude ex = true break end end - ex && continue=# + ex && continue if pi == pj continue end for c_i in I, c_j in J - if !((c_i, c_j) in exclude) - push!(cholmod_batch, - CholmodNode((comp_i, comp_j), (V(c_i), V(c_j)))) - end + push!(cholmod_batch, + CholmodNode((comp_i, comp_j), (V(c_i), V(c_j)))) end end end diff --git a/src/io.jl b/src/io.jl index 61c03518..fa372666 100644 --- a/src/io.jl +++ b/src/io.jl @@ -359,7 +359,7 @@ function read_included_pairs(V, filename) I = pair_list[:,1] J = pair_list[:,2] V = ones(V, size(pair_list, 1)) - max_node = maximum(pair_list) + 1 + max_node = maximum(pair_list) included_pairs = sparse(I, J, V, max_node, max_node) return IncludeExcludePairs(mode, point_ids, Matrix(included_pairs)) diff --git a/src/raster/pairwise.jl b/src/raster/pairwise.jl index c10295cd..2bad818d 100644 --- a/src/raster/pairwise.jl +++ b/src/raster/pairwise.jl @@ -237,14 +237,20 @@ function generate_exclude_pairs(points_rc, included_pairs::IncludeExcludePairs{V mat = included_pairs.include_pairs mode = included_pairs.mode == :include ? 0 : 1 - prune_points!(points_rc, included_pairs.point_ids) - for j = 1:size(mat, 2) - for i = 1:size(mat, 1) - if mat[i,j] == mode + prune_points!(points_rc, included_pairs.point_ids) + for j = 1:size(mat, 2) + for i = 1:size(mat, 1) + if mode == 1 + if mat[i,j] == 1 + push!(exclude_pairs_array, (i,j)) + end + else + if mat[i,j] == 0 && mat[j,i] == 0 push!(exclude_pairs_array, (i,j)) end end end + end exclude_pairs_array end From ff78786c20173d079ad4c1ea5f3b6f4c0c5cb453 Mon Sep 17 00:00:00 2001 From: ranjanan Date: Tue, 8 Jan 2019 22:14:09 -0500 Subject: [PATCH 05/11] Finally get it working like the old software --- src/core.jl | 89 ++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 53 deletions(-) diff --git a/src/core.jl b/src/core.jl index 2e208d57..044e66e0 100644 --- a/src/core.jl +++ b/src/core.jl @@ -75,7 +75,6 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where orig_pts = data.user_points hbmeta = data.hbmeta cellmap = data.cellmap - @show exclude # Flags outputflags = flags.outputflags @@ -114,7 +113,6 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where csinfo("Total number of pair solves has been reduced to $num ") end shortcut = Shortcut(get_shortcut_resistances, voltmatrix, shortcut_res) - @show points for (cid, comp) in enumerate(cc) @@ -158,7 +156,6 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where # Iteration space through all possible pairs rng = i+1:size(csub, 1) - @show i,rng if nprocs() > 1 for j in rng pj = csub[j] @@ -173,53 +170,44 @@ function amg_solver_path(data::GraphData{T,V}, flags, cfg, log)::Matrix{T} where comp_j = something(findfirst(isequal(pj), comp), 0) comp_j = V(comp_j) J = findall(x -> x == pj, points) - @show I,J + + if pi == pj + continue + end # Forget excluded pairs ex = false for c_i in I for c_j in J if (c_i, c_j) in exclude - ex = true - @show ex, c_i,c_j - break + continue end - end - end - ex && continue - - if pi == pj - continue - end - - # Initialize currents - current = zeros(T, size(matrix, 1)) - current[comp_i] = -1 - current[comp_j] = 1 - - # Solve system - # csinfo("Solving points $pi and $pj") - log && csinfo("Solving pair $(d[(pi,pj)]) of $num") - t2 = @elapsed v = solve_linear_system(cfg, matrix, current, P) - csinfo("Time taken to solve linear system = $t2 seconds") - v .= v .- v[comp_i] - - # Calculate resistance - r = v[comp_j] - v[comp_i] - @show "second", I,J - - # Return resistance value - for c_i in I, c_j in J - @show "inside", c_i, c_j - push!(ret, (c_i, c_j, r)) - if get_shortcut_resistances - resistances[c_i, c_j] = r - resistances[c_j, c_i] = r + # Initialize currents + current = zeros(T, size(matrix, 1)) + current[comp_i] = -1 + current[comp_j] = 1 + + # Solve system + # csinfo("Solving points $pi and $pj") + log && csinfo("Solving pair $(d[(pi,pj)]) of $num") + t2 = @elapsed v = solve_linear_system(cfg, matrix, current, P) + csinfo("Time taken to solve linear system = $t2 seconds") + v .= v .- v[comp_i] + + # Calculate resistance + r = v[comp_j] - v[comp_i] + + # Return resistance value + push!(ret, (c_i, c_j, r)) + if get_shortcut_resistances + resistances[c_i, c_j] = r + resistances[c_j, c_i] = r + end + output = Output(points, v, (orig_pts[c_i], orig_pts[c_j]), + (comp_i, comp_j), r, V(c_j), cum) + postprocess(output, component_data, flags, shortcut, cfg) end - output = Output(points, v, (orig_pts[c_i], orig_pts[c_j]), - (comp_i, comp_j), r, V(c_j), cum) - postprocess(output, component_data, flags, shortcut, cfg) end end @@ -371,23 +359,18 @@ function _cholmod_solver_path(data::GraphData{T,V}, flags, comp_j = V(something(findfirst(isequal(pj), comp),0)) J = findall(x -> x == pj, points) - # Forget excluded pairs - ex = false - for c_i in I, c_j in J - if (c_i, c_j) in exclude - ex = true - break - end - end - ex && continue - if pi == pj continue end + # Forget excluded pairs for c_i in I, c_j in J - push!(cholmod_batch, - CholmodNode((comp_i, comp_j), (V(c_i), V(c_j)))) + if (c_i, c_j) in exclude + continue + else + push!(cholmod_batch, + CholmodNode((comp_i, comp_j), (V(c_i), V(c_j)))) + end end end end From 4f6eca76dd8ac4e5d4efd8fb756ef02f51c05d30 Mon Sep 17 00:00:00 2001 From: ranjanan Date: Wed, 9 Jan 2019 12:27:48 -0500 Subject: [PATCH 06/11] Make tests pass as well --- src/io.jl | 71 ++++++++++++------------------------------ src/raster/onetoall.jl | 2 +- 2 files changed, 21 insertions(+), 52 deletions(-) diff --git a/src/io.jl b/src/io.jl index fa372666..51801c00 100644 --- a/src/io.jl +++ b/src/io.jl @@ -289,12 +289,12 @@ function read_included_pairs(V, filename) maxval = 0 mode = :undef - #=if filetype == PAIRS_AAGRID - open(file, "r") do fV + if filetype == FILE_TYPE_INCL_PAIRS_AAGRID + open(filename, "r") do fV minval = parse(Float64, split(readline(f))[2]) maxval = parse(Float64, split(readline(f))[2]) end - included_pairs = readdlm(file, skipstart=2) + included_pairs = readdlm(filename, skipstart=2) point_ids = V.(included_pairs[:,1]) deleteat!(point_ids, 1) included_pairs = included_pairs[2:end, 2:end] @@ -302,15 +302,22 @@ function read_included_pairs(V, filename) idx = findall(x -> x >= minval, included_pairs) mode = :include bin = map(x -> x >= minval ? V(1) : V(0), included_pairs) - IncludeExcludePairs(mode, point_ids, bin) - else - open(file, "r") do f + return IncludeExcludePairs(mode, point_ids, bin) + elseif filetype == FILE_TYPE_INCL_PAIRS + open(filename, "r") do f mode = Symbol(split(readline(f))[2]) end - included_pairs = readdlm(file, skipstart = 1) - #=point_ids = V.(sort!(unique(included_pairs))) - if point_ids[1] == 0 - deleteat!(point_ids, 1) + included_pairs = readdlm(filename, skipstart = 1) + if size(included_pairs, 1) == 1 + pl = zeros(V, 1,2) + pl[1,:] = included_pairs + included_pairs = pl + end + point_ids = V.(sort!(unique(included_pairs))) + idx = findall(x -> x == 0 , point_ids) + if length(idx) > 0 + deleteat!(point_ids, idx) + @warn("Code to include pairs is activated, some entries did not match with focal node file. Some focal nodes may have been dropped") end mat = zeros(V, size(point_ids, 1), size(point_ids, 1)) @@ -320,49 +327,11 @@ function read_included_pairs(V, filename) idx2 = findfirst(x -> x == included_pairs[i, 2], point_ids) if idx1 != nothing && idx2 != nothing mat[idx1,idx2] = 1 - # mat[idx2,idx1] = 1 + mat[idx2,idx1] = 1 end - end=# - - - IncludeExcludePairs(mode, point_ids, mat) - end=# - - if filetype == FILE_TYPE_INCL_PAIRS_AAGRID - - open(filename, "r") do f - minval = parse(Float64, split(readline(f))[2]) - maxval = parse(Float64, split(readline(f))[2]) end - included_pairs = readdlm(filename, skipstart=2) - point_ids = V.(included_pairs[:,1]) - deleteat!(point_ids, 1) - included_pairs = included_pairs[2:end, 2:end] - map!(x -> x > maxval ? 0 : x, included_pairs, included_pairs) - idx = findall(x -> x >= minval, included_pairs) - mode = :include - bin = map(x -> x >= minval ? V(1) : V(0), included_pairs) - return IncludeExcludePairs(mode, point_ids, bin) - - elseif filetype == FILE_TYPE_INCL_PAIRS - open(filename, "r") do f - mode = Symbol(split(readline(f))[2]) - end - pair_list = readdlm(filename, V, skipstart=1,) - point_ids = unique(pair_list) - if size(pair_list, 1) == 1 - pl = zeros(V, 1,2) - pl[1,:] = pair_list - pair_list = pl - end - - I = pair_list[:,1] - J = pair_list[:,2] - V = ones(V, size(pair_list, 1)) - max_node = maximum(pair_list) - included_pairs = sparse(I, J, V, max_node, max_node) - - return IncludeExcludePairs(mode, point_ids, Matrix(included_pairs)) + + return IncludeExcludePairs(mode, point_ids, mat) end end diff --git a/src/raster/onetoall.jl b/src/raster/onetoall.jl index a9160d10..6a909d91 100644 --- a/src/raster/onetoall.jl +++ b/src/raster/onetoall.jl @@ -82,7 +82,7 @@ function onetoall_kernel(data::RasData{T,V}, flags, cfg)::Matrix{T} where {T,V} s = copy(z) n = points_unique[i] if use_included_pairs - for j = 1:num_points_to_solve + for j = 1:size(point_ids,1) if i != j && included_pairs.include_pairs[i,j] == mode exclude = point_ids[j] map!(x -> x == exclude ? 0 : x, point_map, point_map) From 383034eb467e101fd01a5522845aa59b615bb513 Mon Sep 17 00:00:00 2001 From: ranjanan Date: Wed, 9 Jan 2019 15:22:08 -0500 Subject: [PATCH 07/11] Add a test --- src/utils.jl | 2 +- .../raster/pairwise/17/pairs_to_include.txt | 26 +++++++ .../pairwise/17/raster_331464e2628f.asc | 33 +++++++++ test/input/raster/pairwise/17/sgVerify17.ini | 70 +++++++++++++++++++ test/input/raster/pairwise/17/sites.txt | 11 +++ test/output_verify/sgVerify17_resistances.out | 12 ++++ 6 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 test/input/raster/pairwise/17/pairs_to_include.txt create mode 100644 test/input/raster/pairwise/17/raster_331464e2628f.asc create mode 100644 test/input/raster/pairwise/17/sgVerify17.ini create mode 100644 test/input/raster/pairwise/17/sites.txt create mode 100644 test/output_verify/sgVerify17_resistances.out diff --git a/src/utils.jl b/src/utils.jl index 222e2f3e..85f5c334 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -284,7 +284,7 @@ function runtests(f = compute) @testset "Raster Pairwise" begin # Raster pairwise tests - for i = 1:16 + for i = 1:17 # Weird windows 32 stuff if i == 16 && Sys.WORD_SIZE == 32 continue diff --git a/test/input/raster/pairwise/17/pairs_to_include.txt b/test/input/raster/pairwise/17/pairs_to_include.txt new file mode 100644 index 00000000..f9714cb6 --- /dev/null +++ b/test/input/raster/pairwise/17/pairs_to_include.txt @@ -0,0 +1,26 @@ +mode include +1 5 +1 6 +1 7 +1 8 +1 9 +1 10 +1 11 +2 5 +2 6 +2 7 +2 8 +2 9 +2 10 +3 5 +3 6 +3 7 +3 8 +3 9 +3 10 +4 5 +4 6 +4 7 +4 8 +4 9 +4 10 diff --git a/test/input/raster/pairwise/17/raster_331464e2628f.asc b/test/input/raster/pairwise/17/raster_331464e2628f.asc new file mode 100644 index 00000000..95e81c9e --- /dev/null +++ b/test/input/raster/pairwise/17/raster_331464e2628f.asc @@ -0,0 +1,33 @@ +NCOLS 57 +NROWS 27 +XLLCORNER 5.9 +YLLCORNER 45.65 +CELLSIZE 0.0833333333333333 +NODATA_value -9999 +-9999.000000000000000 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 507.285714285714 652.327586206897 697.767123287671 544.477272727273 437 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 477.197183098592 543.174418604651 502.604651162791 453.808510638298 434.333333333333 466.897959183673 416.5625 507.95 437.3 398.625 394.166666666667 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 264.75 260.172413793103 354.615384615385 279.666666666667 307.275862068966 302.8 -9999 389.588235294118 379.127272727273 380.901960784314 365.916666666667 429.04347826087 444.706666666667 385.538461538462 426.15 446.3 485.95 486.58 503.29 531.81 511.54 443.69696969697 402.898550724638 393.678571428571 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 424.238095238095 457.761904761905 475 -9999 -9999 394.142857142857 335.376811594203 318.737373737374 370.41095890411 403.866666666667 456.03 466.738636363636 398.152173913043 489.9 462.41 444.5 516.23 487.64 437.93 509.89 472.39 480.62 511.53 521.21 555.02 557.86 507.99 503.4 464.52 402.74 393.650602409639 400 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 577.575757575758 514.670103092784 474.22 539.923076923077 730.51724137931 650.463414634146 570.243902439024 474.56 540.55 556.34 483.72 556.8 642.19 557.15 514.69 405.57 431.87 496.06 477.6 451.87 483.21 541.99 600.17 671.77 662.55 634.53 591.44 583.74 674.16 679.89 709.25 783.42 550.059523809524 403.666666666667 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 657.333333333333 607.431818181818 650.090909090909 663.7 679.96 631.88 525.34 606.67 712.97 824.83 785.69 757.11 615.52 489.64 436.66 475.54 487.65 457 491.46 535.3 478.33 559.93 479.57 567.97 751.8 865.26 806.6 727.05 846.03 867.01 865.44 960.73 677.86 411.969230769231 407.1 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 784.285714285714 895.170212765957 965.67 896.04 902.98 834.55 963.29 898.03 691.41 566.31 465.4 462.6 486.93 560.55 614.67 565.36 636.15 456.86 508.55 627.31 509.41 528.67 503.35 605.79 768.43 907.29 870.59 986.36 1167.04 1474.79 1188.98 717.785714285714 420.5 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 873.096774193548 1035.59139784946 1037.29 998.6 929.87 836.37 745.87 546.44 483.04 453.76 483.79 528.56 588.34 596.15 561.37 580.19 688.02 573.36 542.77 422.03 530.79 732.47 671.41 641.54 554.25 525.48 502.07 1254.9 1197.22 1426.02 1412.15 725.32 443.133333333333 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 1045.2 1080.39344262295 1070.19191919192 1044.96 1103.27 910.45 634.53 459.01 483.1 540.94 502.93 518.04 654.32 709.87 721.74 692.48 626.74 636.28 599.17 511.84 486.04 520.94 715.69 926.65 1068.85 1057.63 1138.66 1235.14 1029.79 934 1056.16 1034.81 1105.87 1264.2 478.612903225806 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 1100.5625 1101.1038961039 1113.83 965.89 722.96 528.73 456.88 449.41 529.22 613.23 573.55 591 655.98 690.37 819.45 1024.62 990.75 843.68 786.57 811.89 687.15 502.61 631.31 896.01 628.28 1072.67 1300.43 1581.78 1607.19 1389.78 1346.39 1887.17 1879.48 1429.49 946.489795918367 821.505376344086 1631.5632183908 1656.84705882353 1778.35384615385 2115.94444444444 -9999 -9999 -9999 -9999 -9999 2570.66666666667 2384 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 1129.35714285714 1087.02197802198 1030.56 1075.12 867.73 460.63 433.58 456.15 459.22 506.55 570.21 596.51 587.41 615.98 778.23 839.14 795.01 936.8 1013.62 1026.28 1273.26 1386.16 773.21 816.33 1089.69 1124.12 813.35 1610.66 1542.15 1680.16 1951.89 1284.19 1810.75 1538.92 2125.64 2073.99 1702.34 1030.78 1100.43 1177.27 1399.94 2019.66666666667 2189.75 2586 -9999 -9999 2474.82857142857 2389.20652173913 2116.65753424658 1080 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 1110.1875 1157.94 991.65 765.11 454.11 455.26 458.2 515.97 587.82 595.28 649.61 710.92 848.94 612.15 696.86 947.31 943.34 1045.77 1302.43 1323.32 1411.71 799.51 1084.46 1329.14 1800.76 2012.14 1078.2 1397.63 1806.09 2307.35 2004.18 2206.99 2126.86 2228.18 1813.09 1778.55 1325.82 977.96 1541.14 1840.02 2025.5 1685.52 2034.39 2379.77272727273 2704.70731707317 2566.40384615385 2499.81 1993.29 1720.16666666667 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 937.5 1120.10909090909 697.3 472.15 510.74 620.83 577.31 600.76 672.87 662.23 717.43 838.57 1029.58 1045.27 677.18 608.75 931.97 1249.46 1433 1391.62 1215.92 1233.33 1316.93 1815.43 1916.82 2044.95 2234.03 1724.78 1449.18 2161.99 2358.01 2315.87 1716.01 1383.51 1236.26 1335.95 1267.95 1177.43 1760.57 2138.77 2057.67 2061.41 2028.66 2428.46 2429.38 2102.74 2017.99 1823.19 2177.75 2398.56818181818 -9999 -9999 +-9999 -9999 -9999 -9999 1152.72972972973 1067.34117647059 831.88 508.52 582.35 648.25 728.43 679.19 766.07 864.59 804.2 1207.4 1244.49 1434.81 1466.64 1223.08 813.32 690.84 1017.35 952.3 1247.12 1851.71 1886.51 1394.21 1521 2307.46 2583.04 2177.54 1715.01 2233.86 1987.57 1657.02 1749.66 2151.91 1807.99 1467.27 1976.1 1754.15 1190.34 1492.71 1763.94 1682.38 2148.05 2496.56 2563.05 2400.2 2058.72 2327.83 2361.48 2391.17894736842 2812.16666666667 -9999 -9999 +-9999 -9999 1268.125 1190.61971830986 1261.87 1071.89 630.06 510.86 622.42 808.46 713.47 780.67 915.42 927.19 940.14 1245.92 1499.8 1353.48 1521.72 1425.62 1570.33 1131.9 1622.11 1778 1524.42 1784.86 2690.42 2592.65 2247.2 2484.3 2598.73 2099.45 2182.02 2382.65 2339.11 2265.19 2359.47 2323.83 2211.95 2051.27 2319.26 2203.41 1636.98 2157.02 1710.47 2310.5 2088.16 2564.66 2217.69 2165.37 2573.68918918919 2150.16666666667 2331.7012987013 2168.19 2015.53012048193 -9999 -9999 +-9999 -9999 1351.53571428571 1302.86 1056.42 676.47 521.7 415.53 472.22 646.21 721.8 769.23 1153.37 1285.62 1387.23 1543.41 1521.64 1407.92 1670.48 1894.33 1605.26 1643.21 2275.17 2201.79 2747.31 3139.54 3194.05 2802.96 2146.26 2023.32 2490.16 2110.83 1894.49 1810.35 1948.92 1993.92 1465.61 2502.44 2460.31 2204.5 2144.76086956522 2133.95061728395 2057.02197802198 2418.41 2084.26 2616.65 2623.03 2028.17 2453.69 2581.96511627907 2684 -9999 2681.33333333333 2604.52380952381 2622.70833333333 -9999 -9999 +-9999 -9999 1264.69565217391 791.68 535.51 401.065217391304 378.380281690141 372.176470588235 372.3 372.257142857143 401.75 427.268041237113 1025.37 1391.89 1330.61 1608.63 1406.2 1754.46 1535.81 2041.38 2266.05 2381.24 2435.35 2564.53 2919.64 2790.09 2216.9 1942.88 2259.01075268817 2524.72340425532 2374.15555555556 2209.12 1890.77 2039.66 1805.49 1347.4 1214.66 1845.07 2327.51 1939.28 2279.53333333333 2284 2338.48484848485 2351.45 2473.47 2284.12 2219.28 2510.98 2512.25 2462.25 2509.78125 2586.25 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 510.444444444444 434.265957446808 374.826086956522 370 -9999 -9999 -9999 -9999 1681.42105263158 853.45 727.78 1433.01 1611.17 1851.74 2004.2 2389.44 2169.74 2214.59 1769.75 2126.18 1883.73 2224.41 2141.66 1472.54 1832.79 2030.42268041237 2427.42553191489 -9999 2355.53846153846 1770.25 1413.89 1710.9 1683.88 1747.53 891.65 1637.58 1836.1 1577.59 1842.25373134328 -9999 2652.28571428571 2081.0987654321 1924.83 2276.87628865979 2576.70149253731 2948.04545454545 3241.18421052632 2138.39175257732 2073.17808219178 2778.33333333333 -9999 -9999 -9999 -9999 -9999 +-9999 446.25 432.877551020408 389.808080808081 455.277777777778 -9999 -9999 -9999 -9999 -9999 -9999 1435.83050847458 576.73 834.04 1633.29 2190.32 1658.01 1297.6 975.32 961.39 1477.05 1593.45 1742.26 1230.02 1583.43 1852.36 2556.50793650794 2592.92307692308 -9999 -9999 1958.69565217391 1626.26 1392.26 1119.81 1441.57 1534.58 1543.83 1013.72 1287.64 1230.37 1885.45714285714 -9999 -9999 2101.6 2395.03333333333 2841.12 -9999 -9999 -9999 2049.38 1610.69473684211 2151.22222222222 -9999 -9999 -9999 -9999 -9999 +470 421.095744680851 416.92 417.267605633803 459.3125 -9999 -9999 -9999 -9999 -9999 1853.25 1532.48484848485 1706.22 1042.95 2044.37 1034.52 993.05 1299.23 1478.54 2338.02 1984.64 2560.16 2377.56 1926.61 2387.06 2430.93 1932 1794.4 -9999 -9999 -9999 1655.54166666667 1149.22340425532 844.07 725.05 655.16 946.86 611.37 1246.73737373737 1662.64814814815 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 2422.66666666667 1869.6 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 426.7 473.8 -9999 -9999 -9999 -9999 -9999 -9999 -9999 1876.25 2014.8 2101.31632653061 1142.15 837.38 1313.42 2189.25 2439.66 2290.09 2239.9 2519.26 3122.41 2294.73 3301.9 2282.71 2925.28915662651 2199.57142857143 -9999 -9999 -9999 -9999 -9999 1136.05263157895 847.596153846154 412.118644067797 1121.77777777778 737.67 1225.84 1635.93939393939 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 2358.66666666667 1775.55 2284.79120879121 1685.15 1777.93 2212.42 2668.3 2848.4 2661.40816326531 3051.82828282828 2805.01 2394.55 3194.25252525253 2843.88888888889 2824.85714285714 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 613.285714285714 810.011627906977 414.05 800.632653061224 1666 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 2926.3 2128.12 2164.79 3057.8 2713.6091954023 3058.19047619048 3074.05263157895 3078.375 3047.03125 2893.72881355932 3477.60869565217 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 329.444444444444 457.065934065934 929.127272727273 1031 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 2388.60714285714 2449.5 3347.25 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 443.553191489362 587.955882352941 814.666666666667 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 +-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 diff --git a/test/input/raster/pairwise/17/sgVerify17.ini b/test/input/raster/pairwise/17/sgVerify17.ini new file mode 100644 index 00000000..67bc26d6 --- /dev/null +++ b/test/input/raster/pairwise/17/sgVerify17.ini @@ -0,0 +1,70 @@ +[Options for advanced mode] +ground_file_is_resistances = True +remove_src_or_gnd = rmvsrc +ground_file = (Browse for a raster mask file) +use_unit_currents = False +source_file = (Browse for a raster mask file) +use_direct_grounds = False + +[Mask file] +mask_file = (Browse for a raster mask file) +use_mask = False + +[Calculation options] +low_memory_mode = False +parallelize = False +max_parallel = 0 +solver = cholmod +print_timings = False +preemptive_memory_release = False +print_rusages = False + +[Short circuit regions (aka polygons)] +polygon_file = (Browse for a short-circuit region file) +use_polygons = False + +[Options for one-to-all and all-to-one modes] +use_variable_source_strengths = False +variable_source_file = (Browse for a short-circuit region file) + +[Output options] +set_null_currents_to_nodata = True +set_focal_node_currents_to_zero = False +set_null_voltages_to_nodata = True +compress_grids = False +write_volt_maps = False +write_cur_maps = False +output_file = output/sgVerify17.out +write_cum_cur_map_only = False +log_transform_maps = False +write_max_cur_maps = False + +[Version] +version = 4.0.5 + +[Options for reclassification of habitat data] +reclass_file = (Browse for file with reclassification data) +use_reclass_table = False + +[Logging Options] +log_level = critical +log_file = None +profiler_log_file = None +screenprint_log = False + +[Options for pairwise and one-to-all and all-to-one modes] +included_pairs_file = input/raster/pairwise/17/pairs_to_include.txt +use_included_pairs = True +point_file = input/raster/pairwise/17/sites.txt + +[Connection scheme for raster habitat data] +connect_using_avg_resistances = True +connect_four_neighbors_only =False + +[Habitat raster or graph] +habitat_map_is_resistances = True +habitat_file = input/raster/pairwise/17/raster_331464e2628f.asc + +[Circuitscape mode] +data_type = raster +scenario = pairwise diff --git a/test/input/raster/pairwise/17/sites.txt b/test/input/raster/pairwise/17/sites.txt new file mode 100644 index 00000000..87c947c5 --- /dev/null +++ b/test/input/raster/pairwise/17/sites.txt @@ -0,0 +1,11 @@ +1 9.19166666666667 46.775 +2 9.19166666666667 46.9416666666667 +3 8.525 47.1916666666667 +4 9.69166666666667 46.525 +5 8.94166666666667 46.3583333333333 +6 7.775 47.3583333333333 +7 9.19166666666667 46.275 +8 8.69166666666667 46.9416666666667 +9 8.025 46.025 +10 9.94166666666667 46.775 +11 9.19166666666667 46.775 diff --git a/test/output_verify/sgVerify17_resistances.out b/test/output_verify/sgVerify17_resistances.out new file mode 100644 index 00000000..b29dec60 --- /dev/null +++ b/test/output_verify/sgVerify17_resistances.out @@ -0,0 +1,12 @@ +0 1 2 3 4 5 6 7 8 9 10 11 +1 0 -1 -1 -1 847.8940057 892.8560672 984.4589939 799.6920325 2296.848506 1348.276381 0 +2 -1 0 -1 -1 943.3831754 857.9104562 1094.615479 775.5751918 2276.109947 1398.145346 -1 +3 -1 -1 0 -1 812.2000877 407.2958127 999.0983529 427.8051107 1859.930909 1435.18291 -1 +4 -1 -1 -1 0 1408.363856 1460.967189 1493.200115 1384.416311 2867.28732 1152.747572 -1 +5 847.8940057 943.3831754 812.2000877 1408.363856 0 -1 -1 -1 -1 -1 -1 +6 892.8560672 857.9104562 407.2958127 1460.967189 -1 0 -1 -1 -1 -1 -1 +7 984.4589939 1094.615479 999.0983529 1493.200115 -1 -1 0 -1 -1 -1 -1 +8 799.6920325 775.5751918 427.8051107 1384.416311 -1 -1 -1 0 -1 -1 -1 +9 2296.848506 2276.109947 1859.930909 2867.28732 -1 -1 -1 -1 0 -1 -1 +10 1348.276381 1398.145346 1435.18291 1152.747572 -1 -1 -1 -1 -1 0 -1 +11 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 From c6ebfd51925f53ad6ae9e4a8f7c7c1c51cd49350 Mon Sep 17 00:00:00 2001 From: ranjanan Date: Wed, 9 Jan 2019 15:54:01 -0500 Subject: [PATCH 08/11] Fix cswarn --- src/io.jl | 2 +- src/logging.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/io.jl b/src/io.jl index 51801c00..2df61ae4 100644 --- a/src/io.jl +++ b/src/io.jl @@ -317,7 +317,7 @@ function read_included_pairs(V, filename) idx = findall(x -> x == 0 , point_ids) if length(idx) > 0 deleteat!(point_ids, idx) - @warn("Code to include pairs is activated, some entries did not match with focal node file. Some focal nodes may have been dropped") + cswarn("Code to include pairs is activated, some entries did not match with focal node file. Some focal nodes may have been dropped") end mat = zeros(V, size(point_ids, 1), size(point_ids, 1)) diff --git a/src/logging.jl b/src/logging.jl index 2a011678..41e5b0b9 100644 --- a/src/logging.jl +++ b/src/logging.jl @@ -3,7 +3,7 @@ const fmt = x -> Dates.format(x, "yyyy-mm-dd HH:MM:SS") const ui_interface = Ref{Function}((x,y) -> nothing) csinfo(msg) = (@info(string(fmt(Dates.now())) * " : " * msg); ui_interface[](msg, :info)) -cswarn(msg) = (@warn(string(fmt(Dates.now())) * " : " * msg); ui_interace[](msg, :warn)) +cswarn(msg) = (@warn(string(fmt(Dates.now())) * " : " * msg); ui_interface[](msg, :warn)) function update_logging!(cfg) From 7f7cacef3261a931bcfb6b568687cb09951584e7 Mon Sep 17 00:00:00 2001 From: ranjanan Date: Wed, 9 Jan 2019 17:53:44 -0500 Subject: [PATCH 09/11] Add a potential fix for `exclude` option --- src/raster/pairwise.jl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/raster/pairwise.jl b/src/raster/pairwise.jl index 2bad818d..6916bab6 100644 --- a/src/raster/pairwise.jl +++ b/src/raster/pairwise.jl @@ -240,14 +240,8 @@ function generate_exclude_pairs(points_rc, included_pairs::IncludeExcludePairs{V prune_points!(points_rc, included_pairs.point_ids) for j = 1:size(mat, 2) for i = 1:size(mat, 1) - if mode == 1 - if mat[i,j] == 1 - push!(exclude_pairs_array, (i,j)) - end - else - if mat[i,j] == 0 && mat[j,i] == 0 - push!(exclude_pairs_array, (i,j)) - end + if mat[i,j] == mode && mat[j,i] == mode + push!(exclude_pairs_array, (i,j)) end end end From d61555a21adbfe20bcf6fa10b810e21b832f8610 Mon Sep 17 00:00:00 2001 From: ranjanan Date: Mon, 14 Jan 2019 21:59:04 -0500 Subject: [PATCH 10/11] Do not allow cholmod with single precision (no point) --- src/core.jl | 3 --- src/run.jl | 7 ++++--- src/utils.jl | 10 ++++++++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/core.jl b/src/core.jl index 044e66e0..924d9906 100644 --- a/src/core.jl +++ b/src/core.jl @@ -55,9 +55,6 @@ function single_ground_all_pairs(data::GraphData{T,V}, flags, cfg, log = true) w amg_solver_path(data, flags, cfg, log) else csinfo("Solver used: CHOLMOD") - if eltype(data.G) == Float32 - cswarn("CHOLMOD solver mode works only in double precision") - end bs = parse(Int, cfg["cholmod_batch_size"]) _cholmod_solver_path(data, flags, cfg, log, bs) end diff --git a/src/run.jl b/src/run.jl index d2486f8f..81fa377a 100644 --- a/src/run.jl +++ b/src/run.jl @@ -14,11 +14,12 @@ Inputs: function compute(path::String) cfg = parse_config(path) update_logging!(cfg) - #=if cfg["use_64bit_indexing"] in TRUELIST - global INT = Int64 - end=# write_config(cfg) T = cfg["precision"] in SINGLE ? Float32 : Float64 + if T == Float32 && cfg["solver"] in CHOLMOD + cswarn("CHOLMOD solver mode works only in double precision. Switching precision to double.") + T = Float64 + end V = cfg["use_64bit_indexing"] in TRUELIST ? Int64 : Int32 csinfo("Precision used: $(cfg["precision"])") is_parallel = cfg["parallelize"] in TRUELIST diff --git a/src/utils.jl b/src/utils.jl index 85f5c334..3042c9c1 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -76,7 +76,8 @@ function compute_cholmod(str, batch_size = 5) T = cfg["precision"] in SINGLE ? Float32 : Float64 V = cfg["use_64bit_indexing"] in TRUELIST ? Int64 : Int32 if T == Float32 - cswarn("Cholmod supports only double precision. Implicit conversion may occur") + cswarn("Cholmod supports only double precision. Changing precision to double.") + T = Float64 end cfg["solver"] = "cholmod" cfg["cholmod_batch_size"] = string(batch_size) @@ -87,7 +88,12 @@ function compute_single(str) cfg = parse_config(str) cfg["precision"] = "single" V = cfg["use_64bit_indexing"] in TRUELIST ? Int64 : Int32 - _compute(Float32, V, cfg) + T = Float32 + if cfg["solver"] == "cholmod" + cswarn("Cholmod supports only double precision. Changing precision to double.") + T = Float64 + end + _compute(T, V, cfg) end function compute_parallel(str, n_processes = 2) From 3024e356c469f3ae6e0079af8e905a35268abc91 Mon Sep 17 00:00:00 2001 From: ranjanan Date: Wed, 16 Jan 2019 14:17:48 -0500 Subject: [PATCH 11/11] Forget about nightly and 32 bit windows --- .travis.yml | 1 - appveyor.yml | 2 -- 2 files changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f2b40aae..d87a8282 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ # Documentation: http://docs.travis-ci.com/user/languages/julia/ language: julia julia: - - nightly - 1.0 os: - linux diff --git a/appveyor.yml b/appveyor.yml index 7351eb94..06188c5c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,10 +1,8 @@ environment: matrix: - julia_version: 1 - - julia_version: nightly platform: - - x86 # 32-bit - x64 # 64-bit # # Uncomment the following lines to allow failures on nightly julia