From 2246d4002e9f583684dfd44afc403d20ca62bc6f Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Fri, 12 Jan 2024 07:35:01 +1000 Subject: [PATCH] Fix typo in `priority_zone_criteria` docs function docs and format function docs --- src/decision/dMCDA.jl | 35 ++++++++++++++++++++---------- src/decision/location_selection.jl | 24 +++++++++++++------- src/ecosystem/connectivity.jl | 3 ++- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/decision/dMCDA.jl b/src/decision/dMCDA.jl index 1f828fc44..d17c3c879 100644 --- a/src/decision/dMCDA.jl +++ b/src/decision/dMCDA.jl @@ -258,8 +258,10 @@ function rank_sites!( end """ - retrieve_ranks(S::Matrix, site_ids::Vector, weights::Vector{Float64}, mcda_func::Function)::Matrix{Union{Float64,Int64}} - retrieve_ranks(S::Matrix, site_ids::Vector, weights::Vector{Float64}, mcda_func::Type{<:MCDMMethod})::Matrix{Union{Float64,Int64}} + retrieve_ranks(S::Matrix, site_ids::Vector, weights::Vector{Float64}, mcda_func::Function) + ::Matrix{Union{Float64,Int64}} + retrieve_ranks(S::Matrix, site_ids::Vector, weights::Vector{Float64}, mcda_func:: + Type{<:MCDMMethod})::Matrix{Union{Float64,Int64}} retrieve_ranks(site_ids::Vector, scores::Vector, maximize::Bool)::Matrix{Union{Float64,Int64}} Get location ranks using mcda technique specified in mcda_func, weights and a decision matrix S. @@ -307,7 +309,8 @@ function retrieve_ranks( end """ - create_decision_matrix(site_ids, in_conn, out_conn, leftover_space, wave_stress, heat_stress, predec, risk_tol) + create_decision_matrix(site_ids, in_conn, out_conn, leftover_space, wave_stress, + heat_stress, predec, risk_tol) Creates criteria matrix `A`, where each column is a selection criterium and each row is a site. Sites are then filtered based on heat and wave stress risk. @@ -333,7 +336,8 @@ Columns indicate: - `wave_stress` : Probability of wave damage. - `heat_stress` : Probability of site being affected by heat stress - `predec` : List of priority predecessors (sites strongly connected to priority sites). -- `risk_tol` : Tolerance for wave and heat risk (∈ [0,1]). Sites with heat or wave risk> risk_tol are filtered out. +- `risk_tol` : Tolerance for wave and heat risk (∈ [0,1]). Sites with heat or wave + risk> risk_tol are filtered out. """ function create_decision_matrix( site_ids::Vector{Int64}, @@ -916,9 +920,11 @@ function within_depth_bounds( end """ - priority_location_criteria(strong_pred::Vector{Int64}, priority_locations::Vector{Int64}, location_ids::Vector{Int64})::Vector{Float64} + priority_location_criteria(strong_pred::Vector{Int64}, priority_locations::Vector{Int64}, + location_ids::Vector{Int64})::Vector{Float64} -Calculates the priority location criteria, which prioritises priority locations and locations which are larval sources for these. +Calculates the priority location criteria, which prioritises priority locations and locations +which are larval sources for these. # Arguments - `strong_pred` : Strongest predecessor locations for each location. @@ -926,8 +932,8 @@ Calculates the priority location criteria, which prioritises priority locations - `location_ids` : Full set of location indices (same size as `strong_pred`) # Returns -Priority criteria value for each location, the larger the value the better that location contributes to prioritising locations - in the `priority_locations` list. +Priority criteria value for each location, the larger the value the better that location + contributes to prioritising locations in the `priority_locations` list. """ function priority_location_criteria( strong_pred::Vector{Int64}, @@ -938,6 +944,7 @@ function priority_location_criteria( # Work out which priority predecessors are connected to priority locations predprior = strong_pred[in.(location_ids, [priority_locations'])] + # Find index of these locations in location_ids pred_idx = dropdims(sum(predprior .== location_ids'; dims = 1); dims = 1) .> 0 @@ -946,17 +953,19 @@ function priority_location_criteria( end """ - priority_zones_criteria(strong_pred::Vector{Int64}, zones::Vector{String}, priority_zones::Vector{String}, - location_ids::Vector{Int64}; pred_w::Float64=0.2)::Vector{Float64} + priority_zones_criteria(strong_pred::Vector{Int64}, zones::Vector{String}, + priority_zones::Vector{String}, location_ids::Vector{Int64}; pred_w::Float64=0.5)::Vector{Float64} -Calculates the priority zone criteria, which prioritises priority GBRMPA zones and zones which are larval sources for these. +Calculates the priority zone criteria, which prioritises priority GBRMPA zones and zones which +are larval sources for these. # Arguments - `strong_pred` : Strongest predecessor locations for each location. - `zones` : Zone classification for each location - `priority_zones` : Zones to prioritse (in order of priority) - `location_ids` : Full set of location indices (same size as `strong_pred`) -- `pred_w` : Weight designating importance of locations being in the zone vs. larval sources for the zone. +- `pred_w` : Weight designating importance of locations being in the zone vs. larval sources + for the zone. # Returns Priority zones value for each location, the larger the value the better that location contributes to prioritising @@ -970,6 +979,7 @@ function priority_zones_criteria( pred_w::Float64 = 0.5, )::Vector{Float64} n_sites = length(zones) + # Find set of priority zones and scoring system depending on zone priority zone_ids = intersect(priority_zones, unique(zones)) zone_weights = mcda_normalize(collect(length(zone_ids):-1:1)) @@ -979,6 +989,7 @@ function priority_zones_criteria( for (k::Int64, z_name::String) in enumerate(zone_ids) # Find locations which are strongest predecessors of locations in the zone add_zone_weight = strong_pred[zones .== z_name] + # Positional indices of locations in location_ids pred_zone_idx = dropdims(sum(add_zone_weight .== location_ids'; dims = 1); dims = 1) .> 0 diff --git a/src/decision/location_selection.jl b/src/decision/location_selection.jl index 87e760779..cb3f1b264 100644 --- a/src/decision/location_selection.jl +++ b/src/decision/location_selection.jl @@ -3,7 +3,8 @@ using NamedDims, AxisKeys using ADRIA: connectivity_strength, relative_leftover_space, site_k_area """ - _location_selection(domain::Domain, sum_cover::AbstractArray, mcda_vars::DMCDA_vars, guided::Int64)::Matrix + _location_selection(domain::Domain, sum_cover::AbstractArray, mcda_vars::DMCDA_vars, + guided::Int64)::Matrix Select locations for a given domain and criteria/weightings/thresholds, using a chosen MCDA method. @@ -57,9 +58,12 @@ function _location_selection( end """ - rank_locations(domain::Domain, scenarios::DataFrame, sum_cover::NamedDimsArray, area_to_seed::Float64; target_seed_sites=nothing, target_fog_sites=nothing)::NamedDimsArray - rank_locations(domain::Domain,scenarios::DataFrame, sum_cover::NamedDimsArray, area_to_seed::Float64, agg_func::Function, - iv_type::Union{String,Int64}; target_seed_sites=nothing, target_fog_sites=nothing)::AbstractArray + rank_locations(domain::Domain, scenarios::DataFrame, sum_cover::NamedDimsArray, + area_to_seed::Float64; target_seed_sites=nothing, target_fog_sites=nothing) + ::NamedDimsArray + rank_locations(domain::Domain,scenarios::DataFrame, sum_cover::NamedDimsArray, + area_to_seed::Float64, agg_func::Function,iv_type::Union{String,Int64}; + target_seed_sites=nothing, target_fog_sites=nothing)::AbstractArray Return location ranks for a given domain and scenarios. @@ -184,8 +188,10 @@ end """ ranks_to_frequencies(ranks::NamedDimsArray, n_ranks::Int64) - ranks_to_frequencies(ranks::NamedDimsArray{D,T,3,A}; n_ranks=length(ranks.sites), agg_func=x -> dropdims(sum(x; dims=:timesteps); dims=:timesteps),) where {D,T,A} - ranks_to_frequencies(ranks::NamedDimsArray{D,T,2,A}; n_ranks=length(ranks.sites), agg_func=nothing) where {D,T,A} + ranks_to_frequencies(ranks::NamedDimsArray{D,T,3,A}; n_ranks=length(ranks.sites), + agg_func=x -> dropdims(sum(x; dims=:timesteps); dims=:timesteps),) where {D,T,A} + ranks_to_frequencies(ranks::NamedDimsArray{D,T,2,A}; n_ranks=length(ranks.sites), + agg_func=nothing) where {D,T,A} Returns the frequency with which each location was ranked across scenarios. Uses the results from `rank_locations()`. @@ -243,7 +249,8 @@ end """ location_selection_frequencies(ranks::NamedDimsArray; n_iv_locs::Int64=5) - location_selection_frequencies(iv_log::NamedDimsArray{D,T,4,A}; dims::Union{Symbol,Vector{Symbol}}=:coral_id) where {D,T,A} + location_selection_frequencies(iv_log::NamedDimsArray{D,T,4,A}; dims::Union{Symbol, + Vector{Symbol}}=:coral_id) where {D,T,A} Determines the count of times each location was selected for a specific intervention over a set of scenarios. @@ -281,7 +288,8 @@ end _drop_single(x::AbstractMatrix) = dropdims(x; dims = (findall(size(x) .== 1)...,)) """ - selection_score(ranks::NamedDimsArray{D,T,3,A}; dims::Vector{Symbol}=[:scenarios, :timesteps]) where {D,T,A} + selection_score(ranks::NamedDimsArray{D,T,3,A}; dims::Vector{Symbol}=[:scenarios, + :timesteps]) where {D,T,A} selection_score(ranks::NamedDimsArray{D,T,2,A}) where {D,T,A} selection_score(ranks::NamedDimsArray, dims::Vector{Symbol}) diff --git a/src/ecosystem/connectivity.jl b/src/ecosystem/connectivity.jl index ada3d0b53..4ffd859c3 100644 --- a/src/ecosystem/connectivity.jl +++ b/src/ecosystem/connectivity.jl @@ -163,7 +163,8 @@ end """ connectivity_strength(TP_base::AbstractArray)::NamedTuple - connectivity_strength(area_weighted_TP::AbstractMatrix{Float64}, cover::Vector{Float64}, TP_cache::AbstractMatrix{Float64})::NamedTuple + connectivity_strength(area_weighted_TP::AbstractMatrix{Float64}, cover::Vector{Float64}, + TP_cache::AbstractMatrix{Float64})::NamedTuple Create in/out degree centralities for all nodes, and vector of their strongest predecessors.