---
title: "Cyclones in the Southern Indian Ocean"
author: "Duncan Golicher"
date: "12/02/2022"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,warning = FALSE,message = FALSE)
library(tidyverse)
library(mapview)
library(leaflet.extras)
library(sf)
library(giscourse)
con<-sconnect11("clima2")
```

# Introduction

NOAA hold an archive of all the recorded hurricanes, typhoons, tropical cycones and major tropical storms here.

https://www.ncei.noaa.gov/data/international-best-track-archive-for-climate-stewardship-ibtracs/v04r00/access/csv/

The data available on 12 February 2022 have been downloaded and imported into a PostGIS database.


```{r}

# d1 <- read_csv("ibtracs.ALL.list.v04r00.csv")[,2:12]
# nms<-tolower(names(d1))
# d1 <- read_csv("ibtracs.ALL.list.v04r00.csv",skip=1)[,2:12]
# names(d1)<-nms
# library(dplyr)
# d<- sf::st_as_sf(d1, coords = c("lon","lat"),crs=4326)
# st_write(d,con,"ibtracs")
# library(RPostgreSQL)
# RPostgreSQL::dbSendQuery(con, "CREATE INDEX idx_basin 
# ON ibtracs(basin)")
# RPostgreSQL::dbSendQuery(con, "CREATE INDEX idx_year 
# ON ibtracs(season)")
# 
```

# Cyclones since 1950 {.tabset}


```{r}
d<-st_read(con,query="select * from ibtracs where basin like '%SI%' and season >1950")

```

## Numbers registered per year

```{r}
d %>% st_drop_geometry()  %>% group_by(season) %>% summarise(n=length(unique(number))) ->d4
ggplot(d4,aes(x=season,y=n)) +geom_line() +geom_smooth()
```

## Recorded windspeeds over 60km per hour

```{r}
d %>% filter(d$wmo_wind>60) -> winds
mapview(winds,zcol="wmo_wind") ->m
m@map %>% leaflet.extras::addFullscreenControl()
```

## Maximum wind speeds

```{r}
winds %>% sf::st_drop_geometry() %>% group_by(season) %>% summarise(maximum_windspeed=max(wmo_wind)) ->w2
ggplot(w2,aes(x=season,y=maximum_windspeed))+geom_line()+geom_smooth()
```

## Lowest recorded pressure

```{r}
d %>% filter(d$wmo_pres>100) -> winds
winds %>% sf::st_drop_geometry() %>% group_by(season) %>% summarise(minimum_pressure=min(wmo_pres )) ->w2
ggplot(w2,aes(x=season,y=minimum_pressure))+geom_line()+geom_smooth()
```


# Cyclones since 2014 {.tabset}

## Tracks as lines

```{r}

d<-st_read(con,query="select * from ibtracs where basin like '%SI%' and season >2014")

```


```{r}

d %>% group_by(number) %>% summarise(season=min(season),number=min(number)) %>% sf::st_cast("LINESTRING") ->d3
m<-mapview(d3, burst="season", legend=FALSE) 
m@map %>% leaflet.extras::addFullscreenControl()
```

## Points with recordings

```{r}
d %>% mapview(zcol="name", legend=FALSE) ->m
m@map %>% leaflet.extras::addFullscreenControl() 

```

