knitr::opts_chunk$set(echo = TRUE)
options(knitr.kable.NA = '', width = 90)


# load("~/Documents/boku/rpkgs/smires/dev/at_list-columns.rda")
# load("M:/smires/dev/at_list-columns.r")
#at <- at_all <- smires
at_all

# at <- at_all %>%
#  filter(intermittent & years >= 10)

at
library(dplyr)
library(purrr)
library(smires)
library(knitr)
library(lubridate)
library(ggplot2)

smires
smires$data[[19]]
plot_intermittency(smires$data[[19]])

Compute a single metrics for a single station, eg. station number 19.

MAMD(smires$data[[19]])
FAMD(smires$data[[19]])

Compute several metrics for all stations. One can use self-written functions and predifined smires metrics.

nmonths <- function(x, ...)
{
  x <- x$time
  monnb <- function(d) {
    lt <- as.POSIXlt(as.Date(d, origin = "1900-01-01"))
    lt$year*12 + lt$mon
  }

  d <- monnb(max(x, na.rm = T)) - monnb(min(x, na.rm = T))
  return(as.integer(d))
}


f <- list(months = nmonths, 
          MAN = MAN,
          yearStart = function(x, ...) year(min(x$time)),
          yearEnd   = function(x, ...) year(max(x$time)))

m1 <- multiple_metrics(smires, .funs = f)

select(m1, months, MAN, yearStart, yearEnd)

For a few stations there are no coordinates.

basemap(m1) + 
  geom_point(aes(size = MAN, col = MAN), alpha = 0.2)

Compute all IRES metrics but just for a few stations.

set.seed(2804)
m2 <- smires %>%
  select(sid, data, lon, lat) %>%
  sample_n(size = 10) %>%
  all_metrics() %>%
  print()

Exporting the data as a kml file (for upload Google Maps). Change filename to .shp for ESRI Shapefile.

library(sf)
meta <- attr_smires(m2$data, as.sf = TRUE)

export <- meta %>% 
  select(-lon, -lat) %>%
  left_join(m2, by = "sid") %>%
  mutate_if(is.character, iconv, from = "", to = "UTF-8")

st_write(obj = export[,], dsn = "intermittent_austria.kml",
         delete_dsn = TRUE)


mundl/smires documentation built on May 23, 2019, 8:22 a.m.