diff --git a/code/03_network_pfim.jl b/code/03_network_pfim.jl index 5051f1b..316dc1d 100644 --- a/code/03_network_pfim.jl +++ b/code/03_network_pfim.jl @@ -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) @@ -182,10 +181,10 @@ 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(); @@ -193,23 +192,57 @@ 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"]], ) diff --git a/data/processed/networks/pfim_networks_trophic_maximal.jlds b/data/processed/networks/pfim_networks_trophic_maximal.jlds new file mode 100644 index 0000000..0f933e2 Binary files /dev/null and b/data/processed/networks/pfim_networks_trophic_maximal.jlds differ diff --git a/data/processed/networks/pfim_networks_trophic.jlds b/data/processed/networks/pfim_networks_trophic_minimum.jlds similarity index 61% rename from data/processed/networks/pfim_networks_trophic.jlds rename to data/processed/networks/pfim_networks_trophic_minimum.jlds index ba49da4..ae15172 100644 Binary files a/data/processed/networks/pfim_networks_trophic.jlds and b/data/processed/networks/pfim_networks_trophic_minimum.jlds differ diff --git a/data/processed/topology/topology_pfim_trophic.csv b/data/processed/topology/topology_pfim_trophic.csv deleted file mode 100644 index c2e97ff..0000000 --- a/data/processed/topology/topology_pfim_trophic.csv +++ /dev/null @@ -1,4 +0,0 @@ -id,model,richness,connectance,deficiency,complexity,distance,basal,top,generality,vulnerability,S1,S2,S4,S5 -during_traits,pfim_trophic,13,0.07692307692307693,0.8461538461538461,0.9709505944546688,2.0,11.0,2.0,2.516611478423583,0.5773502691896257,0.0,0.0,0.0,10.0 -post_traits,pfim_trophic,13,0.05325443786982249,0.8461538461538461,0.9682379220145413,2.0,11.0,5.0,1.797434068545834,0.6304251719561151,0.0,0.0,0.0,3.0 -pre_traits,pfim_trophic,30,0.06333333333333334,0.8333333333333334,0.8751965104595237,2.0,25.0,7.0,4.596475411322958,1.4467561813504937,0.0,0.0,0.0,49.0 diff --git a/data/processed/topology/topology_pfim_trophic_maximal.csv b/data/processed/topology/topology_pfim_trophic_maximal.csv new file mode 100644 index 0000000..8bc96e6 --- /dev/null +++ b/data/processed/topology/topology_pfim_trophic_maximal.csv @@ -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 diff --git a/data/processed/topology/topology_pfim_trophic_minimum.csv b/data/processed/topology/topology_pfim_trophic_minimum.csv new file mode 100644 index 0000000..271f75b --- /dev/null +++ b/data/processed/topology/topology_pfim_trophic_minimum.csv @@ -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 diff --git a/notebooks/code/figures_pfim.R b/notebooks/code/figures_pfim.R index c2cc5fc..ea2bb35 100644 --- a/notebooks/code/figures_pfim.R +++ b/notebooks/code/figures_pfim.R @@ -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"), @@ -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()) diff --git a/notebooks/figures/pca_pfim.png b/notebooks/figures/pca_pfim.png index de804af..7151872 100644 Binary files a/notebooks/figures/pca_pfim.png and b/notebooks/figures/pca_pfim.png differ diff --git a/notebooks/figures/summary_pfim.png b/notebooks/figures/summary_pfim.png index 8dd1dab..af8dff7 100644 Binary files a/notebooks/figures/summary_pfim.png and b/notebooks/figures/summary_pfim.png differ