```{r setup, include=FALSE}
knitr::opts_chunk$set(
  results = 'asis',
  echo = FALSE,
  warning = FALSE,
  message = FALSE,
  fig.align = 'center'
)

#Load libraries
library(tidyverse)
library(gapminder)
library(kableExtra)
```


# Introduction
I am Elaheh Arjomand and I am doing a Post-doc fellowship on the subject of wellbore integrity and monitoring wells after being decommissioned. I completed my Ph.D. studying the integrity of the cement sheath in petroleum wells after being subjected to pressure and temperature variations at the University of Adelaide in 2018.

# My Project
In this project, the emphasis is placed on the investigations to determine the optimum approaches for monitoring wells after decommissioning in the Northern Territory. 
<center>
![](C:/Data_School/My_FOCUS_Project_EA/My_Summary/My_ProjectSummary_May2020/image/well.jpg)

![Image by Chris Burnett ]
</center>


In the current stage of the project, the aim is to familiarise ourselves with the petroleum wells database in the NT. The scope of this project is limited to onshore gas wells in the NT which also includes the decommissioning of exploration and production wells.

## Preliminary results
To get an overview of decommissioned and abandoned wells, we need to know:  
•	The number of wells abandoned and their distributions among all the basins in NT  
•	The time period at which the abandonment processes of **gas** wells has happened  

```{r preliminary_code, echo=FALSE,fig.align='centre'}
library(tidyverse)
library(readxl)
library(ggplot2)
library(lubridate)
library(dplyr)
library(gganimate)
library(ggplot2)
library(cowplot)
library(magick)
NT_Wells<- read_excel("C:/Data_School/My_FOCUS_Project_EA/My_Summary/My_ProjectSummary_May2020/data/NT Petroleum Wells.xlsx")
main_file <- NT_Wells %>% filter(Status=="Abandoned") %>% rename("RigReleaseDate"="Rig Release Date","TitleID"="Title ID",
"WellName"= "Well Name","TotalDepthDate"="Total Depth Date","HydrocarbonShows"="Hydrocarbon Shows") %>% 
  mutate(RigReleaseDate=year(RigReleaseDate))%>% drop_na(HydrocarbonShows)
groupbybasin <- main_file  %>%   group_by(Basin)%>% summarise(num_rows=n())%>% arrange(num_rows) %>% rename("Number_of_Wells"="num_rows")
p1<-ggplot(data=groupbybasin,mapping = aes(x=Basin,y=Number_of_Wells))+geom_bar(stat="identity", fill="darkblue")+
  theme_minimal()+theme(axis.text.x = element_text(angle = 90))+transition_states(Basin)
a_gif <- animate(p1)

p2<-ggplot(data=main_file,mapping = aes(x=Basin,y=RigReleaseDate,color=HydrocarbonShows))+geom_point()+
  theme_minimal()+theme(axis.text.x = element_text(angle = 90))+ scale_y_continuous(limits=c(1950,2020),breaks=c(1950,1960,1970,1980,1990,2000,2010,2020),
 label=c("1950","1960","1970","1980","1990","2000","2010","2020"))+
scale_colour_manual(values = c("darkblue", "#FF9999", "#FF9999","#FF9999", "darkblue", "#FF9999", "darkblue", "#FF9999"))+transition_states(HydrocarbonShows)

b_gif <- animate(p2)

a_mgif <- image_read(a_gif)
b_mgif <- image_read(b_gif)
new_gif <- image_append(c(a_mgif[1], b_mgif[1]))
for(i in 2:100){
  combined <- image_append(c(a_mgif[i], b_mgif[i]))
  new_gif <- c(new_gif, combined)
}

new_gif


```




### Specific investigations on Amadeus Basin
Amadeus Basin held the greatest number of abandoned wells in the NT. Therefore, further investigation on regards to the number of gas wells, the utilised legislations,the operators companies, and the rig release date (abandonment date) is required.

```{r Amadeus Basin, echo=FALSE}
NT_Wells<- read_excel("C:/Data_School/My_FOCUS_Project_EA/My_Summary/My_ProjectSummary_May2020/data/NT Petroleum Wells.xlsx")
AM <- NT_Wells %>% filter(Status=="Abandoned") %>% rename("RigReleaseDate"="Rig Release Date","TitleID"="Title ID",
"WellName"= "Well Name","TotalDepthDate"="Total Depth Date","HydrocarbonShows"="Hydrocarbon Shows") %>% 
  mutate(RigReleaseDate=year(RigReleaseDate))%>% drop_na(HydrocarbonShows) %>% filter (Basin=="Amadeus Basin")
plot1<- ggplot(data=AM, mapping = aes(x=TitleID,y=RigReleaseDate,color=Purpose)
) +
  geom_point(size=5)+
  scale_x_discrete(labels = abbreviate)+scale_y_continuous(limits=c(1960,2016),breaks=c(1960,1970,1980,1990,2000,2010,2016),label=c("1960","1970","1980","1990","2000","2010","2016"))+theme_minimal()+
theme(axis.text.x= element_text(angle = 90))
plot2<- ggplot(data = AM,
  mapping = aes(x=TitleID,y=RigReleaseDate,shape=HydrocarbonShows,color=HydrocarbonShows))+
  geom_point(size=5)+theme_minimal()+theme(axis.text.x = element_text(angle = 90))+scale_x_discrete(labels = abbreviate)+scale_y_continuous(limits=c(1960,2016),breaks=c(1960,1970,1980,1990,2000,2010,2016),
label=c("1960","1970","1980","1990","2000","2010","2016"))+scale_shape_manual(values=c(15, 16, 17,18,9,10,12))+
scale_colour_manual(values = c("lightblue", "#FF9999", "#FF9999","lightblue", "#FF9999", "lightblue", "#FF9999"))
p_up<- plot_grid(plot1, plot2,align = "h")
plot5<- ggplot(data = AM,
               mapping = aes(x=TitleID,y=RigReleaseDate,shape=Legislation,color=Operator))+
  geom_point(size=5)+theme_minimal()+theme(axis.text.x = element_text(angle = 90))+ 
  scale_x_discrete(labels = abbreviate)+scale_y_continuous(limits=c(1960,2016),breaks=c(1960,1970,1980,1990,2000,2010,2016),label=c("1960","1970","1980","1990","2000","2010","2016"))
cp3<- plot_grid(p_up,plot5,nrow =2)
title <- ggdraw() + draw_label("Amadeus Basin",fontface = 'bold', x = 0,hjust = 0)+ theme(plot.margin = margin(0, 0, 0, 7))
final<- plot_grid(title,cp3,nrow=3,rel_heights = c(0.1,1))
ggsave(plot=final,path="C:/Data_School/My_FOCUS_Project_EA/My_Summary/My_ProjectSummary_May2020/image", width =15, height = 15, dpi = 300, filename = "AM_Basin.png")
```
<center>
![](C:/Data_School/My_FOCUS_Project_EA/My_Summary/My_ProjectSummary_May2020/image/AM_Basin.png)
</center>

# My Digital Toolbox

My favourite toolboxes are:


![](https://raw.githubusercontent.com/tidyverse/ggplot2/master/man/figures/logo.png){width=90px}![](C:/Data_School/My_FOCUS_Project_EA/My_Summary/My_ProjectSummary_May2020/image/cowplot.png){width=90px}![](C:/Data_School/My_FOCUS_Project_EA/My_Summary/My_ProjectSummary_May2020/image/gganimate.png){width=90px}

# My time went ...
I spent most of my time plotting different graphs and choosing which ones deliver the right messages to the audience.


# Next steps
I have learned a lot about making a dataset tidy and how to use ggplot to demonstrate the purpose of the data visually. I would like to learn more about data visualization aspects to be applied in the upcoming stages of this project including heatmaps. 

# My Data School Experience
I have got excellent experiences regarding tidying the data and version controls of different documents. I am sure I will be applying these lessons from now on. 

```


