Skip to content

Commit

Permalink
Merge pull request #111 from jmccreight/xr_datatable2
Browse files Browse the repository at this point in the history
extend xr_datatable to use dictionary based dimension selection.
  • Loading branch information
jmccreight authored Apr 3, 2020
2 parents 7bffeb6 + 71388f5 commit 1e84f6a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion R/xr_datatable.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@

## Example
## some_nc_file =
## '/projects/[email protected]/jtti_domains_keep_cp_scratch/domains/01350000/RouteLink.nc'
## ds = rwrfhydro::xr_datatable(some_nc_file)
## link = ds('link')
## link_sub = ds('link', dim_sel_dict = list('feature_id'=0:2))

#' @export
xr_datatable <- function(file) {
library(data.table)
Expand All @@ -6,9 +14,10 @@ xr_datatable <- function(file) {
pathlib = import('pathlib', convert=TRUE)
py = import_builtins(convert=TRUE)
dataset = xr$open_dataset(file)
data_array_to_table <- function(var_name = NULL, timedelta_res = 'h') {
data_array_to_table <- function(var_name = NULL, timedelta_res = 'h', dim_sel_dict = NULL) {
if(is.null(var_name)) {print(dataset) ; return(invisible(NULL))}
array = dataset[var_name]
if(!is.null(dim_sel_dict)){array = array[dim_sel_dict]}
if(!py$isinstance(array, xr$DataArray)){
stop('The passed array is not an xarray.DataArray.')}
# array = gof_gage_ds$value
Expand Down

0 comments on commit 1e84f6a

Please sign in to comment.