Skip to content

Commit

Permalink
Merge pull request #28 from Seafood-Globalization-Lab/develop
Browse files Browse the repository at this point in the history
Consumption update
  • Loading branch information
theamarks authored Sep 23, 2024
2 parents ca9cbf4 + 8a9af70 commit 83ed281
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ model_inputs/*
outputs/*
*.zip
model_inputs_sau/*
AM_local/*
grateful-report.html
4 changes: 2 additions & 2 deletions 02-artis-pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ if (run_env == "aws") {
}

# Set production data type variable
prod_data_type <- "FAO"
prod_data_type <- "SAU"

# Set up Start date for finding no solution countries
start_date <- Sys.Date()
test_years <- c(2018)
test_years <- c()
#--------------------------------------------------------
# This section generates the solutions for the mass balance problem for all
# countries across all years and HS versions
Expand Down
8 changes: 5 additions & 3 deletions 03-combine-tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# Setup based on the kind of analysis and machine you are working with

# Start with a clean working environment
rm(list=ls())

# rm(list=ls())
#-------------------------------------------------------------------------------
run_env <- "demo"
run_env <- "aws"

if (run_env == "aws") {
# High Performance Computing on AWS Setup
Expand Down Expand Up @@ -40,6 +39,9 @@ outdir_cvxopt <- file.path(outdir, "cvxopt_snet")

final_outdir <- file.path(outdir, "artis_outputs")

# Ensure the 'outputs' directory exists on the aws "local" machine
if (!dir.exists("outputs")) { dir.create("outputs") }
# Ensure the 'artis_outputs' directory exists on the aws "local" machine
if (!dir.exists(final_outdir)) { dir.create(final_outdir) }

build_artis_data(outdir_snet, final_outdir,
Expand Down
50 changes: 38 additions & 12 deletions 04-create-metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,43 @@ taxa_metadata <- taxa %>%
sciname = c("arthropoda", "engraulis", "hippoglossinae", "scombrinae", "clupea",
"chondrichthyes", "salmoninae", "mytilinae", "actinopteri", "animalia",
"homarus", "cypriniformes", "dissostichus", "micromesistius", "echinoida"),

common_name = c("arthropods", "anchovies", "flounders", "mackerels, tunas, and bonitos",
"herrings", "sharks, skates, rays, and chimaeras", "salmons and trouts",
"saltwater mussels", "ray-finned fish", "aquatic animals", "lobsters",
"carps, minnows, loaches, etc", "toothfish", "blue whitings", "sea urchins"),
Genus = NA,
Subfamily = NA,
Family = NA,
Order = NA,
Class = NA,
Superclass = NA,
Phylum = NA,
Kingdom = NA

Genus = c(NA, "engraulis", NA, NA, "clupea",
NA, NA, NA, NA, NA,
"homarus", NA, "dissostichus", "micromesistius", NA),

Subfamily = c(NA, "engraulinae", "hippoglossinae", "scombrinae", "clupeinae",
NA, "salmoninae", "mytilinae", NA, NA,
NA, NA, NA, NA, NA),

Family = c(NA, "engraulidae", "pleuronectidae", "scombridae", "clupeidae",
NA, "salmonidae", "mytilidae", NA, NA,
"nephropidae", NA, "nototheniidae", "gadidae", NA),

Order = c(NA, "clupeiformes", "pleuronectiformes", "scombriformes", " clupeiformes",
NA, "salmoniformes", "mytilida", NA, NA,
"decapoda", "cypriniformes", "perciformes", "gadiformes", "echinoida"),

Class = c(NA, "actinopterygii", "actinopterygii", "actinopterygii", "actinopterygii",
"chondrichthyes", "actinopterygii", "bivalvia", "actinopterygii", NA,
"malacostraca", "actinopterygii", "actinopterygii", "actinopterygii", "echinoidea"),

Superclass = c(NA, NA, NA, NA, NA,
NA, NA, NA, "actinopteri", NA,
NA, NA, NA, NA, NA),

Phylum = c("arthropoda", "chordata", "chordata", "chordata", "chordata",
"chordata", "chordata", "mollusca", "chordata", NA,
"arthropoda", "chordata", "chordata", "chordata", "echinodermata"),

Kingdom = c("animalia", "animalia", "animalia", "animalia", "animalia",
"animalia", "animalia", "animalia", "animalia", "animalia",
"animalia", "animalia", "animalia", "animalia", "animalia")
))


Expand Down Expand Up @@ -400,7 +425,8 @@ for(i in c("96", "02", "07", "12", "17")){
mutate(Code = if_else(str_detect(Code, "^30"), true = str_replace(Code, pattern = "^30", replacement = "030"),
if_else(str_detect(Code, "^511"), true = str_replace(Code, pattern = "^511", replacement = "0511"),
false = Code))) %>%
mutate(hs_version = HS_year_rep)
mutate(hs_version = HS_year_rep) %>%
filter(!is.na(hs_clade))

hs_clade_match <- hs_clade_match %>%
bind_rows(hs_clade_match_i) %>%
Expand Down Expand Up @@ -446,7 +472,8 @@ prod_taxa_classification <- taxa_metadata %>%

code_max_resolved_taxa <- hs_taxa_match %>%
rename(hs6 = Code, sciname = SciName) %>%
left_join(hs_clade_match %>% mutate(hs_version = paste("HS", hs_version, sep="")),
left_join(hs_clade_match %>%
mutate(hs_version = paste("HS", hs_version, sep="")),
by = c("hs6", "HS_version" = "hs_version")) %>%
left_join(prod_taxa_classification, by = c("sciname")) %>%
mutate(code_taxa_level_numeric = case_when(
Expand Down Expand Up @@ -484,8 +511,7 @@ code_max_resolved_taxa <- hs_taxa_match %>%
sciname_hs_modified != "chordata" ~ sciname_hs_modified
)) %>%
select("hs_version" = "HS_version", hs6, sciname, sciname_hs_modified) %>%
mutate(hs_version = as.integer(parse_number(hs_version)),
hs6 = as.character(hs6)) %>%
mutate(hs6 = as.character(hs6)) %>%
distinct()

write.csv(code_max_resolved_taxa, file.path(outdir, "code_max_resolved_taxa.csv"), row.names = FALSE)
Loading

0 comments on commit 83ed281

Please sign in to comment.