Project Description

MeteoSwiss weather observations are available through the opendata.swiss platform. Current project is about a simple R Shiny user interface that produces customised time series plots of various meteorological parameters. It features a dropdown menu with pre-defined reports (see figure 1). A change in this selector triggers an update of the whole UI, filling in the report selections.

Go to Demo

Screenshot of the UI. 1: Report selection, 2: Station selection, 3: Parameter, 4: Time picker, 5: Time inverval, 6: Aggregation function, 6: Perspective (absolute or change by time), 7: Time lag when perspective = change, 8: Download button

Figure 1: Screenshot of the UI. 1: Report selection, 2: Station selection, 3: Parameter, 4: Time picker, 5: Time inverval, 6: Aggregation function, 6: Perspective (absolute or change by time), 7: Time lag when perspective = change, 8: Download button

Example of a time series plot for two stations (Altdorf and Magadino)

Figure 2: Example of a time series plot for two stations (Altdorf and Magadino)

Technology

  • MySQL DB
  • R packages: data.table, dplyr, purrr, RMariaDB, shiny, ggplot2

Code Snippets

The report are stored in a list, but they could also be retrieved from a database or an XML file.

lib.rep <- list(
  list(
    id.rep = 1, 
    descr =  "Overview | TT, TD, FF, FX | SMA, LUG, BAS, BER, GVE"
  ),
  list(
    id.rep = 2, 
    descr = "Overview | QFF, FF, FX | SMA, LUG, BAS, BER, GVE", 
    id.sma = c("SMA", "LUG", "BAS", "BER", "GVE"), 
    code.var = c("p_qff", "ff", "fx"), 
    time.int = "1 hour", 
    agg.fct = "mean"
  ),  
  list(
    id.rep = 3, 
    descr = "Overview Mountains | TT, FF | JUN, SAE, CHA, PIL, NAP, GEN", 
    id.sma = c("JUN", "SAE", "CHA", "PIL", "NAP", "GEN"), 
    code.var = c("tt", "ff"), time.int = "1 hour", agg.fct = "mean"
  ),    
  list(
    id.rep = 4, 
    descr = "Temperature Profile Central | LUZ, NAP, PIL, TIT, JUN", 
    time.int = "1 hour", 
    id.sma = c("LUZ", "NAP", "PIL", "TIT", "JUN"), 
    code.var = "tt", 
    agg.fct = "mean"
  ),
  list(
    id.rep = 5, 
    descr = "Pressure Change QFE | BER, BAS, SMA, LUG", 
    id.sma = c("BER", "BAS", "SMA", "LUG"), 
    code.var = c("p_qfe"),
    time.int = "1 hour", 
    time.lag = "3 hour", 
    agg.fct = "mean", 
    persp = "change"
  )
)

Data is retrieved from the database and processed in real-time. Find below an example \(dplyr\) statement applied to the original data set:

dt %>% mutate(`:=`(time, floor_date(time, "1 hour"))) %>% 
  group_by(id_sma, 
  code_var, name, name_var, time) %>% 
  summarise_at("value", 
  do.call("funs", c(setNames(as.list("mean"), "mean"), list(.args = list(na.rm = T))))) %>% 
  gather(agg, value, -one_of(c("id_sma", "code_var", "name", 
  "name_var", "time"))) %>% 
  ungroup