Skip to content

Commit

Permalink
Merge pull request #107 from rte-antares-rpackage/fix_pollutants
Browse files Browse the repository at this point in the history
fix pollutants part names function and doc + maj site doc of package
  • Loading branch information
berthetclement authored Sep 19, 2023
2 parents 5b2e33b + c3a86e8 commit f712eb2
Show file tree
Hide file tree
Showing 21 changed files with 253 additions and 95 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export(getPlaylist)
export(getVariantCommands)
export(is_antares_v7)
export(is_antares_v820)
export(list_polluants_values)
export(list_pollutants_values)
export(mockSimulationAPI)
export(nodalOptimizationOptions)
export(propertiesLinkOptions)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* `createArea()` integrate "st-storage".
* `removeArea()` integrate "st-storage".
* `writeInputTS()` integrate "mingen" data and dependency between "mod.txt" and "mingen.txt" data.
* `createCluster()` / `editCluster()` have new parameter `list_polluants` for list of pollutants.
* `createCluster()` / `editCluster()` have new parameter `list_pollutants` for list of pollutants.


NEW FEATURES (Antares v8.6) :
Expand Down
34 changes: 17 additions & 17 deletions R/createCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' @param ... Parameters to write in the Ini file. Careful!
#' Some parameters must be set as `integers` to avoid warnings in Antares, for example,
#' to set `unitcount`, you'll have to use `unitcount = 1L`.
#' @param list_polluants `list` named with specific polluants (only for Antares version >= 860)
#' @param list_pollutants `list` named with specific pollutants (only for Antares version >= 860)
#' @param time_series the "ready-made" 8760-hour time-series available for simulation purposes.
#' @param prepro_data Pre-process data, a `data.frame` or `matrix`,
#' default is a matrix with 365 rows and 6 columns.
Expand All @@ -36,7 +36,7 @@
#' @importFrom data.table setcolorder year yday month setnames
#'
#' @note
#' Parameter `list_polluants` is only available for Antares studies >= v8.6.0.
#' Parameter `list_pollutants` is only available for Antares studies >= v8.6.0.
#'
#' You must provide named `list` (numerical values or NULL ) :
#'
Expand Down Expand Up @@ -156,7 +156,7 @@ createCluster <- function(area,
cluster_name,
group = "Other",
...,
list_polluants = list_polluants_values(),
list_pollutants = list_pollutants_values(),
time_series = NULL,
prepro_data = NULL,
prepro_modulation = NULL,
Expand All @@ -167,25 +167,25 @@ createCluster <- function(area,
assertthat::assert_that(inherits(opts, "simOptions"))

# static name of list parameters of pulluants
name_list_param_poll <- names(list_polluants_values())
name_list_param_poll <- names(list_pollutants_values())

# check v860
# check list pulluants parameters
if(opts$antaresVersion >= 860){
if(!is.null(list_polluants) & !assert_that(inherits(list_polluants, "list")))
stop("Parameter 'list_polluants' must be a 'list'")
if(!is.null(list_pollutants) & !assert_that(inherits(list_pollutants, "list")))
stop("Parameter 'list_pollutants' must be a 'list'")

if(!all(names(list_polluants) %in% name_list_param_poll))
stop(append("Parameter 'list_polluants' must be named with the following elements: ",
if(!all(names(list_pollutants) %in% name_list_param_poll))
stop(append("Parameter 'list_pollutants' must be named with the following elements: ",
paste0(name_list_param_poll, collapse= ", ")))

# check if all elements are NULL => replace by NULL
# API (only) can't create with NULL values
all_null <- lapply(list_polluants, is.null)
all_null <- lapply(list_pollutants, is.null)
all_null <- all(unlist(all_null))

if(all_null)
list_polluants <- NULL
list_pollutants <- NULL
}


Expand All @@ -212,7 +212,7 @@ createCluster <- function(area,
cluster_name = cluster_name,
group = group,
...,
list_polluants = list_polluants,
list_pollutants = list_pollutants,
time_series = time_series,
prepro_data = prepro_data,
prepro_modulation = prepro_modulation,
Expand Down Expand Up @@ -270,7 +270,7 @@ createClusterRES <- function(area,
.createCluster <- function(area,
cluster_name,
...,
list_polluants = NULL,
list_pollutants = NULL,
time_series = NULL,
prepro_data = NULL,
prepro_modulation = NULL,
Expand Down Expand Up @@ -302,9 +302,9 @@ createClusterRES <- function(area,
cluster_name <- paste(area, cluster_name, sep = "_")
params_cluster$name <- cluster_name

# v860 polluants
# v860 pollutants
if(opts$antaresVersion >= 860)
params_cluster <- append(params_cluster, list_polluants)
params_cluster <- append(params_cluster, list_pollutants)

# API block
if (is_api_study(opts)) {
Expand Down Expand Up @@ -463,16 +463,16 @@ createClusterRES <- function(area,
# )


#' Output polluants list for thermal clusters
#' Output pollutants list for thermal clusters
#'
#' @param multi_values put values to init list values, default as `NULL`
#'
#' @return a named list
#' @export
#'
#' @examples
#' list_polluants_values()
list_polluants_values <- function(multi_values = NULL) {
#' list_pollutants_values()
list_pollutants_values <- function(multi_values = NULL) {
list("nh3"= multi_values,
"nox"= multi_values,
"pm2_5"= multi_values,
Expand Down
2 changes: 1 addition & 1 deletion R/createClusterST.R
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ createClusterST <- function(area,
}
}

#' Output polluants list for thermal clusters
#' Output pollutants list for thermal clusters
#'
#'
#' @return a named list
Expand Down
12 changes: 6 additions & 6 deletions R/editCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @seealso [createCluster()] or [createClusterRES()] to create new clusters, [removeCluster()] or [removeClusterRES()] to remove clusters.
#'
#' @note
#' Parameter `list_polluants` is only available for Antares studies >= v8.6.0.
#' Parameter `list_pollutants` is only available for Antares studies >= v8.6.0.
#'
#' You must provide named `list` (numerical values or NULL ) :
#'
Expand Down Expand Up @@ -44,7 +44,7 @@
editCluster <- function(area,
cluster_name,
...,
list_polluants = NULL,
list_pollutants = NULL,
time_series = NULL,
prepro_data = NULL,
prepro_modulation = NULL,
Expand All @@ -54,7 +54,7 @@ editCluster <- function(area,
area = area,
cluster_name = cluster_name,
...,
list_polluants = list_polluants,
list_pollutants = list_pollutants,
time_series = time_series,
prepro_data = prepro_data,
prepro_modulation = prepro_modulation,
Expand Down Expand Up @@ -90,7 +90,7 @@ editClusterRES <- function(area,
.editCluster <- function(area,
cluster_name,
...,
list_polluants = NULL,
list_pollutants = NULL,
time_series = NULL,
prepro_data = NULL,
prepro_modulation = NULL,
Expand All @@ -108,9 +108,9 @@ editClusterRES <- function(area,
if (add_prefix)
cluster_name <- paste(area, cluster_name, sep = "_")

# v860 polluants
# v860 pollutants
if(opts$antaresVersion >= 860)
params_cluster <- append(params_cluster, list_polluants)
params_cluster <- append(params_cluster, list_pollutants)

# Handle case sensitivity in name of clusters API
clusters <- names(readIni(file.path("input", cluster_type, "clusters", area, "list"),
Expand Down
21 changes: 9 additions & 12 deletions docs/articles/Antares_new_features_v860.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f712eb2

Please sign in to comment.