CRAN_Status_Badge Travis-CI Build Status codecov

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-"
)

options("citation_format" = "pandoc")
suppressPackageStartupMessages(library(knitcitations))

knitcitations::cleanbib()
# knitcitations:::cite_options(hyperlink=TRUE)
bib_file1 <- system.file("doc", "bibliography.bib", package = "zFactor")
bib_file2 <- system.file("doc", "error_stats.bib", package = "zFactor")
bib <- read.bibtex(bib_file1)
bib2 <- read.bibtex(bib_file2)

zFactor

Computational tools for chemical, petrochemical and petroleum engineers. Calculates the error measures or deviation between different correlations for gas compressibility compared to the original Standing-Katz chart.

Motivation

For the development of vertical lift performance (VLP) curves and other petroleum engineering calculations, it is necessary to calculate properties of hydrocarbons in mixtures, liquid and gaseous phases. Compressibility is one of these hydrocarbon properties. It is important to count with the apropriate correlation and know its range of applicability in order to calculate other properties dependant of z.

There are several compressibility correlations. In this package, few of them, or the most used in the industry, are being evaluated. There have been extensive studies on compressibility correlations. This evaluation is different in the sense that provides a graphical view of the range of applicability as well statistical measures of the errors, besides that the work has been written fully in R providing the analysis and results for peer review and reproducibility purposes. All the code, functions, notes, datasets are available via GitHub.

This analysis focus on sweet hydrocarbon gases. Compressibility correlations for sour gases are little bit more complicated since they show significant deviations from the curves in the Standing-Katz charts. Effects of CO2, H2S and N2 have to be accounted for. In a future release of zFactor correlations for sour hydrocarbons gases will possibly be covered.

Correlations used in this study

The correlations that are implemented in R for the package zFactor are:

Versions

Installation

I recommend installing from GitHub using devtools, that way you get the latest and greatest version. CRAN release cycles allows updates every one to two months.

You can install the latest version of zFactor from GitHub with:

# install.packages("devtools")
devtools::install_github("f0nzie/zFactor")

Or, if your prefer, from CRAN:

install.packages("zFactor")

Usage

library(zFactor)

# get `z` values from the Standing-Katz chart
tpr <- c(1.2, 1.3, 1.5, 2.0, 3.0) 
ppr <- c(0.5, 1.5, 2.5, 3.5, 4.5, 5.5) 
getStandingKatzMatrix(ppr_vector = ppr, tpr_vector = tpr, 
                                 pprRange = "lp")

# calculate `z` using the Beggs-Brill correlation
z.BeggsBrill(pres.pr = 1.5, temp.pr = 2.0)

# calculate `z` using the Hall-Yarborough correlation
z.HallYarborough(pres.pr = 1.5, temp.pr = 2.0)

# calculate `z` using the correlation Dranchuk-AbousKassem
ppr <- c(0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5) 
tpr <- c(1.05, 1.1, 1.7, 2) 
z.DranchukAbuKassem(ppr, tpr)

# We do the same with the Dranchuk-Purvis-Robinson correlation
# but we change the values of the isotherms `Tpr`
tpr <- c(1.4, 1.4, 1.6, 1.7, 1.8) 
z.DranchukPurvisRobinson(pres.pr = ppr, temp.pr = tpr)

# now we use the relative undocumented Shell correlation
z.Shell(ppr, tpr)

# the newly added Papp correlation
z.Papp(ppr, tpr)

# and finally the correlation Kamyab et al that uses Artificial Neural Networks
z.Ann10(ppr, tpr)

Range of Applicability

How to interpret the colors? We use the Mean Absolute Percentage Error or MAPE to visualize how close the correlation follow the experimental values of the Standing-Katz chart.

You can see for yourself which correlation is more stable at different ranges of pseudo-reduce pressures and temperatures.

Beggs-Brill

library(zFactor)
zFactor:::z.plot.range("BB",  interval = "fine")

Hall-Yarborough

zFactor:::z.plot.range("HY",  interval = "fine")
zFactor:::z.plot.range("HY",  interval = "coarse")

Dranchuk-AbouKassem

zFactor:::z.plot.range("DAK", interval = "fine")

Dranchuk-Purvis-Robinson

zFactor:::z.plot.range("DPR", interval = "fine")

Shell (Shell Oil Company)

zFactor:::z.plot.range("SH",  interval = "fine")

Ann10 (Neural Network, 10 neurons)

zFactor:::z.plot.range("N10", interval = "fine")

Papp (explicit)

zFactor:::z.plot.range("PP",  interval = "fine")

Comparative Analysis

The comparative analysis shows tables with different error measurements:

MSE:   Mean Squared Error
RMSE:  Root Mean Squared Error
RSS:   Residual sum of Squares
RMSLE: Root Mean Squared Logarithmic Error. Penalizes understimation.
MAPE:  Mean Absolute Percentage Error = AARE
MPE:   Mean Percentage error = ARE
MAE:   Mean Absolute Error
MAAPE: Mean Arc-tangent Absolute Percentage Error

MAAPE was proposed by r citep(bib2[c("Kim2016")]). Other authors consulted for the error measures are r citep(bib2[c("Makridakis1993")]), r citep(bib2[c("Chen2017")]), r citep(bib2[c("Kobayashi2000")]), r citep(bib2[c("Myttenaere2016")]), r citep(bib2[c("Syntetos2013")]), and r citep(bib2[c("Armstrong1992")]).

What you can do with zFactor

Plotting a specific isotherm of SK chart

library(zFactor)
getStandingKatzCurve(tpr = 1.3, toView = FALSE, toSave = FALSE)
getStandingKatzCurve(tpr = 1.05, pprRange = "lp", toView = FALSE, toSave = FALSE)

Ploting all the Tpr curves of Standing-Katz chart using lapply, getStandingKatzData and data.table::rbindlist:

library(zFactor)
library(ggplot2)
library(data.table)

tpr_vec <- c(1.05, 1.1, 1.2, 1.3, 1.5, 1.6, 1.7, 1.9, 2.0, 2.4, 2.6, 2.8, 3.0)
all_tpr2 <- (lapply(tpr_vec, function(x) getStandingKatzData(tpr = x)))
names(all_tpr2) <- tpr_vec

all_tpr_df <- data.table::rbindlist(all_tpr2, idcol = TRUE)
colnames(all_tpr_df)[1] <- "Tpr"

ggplot(all_tpr_df, aes(x=Ppr, y=z, group=Tpr, color=Tpr)) + 
    geom_line() +
    geom_point()

Build a table of statistical errors between a correlation and SK chart

library(ggplot2)
library(tibble)
library(dplyr)

# get all Tpr curves at low pressure (lp)
tpr_all <- getStandingKatzTpr(pprRange = "lp")
ppr <- c(0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5) 
sk_corr_all <- createTidyFromMatrix(ppr, tpr_all, correlation = "DPR")
grouped <- group_by(sk_corr_all, Tpr, Ppr)

smry_tpr_ppr <- summarise(grouped, 
          RMSE  = sqrt(mean((z.chart-z.calc)^2)), 
          MPE   = sum((z.calc - z.chart) / z.chart) * 100 / n(),
          MAPE  = sum(abs((z.calc - z.chart) / z.chart)) * 100 / n(), 
          MSE   = sum((z.calc - z.chart)^2) / n(), 
          RSS   = sum((z.calc - z.chart)^2),
          MAE   = sum(abs(z.calc - z.chart)) / n(),
          RMLSE = sqrt(1/n()*sum((log(z.calc +1)-log(z.chart +1))^2))
          )
as.tibble(smry_tpr_ppr)

Summary of MAPE statistics

This function shows a statistical summary of the Mean Absolute Percentage Error of all the correlations. We are taking the mean, maximum error, minimum eroor, the median and the mode in the whole range of each opf the correlations.

library(zFactor)
stats_of_z.stats()

Vignettes

The vignettes contain examples on the use and analysis of the various correlations.

Tests

There are unit tests for the correlations under tests/testthat.

How the Standing-Katz chart was constructed

The Standing-Katz (SK) chart data has been read directly from a scanned figure of the original plot drawn by Standing and Katz in 1951. The software used to digitize the data is graphClick for the operating system osX by Apple. This software has been tested and qualified by scolars working on a similar task of digitizing data. r citep(bib[c("Rakap2016")])

Each one of the SK chart pseudo-reduce temperature curves has been digitized. There are some curves where more points were taken to describe the curvature better. Other curves are almost linear and few points were necessary to define the curve.

References

The following books and papers were consulted during the development of this package:

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = ""
)
# suppressPackageStartupMessages(library(knitcitations))
knitcitations::bibliography(style="citation")


f0nzie/zFactor documentation built on Aug. 2, 2019, 1:42 a.m.