Skip to content

Commit

Permalink
🐎 min-max trophic networks
Browse files Browse the repository at this point in the history
  • Loading branch information
TanyaS08 committed Jan 7, 2025
1 parent 2df2625 commit f879fc6
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 13 deletions.
47 changes: 40 additions & 7 deletions code/03_network_pfim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ matrix_names = readdir("../data/clean/trait_maximal")
matrix_names = replace.(matrix_names, ".csv" => "")

# maximal feeding rules

feeding_rules = DataFrame(CSV.File("../data/clean/feeding_rules/feeding_rules_maximal.csv"))

for i in eachindex(matrix_names)
Expand Down Expand Up @@ -182,34 +181,68 @@ save_object(
topology[:, ["id", "model", "network"]],
)

# trophic species
# trophic species - minimum rules

# get the name of all communities
matrix_names = readdir("../data/clean/trophic")
matrix_names = readdir("../data/clean/trophic_minimum")
matrix_names = replace.(matrix_names, ".csv" => "")

topology = topo_df();

for i in eachindex(matrix_names)

file_name = matrix_names[i]
df = DataFrame(CSV.File.(joinpath("../data/clean/trophic", "$file_name.csv"),))
df = DataFrame(CSV.File.(joinpath("../data/clean/trophic_minimum", "$file_name.csv"),))

d = model_summary(df, file_name, "pfim"; feeding_rules = feeding_rules, downsample = false)

d[:model] = "pfim_trophic_minimum"
push!(topology, d)

end

# write summaries as .csv
CSV.write(
"../data/processed/topology/topology_pfim_trophic_minimum.csv",
topology[:, setdiff(names(topology), ["network"])],
)
# write networks as object
save_object(
"../data/processed/networks/pfim_networks_trophic_minimum.jlds",
topology[:, ["id", "model", "network"]],
)

# trophic species - maximal rules

# get the name of all communities
matrix_names = readdir("../data/clean/trophic_maximal")
matrix_names = replace.(matrix_names, ".csv" => "")

# maximal feeding rules
feeding_rules = DataFrame(CSV.File("../data/clean/feeding_rules/feeding_rules_maximal.csv"))

topology = topo_df();

for i in eachindex(matrix_names)

file_name = matrix_names[i]
df = DataFrame(CSV.File.(joinpath("../data/clean/trophic_maximal", "$file_name.csv"),))

d = model_summary(df, file_name, "pfim"; feeding_rules = feeding_rules, downsample = false)

d[:model] = "pfim_trophic"
d[:model] = "pfim_trophic_maximal"
push!(topology, d)

end

# write summaries as .csv
CSV.write(
"../data/processed/topology/topology_pfim_trophic.csv",
"../data/processed/topology/topology_pfim_trophic_maximal.csv",
topology[:, setdiff(names(topology), ["network"])],
)
# write networks as object
save_object(
"../data/processed/networks/pfim_networks_trophic.jlds",
"../data/processed/networks/pfim_networks_trophic_maximal.jlds",
topology[:, ["id", "model", "network"]],
)

Expand Down
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions data/processed/topology/topology_pfim_trophic.csv

This file was deleted.

4 changes: 4 additions & 0 deletions data/processed/topology/topology_pfim_trophic_maximal.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,model,richness,connectance,deficiency,complexity,distance,basal,top,generality,vulnerability,S1,S2,S4,S5
during_traits,pfim_trophic_maximal,13,0.05325443786982249,0.8461538461538461,0.8037424105974534,2.0,11.0,5.0,2.213015114597254,0.6304251719561151,0.0,0.0,0.0,0.0
post_traits,pfim_trophic_maximal,13,0.04142011834319527,0.8461538461538461,0.834630053001768,2.0,11.0,7.0,1.6641005886756874,0.6602252917735248,0.0,0.0,0.0,0.0
pre_traits,pfim_trophic_maximal,37,0.042366691015339665,0.8648648648648649,0.8666874205374346,2.0,32.0,14.0,4.494073508154567,1.4821257357919053,0.0,0.0,0.0,31.0
4 changes: 4 additions & 0 deletions data/processed/topology/topology_pfim_trophic_minimum.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,model,richness,connectance,deficiency,complexity,distance,basal,top,generality,vulnerability,S1,S2,S4,S5
during_traits,pfim_trophic_minimum,13,0.011834319526627219,0.9230769230769231,NaN,2.0,12.0,11.0,0.5547001962252291,0.3755338080994054,0.0,0.0,0.0,0.0
post_traits,pfim_trophic_minimum,13,0.011834319526627219,0.9230769230769231,NaN,2.0,12.0,11.0,0.5547001962252291,0.3755338080994054,0.0,0.0,0.0,0.0
pre_traits,pfim_trophic_minimum,30,0.0044444444444444444,0.9333333333333333,0.9475713327707453,2.0,28.0,27.0,0.5074162634049248,0.43417248545530474,0.0,0.0,0.0,0.0
4 changes: 2 additions & 2 deletions notebooks/code/figures_pfim.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ for (i in seq_along(plot_list)) {
xlab("time") +
ylab("value") +
coord_cartesian(clip = "off") +
scale_colour_brewer(palette = "Dark2") +
#scale_colour_brewer(palette = "Dark2") +
labs(title = levs[i]) +
theme(panel.border = element_rect(colour = 'black',
fill = "#ffffff00"),
Expand Down Expand Up @@ -99,7 +99,7 @@ pca_res <- prcomp(df_pca[3:8], scale. = TRUE)

autoplot(pca_res, data = df_pca, colour = 'model', shape = 'id', size = 4, alpha = 0.7) +
theme_classic() +
scale_colour_brewer(palette = "Dark2") +
#scale_colour_brewer(palette = "Dark2") +
theme(panel.border = element_rect(colour = 'black',
fill = "#ffffff00"),
axis.ticks.x = element_blank())
Expand Down
Binary file modified notebooks/figures/pca_pfim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified notebooks/figures/summary_pfim.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f879fc6

Please sign in to comment.