Skip to content
Snippets Groups Projects
Commit 01891657 authored by phit0's avatar phit0 Committed by Johannes Boog
Browse files

active field for h5_path - vignette entry for rhdf5

parent e8d0f229
No related branches found
No related tags found
1 merge request!34Resolve "Class to read ogs output in *HDF5* format"
......@@ -21,6 +21,7 @@ test:
# checks if the packages from the Imports, Suggests, LinkinTo field
# are already installed in the cache
- R -e '.libPaths(new = Sys.getenv("R_LIBS_USER"))'
- R -e 'withr::with_libpaths(new = Sys.getenv("R_LIBS_USER"), {install.packages("BiocManager"); BiocManager::install("rhdf5")})'
# Build and Check r2ogs6
- R CMD build . --no-build-vignettes --no-manual
- R CMD check $(ls -1t *.tar.gz | head -n 1) --no-build-vignettes --no-manual
......
......@@ -18,7 +18,7 @@ OGS6_h5 <- R6::R6Class("OGS6_h5",
assertthat::is.string(h5_path)
assertthat::assert_that(file.exists(h5_path))
private$h5_info <- rhdf5::h5ls(h5_path)
private$h5_path <- h5_path
private$.h5_path <- h5_path
private$valid_names <-
c("/",
apply(private$h5_info[, 1:2], 1,
......@@ -39,7 +39,7 @@ OGS6_h5 <- R6::R6Class("OGS6_h5",
print = function(){
cat("OGS6_h5\n")
cat("h5 path:\n")
cat(private$h5_path, "\n\n")
cat(private$.h5_path, "\n\n")
cat("# h5 file structure",
paste0(rep("-", cli::console_width() - 20), collapse = ""),
"\n")
......@@ -58,10 +58,9 @@ OGS6_h5 <- R6::R6Class("OGS6_h5",
#' \dontrun{h5_list <- ogs6_obj$h5s[[1]]$get_h5("/times")}
get_h5 = function(name = "/", ...) {
assertthat::assert_that(name %in% private$valid_names)
return(rhdf5::h5read(file = private$h5_path, name, ...))
return(rhdf5::h5read(file = private$.h5_path, name, ...))
},
#' @title Extract a *tibble* from a *.h5 file
#' @description Method to retrieve \code{HDF5} output as a \code{tibble}
#' assuming a standardized structure of \code{OGS6 HDF5} output.
#' times and geometry are added by default.
......@@ -96,7 +95,7 @@ OGS6_h5 <- R6::R6Class("OGS6_h5",
names[which(!name_paths %in%
private$valid_names)],
" not found in file ",
basename(private$h5_path)
basename(private$.h5_path)
))
lst <- private$add_geo_time(group) # adds geometry and time
......@@ -119,9 +118,23 @@ OGS6_h5 <- R6::R6Class("OGS6_h5",
return(dplyr::bind_cols(lst))
}
),
# === active fields
active = list(
#' @field h5_path
#' Getter/setter for private parameter `.h5_path`
h5_path = function(value) {
if (missing(value)) {
private$.h5_path
} else {
assertthat::assert_that(assertthat::is.string(value))
private$.h5_path <- value
}
}
),
private = list(
h5_info = NULL,
h5_path = NULL,
.h5_path = NULL,
valid_names = NULL,
add_geo_time = function(group) {
......
---
title: "r2ogs6 User Guide"
author: "Ruben Heinrich"
#output: html_document
output: rmarkdown::html_vignette
output: html_document
#output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{r2ogs6 User Guide}
%\VignetteEngine{knitr::rmarkdown}
......@@ -182,7 +182,16 @@ As can be seen, hdf5 files have a very particular structure. To work with the da
```{r}
h5_list <- ogs6_obj$h5s[[1]]$get_h5("/")
```
Other functions such as HDF5 handles for dataset processing can be used directly from the *rhdf5* package, of course. The path to the hd5 file is available as an active field `h5_path` that can be accessed or changed in the *OGS6* object.
```{r}
example_h5 <- rhdf5::H5Fopen(ogs6_obj$h5s[[1]]$h5_path)
example_h5
str(example_h5$t_0)
rhdf5::h5closeAll()
```
If the file has a reasonably "clean" structure, a more convenient way of importing the data is using the method `get_df` that returns a *tibble* table.
```{r}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment