Skip to content

Commit fddf2fa

Browse files
authored
Merge pull request #95 from COMPASS-DOE/cec-iron-l2
Cations and Iron L2 Data
2 parents 567342a + a66ef87 commit fddf2fa

File tree

3 files changed

+84
-40
lines changed

3 files changed

+84
-40
lines changed

Processing_Scripts/l0_to_l2.R

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ p_load(tidyverse)
1818
## Set ggplot theme
1919
theme_set(theme_bw())
2020

21+
L1directory = "https://drive.google.com/drive/folders/1yhukHvW4kCp6mN2jvcqmtq3XA5niKVR3"
22+
L2directory = "https://drive.google.com/drive/u/1/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
23+
2124

2225
# 2. Import datasets -----------------------------------------------------------
2326

@@ -61,9 +64,6 @@ import_l1_bd_data = function(directory){
6164
dat
6265
}
6366
## Remove flagged values then remove flag column
64-
65-
L1directory = "https://drive.google.com/drive/folders/1yhukHvW4kCp6mN2jvcqmtq3XA5niKVR3"
66-
6767
bd_l1 = import_l1_bd_data(L1directory)
6868

6969
bd_l2 <-
@@ -77,8 +77,6 @@ bd_l2 <-
7777
#soil
7878
bd_l2 %>% write.csv("./ec1_soil_bulk_density_L2.csv", row.names = FALSE)
7979

80-
L2directory = "https://drive.google.com/drive/u/1/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
81-
8280
drive_upload(media = "ec1_soil_bulk_density_L2.csv", name= "ec1_soil_bulk_density_L2.csv", path = L2directory )
8381

8482
file.remove("ec1_soil_bulk_density_L2.csv")
@@ -104,8 +102,6 @@ import_l1_gwc_data = function(directory){
104102
dat
105103
}
106104
## Remove flagged values then remove flag column
107-
108-
L1directory = "https://drive.google.com/drive/folders/1yhukHvW4kCp6mN2jvcqmtq3XA5niKVR3"
109105

110106
gwc_l1 = import_l1_gwc_data(L1directory)
111107

@@ -121,17 +117,13 @@ gwc_l2_soil <- gwc_l2 %>% filter(transect_location != "sediment") %>% arrange(ki
121117
## Write out to drive
122118
gwc_l2_sed %>% write.csv("./ec1_sediment_gwc_L2.csv", row.names = FALSE)
123119

124-
L2directory = "https://drive.google.com/drive/u/1/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
125-
126120
drive_upload(media = "ec1_sediment_gwc_L2.csv", name= "ec1_sediment_gwc_L2.csv", path = L2directory )
127121

128122
file.remove("ec1_sediment_gwc_L2.csv")
129123

130124
#soil
131125
gwc_l2_soil %>% write.csv("./ec1_soil_gwc_L2.csv", row.names = FALSE)
132126

133-
L2directory = "https://drive.google.com/drive/u/1/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
134-
135127
drive_upload(media = "ec1_soil_gwc_L2.csv", name= "ec1_soil_gwc_L2.csv", path = L2directory )
136128

137129
file.remove("ec1_soil_gwc_L2.csv")
@@ -176,8 +168,6 @@ import_l1_wq_data = function(directory){
176168
}
177169
## Remove flagged values then remove flag column
178170

179-
L1directory = "https://drive.google.com/drive/folders/1yhukHvW4kCp6mN2jvcqmtq3XA5niKVR3"
180-
181171
wq_l1 = import_l1_wq_data(L1directory)
182172

183173
#leaving all these together since they all do match. need to seperate if we have one indvidually though. We don't.
@@ -198,8 +188,6 @@ wq_l2 %>% select(campaign, kit_id, transect_location, sal_psu) %>% arrange(kit_i
198188
wq_l2 %>% select(campaign, kit_id, transect_location, orp_mv) %>% arrange(kit_id) %>% write.csv("ec1_water_ORP_L2.csv", row.names = FALSE)
199189
wq_l2 %>% select(campaign, kit_id, transect_location, alk_mgl_caco3) %>% arrange(kit_id) %>% write.csv("ec1_water_alkalinity_L2.csv", row.names = FALSE)
200190

201-
L2directory = "https://drive.google.com/drive/u/1/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
202-
203191
drive_upload(media = "ec1_water_ph_L2.csv", name= "ec1_water_pH_L2.csv", path = L2directory)
204192
drive_upload(media = "ec1_water_salinity_L2.csv", name= "ec1_water_salinity_L2.csv", path = L2directory)
205193
drive_upload(media ="ec1_water_orp_L2.csv", name= "ec1_water_ORP_L2.csv", path = L2directory)
@@ -249,8 +237,6 @@ cond_L1 %>%
249237
arrange(kit_id) -> cond_L2
250238

251239
## Write out to drive
252-
L2directory = "https://drive.google.com/drive/u/1/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
253-
254240
ph_L2 %>% write.csv("./ec1_soil_ph_L2.csv", row.names = FALSE)
255241
cond_L2 %>% write.csv("./ec1_soil_cond_L2.csv", row.names = FALSE)
256242

@@ -295,7 +281,6 @@ tn_full %>%
295281
select(-tn_flag) -> tn_L2
296282

297283
# Write out
298-
L2directory = "https://drive.google.com/drive/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
299284

300285
tc_L2 %>% write.csv("ec1_soil_tc_L2.csv", row.names = FALSE)
301286
tn_L2 %>% write.csv("ec1_soil_tn_L2.csv", row.names = FALSE)
@@ -317,8 +302,6 @@ tss_full %>%
317302
# Write out
318303
tss_l2 %>% write.csv("ec1_water_tss_L2.csv", row.names = FALSE)
319304

320-
L2directory = "https://drive.google.com/drive/u/1/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
321-
322305
drive_upload(media = "ec1_water_tss_L2.csv", name= "ec1_water_tss_L2.csv", path = L2directory)
323306

324307
file.remove("ec1_water_tss_L2.csv")
@@ -338,8 +321,6 @@ full_tdn %>%
338321
npoc_l2 %>% write_csv("ec1_water_doc_L2.csv")
339322
tdn_l2 %>% write_csv("ec1_water_tdn_L2.csv")
340323

341-
L2directory = "https://drive.google.com/drive/u/1/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
342-
343324
drive_upload(media = "ec1_water_doc_L2.csv", name= "ec1_water_doc_L2.csv", path = L2directory)
344325
drive_upload(media = "ec1_water_tdn_L2.csv", name= "ec1_water_tdn_L2.csv", path = L2directory)
345326

@@ -359,11 +340,42 @@ soil_sed_viz %>% filter(transect_location == "sediment") -> sediment_visualmetri
359340
soil_visualmetrics_l2 %>% write_csv("ec1_soil_visualmetrics_L2.csv")
360341
sediment_visualmetrics_l2 %>% write_csv("ec1_sediment_visualmetrics_L2.csv")
361342

362-
L2directory = "https://drive.google.com/drive/u/1/folders/1M-ASGuRoKqswiKbUWylWzoAyUmMPm367"
363-
364343
drive_upload(media = "ec1_soil_visualmetrics_L2.csv", name= "ec1_soil_visualmetrics_L2.csv", path = L2directory)
365344
drive_upload(media = "ec1_sediment_visualmetrics_L2.csv", name= "ec1_sediment_visualmetrics_L2.csv", path = L2directory)
366345

367346
file.remove("ec1_soil_visualmetrics_L2.csv")
368347
file.remove("ec1_sediment_visualmetrics_L2.csv")
369348

349+
# Clean up and export L2 Soil Cations ------------------------------------------
350+
351+
cations_l1 %>%
352+
select(-notes_flags) %>%
353+
pivot_longer(cols = where(is.numeric)) %>%
354+
filter(!is.na(value)) %>%
355+
pivot_wider(names_from = name, values_from = value) -> cations_filtered
356+
357+
cations_filtered %>% filter(transect_location != "sediment") %>% arrange(kit_id) -> soil_cations_l2
358+
cations_filtered %>% filter(transect_location == "sediment") %>% arrange(kit_id) -> sediment_cations_l2
359+
360+
# Write out
361+
soil_cations_l2 %>% write_csv("ec1_soil_cations_L2.csv")
362+
sediment_cations_l2 %>% write_csv("ec1_sediment_cations_L2.csv")
363+
364+
drive_upload(media = "ec1_soil_cations_L2.csv", name= "ec1_soil_cations_L2.csv", path = L2directory)
365+
drive_upload(media = "ec1_sediment_cations_L2.csv", name= "ec1_sediment_cations_L2.csv", path = L2directory)
366+
367+
file.remove("ec1_soil_cations_L2.csv")
368+
file.remove("ec1_sediment_cations_L2.csv")
369+
370+
# Clean up and export L2 Soil Iron ---------------------------------------------
371+
372+
soil_iron %>%
373+
select(-notes) %>%
374+
filter(!is.na(Fe_ug_g)) -> soil_iron_final
375+
376+
# Write out
377+
soil_iron_final %>% write_csv("ec1_soil_iron_L2.csv")
378+
379+
drive_upload(media = "ec1_soil_iron_L2.csv", name= "ec1_soil_iron_L2.csv", path = L2directory)
380+
381+
file.remove("ec1_soil_iron_L2.csv")

Processing_Scripts/soil_cec.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,21 @@ metadata_collected %>%
190190

191191
data_clean %>%
192192
full_join(meta_filter, by = c("campaign", "kit_id", "transect_location")) %>%
193-
mutate(notes = case_when(kit_id == "K050" & transect_location == "upland" ~ "not enough material for extraction"#,
193+
mutate(notes = case_when(kit_id == "K050" & transect_location == "upland" ~ "not enough material for extraction",
194+
kit_id == "K024" & transect_location == "wetland" ~ "sample compromised",
195+
collected == FALSE ~ "sample not collected",
194196
TRUE ~ notes),
195-
#across(is.numeric & kit_id == "K001", NA)
196-
) -> full
197+
notes_flags = case_when(is.na(notes) ~ flag,
198+
TRUE ~ notes)) -> full
197199

198-
#
199-
# 12. Write L0B data -----------------------------------------------------------
200-
write_csv(cations_and_cec, paste0("Data/Processed/EC1_Soil_ICP_CEC_L0B_", Sys.Date(), ".csv"))
200+
nums <- sapply(full, is.numeric) # identify numeric columns
201+
full[!is.na(full$notes), which(nums)] <- NA # set compromised kits to NA
201202

203+
full %>% select(campaign, kit_id, transect_location, contains("meq_100"), notes_flags) -> cations_l1
202204

205+
#
206+
# 13. Write L0B data -----------------------------------------------------------
207+
write_csv(cations_l1, paste0("~/Documents/ec1_soil_cations_L1_", Sys.Date(), ".csv"))
203208

204209
## extras ----
205210
# testing

Processing_Scripts/soil_iron.R

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,24 +182,51 @@ samples2 =
182182
dplyr::select(sample_label, ppm_corrected) %>%
183183
separate(sample_label, sep = "_", into = c("kit_id", "transect_location")) %>%
184184
mutate(transect_location = case_match(transect_location, "U" ~ "upland", "T" ~ "transition", "W" ~ "wetland")) %>%
185-
left_join(weights) %>%
185+
left_join(weights, by = c("kit_id", "transect_location")) %>%
186186
mutate(ppm_corrected = as.numeric(ppm_corrected),
187187
weight_g = as.numeric(weight_g),
188188
HCl_mL = as.numeric(HCl_mL),
189189
Fe_ug_g = ppm_corrected * ((HCl_mL)/weight_g),
190190
Fe_ug_g = round(Fe_ug_g, 2)) %>%
191191
dplyr::select(kit_id, transect_location, Fe_ug_g) %>%
192-
mutate(transect_location = factor(transect_location, levels = c("upland", "transition", "wetland"))) %>%
193-
arrange(kit_id, transect_location)
194-
195-
#
196-
# 5. Export L0B data ------------------------------------------------------
197-
write_csv(samples2, paste0("Data/Processed/EC1_Soil_iron_ferrozine_", Sys.Date(), ".csv"))
198-
199-
200-
192+
mutate(campaign = "EC1",
193+
transect_location = factor(transect_location, levels = c("upland", "transition", "wetland"))) %>%
194+
arrange(kit_id, transect_location) %>%
195+
select(campaign, kit_id, transect_location, Fe_ug_g)
201196

197+
# 5. Clean data ----------------------------------------------------------------
202198

199+
samples2 %>%
200+
# switch wetland and transition names due to a...
201+
# ...sampling error: wetland soil was sampled and put into a jar labeled "transition" incorrectly
202+
mutate(transect_location = case_when(kit_id == "K046" & transect_location == "transition" ~ "wetland",
203+
kit_id == "K046" & transect_location == "wetland" ~ "transition",
204+
TRUE ~ transect_location)) -> data_clean
205+
206+
# 6. Check with Metadata for missing samples -----------------------------------
207+
208+
source("./Processing_Scripts/Metadata_kit_list.R")
209+
210+
metadata_collected %>%
211+
filter(sample_method == "jar") -> meta_filter
212+
213+
data_clean %>%
214+
full_join(meta_filter, by = c("campaign", "kit_id", "transect_location")) %>%
215+
# 2024-03-13: need to split soil and sediments in this script because not all sediments have been ran yet
216+
filter(sample_type == "soil") %>%
217+
mutate(notes = case_when(kit_id == "K018" & transect_location == "transition" ~ "not enough material for extraction",
218+
kit_id == "K044" & transect_location == "transition" ~ "not enough material for extraction",
219+
kit_id == "K048" & transect_location == "upland" ~ "not enough material for extraction",
220+
kit_id == "K050" & transect_location == "upland" ~ "not enough material for extraction",
221+
collected == TRUE & is.na(Fe_ug_g) & is.na(notes) ~ "not enough material for extraction",
222+
collected == FALSE & is.na(Fe_ug_g) ~ "sample not collected",
223+
TRUE ~ notes),
224+
Fe_ug_g = case_when(!is.na(notes) ~ NA,
225+
TRUE ~ Fe_ug_g)) %>%
226+
select(campaign, kit_id, transect_location, Fe_ug_g, notes) -> soil_iron
227+
228+
# 7. Export L0B data -----------------------------------------------------------
229+
write_csv(soil_iron, paste0("~/Documents/ec1_soil_iron_L1_", Sys.Date(), ".csv"))
203230

204231
## extras ----
205232
# load sample key

0 commit comments

Comments
 (0)