From 148eed9e30df3adfc840f4070d5e3ddedad05dd2 Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Mon, 27 Nov 2023 16:37:20 +1000 Subject: [PATCH 1/8] Fix input to MCDAvars constructor in `rank_locations` Fourth arg should be leftover space in metres now, not proportionate cover --- src/decision/location_selection.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/decision/location_selection.jl b/src/decision/location_selection.jl index 4e1a49576..afd708f49 100644 --- a/src/decision/location_selection.jl +++ b/src/decision/location_selection.jl @@ -1,6 +1,6 @@ using NamedDims, AxisKeys -using ADRIA: connectivity_strength +using ADRIA: connectivity_strength, relative_leftover_space, site_k_area """ _location_selection(domain::Domain, sum_cover::AbstractArray, mcda_vars::DMCDA_vars, guided::Int64)::Matrix @@ -87,6 +87,7 @@ function rank_locations( target_fog_sites=nothing, )::NamedDimsArray n_locs = n_locations(domain) + k_area_locs = site_k_area(domain) ranks_store = NamedDimsArray( zeros(n_locs, 2, nrow(scenarios)), @@ -124,7 +125,12 @@ function rank_locations( depth_priority = findall(depth_criteria) considered_sites = target_site_ids[findall(in(depth_priority), target_site_ids)] - mcda_vars_temp = DMCDA_vars(domain, scen, considered_sites, sum_cover[scen_idx, :], area_to_seed, + mcda_vars_temp = DMCDA_vars( + domain, + scen, + considered_sites, + relative_leftover_space(sum_cover[scen_idx, :]) .* k_area_locs, + area_to_seed, summary_stat_env(wave_scens[:, :, target_wave_scens], (:timesteps, :scenarios)), summary_stat_env(dhw_scens[:, :, target_dhw_scens], (:timesteps, :scenarios)) ) From 7537b8a07c8ddc73f24ecd29b5351156af43a4b5 Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Tue, 28 Nov 2023 13:46:30 +1000 Subject: [PATCH 2/8] Fix type mismatches in `relative_lefover_space` usage Input is different type in standalone site selection case --- src/Domain.jl | 6 ++++-- src/decision/location_selection.jl | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Domain.jl b/src/Domain.jl index 892ca9f61..54e224b5f 100644 --- a/src/Domain.jl +++ b/src/Domain.jl @@ -232,7 +232,7 @@ function n_locations(domain::Domain)::Int64 end """ - relative_leftover_space(loc_coral_cover::Matrix{Float64})::Matrix{Float64} + relative_leftover_space(loc_coral_cover::Union{Matrix{Float64},Vector{Float32}})::Union{Matrix{Float64},Vector{Float32}} Get proportion of leftover space, given site_k and proportional cover on each site, summed over species. @@ -243,7 +243,9 @@ over species. # Returns Leftover space ∈ [0, 1] """ -function relative_leftover_space(loc_coral_cover::Matrix{Float64})::Matrix{Float64} +function relative_leftover_space( + loc_coral_cover::Union{Matrix{Float64},Vector{Float32}} +)::Union{Matrix{Float64},Vector{Float64}} return max.(1.0 .- loc_coral_cover, 0.0) end diff --git a/src/decision/location_selection.jl b/src/decision/location_selection.jl index afd708f49..afc912598 100644 --- a/src/decision/location_selection.jl +++ b/src/decision/location_selection.jl @@ -129,7 +129,9 @@ function rank_locations( domain, scen, considered_sites, - relative_leftover_space(sum_cover[scen_idx, :]) .* k_area_locs, + relative_leftover_space( + AxisKeys.keyless(NamedDims.unname(sum_cover[scen_idx, :])) + ) .* k_area_locs, area_to_seed, summary_stat_env(wave_scens[:, :, target_wave_scens], (:timesteps, :scenarios)), summary_stat_env(dhw_scens[:, :, target_dhw_scens], (:timesteps, :scenarios)) From 0b791ad009f21ed90344402adcbd23eb29ba453c Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Wed, 29 Nov 2023 10:37:30 +1000 Subject: [PATCH 3/8] Fix docs so it is clear that cover inputs to `rank_locations` and `_location_selection` --- src/decision/location_selection.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/decision/location_selection.jl b/src/decision/location_selection.jl index afc912598..e64343878 100644 --- a/src/decision/location_selection.jl +++ b/src/decision/location_selection.jl @@ -10,7 +10,7 @@ MCDA method. # Arguments - `domain` : The geospatial domain to assess -- `sum_cover` : Absolute coral cover at each location +- `sum_cover` : Relative coral cover at each location - `mcda_vars` : Parameters for MCDA - `guided` : ID of MCDA algorithm to apply @@ -66,7 +66,7 @@ Return location ranks for a given domain and scenarios. # Arguments - `domain` : The geospatial domain locations were selected from - `scenarios` : Scenario specification -- `sum_cover` : Matrix[n_scenarios ⋅ n_sites] containing the total coral cover at each +- `sum_cover` : Matrix[n_scenarios ⋅ n_sites] containing the total relative coral cover at each location, for each scenario - `area_to_seed` : Area of coral to be seeded at each time step in km² - `agg_func` : Aggregation function to apply, e.g `ranks_to_frequencies` or From 46ca4d98224076dd9b98ec503bbb876ce08ffbb4 Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Wed, 29 Nov 2023 14:01:55 +1000 Subject: [PATCH 4/8] Add description for `cover` variable in `connectivity_strength` to clarify input is relative cover --- src/ecosystem/connectivity.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecosystem/connectivity.jl b/src/ecosystem/connectivity.jl index e0a816eba..a838fa176 100644 --- a/src/ecosystem/connectivity.jl +++ b/src/ecosystem/connectivity.jl @@ -170,7 +170,7 @@ Create in/out degree centralities for all nodes, and vector of their strongest p # Arguments - `TP_base` : Base transfer probability matrix to create Directed Graph from. - `area_weighted_TP` : Transfer probability matrix weighted by location `k` area -- `cover` : Total coral cover at location +- `cover` : Total relative coral cover at location - `TP_cache` : Cache matrix of same size as TP_base to hold intermediate values # Returns From 53b2e0ebbb2dbe43bc2604bf2c5218f6d74e86b8 Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Wed, 6 Dec 2023 08:27:28 +1000 Subject: [PATCH 5/8] Replace `keyless` and `unname` with `collect` in `relative_leftover_space` call --- src/decision/location_selection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/decision/location_selection.jl b/src/decision/location_selection.jl index e64343878..149468ec4 100644 --- a/src/decision/location_selection.jl +++ b/src/decision/location_selection.jl @@ -130,7 +130,7 @@ function rank_locations( scen, considered_sites, relative_leftover_space( - AxisKeys.keyless(NamedDims.unname(sum_cover[scen_idx, :])) + collect(sum_cover[scen_idx, :]), ) .* k_area_locs, area_to_seed, summary_stat_env(wave_scens[:, :, target_wave_scens], (:timesteps, :scenarios)), From 90be725bd3624ddd34c8dc4861aded10dff38e93 Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Wed, 6 Dec 2023 11:01:50 +1000 Subject: [PATCH 6/8] Change input type for `relative_leftover_space` to `AbstractArray` --- src/Domain.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Domain.jl b/src/Domain.jl index 54e224b5f..3f56b0e6e 100644 --- a/src/Domain.jl +++ b/src/Domain.jl @@ -232,7 +232,7 @@ function n_locations(domain::Domain)::Int64 end """ - relative_leftover_space(loc_coral_cover::Union{Matrix{Float64},Vector{Float32}})::Union{Matrix{Float64},Vector{Float32}} + relative_leftover_space(loc_coral_cover::AbstractArray)::AbstractArray Get proportion of leftover space, given site_k and proportional cover on each site, summed over species. @@ -244,8 +244,8 @@ over species. Leftover space ∈ [0, 1] """ function relative_leftover_space( - loc_coral_cover::Union{Matrix{Float64},Vector{Float32}} -)::Union{Matrix{Float64},Vector{Float64}} + loc_coral_cover::AbstractArray, +)::AbstractArray return max.(1.0 .- loc_coral_cover, 0.0) end From 6feb80c8785d92bdd5129c2d6898049402bf02a2 Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Wed, 6 Dec 2023 11:02:18 +1000 Subject: [PATCH 7/8] Use `.data` instead of `collect` to convert to vector --- src/decision/location_selection.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/decision/location_selection.jl b/src/decision/location_selection.jl index 149468ec4..ecc38bcaa 100644 --- a/src/decision/location_selection.jl +++ b/src/decision/location_selection.jl @@ -130,7 +130,7 @@ function rank_locations( scen, considered_sites, relative_leftover_space( - collect(sum_cover[scen_idx, :]), + sum_cover[scen_idx, :].data, ) .* k_area_locs, area_to_seed, summary_stat_env(wave_scens[:, :, target_wave_scens], (:timesteps, :scenarios)), From 968f1bc5363a150bb9318ec9259f59aa2ad3daba Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Wed, 6 Dec 2023 15:31:28 +1000 Subject: [PATCH 8/8] Allocate `leftover_space_scens` outside of scenario for loop --- src/decision/location_selection.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/decision/location_selection.jl b/src/decision/location_selection.jl index ecc38bcaa..ad547fd45 100644 --- a/src/decision/location_selection.jl +++ b/src/decision/location_selection.jl @@ -116,6 +116,8 @@ function rank_locations( target_site_ids = collect(1:length(domain.site_ids)) end + leftover_space_scens = relative_leftover_space(sum_cover.data) .* k_area_locs' + for (scen_idx, scen) in enumerate(eachrow(scenarios)) depth_criteria = within_depth_bounds( domain.site_data.depth_med, @@ -124,14 +126,13 @@ function rank_locations( ) depth_priority = findall(depth_criteria) + considered_sites = target_site_ids[findall(in(depth_priority), target_site_ids)] mcda_vars_temp = DMCDA_vars( domain, scen, considered_sites, - relative_leftover_space( - sum_cover[scen_idx, :].data, - ) .* k_area_locs, + leftover_space_scens[scen_idx, :], area_to_seed, summary_stat_env(wave_scens[:, :, target_wave_scens], (:timesteps, :scenarios)), summary_stat_env(dhw_scens[:, :, target_dhw_scens], (:timesteps, :scenarios))