Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Next release 0.17 #40

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1a53c92
#33 add correctBalance() : work with opts, antaresDataList and antare…
jalazawa Oct 25, 2018
30e9ecd
move some internal H5 functions to zzz.R
jalazawa Oct 25, 2018
812b8fa
update docs
jalazawa Oct 25, 2018
0341a8b
use antaresRead@develop
jalazawa Oct 25, 2018
e57bcc6
appveyor : use rtools
jalazawa Oct 25, 2018
2dad76e
travis install devtools cran
jalazawa Oct 25, 2018
cb7399e
#32 addUpwardMargin() must work with an antaresDataList without virtu…
jalazawa Oct 26, 2018
a2aff77
test : bug : delete an old path
jalazawa Oct 30, 2018
085403e
travis : does not work for mac travis-ci/travis-build#1553
jalazawa Oct 30, 2018
55abcf5
add function addMonotones()
jalazawa Nov 7, 2018
e09f95b
#37 addMonotones() works now with all variables types and now merge b…
jalazawa Nov 8, 2018
8514f99
update doc correctBalance
jalazawa Nov 8, 2018
cbe32ac
update NEWS / Description
jalazawa Nov 8, 2018
b5cc7e4
correct doc
jalazawa Nov 8, 2018
bc00a3d
update doc
jalazawa Nov 8, 2018
28bbbad
correct name file
jalazawa Nov 8, 2018
94b548d
typo
jalazawa Nov 22, 2018
d2141bd
#21 add neighbours()
jalazawa Nov 23, 2018
61668ee
#21 add priceConvergenceSystem()
jalazawa Nov 23, 2018
fafce19
typo
jalazawa Nov 26, 2018
f870507
#21 add function addConvergencePriceArea
jalazawa Nov 26, 2018
9d46187
add examples
jalazawa Nov 26, 2018
30cf7a3
update doc
jalazawa Nov 27, 2018
62814bf
correction for R CMD Check
jalazawa Nov 27, 2018
a075807
add some useful functions
jalazawa Nov 28, 2018
5db4769
update branch antaresRead
jalazawa Nov 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ language: R
sudo: true
cache: packages

#remove this line when this pull request is closed
# https://github.com/travis-ci/travis-build/pull/1553
fortran: false

bioc_required: true
bioc_use_devel: true
Expand All @@ -19,8 +22,8 @@ r:


r_github_packages:
- hadley/devtools#1263
- rte-antares-rpackage/antaresRead@next_release
- rte-antares-rpackage/antaresRead@master
# - hadley/devtools#1263
#before - Bioconductor-mirror/zlibbioc
# - Bioconductor-mirror/rhdf5
#after
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: antaresProcessing
Type: Package
Title: 'Antares' Results Processing
Version: 0.16.0
Version: 0.16.0.902
Date: 2018-09-28
Authors@R: c(
person("Jalal-Edine", "ZAWAM", , "[email protected]", role = c("aut", "cre")),
Expand All @@ -23,7 +23,7 @@ BugReports: https://github.com/rte-antares-rpackage/antaresProcessing/issues
License: GPL (>= 2) | file LICENSE
LazyData: TRUE
Depends: antaresRead (>= 1.1.5)
Imports: data.table, methods, stats
Imports: data.table, methods, stats, stringi
Suggests: rhdf5 (>= 2.24.0), parallel, testthat, knitr, rmarkdown, covr
RoxygenNote: 6.1.0
VignetteBuilder: knitr
Expand Down
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
# Generated by roxygen2: do not edit by hand

export(.setAliasH5)
export(addConvergencePriceArea)
export(addConvergencePriceSystem)
export(addDownwardMargin)
export(addExportAndImport)
export(addLoadFactorLink)
export(addMonotones)
export(addNeighbours)
export(addNetLoad)
export(addProcessingH5)
export(addUpwardMargin)
export(compare)
export(correctBalance)
export(externalDependency)
export(getAllNeighbours)
export(getValues)
export(loadFactor)
export(mergeAllAntaresData)
export(modulation)
export(neighbours)
export(netLoadRamp)
export(surplus)
export(surplusClusters)
Expand All @@ -26,3 +33,4 @@ importFrom(stats,as.formula)
importFrom(stats,median)
importFrom(stats,quantile)
importFrom(stats,sd)
importFrom(stringi,stri_detect_fixed)
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
Copyright © 2016 RTE Réseau de transport d’électricité

Changes in version 0.17.0 (2018-11-08)

NEW FEATURES:
* New function addMonotones() computes monotones and add it to the input (#37).
* New function correctBalance() corrects the BALANCE with 'ROW BAL' (#33).
* New functions neighbours(), addNeighbours() and getAllNeighbours() to get neighbours (#21).
* New functions addConvergencePriceSystem() computes the biggest system without congestion (#21).
* New functions addConvergencePriceArea() computes the biggest system without congestion for each area (#21).

Changes in version 0.16.0 (2018-09-28)

NEW FEATURES:
Expand Down
109 changes: 109 additions & 0 deletions R/addConvergencePriceArea.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#' addConvergencePriceArea
#'
#' This function computes priceConvergenceArea, priceConvergenceArea represent
#' the biggest system without congestion for one area.
#'
#' @param antaresData Object of class \code{antaresData} created with function
#' \code{\link[antaresRead]{readAntares}}. antaresData must contains areas and
#' links details hourly data with linkCapacity.
#' @examples
#' \dontrun{
#'
#' myData <- readAntares(areas = "all",
#' links = "all",
#' showProgress = FALSE,
#' linkCapacity = TRUE,
#' mcYears = "all")
#'
#' myDataRV <- removeVirtualAreas(x = myData,
#' storageFlexibility = getAreas(c("psp", "hub")),
#' production = getAreas("off"))
#'
#' addConvergencePriceArea(myData)
#' }
#' @importFrom stringi stri_detect_fixed
#' @export
addConvergencePriceArea <- function(antaresData = NULL){
.check_x(antaresData)
if((!is(antaresData, "antaresDataList")) | !("areas" %in% names(antaresData))){
stop("Import areas data. antaresData must be an antaresDataList.")
}
if(attr(antaresData, "synthesis") | attr(antaresData, "timeStep") != "hourly"){
stop("Import hourly details data")
}

if(is.null(antaresData$areas$neighbours)){
addNeighbours(antaresData)
}
if(is.null(antaresData$areas$priceConvergenceSystem)){
addConvergencePriceSystem(antaresData)
}
#pb with R check, init variable
priceConvergenceAreaN <- NULL
priceConvergenceAreaN1 <- NULL
priceConvergenceSystem <- NULL
priceConvergenceArea <- NULL
neighboursN <- NULL
neighboursN1 <- NULL

#priceConvergenceArea = area
antaresData$areas[, priceConvergenceAreaN := as.character(area),
by=.(area, mcYear, timeId)]
antaresData$areas[, ':=' (neighboursN = neighbours)]

#we must get the virtual areas
resAttr <- attributes(antaresData)
virtualAreas <- resAttr$virtualNodes$storageFlexibility
virtualAreas <- c(virtualAreas, resAttr$virtualNodes$production)

#priceConvergenceArea = area + neighbours in priceConvergenceSystem if area in priceConvergenceSystem
#init
antaresData$areas[, priceConvergenceAreaN1 := priceConvergenceAreaN]
indexToEdit <- antaresData$areas[stringi::stri_detect_fixed(pattern = area,
str = priceConvergenceSystem),
which=TRUE]

antaresData$areas[indexToEdit, ':=' (priceConvergenceAreaN1 = paste(sort(unique(c(intersect(strsplit(priceConvergenceSystem, split = " ")[[1]],
strsplit(neighboursN, split = " ")[[1]]),
strsplit(priceConvergenceAreaN, split = " ")[[1]]))),
collapse = " ")),
by = .(priceConvergenceSystem, priceConvergenceAreaN)]

#for all index where priceConvergenceArea != priceConvergenceSystem
#then test if neighbours of neighbours are in priceConvergenceSystem
#init system
antaresData$areas[, ':=' (neighboursN = neighbours)]
antaresData$areas[, ':=' (neighboursN1 = neighbours)]

#antaresData$areas[, priceConvergenceAreaN1 := priceConvergenceAreaN]
indexWhereSomethingChange <- c(1, 2)
i <- 0
while (length(indexWhereSomethingChange) > 0) {
indexWhereSomethingChange <- antaresData$areas[priceConvergenceAreaN!=priceConvergenceAreaN1, which=TRUE]

# iterate N1 := N
antaresData$areas[indexWhereSomethingChange, priceConvergenceAreaN := priceConvergenceAreaN1]
antaresData$areas[indexWhereSomethingChange, ':=' (neighboursN = neighboursN1)]

#compute N1
antaresData$areas[indexWhereSomethingChange, ':=' (neighboursN1 = paste(getAllNeighbours(neighboursN,
virtualAreas = virtualAreas),
collapse = " ")),
by = .(neighboursN)]
antaresData$areas[indexWhereSomethingChange, ':=' (priceConvergenceAreaN1 = paste(sort(unique(c(intersect(strsplit(priceConvergenceSystem, split = " ")[[1]],
strsplit(neighboursN1, split = " ")[[1]]),
strsplit(priceConvergenceAreaN, split = " ")[[1]]))),
collapse = " ")),
by = .(priceConvergenceSystem, priceConvergenceAreaN)]

i <- i +1
}

antaresData$areas[, priceConvergenceArea := priceConvergenceAreaN1]

antaresData$areas[, c("priceConvergenceAreaN",
"priceConvergenceAreaN1",
"neighboursN",
"neighboursN1") := NULL]
invisible(antaresData)
}
62 changes: 62 additions & 0 deletions R/addConvergencePriceSystem.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#' addConvergencePriceSystem
#'
#' This function computes priceConvergenceSystem, priceConvergenceSystem represent
#' the biggest system without congestion.
#'
#' @param antaresData Object of class \code{antaresData} created with function
#' \code{\link[antaresRead]{readAntares}}. antaresData must contains areas and
#' links details data with linkCapacity.
#' @examples
#' \dontrun{
#'
#' myData <- readAntares(areas = "all",
#' links = "all",
#' showProgress = FALSE,
#' linkCapacity = TRUE,
#' mcYears = "all")
#'
#' myDataRV <- removeVirtualAreas(x = myData,
#' storageFlexibility = getAreas(c("psp", "hub")),
#' production = getAreas("off"))
#'
#' addConvergencePriceSystem(myData)
#' }
#' @export
addConvergencePriceSystem <- function(antaresData = NULL){
.check_x(antaresData)
if((!is(antaresData, "antaresDataList")) | !("areas" %in% names(antaresData)) |
!("links" %in% names(antaresData)) ){
stop("Import areas and links data.")
}
if(attr(antaresData, "synthesis") | attr(antaresData, "timeStep") != "hourly"){
stop("Import hourly details data")
}

if(is.null(antaresData$links$congestion)){
antaresData <- addLoadFactorLink(antaresData)
}
#R CMD CHECK, init some variables
congestion <- NULL
priceConvergenceArea <- NULL
areasConver <- NULL
allAreasTgList <- NULL
i.areasConver <- NULL


antaresData$links[, ':=' (from = strsplit(link, split = " - " )[[1]][1],
to = strsplit(link, split = " - " )[[1]][2]),
by = .(link)]
dontSeperate <- antaresData$links[congestion==0, .(mcYear, timeId, from, to)]

converAreas <- dontSeperate[, list(allAreasTgList = list(c(from,to))) ,
by=.(mcYear, timeId)]

converAreas[ , areasConver := as.vector(paste(sort(unique(allAreasTgList[[1]])),
collapse = " ")),
by=.(mcYear, timeId)]

antaresData$areas[converAreas,(paste("priceConvergenceSystem")) := i.areasConver,
on=.(mcYear, timeId)]

invisible(antaresData)
}
123 changes: 123 additions & 0 deletions R/addMonotones.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#Copyright © 2016 RTE Réseau de transport d’électricité

#' addMonotones
#'
#' This function computes monotones for some variables.
#' @param antaresData Object of class \code{antaresData} created with function
#' \code{\link[antaresRead]{readAntares}}.
#' @param variable An ANTARES variable.
#'
#' @return
#' \code{addMonotones} modifies its input by adding monotones.
#'
#'
#' @examples
#' \dontrun{
#' # First simulation
#' studyPath <- "path/to/study/"
#'
#' setSimulationPath(studyPath, 1)
#' myData1 <- readAntares(areas = "all",
#' districts = "all", synthesis = FALSE)
#' addMonotones(antaresData = myData1,
#' variable = "LOAD")
#'
#' }
#'
#' @export
#'
addMonotones <- function(antaresData = NULL, variable = NULL){

.check_x(antaresData)

if(attr(antaresData, "synthesis")){
stop("antaresData are synthesis, addMonotones() needs detail data.")
}

if(!is.character(variable)){
stop("variable is not a character")
}

if(is(antaresData, "antaresDataList")){
#chack if variable is correct
nameCol <- NULL
for(i in 1:length(antaresData)){
nameCol <- c(nameCol, names(antaresData[[i]]))
}
if(!(variable %in% nameCol)){
stop("incorrect variable")
}
#call antaresData for an antaresDataTable
for(na in names(antaresData)){
if(variable %in% names(antaresData[[na]])){
addMonotones(antaresData[[na]], variable = variable)
}
}
}else{
if(!(variable %in% names(antaresData))){
stop("Incorrect variable")
}
classVariable <- class(antaresData[[variable]])
if(classVariable %in% c("factor", "POSIXt", "character")){
stop("Incorrect variable class")
}else if(classVariable=="numeric"){
funcClass <- as.numeric
digitMonoMean <- 2
}else if(classVariable=="integer"){
funcClass <- as.integer
digitMonoMean <- 0
}else if(classVariable=="double"){
funcClass <- as.double
digitMonoMean <- 2
}else{
stop("wrong class variable")
}

if(length(unique(antaresData$mcYear)) <= 1){
stop("antaresData must contain at least two mcYears.")
}
#variable to take from x
idCols <- .idCols(antaresData)
varToTake <- variable

antaresDataCopy <- copy(antaresData[, mget(c(idCols, varToTake))])
#by of x
getByA <- setdiff(getIdCols(antaresDataCopy), pkgEnv$idTimeVars)

#get only what you want
nameNewColumn <- paste0(varToTake, "Mono")
antaresDataCopy[, (nameNewColumn) := funcClass(0)]
#maybe faster but we must deal with column/string
# resMono <- antaresData[, eval(quote(.(nameNewColumn =
# sort(get(varToTake),
# decreasing = TRUE)))),
# by = getByA]
antaresDataCopy <- antaresDataCopy[, (nameNewColumn) := sort(get(varToTake),
decreasing = TRUE),
by = getByA]
antaresDataCopy[, c(varToTake) := NULL]
#Cast the result to be able to make a rowMean
IdColsWMcYear <- idCols[idCols!="mcYear"]
myFormula <- sprintf("%s ~ mcYear", paste(IdColsWMcYear, collapse = "+"))
antaresDataCopy <- data.table::dcast(data = antaresDataCopy,
formula = as.formula(myFormula),
value.var = c(paste0(varToTake, "Mono")))
newNameColumnnMonoMc <- paste0(varToTake,"MonoMc" , unique(antaresData$mcYear))
data.table::setnames(x = antaresDataCopy,
old = as.character(unique(antaresData$mcYear)),
new = newNameColumnnMonoMc)
#make a monotone rowMean
nameNewColum <- c(paste0(varToTake, "MonoMean"))
antaresDataCopy[, (nameNewColum) := funcClass(0)]
antaresDataCopy <- antaresDataCopy[, (nameNewColum) := funcClass(round(rowMeans(.SD), digitMonoMean)),
by = IdColsWMcYear, .SDcols = newNameColumnnMonoMc]
#antaresData <- merge(antaresData, resMonoMean, by = IdColsWMcYear)
colToAdd <- setdiff(names(antaresDataCopy), IdColsWMcYear)
antaresData[antaresDataCopy,
(colToAdd) := mget(paste0("i.", colToAdd)),
on = IdColsWMcYear]
invisible(antaresData)
}
}


3 changes: 1 addition & 2 deletions R/addUpwardMargin.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#' This function computes isolated and interconnected upward margins of areas and
#' add them to an antaresData object.
#'
#' @param x An object of class \code{antaresData} created with
#' \code{\link[antaresRead]{readAntares}}
#' @param x An object of class \code{\link[antaresRead]{readAntares}} (or \code{\link[antaresRead]{simOptions}}) created with 'readAntares()' (or 'setSimulationPath()')
#'
#' @return
#' The function modifies its input by adding to it two new columns
Expand Down
Loading