-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.rmd
159 lines (112 loc) · 4.4 KB
/
README.rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
---
output:
github_document:
html_preview: true
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "tools/readme/README-",
out.width = "100%"
)
```
# kiwisR <img src="tools/readme/kiwisR_small.png" align="right" />
<!-- badges: start -->
[![R-CMD-check](https://github.com/rywhale/kiwisR/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rywhale/kiwisR/actions/workflows/R-CMD-check.yaml)
[![LICENSE](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/kiwisR)](https://cran.r-project.org/package=kiwisR) [![CRAN Download](https://cranlogs.r-pkg.org/badges/kiwisR?color=brightgreen)](https://CRAN.R-project.org/package=kiwisR)
<!-- badges: end -->
## Overview
A wrapper for querying [KISTERS WISKI databases](https://www.kisters.net/NA/products/wiski/) via the [KiWIS API](https://www.kisters.eu/water-weather-and-environment/). Users can toggle between various databases by specifying the `hub` argument. Currently, the default hubs are:
* _kisters_ : [KISTERS KiWIS Example Server](https://kiwis.kisters.de/KiWIS/)
* _swmc_ : [Ontario Surface Water Monitoring Centre](https://www.ontario.ca/page/surface-water-monitoring)
* _quinte_ : [Quinte Conservation Authority](https://www.quinteconservation.ca/en/index.aspx)
All data is returned as tidy [tibbles](https://CRAN.R-project.org/package=tibble).
## Installation
You can install ```kiwisR``` from CRAN:
```{r eval = FALSE}
install.packages('kiwisR')
```
To install the development version of ```kiwisR``` you first need to install ```devtools```.
```{r eval = FALSE}
if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github('rywhale/kiwisR')
```
Then load the package with
```{r eval = FALSE,message=FALSE,warning=FALSE}
library(kiwisR)
```
```{r eval=TRUE,message=FALSE,warning=FALSE, include=FALSE}
devtools::load_all()
```
## Usage
### Get Station Information
By default, ```ki_station_list()``` returns a tibble containing information for all available stations for the selected hub.
```{r}
# With swmc as the hub
ki_station_list(hub = 'swmc')
```
### Get Time Series Information
You can use the ```station_id``` column returned using ```ki_station_list()``` to figure out
which time series are available for a given station.
#### One Station
```{r}
# Single station_id
available_ts <- ki_timeseries_list(
hub = 'swmc',
station_id = "144659"
)
available_ts
```
#### Multiple Stations
If you provide a vector to ```station_id```, the returned tibble will have all the
available time series from _all_ stations. They can be differentiated using the
```station_name``` column.
```{r}
# Vector of station_ids
my_station_ids <- c("144659", "144342")
available_ts <- ki_timeseries_list(
hub = 'swmc',
station_id = my_station_ids
)
available_ts
```
### Get Time Series Values
You can now use the ```ts_id``` column in the tibble produced by ```ki_timeseries_list()``` to query values for
chosen time series.
By default this will return values for the past 24 hours. You can specify the dates you're interested in
by setting ```start_date``` and ```end_date```. These should be set as date strings with the format 'YYYY-mm-dd'.
You can pass either a single or multiple ```ts_id```(s).
#### One Time Series
```{r}
# Past 24 hours
my_values <- ki_timeseries_values(
hub = 'swmc',
ts_id = '966435042'
)
my_values
```
#### Multiple Time Series
```{r}
# Specified date, multiple time series
my_ts_ids <- c("1125831042","908195042")
my_values <- ki_timeseries_values(
hub = 'swmc',
ts_id = my_ts_ids,
start_date = "2015-08-28",
end_date = "2018-09-13"
)
my_values
```
## Using Other Hubs
You can use this package for a KiWIS hub not included in this list by feeding the location of the API service to the ```hub``` argument.
For instance:
If your URL looks like
`http://kiwis.kisters.de/KiWIS/KiWIS?datasource=0&service=kisters&type=queryServices&request=getrequestinfo`
specify the ```hub``` argument with
`http://kiwis.kisters.de/KiWIS/KiWIS?`
If you'd like to have a hub added to the defaults, please [Submit an Issue](https://github.com/rywhale/kiwisR/issues)
## Contributing
See [here](https://github.com/rywhale/kiwisR/blob/master/.github/CONTRIBUTING.md) if you'd like to contribute.