Choosing a clifro Station

Blake Seers

2017-10-05

Introduction

Choosing clifro stations is made easy with the single cf_find_station function. This function is all that is required to find clifro stations. This function is equivalent to conducting the same search on the find stations page when conducting a query online at CliFlo, except without some of the errors and bugs. This means that the searches and the types of searches possible are exactly the same however, clifro extends functionality to exploring the spatial nature of stations via KML files that can be opened by Google Earth(TM), or plotting directly in R. This is the main advantage in searching for stations using clifro as locating suitable stations on a map is generally the preferred search tool.

There are four possible types of searches:

For each of these searches either all, open or closed stations may be returned and these searches also may only return stations where given datatypes are available. The primary goal in searching for stations is to find the unique station agent number required to create a cfStation object. This vignette details the various search options in clifro and ways to find these requisite agent numbers, primarily by way of example.

Ignoring datatypes

The following examples detail how to use the cf_find_station search function ignoring any datatypes.

Return all stations within a region

This broad search returns all, open or closed stations within one of the 29 preselected New Zealand regions (note that stations can belong to more than one region). The search = "region" argument must be added to the cf_find_station function to conduct these searches. If the region is unknown then the search argument may be missing which brings up an interactive menu of the 29 regions for the user to select (cf_find_station(search = "region")), otherwise partial matching is used.

# Partial match for the Queenstown region
open.queenstown.stations = cf_find_station("queen", search = "region")

Typing open.queenstown.stations into R will then return all the 220 open Queenstown stations. This is clearly a burden to choose stations based on a large list of numbers hence plotting them on a map (covered below) to assess their spatial extent will make this task much easier.

Conducting this same search on CliFlo returns 476 stations where some of these ‘open’ stations haven’t had any data input since November 2001. If these stations are of interest then add the status = "all" argument to the cf_find_station function call.

Return all stations within the vicinity of a given location

This location based search is conducted by including the search = "latlong" argument to the cf_find_station function. There are three parameters needed for this search; latitude, longitude and radius (kilometres). Just like any other function in R, if these arguments aren’t named then the order matters and should be written in the order specified above. The latitude and longitude must be given in decimal degrees.

We are (still) interested in finding all open stations around the small town of Takaka. From GeoHack we can see that the latitude is -40.85 and the longitude is 172.8. We are interested in all open stations within a 10km radius of the main township.

takaka.town.st = cf_find_station(lat = -40.85, long = 172.8, rad = 10, search = "latlong")
takaka.town.st[, -c(8, 9)]
##                   name network agent      start        end open distance
## 1 Takaka, Kotinga Road  F02882  3788 1970-08-01 2015-03-01 TRUE      2.6
## 2        Takaka Pohara  F02884  3790 1986-07-01 2015-03-01 TRUE      5.7
## 3           Takaka Ews  F02885 23849 2002-04-30 2015-03-01 TRUE      1.6
# We may rather order the stations by distance from the township
takaka.town.st[order(takaka.town.st$distance), -c(8, 9)]
##                   name network agent      start        end open distance
## 3           Takaka Ews  F02885 23849 2002-04-30 2015-03-01 TRUE      1.6
## 1 Takaka, Kotinga Road  F02882  3788 1970-08-01 2015-03-01 TRUE      2.6
## 2        Takaka Pohara  F02884  3790 1986-07-01 2015-03-01 TRUE      5.7

Searches based on datatypes

All the above searches did not include a datatype therefore they ignore the datatypes available at these stations. Imagine we are looking for hourly rain data at an open station in Takaka (using any of the aforementioned searches), we would need to include the hourly rain datatype in the search for it to return a suitable station.

Note

Unless the Reefton EWS station is the only CliFlo station of interest, the user will need a CliFlo account to get data from other stations.

# Create a clifro datatype for hourly rain
hourly.rain.dt = cf_datatype(3, 1, 2)
hourly.rain.dt
##           dt.name              dt.type dt.options dt.combo
## dt1 Precipitation Rain (fixed periods)   [Hourly]
# Conduct the search
cf_find_station("takaka", datatype = hourly.rain.dt)
##          name network agent      start        end open distance       lat      lon
## 1) Takaka Ews  F02885 23849 2002-06-02 2015-01-30 TRUE        0 -40.86364 172.8057

This tells us that the only open station in Takaka where hourly rain data is available is at the Takaka Ews station.

More than one search at a time

Since the cf_find_station function returns cfStation objects, any of these methods work on objects created from the cf_station function (see the working with clifro stations vignette for more details). We can conduct two or more seaches at a time using the addition sign, just like we did for cfDatatypes (see the choose datatypes vignette).

We would like to return all open stations within a 10km radius of the Takaka township in the South Island, and the open stations in Kaitaia, in the North Island that collect hourly rain data.

my.composite.search = takaka.town.st + cf_find_station("kaitaia", 
                                                       search = "region", 
                                                       datatype = hourly.rain.dt)
my.composite.search
##                       name network agent      start        end open
## 1)        Kaitaia Aero Ews  A53026 18183 2000-06-15 2015-03-03 TRUE
## 2)            Trounson Cws  A53762 37131 2009-06-04 2015-03-03 TRUE
## 3)             Kaikohe Aws  A53487  1134 1985-11-14 2015-03-02 TRUE
## 4)             Purerua Aws  A54101  1196 1995-01-01 2015-03-02 TRUE
## 5)         Cape Reinga Aws  A42462  1002 1995-01-01 2015-03-02 TRUE
## 6)  Kerikeri Aerodrome Aws  A53295 37258 2008-06-26 2015-03-02 TRUE
## 7)    Takaka, Kotinga Road  F02882  3788 1970-08-01 2015-03-01 TRUE
## 8)           Takaka Pohara  F02884  3790 1986-07-01 2015-03-01 TRUE
## 9)              Takaka Ews  F02885 23849 2002-04-30 2015-03-01 TRUE
## 10)            Kaitaia Ews  A53127 17067 1998-12-17 2015-02-25 TRUE
## 11)           Kerikeri Ews  A53191  1056 2002-06-28 2015-02-14 TRUE
## 12)       Dargaville 2 Ews  A53987 25119 2003-10-30 2015-02-13 TRUE
##     distance       lat      lon
## 1)       0.0 -35.06770 173.2874
## 2)       0.0 -35.72035 173.6515
## 3)       0.0 -35.42400 173.8220
## 4)       0.0 -35.12900 174.0150
## 5)       0.0 -34.43200 172.6820
## 6)       0.0 -35.26200 173.9110
## 7)       2.6 -40.87200 172.8090
## 8)       5.7 -40.84500 172.8670
## 9)       1.6 -40.86364 172.8057
## 10)      0.0 -35.13500 173.2620
## 11)      0.0 -35.18300 173.9260
## 12)      0.0 -35.93145 173.8532
# How long have these stations been open for?
transform(my.composite.search, ndays = round(end - start))[, c(1, 10)]
##                      name      ndays
## 1        Kaitaia Aero Ews  5374 days
## 2            Trounson Cws  2098 days
## 3             Kaikohe Aws 10700 days
## 4             Purerua Aws  7365 days
## 5         Cape Reinga Aws  7365 days
## 6  Kerikeri Aerodrome Aws  2440 days
## 7    Takaka, Kotinga Road 16283 days
## 8           Takaka Pohara 10470 days
## 9              Takaka Ews  4688 days
## 10            Kaitaia Ews  5914 days
## 11           Kerikeri Ews  4614 days
## 12       Dargaville 2 Ews  4124 days

So where are these stations?

Up until now there probably hasn’t been any good reason to choose clifro to search for stations instead of the ‘Choose Stations’ form on CliFlo. However, the real advantage of using clifro is to visualise the station locations on a map by returning a KML file, particularly when there are lots of stations returned by the search. This Keyhole Markup Language (KML) is an XML-based language provided by Google(TM) for defining the graphic display of spatial data in applications such as Google Earth(TM) and Google Maps(TM).

To return the stations as a KML file simply use the cf_save_kml function on any cfStation object. The cf_find_station function returns cfStation objects therefore it’s very easy to plot these on a map. To assess the geographic extent of the Auckland stations we can return a KML file from the search and open it using our preferred KML-friendly software.

# First, search for the stations
all.auckland.st = cf_find_station("auckland", search = "region", status = "all")

Now all.auckland.st contains all the 522 Auckland stations where data have been recorded on CliFlo.

# Then save these as a KML
cf_save_kml(all.auckland.st, file_name = "all_auckland_stations")

The green markers represent the open stations and the red markers indicate closed stations. The resulting KML file is saved to the current R session’s working directory by default. Have a look at the clifro station vignette for more methods and plotting of cfStation objects.

auckland stations

auckland stations

Note on the left of the map, the cf_save_kml function has organised the stations into ‘open’ and ‘closed’ stations so removing all the open/closed stations is easily done.