-
Notifications
You must be signed in to change notification settings - Fork 0
/
antaresReadME.Rmd
233 lines (157 loc) · 6.1 KB
/
antaresReadME.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
---
title: "antaresRead 2.1.0 More Examples"
author: "Jalal-Edine ZAWAM"
date: "22 mars 2018"
output:
html_document:
number_sections: yes
toc: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r param, echo=FALSE}
#param of all examples
pathStudy<-"E:\\ANTARES\\Exemple_antares\\2_exemple_etudes_importantes\\TYNDP\\ST2030\\ST2030"
pathStudyL<-"E:\\ANTARES\\Exemple_antares\\3_petit_exemple\\PackagesR\\Test_packages_R_602"
```
# Areas and Links
## How to import daily, weekly, monthly and annual data ?
Import daily data
```{r importDailyData, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudy,-1))
myData<-suppressWarnings(readAntares(areas = "fr", links = "all", timeStep = "daily", showProgress = FALSE))
```
Check your import
```{r CheckDailyData, echo=TRUE}
length(myData$areas$time)
```
Import weekly data
```{r importWeeklyData, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudy,-1))
myData<-suppressWarnings(readAntares(areas = "fr", links = "all", timeStep = "weekly", showProgress = FALSE))
```
Check your import
```{r CheckWeeklyData, echo=TRUE}
length(myData$areas$time)
```
Import monthly data
```{r importMonthlyData, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudy,-1))
myData<-suppressWarnings(readAntares(areas = "fr", links = "all", timeStep = "monthly", showProgress = FALSE))
```
Check your import
```{r CheckMonthlyData, echo=TRUE}
length(myData$areas$time)
```
Import annual data
```{r importAnnualData, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudy,-1))
myData<-suppressWarnings(readAntares(areas = "fr", links = "all", timeStep = "annual", showProgress = FALSE))
```
Check your import
```{r CheckAnnualData, echo=TRUE}
length(myData$areas$time)
```
## How to write some variables in a csv file ?
Import your data
```{r importExCsv, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudy,-1))
myData<-suppressWarnings(readAntares(areas = "all", links = "all", showProgress = FALSE, select = c("economy", "FLOW LIN.", "CONG. PROB +", "CONG. PROB -")))
```
Write some variables
```{r writeCsv, echo=TRUE}
write.csv2(file="myFileArea.csv", myData$areas[area=="fr",])
write.csv2(file="myFileLink.csv", myData$links[link=="0_pump_daily - fr", ])
```
## How can I know the type and class of my ANTARES object ?
If you import areas and links you will get an antaresDataList. You can find more information about antareDataList with the help of the function `as.antaresDataList` in the package antaresRead.
If you import only areas or links you will get an antaresDataTable. An antaresDataTable is also a data.table and a data.frame. If you don't know what's a data.table you can find more information [here](https://github.com/Rdatatable/data.table/wiki). If you don't know what's a data.frame you can find more information [here](http://www.r-tutor.com/r-introduction/data-frame). We advise you to use the data.table features.
```{r classList, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudy,-1))
myDataL<-suppressWarnings(readAntares(areas = "all", links = "all", showProgress = FALSE, select = c("economy")))
myDataTA<-suppressWarnings(readAntares(areas = "all", showProgress = FALSE, select = c("economy")))
myDataTL<-suppressWarnings(readAntares(links = "all", showProgress = FALSE))
```
Get the class and type of your object
```{r getClass, echo=TRUE}
class(myDataL)
typeof(myDataL)
class(myDataTA)
typeof(myDataTA)
class(myDataTL)
typeof(myDataTL)
```
## How can I get the names of the columns ?
Import your data
```{r importListColumn, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudyL,-1))
myData<-suppressWarnings(readAntares(areas = "all", links = "all", showProgress = FALSE, select = c("economy", "FLOW LIN.", "CONG. PROB +", "CONG. PROB -")))
```
Check the list
```{r CheckListColumn, echo=TRUE}
names(myData$areas)
names(myData$links)
```
## How can I edit an existing column in an antaresData or in a data.table ?
Import your data
```{r importEditColumn, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudyL,-1))
myData<-suppressWarnings(readClusterDesc())
myData
```
Edit an existing column
```{r EditColumn, echo=TRUE}
dim(myData[is.na(co2), ])[1]
#When co2 is na, replace the value by 0
myData[is.na(co2), co2:=0]
dim(myData[is.na(co2), ])[1]==0
myData
```
## How can I add a new column in an antaresData or in a data.table ?
Import your data
```{r importAddNewColumn, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudyL,-1))
myData<-suppressWarnings(readAntares(areas = "all", links = "all", showProgress = FALSE, select = c("allAreas", "FLOW LIN.", "CONG. PROB +", "CONG. PROB -")))
```
Add a new column
```{r addNewColumn, echo=TRUE}
names(myData$areas)
myData$areas[, newColumn:=LOAD*0.5+WIND-SOLAR]
names(myData$areas)
names(myData$links)
myData$links[, newColumnLink:= `CONG. PROB +`+`CONG. PROB -`]
names(myData$links)
```
# Links
## How to get the value of maximum flow capacity for a link ?
Import your data
```{r importCapaLink, echo=TRUE}
library(antaresRead)
#pathStudy : path to my study
suppressWarnings(opts<-setSimulationPath(pathStudy,-1))
myData<-suppressWarnings(readAntares(links = "all", linkCapacity = TRUE, showProgress = FALSE))
```
Get the maximum flow capacity for a link
```{r maximumFlow, echo=TRUE}
max(myData[link=="0_pump_daily - fr", transCapacityDirect])
max(myData[link=="0_pump_daily - fr", transCapacityIndirect])
```