---
title: "Storms"
author: "Duncan Golicher"
date: "12/02/2022"
output: html_document
---

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

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

```{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)")
# 
```

```{r}

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

```


```{r}

d %>% group_by(number) %>% summarise(year=min(season),number=min(number)) %>% sf::st_cast("LINESTRING") ->d3
mapview(d3, burst="year", legend=FALSE)

```

```{r}
d<-st_read(con,query="select * from ibtracs where basin like '%SI%' and season >1950")
d %>% st_drop_geometry()  %>% group_by(season) %>% summarise(n=length(unique(number))) ->d4
ggplot(d4,aes(x=season,y=n)) +geom_line() +geom_smooth()
```


```{r}
library(dygraphs)
dygraph(d4)
```

