---
title: "Daily maximum temperatures in France"
author: "Duncan Golicher"

output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,message=FALSE,warning=FALSE)
library(giscourse)
library(tidyverse)
library(mapview)
library(dygraphs)
library(xts)
library(sf)
library(lubridate)
# conn<-sconnect11("clima2")
# query<-"select id, geometry from ghcnd where st_Y(geometry)>42 and  st_Y(geometry)<49 and st_X(geometry)>-2 and st_X(geometry)<5"
# d<-st_read(conn,query=query)
# st_crs(d)
# mapview(d)
# f<-function(x)data.frame(id=x,get_ghcnd(x))
# climate<-lapply(unique(d$id), f)
#  climate<-as.data.frame(do.call("rbind",climate))
# 
# save(climate,d,file="french_climate.rda")
load("french_climate.rda")
climate %>% group_by(id, element) %>% summarise(n(), max(date)) ->cd
climate$month<-month(climate$date)
climate$year<-year(climate$date)  
```

# Introduction

The BBC reports that France is suffesring an unprecedented heat wave attributable to climate change. This has resulted in the declaration of an emergency.


https://www.bbc.com/news/world-europe-61838543

"In Gironde, officials said public events, including some of the official 18 June Resistance celebrations, will be prohibited from Friday at 14:00 (12:00 GMT) "until the end of the heat wave". Indoor events at venues without air-conditioning are also banned.Private celebrations, such as weddings, will still be allowed.

"Everyone now faces a health risk", local official Fabienne Buccio told France Bleu radio.

To see how unprecedented the situation is I downloaded data from the NOAA GHCND data base and plotted out daily maximums.

# Data {.tabset}


## Loire maximum temperatures

```{r}
climate %>% filter(id %in% c("FR000007255")) %>% filter(element=="TMAX") %>% mutate(value=value/10)->clim
```

```{r}
clim<-xts(clim[,4],order.by =clim$date) ->tm
dygraph(tm) %>% dygraphs::dyRangeSelector() %>% dyRoller(roll=1)
```

## Gironde maximum temperatures

```{r}
climate %>% filter(id %in% c( "FRM00007607")) %>% filter(element=="TMAX") %>% mutate(value=value/10)->clim
```

```{r}
clim<-xts(clim[,4],order.by =clim$date) ->tm
dygraph(tm) %>% dygraphs::dyRangeSelector() %>% dyRoller(roll=1)
```

## Loire hottest day of the year

```{r}
climate %>% filter(id %in% c( "FR000007255")) %>% filter(element=="TMAX") %>% mutate(value=value/10)->clim
clim %>% group_by(year) %>% summarise(maximum=max(value)) %>% arrange(-maximum) %>% aqm::dt()
```


## Gironde hottest day of the year

```{r}
climate %>% filter(id %in% c( "FRM00007607")) %>% filter(element=="TMAX") %>% mutate(value=value/10)->clim
clim %>% group_by(year) %>% summarise(maximum=max(value)) %>% arrange(-maximum) %>% aqm::dt()
```

## Position of climate station


```{r}
d %>% filter(id %in% c( "FR000007255", "FRM00007607"))->stations
mapview(stations)
```

