Skip to content

Commit

Permalink
Merge pull request #97 from COMPASS-DOE/viz-metrics-fixes
Browse files Browse the repository at this point in the history
Viz metrics fixes
  • Loading branch information
stephpenn1 authored Apr 11, 2024
2 parents 263da5c + 6c89694 commit b8f4163
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Processing_Scripts/sample_catalog_matrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ sample_catalog <- csvs_2 %>%
TRUE ~ status)) %>%
left_join(metadata_collected, by = c("campaign", "kit_id", "transect_location", "sample_method")) %>% #we need to take into account sample_method, need to know which analytes used which method
mutate(status = case_when(collected == TRUE & is.na(status) ~ "data available",
TRUE ~ status)) %>%
TRUE ~ status),
transect_location = factor(transect_location, levels = c("upland", "transition", "wetland", "sediment", "water"))) %>%
select(-sample_type, -sample_method, -collected, -notes) %>%
distinct() %>%
pivot_wider(names_from = analyte, values_from = status) %>%
Expand Down
6 changes: 4 additions & 2 deletions Processing_Scripts/soil_cec.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,14 @@ metadata_collected %>%

data_clean %>%
full_join(meta_filter, by = c("campaign", "kit_id", "transect_location")) %>%
mutate(notes = case_when(kit_id == "K050" & transect_location == "upland" ~ "not enough material for extraction",
mutate(transect_location = factor(transect_location, levels = c("upland", "transition", "wetland", "sediment")),
notes = case_when(kit_id == "K050" & transect_location == "upland" ~ "not enough material for extraction",
kit_id == "K024" & transect_location == "wetland" ~ "sample compromised",
collected == FALSE ~ "sample not collected",
TRUE ~ notes),
notes_flags = case_when(is.na(notes) ~ flag,
TRUE ~ notes)) -> full
TRUE ~ notes)) %>%
arrange(kit_id, transect_location) -> full

nums <- sapply(full, is.numeric) # identify numeric columns
full[!is.na(full$notes), which(nums)] <- NA # set compromised kits to NA
Expand Down
6 changes: 4 additions & 2 deletions Processing_Scripts/soil_iron.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ data_clean %>%
full_join(meta_filter, by = c("campaign", "kit_id", "transect_location")) %>%
# 2024-03-13: need to split soil and sediments in this script because not all sediments have been ran yet
filter(sample_type == "soil") %>%
mutate(notes = case_when(kit_id == "K018" & transect_location == "transition" ~ "not enough material for extraction",
mutate(transect_location = factor(transect_location, levels = c("upland", "transition", "wetland")),
notes = case_when(kit_id == "K018" & transect_location == "transition" ~ "not enough material for extraction",
kit_id == "K044" & transect_location == "transition" ~ "not enough material for extraction",
kit_id == "K048" & transect_location == "upland" ~ "not enough material for extraction",
kit_id == "K050" & transect_location == "upland" ~ "not enough material for extraction",
Expand All @@ -223,7 +224,8 @@ data_clean %>%
TRUE ~ notes),
Fe_ug_g = case_when(!is.na(notes) ~ NA,
TRUE ~ Fe_ug_g)) %>%
select(campaign, kit_id, transect_location, Fe_ug_g, notes) -> soil_iron
select(campaign, kit_id, transect_location, Fe_ug_g, notes) %>%
arrange(kit_id, transect_location) -> soil_iron

# 7. Export L0B data -----------------------------------------------------------
write_csv(soil_iron, paste0("~/Documents/ec1_soil_iron_L1_", Sys.Date(), ".csv"))
Expand Down
27 changes: 18 additions & 9 deletions Processing_Scripts/soilsediment_visual_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,25 @@ data_processed <- data_raw %>%
root_presence = root_mass) %>%
dplyr::select(-do_not_use_had_misclassified, -sand_content) %>%
mutate(campaign = "EC1",
root_thickness = tolower(root_thickness),
pebbles_angular_rounded = case_match(pebbles_angular_rounded,
c("angular, rounded", "rounded, angular") ~ "both",
c("angular, rounded", "rounded, angular") ~ "angular and rounded",
.default = pebbles_angular_rounded),
root_presence = case_when(grepl("no roots", root_presence) ~ "none",
grepl("few", root_presence) ~ "few",
grepl("moderate", root_presence) ~ "moderate",
grepl("root dominated", root_presence) ~ "many",
.default = root_presence)) %>%
.default = root_presence),
uninhabited_shells = case_match(uninhabited_shells,
"intact shells" ~ "intact",
c("intact, fragments", "intact, broken", "broken, intact") ~ "intact and fragments",
"broken" ~ "fragments",
.default = uninhabited_shells),
visible_minerals = case_match(visible_minerals,
"quarts" ~ "quartz",
.default = visible_minerals)) %>%
mutate(root_thickness = case_when(root_presence == "none" ~ NA,
root_thickness == "Coarse" ~ "fine",
.default = root_thickness)) %>%
relocate(campaign)

#
Expand All @@ -83,7 +93,7 @@ cat("Applying flags to", var, "data...")
## manipulate a parameter and its flag together
data_qc <- function(data) {
data %>%
select(-notes, -cohesion_post_lyopholization) %>%
select(-notes, -cohesion_post_lyopholization, -white_flakes) %>%
mutate(
# switch wetland and transition names due to a...
# ...sampling error: wetland soil was sampled and put into a jar labeled "transition" incorrectly
Expand All @@ -104,7 +114,8 @@ metadata_collected %>%
data_clean %>%
full_join(meta_filter, by = c("campaign", "kit_id", "transect_location")) %>%
# add rows for samples not collected, creating a "full" dataset of all possible samples
mutate(pebbles_angular_rounded = case_when(notes == "kit compromised" ~ NA,
mutate(transect_location = factor(transect_location, levels = c("upland", "transition", "wetland", "sediment")),
pebbles_angular_rounded = case_when(notes == "kit compromised" ~ NA,
notes == "sample compromised" ~ NA,
TRUE ~ pebbles_angular_rounded),
root_presence = case_when(notes == "kit compromised" ~ NA,
Expand All @@ -128,12 +139,10 @@ data_clean %>%
glass_plastic = case_when(notes == "kit compromised" ~ NA,
notes == "sample compromised" ~ NA,
TRUE ~ glass_plastic),
white_flakes = case_when(notes == "kit compromised" ~ NA,
notes == "sample compromised" ~ NA,
TRUE ~ white_flakes),
notes = case_when(collected == FALSE ~ "sample not collected",
TRUE ~ notes)) %>%
select(-c(sample_type, sample_method, collected)) -> vizmetrics_full
select(-c(sample_type, sample_method, collected)) %>%
arrange(kit_id, transect_location) -> vizmetrics_full

# 6. Write cleaned data to drive -----------------------------------------------

Expand Down

0 comments on commit b8f4163

Please sign in to comment.