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)
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.
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.
The correlations that are implemented in R for the package zFactor are:
Beggs and Brill (BB) r citep(bib[c("Azizi2010")])
Hall and Yarborough (HY) r citep(bib[c("Hall1973")])
Dranchuk and Abou-Kassem (DAK) r citep(bib[c("Dranchuk1975")])
Dranchuk, Purvis and Robinson (DPR) r citep(bib[c("Dranchuk1973")])
A correlation by Shell Oil Company (SH) r citep(bib[c("Kumar2004")])
, r citep(bib["bahadori"])
, r citep(bib["Almeida2014"])
, r citep(bib["Al-Anazi2011"])
, r citep(bib["Azizi2010"])
, r citep(bib["Mohamadi-Baghmolaei2015"])
. The Shell correlation was found cited in two books and several papers (including the equation and constants), but the original paper or authors could not be identified.
A correlation developed with Artificial Neural Networks (Ann10) by Kamyab et al. r citep(bib[c("Kamyab2010")])
An explicit correlation by I. Papp r citep(bib[c("Papp1979")])
mentioned in the comparative analysis paper by Gabor Takacs r citep(bib[c("Takacs1989")])
. Papp's paper is not available in English.
v 0.1.7
development versions
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")
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)
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.
Blue
: the MAPE is zero or near zeroYellow
: the MAPE is around 10 percent.Red
: the MAPE has reached 25%.Grey
: the mean absolute percentage error is above or way above 25%.You can see for yourself which correlation is more stable at different ranges of pseudo-reduce pressures and temperatures.
library(zFactor) zFactor:::z.plot.range("BB", interval = "fine")
zFactor:::z.plot.range("HY", interval = "fine") zFactor:::z.plot.range("HY", interval = "coarse")
zFactor:::z.plot.range("DAK", interval = "fine")
zFactor:::z.plot.range("DPR", interval = "fine")
zFactor:::z.plot.range("SH", interval = "fine")
zFactor:::z.plot.range("N10", interval = "fine")
zFactor:::z.plot.range("PP", interval = "fine")
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 arer citep(bib2[c("Makridakis1993")])
,r citep(bib2[c("Chen2017")])
,r citep(bib2[c("Kobayashi2000")])
,r citep(bib2[c("Myttenaere2016")])
,r citep(bib2[c("Syntetos2013")])
, andr citep(bib2[c("Armstrong1992")])
.
zFactor
z
with any of the correlations providedPpr
) digitizedTpr
) are available from the Standing and Katz chartz
in graphical formz
values calculated from any correlation where the rows are the pseudo-reduced temperatures and the columns the pseudo-reduced pressureslibrary(zFactor) getStandingKatzCurve(tpr = 1.3, toView = FALSE, toSave = FALSE) getStandingKatzCurve(tpr = 1.05, pprRange = "lp", toView = FALSE, toSave = FALSE)
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()
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)
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()
The vignettes contain examples on the use and analysis of the various correlations.
There are unit tests for the correlations under tests/testthat.
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.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.