SILO data in R

Accessing SILO climatic data for Australia in R

## Registered S3 methods overwritten by 'ggplot2':
##   method         from 
##   [.quosures     rlang
##   c.quosures     rlang
##   print.quosures rlang

This short post will describe how to access SILO climatic data for Australia..

Since the first time I wrote this post, there has been a significant overhaul of the API so write a simplified (but functioning!) version of the previous post here.

library(tidyverse)
library(sf)
library(tmap)
res <- httr::GET("https://www.longpaddock.qld.gov.au/cgi-bin/silo/PatchedPointDataset.php?format=name&nameFrag=_")
recs <- read_delim(httr::content(res, as="text"), delim = "|", 
                   col_names = c('number','name','latitude','longitude','state', 'elevation', 'extra')) %>%
  mutate(latitude = as.numeric(latitude)) %>%
  mutate(longitude = as.numeric(longitude))
stationsmeta = recs %>% 
  st_as_sf(coords = c('longitude', 'latitude'), crs = 4326)

We can plot the location of weather stations using the tmap package.

tm_shape(spData::world %>% filter(name_long == "Australia")) +
  tm_borders() +
  tm_shape(stationsmeta) +
  tm_dots(col = NA, alpha = 0.3) +
  tm_style('gray', title = "SILO weather \nstations", 
            outer.bg.color = rgb(.2,.21,.27))

Fill in the longitude and latitude of the site, date range, format, and requested data.

params = list(
  lat="-27.50",
  lon="135.00",
  start="20160101", 
  finish="20160131",
  format="csv",
  comment="RXN",
  username="john.doe@xyz.com.au",
  password="silo"
)
res <- httr::GET("https://www.longpaddock.qld.gov.au/cgi-bin/silo/DataDrillDataset.php", query=params)
silodata <- read_csv(httr::content(res, as="text")) 
head(silodata)
## # A tibble: 6 x 10
##   latitude longitude `YYYY-MM-DD` daily_rain daily_rain_sour~ max_temp
##      <dbl>     <dbl> <date>            <dbl>            <dbl>    <dbl>
## 1    -27.5       135 2016-01-01          9.4               25     26.5
## 2    -27.5       135 2016-01-02          0                 25     36  
## 3    -27.5       135 2016-01-03          0                 25     36.5
## 4    -27.5       135 2016-01-04          0                 25     35.5
## 5    -27.5       135 2016-01-05          0                 25     35.5
## 6    -27.5       135 2016-01-06          0                 25     38  
## # ... with 4 more variables: max_temp_source <dbl>, min_temp <dbl>,
## #   min_temp_source <dbl>, metadata <chr>

And finally, plot the data.

silodata %>%
  mutate(date = `YYYY-MM-DD`) %>%
  select(date, `Rain, mm` = daily_rain, `Min temp, C` =min_temp, `Max temp, C` = max_temp) %>%
  gather(variable, value, -date) %>%
  ggplot() + 
    geom_line(aes(date, value, colour = variable)) + 
    xlab('') + ylab('') +
    mydarktheme

Related

comments powered by Disqus