-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add/xml-upgrades/v11
- Loading branch information
Showing
24 changed files
with
503 additions
and
111 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
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
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,25 @@ | ||
#' Convert day number into date | ||
#' | ||
#' Computes the date corresponding to a given day number (or vector of) | ||
#' with reference to a start year. Typically, the start year should | ||
#' be the year of a STICS simulation start, but not necessarily. | ||
#' @param day day number(s) to be converted | ||
#' @param start_year year to be used as time reference (simulation start year). | ||
#' | ||
#' @return Date vector | ||
#' @author Timothee Flutre | ||
#' @examples | ||
#' | ||
#' compute_date_from_day(day = 290, start_year = 1994) | ||
#' | ||
#' compute_date_from_day(day = 700, start_year = 1994) | ||
#' | ||
#' @export | ||
#' | ||
compute_date_from_day <- function(day, start_year){ | ||
stopifnot(all(is.numeric(day)), | ||
length(start_year) == 1, | ||
is.numeric(start_year)) | ||
|
||
return(as.Date(day - 1, origin = paste0(start_year, "-01-01"))) | ||
} |
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,38 @@ | ||
#' @title Get the cultivar names for an xml plant file (*_plt.xml) | ||
#' | ||
#' @description Extracts the cultivar names from a plant file | ||
#' | ||
#' @param file The path of a plant file. | ||
#' | ||
#' @return A vector of cultivar names | ||
#' | ||
#' @examples | ||
#' path <- get_examples_path(file_type = "xml") | ||
#' | ||
#' # Read from a plant file (all cultivars available in a plant file) | ||
#' cv_list <- get_cultivars_list(file = file.path(path, "file_plt.xml")) | ||
#' | ||
#' @export | ||
#' | ||
get_cultivars_list <- function(file) { | ||
|
||
xml_doc <- xmldocument(file) | ||
|
||
stopifnot(is_stics_plt(xml_doc)) | ||
|
||
xml_name <- "variete" | ||
|
||
cv_list <- unique( | ||
unlist( | ||
lapply( | ||
XML::getNodeSet(doc = xml_doc@content, | ||
path = paste0("//", xml_name)), | ||
function(x) { | ||
XML::xmlGetAttr(x, "nom") | ||
} | ||
) | ||
) | ||
) | ||
|
||
return(cv_list) | ||
} |
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,28 @@ | ||
#' @title Get the values of cultivar-specific parameters from an xml | ||
#' plant file (*_plt.xml) | ||
#' | ||
#' @description Extracts the values of cultivar-specific parameters from a | ||
#' plant file | ||
#' | ||
#' @param file The path of a plant file. | ||
#' | ||
#' @return A data.frame with one row per cultivar and one column per parameter | ||
#' | ||
#' @examples | ||
#' path <- get_examples_path(file_type = "xml") | ||
#' | ||
#' # Read from a plant file (all cultivars available in a plant file) | ||
#' cv_param_df <- get_cultivars_param(file = file.path(path, "file_plt.xml")) | ||
#' | ||
#' @export | ||
#' | ||
get_cultivars_param <- function(file) { | ||
|
||
cv_list <- get_cultivars_list(file) | ||
|
||
out <- get_param_xml(file, select = "variete", select_value = cv_list) | ||
out <- as.data.frame(do.call(cbind, out[[1]])) | ||
rownames(out) <- cv_list | ||
|
||
return(out) | ||
} |
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
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
Oops, something went wrong.