Skip to content

Commit

Permalink
Merge pull request #64 from stineb/master
Browse files Browse the repository at this point in the history
Update to terra
  • Loading branch information
stineb authored Jul 18, 2024
2 parents 24998cb + b24ff93 commit e2c5ac3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
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

0 comments on commit e2c5ac3

Please sign in to comment.