Skip to content

Commit

Permalink
Merge pull request #421 from Circuitscape/RA/source_and_ground
Browse files Browse the repository at this point in the history
Support flags: use_unit_currents and use_direct_grounds
  • Loading branch information
ranjanan authored Aug 25, 2024
2 parents 79e0984 + 59363ff commit ec267c2
Show file tree
Hide file tree
Showing 6 changed files with 1,186 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,12 @@ end


function read_source_and_ground_maps(T, V, source_file, ground_file, habitatmeta,
is_res)
is_res, cfg)

ground_map = Matrix{T}(undef,0,0)
source_map = Matrix{T}(undef,0,0)
use_unit_currents = cfg["use_unit_currents"] in TRUELIST
use_direct_grounds = cfg["use_direct_grounds"] in TRUELIST

f = endswith(ground_file, "gz") ? GZip.open(ground_file, "r") : open(ground_file, "r")
filetype = _guess_file_type(ground_file, f)
Expand All @@ -276,9 +278,10 @@ function read_source_and_ground_maps(T, V, source_file, ground_file, habitatmeta
if filetype == FILE_TYPE_AAGRID || filetype == FILE_TYPE_GEOTIFF
source_map = read_polymap(T, source_file, habitatmeta)
source_map = map(T, source_map)
source_map[findall(isequal(-9999), source_map)] .= 0
elseif filetype == FILE_TYPE_TXTLIST
rc = _txt_list_reader(source_file, T, habitatmeta)
source_map = -9999 * ones(T, habitatmeta.nrows, habitatmeta.ncols)
source_map = zeros(T, habitatmeta.nrows, habitatmeta.ncols)
for (x,y,v) in zip(rc[:,2], rc[:,3], rc[:,1])
source_map[V(x), V(y)] = v
end
Expand All @@ -296,6 +299,14 @@ function read_source_and_ground_maps(T, V, source_file, ground_file, habitatmeta
ground_map[ind] .= 0
end

# use_unit_currents & use_direct_grounds
if use_unit_currents
source_map[findall(!iszero, source_map)] .= 1
end
if use_direct_grounds
ground_map[findall(!iszero, ground_map)] .= Inf
end

source_map, ground_map
end

Expand Down Expand Up @@ -467,7 +478,7 @@ function load_raster_data(T, V, cfg)::RasterData{T,V}
if is_advanced
source_map, ground_map =
read_source_and_ground_maps(T, V, source_file, ground_file,
hbmeta, ground_is_res)
hbmeta, ground_is_res, cfg)
else
source_map, ground_map = Matrix{T}(undef,0,0), Matrix{T}(undef,0,0)
end
Expand Down
361 changes: 361 additions & 0 deletions test/input/raster/advanced/7/TestArea1_GroundNodes_raster.asc

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions test/input/raster/advanced/7/TestArea1_SourcePoints25.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
1 631110.108 3400879.813
2 631110.108 3398906.798
3 631110.108 3396933.784
4 631110.108 3394960.769
5 631110.108 3392987.754
6 631110.108 3391014.740
7 629703.647 3390448.186
8 627730.632 3390448.185
9 625757.617 3390448.185
10 623784.603 3390448.185
11 621811.588 3390448.184
12 619838.573 3390448.184
13 617865.559 3390448.184
14 616879.054 3391434.693
15 616879.054 3393407.708
16 616879.054 3395380.723
17 616879.054 3397353.737
18 616879.054 3399326.752
19 617299.005 3400879.815
20 619272.020 3400879.815
21 621245.035 3400879.815
22 623218.049 3400879.814
23 625191.064 3400879.814
24 627164.079 3400879.814
25 629137.093 3400879.813
64 changes: 64 additions & 0 deletions test/input/raster/advanced/7/mgVerify7.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
[Options for advanced mode]
ground_file_is_resistances = False
remove_src_or_gnd = keepall
ground_file = input/raster/advanced/7/TestArea1_GroundNodes_raster.asc
use_unit_currents = True
source_file = input/raster/advanced/7/TestArea1_SourcePoints25.txt
use_direct_grounds = False

[Mask file]


[Calculation options]
low_memory_mode = False
parallelize = False
solver = cg+amg
print_timings = True
preemptive_memory_release = False
print_rusages = False
max_parallel = 30

[Short circuit regions (aka polygons)]


[Options for one-to-all and all-to-one modes]


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

[Version]
version = 5

[Options for reclassification of habitat data]


[Logging Options]
log_level = INFO
log_file = output/mgVerify7.log
profiler_log_file = output/mgVerify7_rusages.log
screenprint_log = False

[Options for pairwise and one-to-all and all-to-one modes]


[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/advanced/7/resistance_TestArea1.asc

[Circuitscape mode]
data_type = raster
scenario = advanced
Loading

0 comments on commit ec267c2

Please sign in to comment.