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

typo

parent 7f04649d
#' era5spoblobs
#'
#' era5spoblobs
#' @param path_metadata path or url of metadata
#' @param path_metadata_url path or url of metadata_url
#' @keywords era5spoblobs
#' @export
#' @examples
#' \dontrun{
#' era5spoblobs(path)
#' }
era5spoblobs <- function(path_metadata,path_metadata_url){
era5spoblobs_object(path_metadata,path_metadata_url)
}
era5spoblobs_object <- function(path_metadata,path_metadata_url){
# load metadatas
metadata <- data.table::fread(path_metadata)
metadata_url <- data.table::fread(path_metadata_url)
object <- local({
meta <- function(stationIDs=NULL,west=NULL,south=NULL,east=NULL,north=NULL,elementIDs=NULL){
if (!is.null(stationIDs) && (is.null(north) && is.null(south) && is.null(east) && is.null(west)) ) {
res <- unique(metadata[metadata$AirQualityStationEoICode %in% stationIDs, ])
} else if (is.null(stationIDs) && (!is.null(north) && !is.null(south) && !is.null(east) && !is.null(west)) ) {
res <- unique(metadata[(as.numeric(metadata$lon)>=west & as.numeric(metadata$lon)<=east & as.numeric(metadata$lat)>=south & as.numeric(metadata$lat)<=north) , ])
} else res <- metadata
if (!is.null(elementIDs)){
res <- res[res$AirPollutant %in% elementIDs,]
}
return(res)
}
ts <- function(fromDateTime,toDateTime,stationIDs,elementIDs,levelIDs){
# get the years and months between start_date and end_date
date_seq <- as.POSIXlt(seq(as.POSIXlt(fromDateTime,tz="UTC"),as.POSIXlt(toDateTime,tz="UTC"),by="month"))
years_months <- unique(paste0(get_year(date_seq,CHAR=TRUE),"_",get_month(date_seq,CHAR=TRUE),".csv"))
metadata_target <- unique(metadata_url[metadata_url$station %in% stationIDs & metadata_url$variable %in% elementIDs & metadata_url$pressure_level %in% levelIDs & grepl(paste(years_months,collapse="|"),metadata_url$url), ])
res = data.table::data.table(date = as.POSIXct(integer(0),tz="UTC"), values = numeric(0),variable = character(0),level = character(0),unit = character(0),
SamplingPoint = character(0), station = character(0),
stringsAsFactors=FALSE)
# Access and join SPO timeseries
for (i in 1:nrow(metadata_target)){
tmp <- data.table::fread(metadata_target$url[i])
tmp$SamplingPoint <- rep(metadata_target$spo[i],nrow(tmp))
tmp$station <- rep(metadata_target$station[i],nrow(tmp))
res <- rbind(res,tmp)
}
return(res)
}
environment()
})
lockEnvironment(object, TRUE)
structure(object, class=c("era5spoblobs", class(object)))
}
#' era5spoblobs
#'
#' era5spoblobs
#' @param path_metadata path or url of metadata
#' @param path_metadata_url path or url of metadata_url
#' @keywords era5spoblobs
#' @export
#' @examples
#' \dontrun{
#' era5spoblobs(path)
#' }
era5spoblobs <- function(path_metadata,path_metadata_url){
era5spoblobs_object(path_metadata,path_metadata_url)
}
era5spoblobs_object <- function(path_metadata,path_metadata_url){
# load metadatas
metadata <- data.table::fread(path_metadata)
metadata_url <- data.table::fread(path_metadata_url)
object <- local({
meta <- function(stationIDs=NULL,west=NULL,south=NULL,east=NULL,north=NULL,elementIDs=NULL){
if (!is.null(stationIDs) && (is.null(north) && is.null(south) && is.null(east) && is.null(west)) ) {
res <- unique(metadata[metadata$AirQualityStationEoICode %in% stationIDs, ])
} else if (is.null(stationIDs) && (!is.null(north) && !is.null(south) && !is.null(east) && !is.null(west)) ) {
res <- unique(metadata[(as.numeric(metadata$lon)>=west & as.numeric(metadata$lon)<=east & as.numeric(metadata$lat)>=south & as.numeric(metadata$lat)<=north) , ])
} else res <- metadata
if (!is.null(elementIDs)){
res <- res[res$AirPollutant %in% elementIDs,]
}
return(res)
}
ts <- function(fromDateTime,toDateTime,stationIDs,elementIDs,levelIDs){
# get the years and months between start_date and end_date
date_seq <- as.POSIXlt(seq(as.POSIXlt(fromDateTime,tz="UTC"),as.POSIXlt(toDateTime,tz="UTC"),by="month"))
years_months <- unique(paste0(get_year(date_seq,CHAR=TRUE),"_",get_month(date_seq,CHAR=TRUE),".csv"))
metadata_target <- unique(metadata_url[metadata_url$station %in% stationIDs & metadata_url$variable %in% elementIDs & metadata_url$pressure_level %in% levelIDs & grepl(paste(years_months,collapse="|"),metadata_url$url), ])
res = data.table::data.table(date = as.POSIXct(integer(0),tz="UTC"), values = numeric(0),variable = character(0),level = character(0),unit = character(0),
SamplingPoint = character(0), station = character(0),
stringsAsFactors=FALSE)
# Access and join SPO timeseries
for (i in 1:nrow(metadata_target)){
tmp <- data.table::fread(metadata_target$url[i])
tmp$SamplingPoint <- rep(metadata_target$spo[i],nrow(tmp))
tmp$station <- rep(metadata_target$station[i],nrow(tmp))
res <- rbind(res,tmp)
}
return(res)
}
environment()
})
lockEnvironment(object, TRUE)
structure(object, class=c("era5spoblobs", class(object)))
}
......@@ -13,7 +13,7 @@ cd ~/
# if windows cd ~/Documents
mkdir tmp
cd tmp
git clone git@git.nilu.no:blob/core-client/era5spoblobs.git
git clone git@git.nilu.no:aqdl/blobs/core-client/era5spoblobs.git
```
In R, write:
......
Supports Markdown
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