-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextract_gor_from_step.Rmd
133 lines (107 loc) · 4.07 KB
/
extract_gor_from_step.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
---
title: "GOR extraction from step block"
draft: true
output:
html_document:
df_print: paged
---
```{r setup, include = FALSE, error=TRUE, message=FALSE, warning=FALSE}
knitr::opts_chunk$set(echo = TRUE,
comment = "#>",
collapse = TRUE,
error = TRUE,
warning = FALSE,
message = FALSE,
fig.align = 'center',
autodep=FALSE
)
```
```{r read-prt-file}
library(dplyr)
library(ggplot2)
# read the Eclipse PRT output report
proj_root <- rprojroot::find_rstudio_root_file()
# had to zip the PRT file because it's 225 MB and too big for Github
volve_2016_zip <- file.path(proj_root, "inst/rawdata", "VOLVE_2016.zip")
temp <- tempdir()
volve_2016_txt <- readLines(unzip(volve_2016_zip, exdir = temp))
```
Once with the contents of `VOLVE_2016.PRT` loaded in the object __volve_2016_txt__, we proceed to perform the extraction.
We start by extracting few rows after the __STEP__ keyword.
```{r}
# get a list of rows from " STEP"
# find the rows where we find the word " STEP"
step_rows <- grep("^ STEP", volve_2016_txt)
# add rows ahead to where the keyword was found
step_info_range <- lapply(seq_along(step_rows), function(x)
c(step_rows[x], step_rows[x]+1:2)) # add two extra row indices
step_info_range[[1]] # sample for report page 1 only
```
```{r}
# get the text from all pages and put them in a list
steps_info_txt_pages <- lapply(seq_along(step_info_range), function(x)
volve_2016_txt[step_info_range[[x]]])
```
For example, this is an example of the first page for step #1.
```{r}
steps_info_txt_pages[1]
```
## Extract the GOR value
### Explanation
* `.*GOR=.*?`: any characters up to "GOR="
* `(\\d+.\\d+)`: capture group of digits, dot. and digits
* `.*`: any characters to the end
```{r}
# iterate through the list of pages: dates
gor_dfs <- lapply(seq_along(steps_info_txt_pages), function(x) {
page <- steps_info_txt_pages[[x]] # put all pages text in a list
gor_row_txt <- grep(" GOR", page)
gor_value <- sub(".*GOR=.*?(\\d+.\\d+).*", "\\1", page[gor_row_txt])
# dataframe
data.frame(gor = gor_value, stringsAsFactors = FALSE)
})
gor_df <- do.call("rbind", gor_dfs)
gor_df
```
## Water Gas Ratio (WGR)
###
```{r}
# iterate through the list of pages: WATERCUT
wgr_dfs <- lapply(seq_along(steps_info_txt_pages), function(x) {
page <- steps_info_txt_pages[[x]] # put all pages text in a list
row_txt <- grep(" WGR=", page)
wgr_value <- sub(".*WGR=.*?(\\d+.\\d+).*", "\\1", page[row_txt])
# dataframe
data.frame(wgr = wgr_value, stringsAsFactors = FALSE)
})
wgr_df <- do.call("rbind", wgr_dfs)
wgr_df
```
```{r rows.print=50}
# iterate through the list of pages
step_info_dfs <- lapply(seq_along(steps_info_txt_pages), function(x) {
page <- steps_info_txt_pages[[x]] # put all pages text in a list
row_txt <- grep(" STEP", page)
date_value <- sub(".*?(\\d{1,2}-[A-Z]{3}-\\d{4}).", "\\1", page[row_txt])
# step number
step_value <- sub(".*STEP.*?(\\d+)+.*", "\\1", page[row_txt]) # extract the days
# get step in days
row_txt <- grep(" TIME", page)
days_value <- sub(".*TIME=.*?(\\d+.\\d.)+.*", "\\1", page[row_txt]) # extract the days
# Get the average pressure PAV
row_txt <- grep(" PAV", page)
pav_value <- sub(".*PAV=.*?(\\d+.\\d+).*", "\\1", page[row_txt])
# get the GOR
row_txt <- grep(" GOR", page)
gor_value <- sub(".*GOR=.*?(\\d+.\\d+).*", "\\1", page[row_txt])
# get the WGR
row_txt <- grep(" WGR=", page)
wgr_value <- sub(".*WGR=.*?(\\d+.\\d+).*", "\\1", page[row_txt])
# dataframe
data.frame(step=step_value, date = date_value, days = days_value,
pav_bar = pav_value, gor_m3m3 = gor_value, wgr_m3m3 = wgr_value,
stringsAsFactors = FALSE)
})
step_info <- do.call("rbind", step_info_dfs)
step_info
```