From 1a677cc0d44067d9e48932c96612f6139480ee26 Mon Sep 17 00:00:00 2001 From: Rose Crocker Date: Wed, 13 Nov 2024 13:42:18 +1000 Subject: [PATCH] Add testing criteria visualisations to site selection tests Formatting Put func docstrings on single lines --- ext/AvizExt/viz/location_selection.jl | 8 ++--- ext/AvizExt/viz/spatial.jl | 7 ++-- test/site_selection.jl | 51 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/ext/AvizExt/viz/location_selection.jl b/ext/AvizExt/viz/location_selection.jl index dad016e03..a94e5483f 100644 --- a/ext/AvizExt/viz/location_selection.jl +++ b/ext/AvizExt/viz/location_selection.jl @@ -131,12 +131,8 @@ function ADRIA.viz.ranks_to_frequencies( end """ - ADRIA.viz.selection_criteria_map(rs::Union{Domain,ResultSet}, decision_matrix::YAXArray, scores::Vector{Float64}; - criteria::Vector{Symbol}=Array(decision_matrix.criteria), opts::OPT_TYPE=DEFAULT_OPT_TYPE(), fig_opts::OPT_TYPE=set_figure_defaults(DEFAULT_OPT_TYPE()), - axis_opts::OPT_TYPE=set_axis_defaults(DEFAULT_OPT_TYPE())) - ADRIA.viz.selection_criteria_map!(g::Union{GridLayout,GridPosition}, rs::Union{Domain,ResultSet}, decision_matrix::YAXArray, - scores::Vector{Float64}; criteria::Vector{Symbol}=Array(decision_matrix.criteria), opts::OPT_TYPE=DEFAULT_OPT_TYPE(), - axis_opts::OPT_TYPE=set_axis_defaults(DEFAULT_OPT_TYPE())) + ADRIA.viz.selection_criteria_map(rs::Union{Domain,ResultSet}, decision_matrix::YAXArray, scores::Vector{Float64}; criteria::Vector{Symbol}=Array(decision_matrix.criteria), opts::OPT_TYPE=DEFAULT_OPT_TYPE(), fig_opts::OPT_TYPE=set_figure_defaults(DEFAULT_OPT_TYPE()), axis_opts::OPT_TYPE=set_axis_defaults(DEFAULT_OPT_TYPE())) + ADRIA.viz.selection_criteria_map!(g::Union{GridLayout,GridPosition}, rs::Union{Domain,ResultSet}, decision_matrix::YAXArray, scores::Vector{Float64}; criteria::Vector{Symbol}=Array(decision_matrix.criteria), opts::OPT_TYPE=DEFAULT_OPT_TYPE(), axis_opts::OPT_TYPE=set_axis_defaults(DEFAULT_OPT_TYPE())) Plot several spatial maps showing spatial distribution of location selection criteria, with the final map being the aggregate location selection score. diff --git a/ext/AvizExt/viz/spatial.jl b/ext/AvizExt/viz/spatial.jl index cfc8789e5..b20cc9f36 100644 --- a/ext/AvizExt/viz/spatial.jl +++ b/ext/AvizExt/viz/spatial.jl @@ -254,15 +254,14 @@ function ADRIA.viz.map!( end """ - ADRIA.viz.map(rs::Union{Domain,ResultSet}, outputs_matrix::Matrix, map_titles::Vector{String}; opts::OPT_TYPE=DEFAULT_OPT_TYPE(), - fig_opts::OPT_TYPE=set_figure_defaults(DEFAULT_OPT_TYPE()), axis_opts::OPT_TYPE=set_axis_defaults(DEFAULT_OPT_TYPE())) - ADRIA.viz.map!(g::Union{GridLayout,GridPosition}, rs::Union{Domain,ResultSet}, outputs_matrix::Matrix, map_titles::Vector{String}; - opts::OPT_TYPE=DEFAULT_OPT_TYPE(), axis_opts::OPT_TYPE=set_axis_defaults(DEFAULT_OPT_TYPE())) + ADRIA.viz.map(rs::Union{Domain,ResultSet}, outputs_matrix::Matrix, map_titles::Vector{String}; opts::OPT_TYPE=DEFAULT_OPT_TYPE(), fig_opts::OPT_TYPE=set_figure_defaults(DEFAULT_OPT_TYPE()), axis_opts::OPT_TYPE=set_axis_defaults(DEFAULT_OPT_TYPE())) + ADRIA.viz.map!(g::Union{GridLayout,GridPosition}, rs::Union{Domain,ResultSet}, outputs_matrix::Matrix, map_titles::Vector{String}; opts::OPT_TYPE=DEFAULT_OPT_TYPE(), axis_opts::OPT_TYPE=set_axis_defaults(DEFAULT_OPT_TYPE())) Plot a series of maps from an arbitrary (n_locs*n_maps) matrix of outputs. # Arguments - `rs` : ResultSet +- `g` : Figure GridPosition or GridLayout. - `outputs_matrix` : Matrix of outputs where n_locs is the numberof locations and n_maps is the number of different maps to plot. - `map_titles` : Titles for each map to be plotted. diff --git a/test/site_selection.jl b/test/site_selection.jl index ddf02c7f2..3b4a9a6e9 100644 --- a/test/site_selection.jl +++ b/test/site_selection.jl @@ -89,3 +89,54 @@ end rank in 1:size(s_order, 1) ]) || "Ranking does not match mcda score ordering" end + +@testset "Test decision matrix spatial plotting" begin + dom = ADRIA.load_domain(TEST_DOMAIN_PATH, 45) + N = 2^3 + scens = ADRIA.sample_selection(dom, N) # get scenario dataframe + scen = scens[1, :] + + # Get seeding preferences + seed_pref = ADRIA.decision.SeedPreferences(dom, scen) + + # Calculate criteria vectors + # Cover + sum_cover = vec(sum(dom.init_coral_cover; dims=1).data) + # DHWS + dhw_scens = dom.dhw_scens[:, :, Int64(scen["dhw_scenario"])] + plan_horizon = Int64(scen["plan_horizon"]) + decay = 0.99 .^ (1:(plan_horizon + 1)) .^ 2 + dhw_projection = ADRIA.decision.weighted_projection( + dhw_scens, 1, plan_horizon, decay, 75 + ) + # Connectivity + area_weighted_conn = dom.conn.data .* ADRIA.site_k_area(dom) + conn_cache = similar(area_weighted_conn) + in_conn, out_conn, network = ADRIA.connectivity_strength( + area_weighted_conn, sum_cover, conn_cache + ) + + # Create decision matrix + seed_decision_mat = ADRIA.decision.decision_matrix( + dom.loc_ids, + seed_pref.names; + seed_in_connectivity=in_conn, + seed_out_connectivity=out_conn, + seed_heat_stress=dhw_projection, + seed_coral_cover=sum_cover + ) + + # Get results from applying MCDA algorithm + crit_agg = ADRIA.decision.criteria_aggregated_scores( + seed_pref, seed_decision_mat, mcda_funcs[1] + ) + + # Don't plot constant criteria + is_const = Bool[length(x) == 1 for x in unique.(eachcol(seed_decision_mat.data))] + + # Plot normalized scores and criteria as map + decision_mat_fig = ADRIA.viz.selection_criteria_map( + dom, seed_decision_mat[criteria=.!is_const], + crit_agg.scores ./ maximum(crit_agg.scores) + ) +end