Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to terra #64

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/ingest.R
Original file line number Diff line number Diff line change
Expand Up @@ -868,8 +868,9 @@ ingest <- function(

} else if (source == "hwsd"){

# Get HWSD soil data. year_start and year_end not required

# https://github.com/bluegreen-labs/hwsdr
# Get HWSD soil data. year_start and year_end not required

# TODO replace with {hwsdr} call
# con <- rhwsd::get_hwsd_con()
Expand Down
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
4 changes: 3 additions & 1 deletion vignettes/example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,8 @@ Four steps are required before you can use `ingest()` to get HWSD data:
```{r warning=FALSE, eval = FALSE}
if(!require(devtools)){install.packages(devtools)}
devtools::install_github("stineb/rhwsd")

# XXX to change to https://github.com/bluegreen-labs/hwsdr
```

2. Install additionally required packages: DBI and RSQLite.
Expand Down Expand Up @@ -1190,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
Loading