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

Load the necessary Packages

library(soilmoistr)
library(here)
library(iffitoR)
library(tidyverse)
library(raster)
library(stars)
library(sf)

What does the function get_sm_data do?

When using points and no buffer

res = get_sm_data(<path_to_soilmoisture_data>,
                  landsld = <landslide-object>)

When using points and a buffer arround them

res = get_sm_data(<path_to_soilmoisture_data>,
                  landsld = <landslide-object>,
                  point_buffer = 300,
                  aggre_fun = c("mean"))

Example

data = landsld[grepl("translational|rotational", landsld$second_level), ]
dim(data)
copy = data.frame(data) %>% st_as_sf()
copy[["date"]] = NULL # remove the date column
res = get_sm_data(
  landsld = copy,
  path_sm = path_sm
)
path_sm = "/mnt/CEPH_PROJECTS/Proslide/soilmoisture/32632/"

# data = data[1:50, ]

res = get_sm_data(
  landsld = data,
  path_sm = path_sm,
  quiet = F
)

Work with the extracted data

res %>% dplyr::select(c(date, PIFF_ID, second_level, sm_values)) %>% glimpse()
# add fonts
library(showtext)
library(ggtext)

# where does the package look for fonts?
# font_paths()
# show local fonts
# font_files()
# add the font by providing the family and the name of the truetypefont (.ttf)
font_add(family = "DejaVu Serif", regular = "DejaVuSerif-Bold.ttf")

# create color scale for true and false
pal = c("TRUE" = "#b9cb99", "FALSE" = "#c23b22")

res %>% 
  mutate(
    intersection = case_when(
      is.na(sm_values) ~ FALSE,
      TRUE ~ TRUE
    )
  ) %>% 
  count(intersection) %>% 
  ggplot() +
  geom_col(
    aes(
      x = n,
      y = intersection,
      fill = intersection
    )
  ) +
  scale_fill_manual(values = pal) +
  theme_light() + 
  labs(
    y = "",
    x = "#",
    title = "Number of Soilmoisture rasters intersecting in time with the landslide data",
    caption = "Considered were only the translational and rotational slides.
               A temoral buffer of 5 days was applied to the slides."
  ) +
  theme(
    legend.position = c(0.8,0.8),
    title = element_text(family = "mono"),
    legend.text = element_text(family = "mono"),
    legend.background = element_blank(),
    axis.text.y = element_blank()
  )


RobinKohrs/soilmoistr documentation built on Dec. 18, 2021, 10:55 a.m.