Skip to content

Commit

Permalink
Merge pull request #187 from Circuitscape/RA/out
Browse files Browse the repository at this point in the history
Fix 181 once and for all
  • Loading branch information
ranjanan authored May 9, 2019
2 parents 0e3de70 + 12cf22e commit 7d5d23c
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 14 deletions.
8 changes: 4 additions & 4 deletions src/out.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function write_cur_maps(name, output, component_data, finitegrounds, flags, cfg)
end

function write_currents(node_curr_arr, branch_curr_arr, name, cfg)
pref = split(cfg["output_file"], '.')[1]
pref = split(cfg["output_file"], ".out")[1]
writedlm("$(pref)_node_currents$(name).txt", node_curr_arr, '\t')
writedlm("$(pref)_branch_currents$(name).txt", branch_curr_arr, '\t')
end
Expand Down Expand Up @@ -347,7 +347,7 @@ function write_aagrid(cmap, name, cfg, hbmeta, cellmap;
voltage = false, cum = false, max = false,
log_transform = false, set_null_to_nodata = false)

pref = split(cfg["output_file"], '.')[1]
pref = split(cfg["output_file"], ".out")[1]

if log_transform
map!(x -> x > 0 ? log10(x) : float(hbmeta.nodata), cmap, cmap)
Expand Down Expand Up @@ -414,7 +414,7 @@ function write_voltages(output, name, voltages::Vector{T}, cc) where {T}
volt_arr[:,1] = cc
volt_arr[:,2] = voltages

pref = split(output, '.')[1]
pref = split(output, ".out")[1]
writedlm("$(pref)_voltages$(name).txt", volt_arr)

end
Expand Down Expand Up @@ -453,7 +453,7 @@ function accum_currents!(base, newcurr, cfg, G, voltages, finitegrounds, nodemap
end

function save_resistances(r, cfg)
pref = split(cfg["output_file"], '.')[1]
pref = split(cfg["output_file"], ".out")[1]
filename = "$(pref)_resistances.out"
filename_3col = "$(pref)_resistances_3columns.out"
rcol = compute_3col(r)
Expand Down
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function accumulate_current_maps(path, f)
base = basename(path)

# If base file has a dot
name = split(base, '.')[1]
name = split(base, ".out")[1]

cmap_list = readdir(dir) |>
x -> filter(y -> startswith(y, "$(name)_"), x) |>
Expand Down Expand Up @@ -332,7 +332,7 @@ function runtests(f = compute)
end
end

@testset "Raster ALl to One" begin
@testset "Raster All to One" begin
# Raster all to one test
for i in 1:12
@info("Testing allToOneVerify$i")
Expand Down
16 changes: 16 additions & 0 deletions test/input/raster/extra.one/1/cellmap.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ncols 10
nrows 10
xllcorner 1
yllcorner 1
cellsize 1
NODATA_value -9999
1 2 3 4 5 6 7 8 9 10
2 -9999 -9999 1 1 2 1 1 1 1
3 2 1 1 -9999 2 1 1 1 1
4 2 1 1 1 2 -9999 -9999 1 2
5 2 1 1 1 2 -9999 -9999 1 3
-9999 -9999 -9999 -9999 7 2 -9999 -9999 1 4
7 -9999 2 -9999 1 2 -9999 -9999 1 5
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999
9 -9999 2 -9999 1 2 -9999 -9999 1 7
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999
59 changes: 59 additions & 0 deletions test/input/raster/extra.one/1/oneToAllVerify1.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[Options for advanced mode]
ground_file_is_resistances = False
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

[Calculation options]
low_memory_mode = False
solver = cg+amg
print_timings = False

[Options for pairwise and one-to-all and all-to-one modes]
included_pairs_file = None
use_included_pairs = False
point_file = input/raster/one_to_all/1/points.asc

[Output options]
write_cum_cur_map_only = False
log_transform_maps = False
output_file = output/oneToAllVerify1.out
write_max_cur_maps = False
write_volt_maps = True
set_null_currents_to_nodata = False
set_null_voltages_to_nodata = False
compress_grids = False
write_cur_maps = True

[Short circuit regions (aka polygons)]
use_polygons = True
polygon_file = input/raster/one_to_all/1/polygons.asc

[Connection scheme for raster habitat data]
connect_four_neighbors_only = True
connect_using_avg_resistances = True

[Habitat raster or graph]
habitat_file = input/raster/one_to_all/1/cellmap.asc
habitat_map_is_resistances = True

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

[Version]
version = unknown

[Mask file]
use_mask = False
mask_file = None

[Circuitscape mode]
data_type = raster
scenario = one-to-all

parallelize = True
max_parallel = 2

16 changes: 16 additions & 0 deletions test/input/raster/extra.one/1/points.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ncols 10
nrows 10
xllcorner 1
yllcorner 1
cellsize 1
NODATA_value -9999
1 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 2
-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 4
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 9 -9999
-9999 -9999 -9999 -9999 -9999 8 -9999 -9 -9999 5
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 6
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999
51 -9999 11 -9999 -9999 -9999 -9999 3 -9999 -9999
16 changes: 16 additions & 0 deletions test/input/raster/extra.one/1/polygons.asc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ncols 10
nrows 10
xllcorner 1
yllcorner 1
cellsize 1
NODATA_value -9999
-9999 -9999 -9999 6 6 6 -9999 -9999 -9999 -9999
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 1
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 1
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 1
-9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 -9999 1
-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
20 changes: 12 additions & 8 deletions test/internal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,15 @@ SIZE_3 =

@test model_problem(3) == SIZE_3

# Issue 151
# Issue 151
try
Circuitscape.read_point_map(Int32, "samples.txt",
Circuitscape.RasterMeta(50, 50, 0.0, 0.0, 0.5, -9999.0, 2))
catch e
@test e == "At least one focal node location falls outside of habitat map"
end
# Issue 151
# Issue 151
try
Circuitscape.read_point_map(Int32, "samples.txt",
Circuitscape.RasterMeta(50, 50, 0.0, 0.0, 0.5, -9999.0, 2))
catch e
@test e == "At least one focal node location falls outside of habitat map"
end

# Users with dots in their names - issue #181
# Just check that this does not break
compute("input/raster/extra.one/1/oneToAllVerify1.ini")

2 comments on commit 7d5d23c

@ranjanan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Version 5.5.2 already exists

Please sign in to comment.