Skip to content

Commit

Permalink
Add testing criteria visualisations to site selection tests
Browse files Browse the repository at this point in the history
Formatting

Put func docstrings on single lines
  • Loading branch information
Rosejoycrocker committed Nov 13, 2024
1 parent 01a997c commit 1a677cc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 10 deletions.
8 changes: 2 additions & 6 deletions ext/AvizExt/viz/location_selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions ext/AvizExt/viz/spatial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
51 changes: 51 additions & 0 deletions test/site_selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1a677cc

Please sign in to comment.