-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the extract_sd and get_qc function
- Loading branch information
Showing
7 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,6 @@ Imports: | |
lubridate, | ||
tidyr, | ||
dplyr, | ||
magrittr | ||
magrittr, | ||
stringr, | ||
janitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#' Extract QC of variables | ||
#' | ||
#' @description Create a data frame with the QC of selected variable along the depth of the profile | ||
#' | ||
#' @import stringr | ||
#' @importFROM tidyr pivot_wider | ||
#' | ||
#' @param vars is a vector of variable | ||
#' @param nc_path is the path of the ncdf file | ||
#' | ||
#' @return a tbale with QC value of each variable along the depth | ||
#' @export | ||
|
||
get_qc <- function(vars, nc_path){ | ||
nc <- nc_open(nc_path) | ||
qc_table <- data.frame('vars' = character(), | ||
'qc'= numeric()) | ||
|
||
for(i in vars){ | ||
t <- ncvar_get(nc, paste(i, 'QC', sep = '_')) | ||
if(grepl('/SD[0-9]', nc_path)){ | ||
qc_vec <- unlist(str_split(t, pattern = '')) | ||
} | ||
else if(grepl('/BD[0-9]', nc_path)){ | ||
qc_vec <- unlist(str_split(t[[3]], pattern = '')) | ||
} | ||
qc_vec <- as.numeric(gsub(' ', NA, qc_vec)) | ||
depth <- seq(1:length(qc_vec)) | ||
qc_var <- data.frame('vars' = paste(i, '_qc'), 'qc' = qc_vec, 'depth' = depth) | ||
qc_table <- bind_rows(qc_table, qc_var) | ||
} | ||
|
||
qc_table <- pivot_wider(qc_table, names_from = 'vars', values_from = 'qc') | ||
nc_close(nc) | ||
return(qc_table) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters