Skip to content

Commit

Permalink
Add testing mcda visualisations to mcda tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosejoycrocker committed Nov 13, 2024
1 parent 01a997c commit 15e7273
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions test/site_selection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,51 @@ 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 15e7273

Please sign in to comment.