Skip to content

Commit

Permalink
ebv_taxonomy_app: continue time-slider, quantiles
Browse files Browse the repository at this point in the history
  • Loading branch information
LuiseQuoss committed Sep 13, 2024
1 parent 071e01d commit a842e2a
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 85 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
data-raw/
tests/testdata/
to-dos.md
test_taxonomy.nc
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Imports:
rhdf5,
shiny,
shinyFiles,
shinyWidgets,
stringr,
terra,
tidyterra,
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export(ebv_taxonomy_app)
export(ebv_trend)
export(ebv_write)
exportClasses("EBV netCDF properties")
importFrom(bslib,bs_theme)
importFrom(grDevices,colors)
importFrom(shinyFiles,shinyFilesButton)
importFrom(shinyWidgets,sliderTextInput)
importFrom(stats,quantile)
importFrom(utils,capture.output)
importFrom(utils,head)
Expand Down
5 changes: 4 additions & 1 deletion R/ebv_read.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ ebv_read <- function(filepath, datacubepath = NULL, entity=NULL, timestep=1,


#set nodata value
h5array <- terra::classify(h5array, cbind(fillvalue, NA))
# print(fillvalue)
if(!is.na(fillvalue)){
h5array <- terra::classify(h5array, cbind(fillvalue, NA))
}
}

} else {
Expand Down
4 changes: 4 additions & 0 deletions R/ebv_taxonomy_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#'
#' @note Works with all EBV netCDFs created with
#' [ebvcube::ebv_create_taxonomy()].
#'
#' @importFrom shinyWidgets sliderTextInput
#' @importFrom shinyFiles shinyFilesButton
#' @importFrom bslib bs_theme
#' @export
ebv_taxonomy_app <- function() {
shiny::runApp(appDir = system.file('shiny', package='ebvcube'))
Expand Down
28 changes: 28 additions & 0 deletions R/ebv_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -984,3 +984,31 @@ ebv_i_p <- function(row){
replacement = "",
x = paste0(row, collapse='')))
}

#' Read time integers and turn into dates used for
#' shiny app
#'
#' @return Vector of strings (ISO-formatted dates)
#' @noRd
ebv_i_get_dates <- function(hdf){
#read time integers and turn into dates
add <- 40177
time_data <- suppressWarnings(rhdf5::h5read(hdf, 'time'))
dates <- as.Date(time_data - add, origin = '1970-01-01')
#get time resolution
res <-ebv_i_read_att(hdf, 'time_coverage_resolution', FALSE)
#modify date
if(res!='Irregular'){
y <- stringr::str_split(stringr::str_remove(res, 'P')[[1]], '-')[[1]][1]
m <- stringr::str_split(stringr::str_remove(res, 'P')[[1]], '-')[[1]][2]
d <- stringr::str_split(stringr::str_remove(res, 'P')[[1]], '-')[[1]][3]
if(d == '00' && m == '00'){
time_natural <- strtrim(dates, 4)
# time_natural <- gsub("-.*", "", time_natural)
} else if(d == '00'){
time_natural <- strtrim(dates, 7)
}
}
names(dates) <- time_natural
return(dates)
}
Loading

0 comments on commit a842e2a

Please sign in to comment.