Maintenance is scheduled between 16:00 and 23:59 CEST (14:00 and 21:59 UTC) on Thursday 2021-09-30. The system may be unavailable at any time during this timeframe. Please plan accordingly.

Commit a34b8a27 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

first commit

parents
Package: data.synthaq.oslo10.seed123
Type: Package
Version: 0.0.1
Authors@R: c(person("Jean-Marie", "Lepioufle", , "jml@nilu.no", role=c("aut","cre")))
Title: data.synthaq.oslo10.seed123
Description: Synthetic data of hourly concentration of NO2 in Oslo.
The package gather NO2 synthetic observations of 10 stations in Oslo from 2015 to 2018.
The data has been generated with the R-package aqoslogen.
Depends:
R (>= 3.2.3)
Imports:
dplyr,
tibble
Suggests:
knitr
License: GPL-3
Encoding: UTF-8
VignetteBuilder: knitr
LazyData: false
RoxygenNote: 6.1.1
# Generated by roxygen2: do not edit by hand
export(get_short_data)
export(get_short_meta_station)
importFrom(dplyr,"%>%")
importFrom(dplyr,filter)
importFrom(dplyr,mutate)
importFrom(dplyr,select)
#' aqoslosynth
#'
#' Synthetic data of hourly concentration of NO2 at the 10 monitoring stations in Oslo from 2015/01/01 00:00:00 to 2018/12/31 23:00:00
#' The data has been generated by using the R-package aqoslogen.
#' @docType data
#' @name aqoslosynth
#' @format A rda file
#' @keywords data.synthaq.oslo10.seed123
#' @source https://nilu.no
NULL
#' luft_meta
#'
#' luft_meta provides the metadata about hourly NO2 observations of 10 stations in Oslo from NILU luftkval database.
#'
#' @docType data
#' @name luft_meta
#' @format A rda file
#' @keywords data.synthaq.oslo10.seed123
#' @references NILU
#' @source https://www.nilu.no
NULL
#' get_short_data
#' get_short_data
#' @param stations station ids
#' @param referencetimeFrom referencetimeFrom
#' @param referencetimeTo referencetimeTo
#' @param timeResolution timeResolution
#' @param elements elements
#' @keywords data.synthaq.oslo10.seed123
#' @export
get_short_data <- function(stations=NULL,referencetimeFrom=NULL,referencetimeTo=NULL,timeResolution=NULL,elements=NULL) {
res <- short_data_init()
if (!is.null(stations) && !is.null(referencetimeFrom) && !is.null(referencetimeTo) && !is.null(timeResolution) && !is.null(elements)) {
res <- build_data_df(station=stations,referencetimeFrom=referencetimeFrom,referencetimeTo=referencetimeTo,timeResolution=timeResolution,element=elements)
}
res <- tibble::as_tibble(res)
return(res)
}
build_data_df <- function(station,referencetimeFrom,referencetimeTo,timeResolution,element){
tr_file <- switch(timeResolution,
#"yearly" = "yly",
#"monthly" = "mly",
#"daily" = "dly",
"hourly" = "hourly",
stop("no data or not taken into account yet"))
path <- normalizePath(file.path(.libPaths()[1],"data.luftkval.oslo10","data","aqoslosynth.rda"),mustWork=FALSE)
# load the timeseries
ld <- try(load(path),silent=TRUE)
if (!inherits(ld,"try-error")) {
tmp <- get("aqoslosynth",envir=environment())
# build the results
if (!is.null(element) ) {
res <- tmp %>% filter(date>=as.POSIXct(referencetimeFrom,tz="UTC"),date<=as.POSIXct(referencetimeTo,tz="UTC"),ID %in% station,CO_NAME %in% element) %>% select(date,ID,CO_NAME,timeResolution,unit,value)
} else {
res <- short_data_init()
}
names(res) <- c("date","ID","CO_NAME","timeResolution","unit","value")
rm(tmp)
} else {
res <- short_data_init()
}
return(res)
}
short_data_init <- function(){
df <- data.frame(date = character(0),
ID = character(0),
CO_NAME = character(0),
timeResolution = character(0),
unit = character(0),
value = numeric(0)
)
return(df)
}
#' get_short_meta_station
#' get_short_meta_station
#' @param stations station ids
#' @param west west
#' @param south south
#' @param east east
#' @param north north
#' @keywords data.eimetr
#' @export
get_short_meta_station <- function(stations=NULL,west=NULL,south=NULL,east=NULL,north=NULL) {
metadata_file <- "luft_meta-no2-oslo"
metadata_file_rda <- paste0(metadata_file,".rda")
path <- try(normalizePath(file.path(.libPaths()[1],"data.synthaq.oslo10.seed123","data",metadata_file_rda),mustWork=TRUE))
# load the metadta
ld <- try(load(path),silent=TRUE)
if (!inherits(ld,"try-error")) {
tmp <- get("luft_meta",envir=environment())
# build the results
if (!is.null(stations)) {
res <- tmp %>% filter(ID %in% stations) %>% select(ID,LAT,LON,ALT,NAME)
} else if (!is.null(west) && !is.null(south) && !is.null(east) && !is.null(north) ) {
res <- tmp %>% filter(LAT>=south,LAT<=north,LON>=west,LON<=east) %>% select(ID,LAT,LON,ALT,NAME)
}
res <- unique(res)
rm(tmp)
} else {
res <- data.frame(ID = character(0),
LAT = numeric(0),
LON = numeric(0),
ALT = numeric(0),
NAME = character(0),
CO_NAME = character(0))
}
res <- tibble::as_tibble(res)
return(res)
}
#' @importFrom dplyr %>% select filter mutate
NULL
tmp <- aqoslogen::simple_concentration_on_stations(from="2015/01/01 00:00:00",to="2018/12/31 23:00:00",timeResolution="hourly",
max_mean_emission=60,spatial_range_normal=500,
max_mean_advection_intensity=0.1,max_mean_advection_degree=360,
seed=123)
target <- c("NO2_7","NO2_464", "NO2_827", "NO2_665", "NO2_9", "NO2_11", "NO2_163", "NO2_504","NO2_809")
tmp <- friendlyts::dfts(tbl_fts=tmp,timeResolution="hourly",tzone="UTC")
tmp <- tibble::as_tibble(dplyr::select(tmp,c("date",target)))
names(tmp) <- c("date","7","464", "827", "665", "9", "11", "163", "504","809")
# gather
df <- tmp %>% tidyr::gather("ID", "value", -"date")
aqoslosynth <- dplyr::bind_cols(df,CO_NAME=rep("NO2",nrow(df)),unit=rep("ug/m3",nrow(df)),timeResolution=rep("hourly",nrow(df)),)
save(aqoslosynth,file="aqoslosynth.rda",compress="xz")
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{aqoslosynth}
\alias{aqoslosynth}
\title{aqoslosynth}
\format{A rda file}
\source{
https://nilu.no
}
\description{
Synthetic data of hourly concentration of NO2 at the 10 monitoring stations in Oslo from 2015/01/01 00:00:00 to 2018/12/31 23:00:00
The data has been generated by using the R-package aqoslogen.
}
\keyword{data.synthaq.oslo10.seed123}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_data.R
\name{get_short_data}
\alias{get_short_data}
\title{get_short_data
get_short_data}
\usage{
get_short_data(stations = NULL, referencetimeFrom = NULL,
referencetimeTo = NULL, timeResolution = NULL, elements = NULL)
}
\arguments{
\item{stations}{station ids}
\item{referencetimeFrom}{referencetimeFrom}
\item{referencetimeTo}{referencetimeTo}
\item{timeResolution}{timeResolution}
\item{elements}{elements}
}
\description{
get_short_data
get_short_data
}
\keyword{data.synthaq.oslo10.seed123}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_meta.R
\name{get_short_meta_station}
\alias{get_short_meta_station}
\title{get_short_meta_station
get_short_meta_station}
\usage{
get_short_meta_station(stations = NULL, west = NULL, south = NULL,
east = NULL, north = NULL)
}
\arguments{
\item{stations}{station ids}
\item{west}{west}
\item{south}{south}
\item{east}{east}
\item{north}{north}
}
\description{
get_short_meta_station
get_short_meta_station
}
\keyword{data.eimetr}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{luft_meta}
\alias{luft_meta}
\title{luft_meta}
\format{A rda file}
\source{
https://www.nilu.no
}
\description{
luft_meta provides the metadata about hourly NO2 observations of 10 stations in Oslo from NILU luftkval database.
}
\references{
NILU
}
\keyword{data.synthaq.oslo10.seed123}
---
title: "get_data"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{get_data}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r setup, include = FALSE}
library("data.synthaq.oslo10.seed123")
knitr::opts_chunk$set(collapse = T, comment = "#>")
```
## Get easily data
```R
tmp <- data.synthaq.oslo10.seed123::get_short_meta_station(stations = c("7","464", "827", "665", "9", "11", "163", "504","809"))
tmp <- data.synthaq.oslo10.seed123::get_short_data(stations= c("7","464", "827", "665", "9", "11", "163", "504","809"),referencetimeFrom="2016/03/01 02:00:00",referencetimeTo="2016/03/01 09:00:00",timeResolution="hourly",elements=c("NO2"))
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment