Skip to content

Commit

Permalink
revised GSDE data ingest after update to terra
Browse files Browse the repository at this point in the history
  • Loading branch information
stineb committed Jul 18, 2024
1 parent 8b9dd02 commit b24ff93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions R/ingest_globalfields.R
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,10 @@ ingest_globalfields <- function(
df_out_top <- extract_pointdata_allsites( paste0(dir, "/", filename), df_lonlat, get_time = FALSE ) %>%
dplyr::select(-lon, -lat) %>%
tidyr::unnest(data) %>%
dplyr::rename(!!layer := V1) %>%
dplyr::select(sitename, !!layer)
tidyr::pivot_longer(cols = starts_with("PBR_depth")) %>%
dplyr::rename(!!layer := value, depth = name) %>%
dplyr::mutate(depth = as.numeric(str_remove(depth, "PBR_depth="))) %>%
dplyr::select(sitename, !!layer, depth)

# bottom soil layers
filename <- list.files(dir, pattern = paste0(layer, "2.nc"))
Expand All @@ -477,8 +479,10 @@ ingest_globalfields <- function(
df_out_bottom <- extract_pointdata_allsites( paste0(dir, "/", filename), df_lonlat, get_time = FALSE ) %>%
dplyr::select(-lon, -lat) %>%
tidyr::unnest(data) %>%
dplyr::rename(!!layer := V1) %>%
dplyr::select(sitename, !!layer)
tidyr::pivot_longer(cols = starts_with("PBR_depth")) %>%
dplyr::rename(!!layer := value, depth = name) %>%
dplyr::mutate(depth = as.numeric(str_remove(depth, "PBR_depth="))) %>%
dplyr::select(sitename, !!layer, depth)

# combine for layers read from each file
df_out <- bind_rows(df_out_top, df_out_bottom) %>%
Expand All @@ -497,7 +501,8 @@ ingest_globalfields <- function(
rename(value = !!layer) %>%

# interpret missing values
na_if(-999) %>%
ungroup() %>%
mutate(value = ifelse(value == -999, NA, value)) %>%
mutate(value = ifelse(varnam %in% c("PHH2O", "PHK", "PHCA") & value == 100,
NA,
value)) %>%
Expand Down
2 changes: 1 addition & 1 deletion vignettes/example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ df_gsde <- ingest(
siteinfo_fluxnet2015 %>% slice(1:2),
source = "gsde",
settings = settings_gsde,
dir = "~/data/soil/shangguan"
dir = "/data/archive/soil_shangguan_2014/data/"
)
```

Expand Down

0 comments on commit b24ff93

Please sign in to comment.