knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Intro

library(rainfallR)
library(stars)
library(ncdf4)
library(tidyverse)
library(scales)
library(raster)
library(sf)
os = Sys.info()["sysname"]

if(os == "Linux"){
  path_data = "/mnt/CEPH_PROJECTS/Proslide/PREC_GRIDS_updated/"
  su_path = "/mnt/CEPH_PROJECTS/Proslide/Envir_data/SlopeUnits/su_opt_16_TAA/su_16_TAA.shp" 
}else{
  # the path to the data
  path_data = "\\\\projectdata.eurac.edu/projects/Proslide/PREC_GRIDS_updated/"
  # path to the slop units
  su_path = "\\\\projectdata.eurac.edu/projects/Proslide/Envir_data/SlopeUnits/su_opt_16_TAA/su_16_TAA.shp"
}
# set some parameters for the rainfallR
day = as.Date("2016-08-16")

# get the day as integer
day_int = format(day, "%d")

# we only want one raster to get the bounding box in order to draw s shape
days_back = 1

# create the path to the NetCDF
path_ncdf = rainfallR::get_nc_paths(path_data, day, days_back) %>% .[[1]]

# read in one raster with stars
r = read_ncdf(path_ncdf) 

# extract one raster
r = r[,,,16]
set.seed(2)

# read in the slope units and select a random one
su = read_sf(su_path)

# select a random one
su = su %>% slice(sample(1:nrow(su), 1))

Extract the rainfall for one date for that polygon

rainfall = rainfallR::ex_rainfall(
  data_path = path_data,
  spatial.obj = su,
  date = day,
  fun = c("mean", "max"),
  days_back = 3
)

# what have we got?
print(rainfall)


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