-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.Rmd
More file actions
61 lines (44 loc) · 1.56 KB
/
README.Rmd
File metadata and controls
61 lines (44 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
---
title: "Dwd SPEI"
author: "Kmicha71"
date: "7 7 2020"
output:
html_document:
keep_md: true
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## DWD SPEI
Use downloaded and converted precipitation data from DWD (monthly & regional summary)
```{r spi}
#install.packages("SCI") # MAAS, Matrix,
require("SCI")
prec <- read.csv("https://raw.githubusercontent.com/climdata/dwdPrecipitation/master/csv/monthly_precipitation_de.csv", sep=",")
prec <- prec[order(prec$ts),]
spi <- data.frame(prec$year, prec$month)
names(spi)[names(spi) == "prec.year"] <- "year"
names(spi)[names(spi) == "prec.month"] <- "month"
spi$ts <- signif(spi$year + (spi$month-0.5)/12, digits=6)
spi$time <- paste(spi$year,spi$month, '15 00:00:00', sep='-')
start <- prec$month[1]
for (m in c(1,2,3,4,5,6,7,8,9,10,11,12)) {
tmp.para <- fitSCI(prec$Deutschland, first.mon=start,distr="gamma",time.scale=m,p0=TRUE)
tmp.spi <- transformSCI(prec$Deutschland,first.mon=start,obj=tmp.para)
spi$new <- signif(tmp.spi, digits=6)
names(spi)[names(spi) == "new"] <- paste("spi", m, sep="")
}
write.table(spi, file = "csv/spei_de.csv", append = FALSE, quote = TRUE, sep = ",",
eol = "\n", na = "NA", dec = ".", row.names = FALSE,
col.names = TRUE, qmethod = "escape", fileEncoding = "UTF-8")
```
## Plot Drought time line
```{r plot, echo=TRUE}
require("ggplot2")
#spi <- read.csv("./csv/spei_de.csv", sep=",")
mp <- ggplot() +
geom_line(aes(y=spi$spi12, x=spi$ts), color="blue") +
xlab("Year") + ylab("SPI12 []")
mp
```