knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(here)
library(sf)
library(dplyr)
library(tidyverse)
library(rainfallR)
library(ncdf4)
library(raster)
library(stars)
path_ncdf = "\\\\projectdata.eurac.edu/projects/Proslide/PREC_GRIDS/"
path_source_points = "\\\\projectdata.eurac.edu/projects/Proslide/Landslides/Iffi_db_xxxx_to_2018/exportperEurac2020/Shapefiles/IFFI10_1.shp"

# which netcdf to read
year = 2016
month = 08

# build the path to the netcdf
path_ncdf = paste0(path_ncdf, year, "/", "DAILYPCP_", year, formatC(month, flag = 0, width = 2), ".nc")
points = st_read(path_source_points)
ras = read_stars(path_ncdf)

# get the dates
ncin = ncdf4::nc_open(path_ncdf)
dates = rainfallR::get_dates_ncdf(ncin)

# change the DATE dimension
ras = st_set_dimensions(ras, which = "DATE", dates)

# slice
three_days = dplyr::slice(ras, index=c(14,15,16), along="DATE")

# plot it normally
plot(three_days)
ggplot() +
  geom_stars(data = three_days, aes(x=x, y=y, fill = DAILYPCP_201608.nc)) +
  scale_fill_continuous(name="precip [mm/day]", na.value="transparent") +
  coord_equal() +
  facet_wrap(~DATE) +
  theme_light()
ggplot() +
  geom_stars(data=r, aes(x = x, y = y, fill=DAILYPCP_201608.nc)) +
  scale_fill_continuous(name="precip [mm/day]", na.value="transparent") +
  geom_sf(data = points, alpha=.4, size=.4, aes(color="Mass Movements")) +
  labs(colour="",
       title="Rainfall [mm] on the 16.08.2016")


RobinKohrs/rainfallR documentation built on Oct. 3, 2021, 1:42 a.m.