luftlyr_get.R 2.79 KB
Newer Older
1
#' luftlyr_get_data
2

3
#' luftlyr_get_data
4
#' @param x request object
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
5
6
#' @param username username
#' @param password password
7
8
9
10
#' @keywords luftlyr
#' @export
#' @examples
#' \dontrun{
11
#' luftlyr_get_data()
12
#' }
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
13
luftlyr_get_data <- function(x,username,password) {
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
14
  db <- luftkvalr::luftkvalr()
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
15
  db$start(username,password)
16
17
  tmp_st <- db$GetAQStations(stationIDs=x$stationObj$station_id,west=x$stationObj$west,south=x$stationObj$south,east=x$stationObj$east,north=x$stationObj$north)
  tmp_ts <- db$GetAQTimeseries(stationIDs=unique(tmp_st$ST_ID),componentName=x$elementObj$element_id)
18
  if (nrow(tmp_st)>0) {
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
19

20
     res <- db$GetAQData(stationIDs=unique(tmp_st$ST_ID),
21
                      timeSeriesIDs=tmp_ts$TS_ID,
22
23
                      fromDateTime=as.character(x$timeObj$fromDateTime()+3600), #UTC+1, no summer time
                      toDateTime=as.character(x$timeObj$toDateTime()+3600))     #UTC+1, no summer time
24
25
26
27
28
     db$stop()
     #Negative values
     res[which(res$TE_VALUE<0),"TE_VALUE"]<-NA
     return(res)
  } else stop("number of stations is null")
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
29
}
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
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
#' luftlyr_get_qa

#' luftlyr_get_qa
#' @param x request object
#' @param username username
#' @param password password
#' @keywords luftlyr
#' @export
#' @examples
#' \dontrun{
#' luftlyr_get_qa()
#' }
luftlyr_get_qa <- function(x,username,password) {
  db <- luftkvalr::luftkvalr()
  db$start(username,password)
  tmp_st <- db$GetAQStations(stationIDs=x$stationObj$station_id,west=x$stationObj$west,south=x$stationObj$south,east=x$stationObj$east,north=x$stationObj$north)
  tmp_ts <- db$GetAQTimeseries(stationIDs=unique(tmp_st$ST_ID),componentName=x$elementObj$element_id)
  if (nrow(tmp_st)>0) {

     res <- db$GetAQqaData(stationIDs=unique(tmp_st$ST_ID),
                      timeSeriesIDs=tmp_ts$TS_ID,
                      fromDateTime=as.character(x$timeObj$fromDateTime()+3600), #UTC+1, no summer time
                      toDateTime=as.character(x$timeObj$toDateTime()+3600))     #UTC+1, no summer time
     db$stop()
     return(res)
  } else stop("number of stations is null")
}

59
#' luftlyr_get_meta
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
60
61
62

#' luftlyr_getmeta
#' @param x request object
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
63
64
#' @param username username
#' @param password password
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
65
66
67
68
#' @keywords luftlyr
#' @export
#' @examples
#' \dontrun{
69
#' luftlyr_get_meta()
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
70
#' }
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
71
luftlyr_get_meta <- function(x,username,password) {
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
72
  db <- luftkvalr::luftkvalr()
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
73
  db$start(username,password)
74
  tmp_st <- db$GetAQStations(stationIDs=x$stationObj$station_id,west=x$stationObj$west,south=x$stationObj$south,east=x$stationObj$east,north=x$stationObj$north)
75
  if (nrow(tmp_st)>0) {
76
    tmp_ts <- db$GetAQTimeseries(stationIDs=unique(tmp_st$ST_ID),componentName=x$elementObj$element_id)
77
78
79
80
    db$stop()
    colnames(tmp_ts) <- c("ID","NAME","ALT","LAT","LON","TS_ID","CO_NAME","TS_Z1","TS_Z2")
    return(tmp_ts[,c(1:5,7)])
  } else stop("number of stations is null")
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
81
}