Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jobonaf committed Jul 9, 2015
1 parent 3cb4c19 commit 1a8dac1
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 16 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: pesco
Type: Package
Title: Data fusion for air quality data
Version: 0.2.4
Date: 2015-06-22
Version: 0.3.0
Date: 2015-07-09
Author: Lucia Paci, Giovanni Bonafe'
Maintainer: G.Bonafe' <[email protected]>
Imports: geoR, akima, fields, caTools, ncdf, timeDate, chron
Expand Down
18 changes: 18 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
Changes in pesco 0.3.0 [2015-07-09]
=====================================
* now prepare.obs requires pollutant specification

Changes in pesco 0.2.7 [2015-07-08]
=====================================
* in read.qaria changed BST to Africa/Algiers
* bug fixed in prepare.obs

Changes in pesco 0.2.6 [2015-07-01]
=====================================
* modified read.ncdf.arpaer

Changes in pesco 0.2.5 [2015-06-23]
=====================================
* bug fixed in qaria2long
* modified read.ncdf.arpaer

Changes in pesco 0.2.4 [2015-06-22]
=====================================
* bug fixed in read.sql
Expand Down
18 changes: 9 additions & 9 deletions R/prepare.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ prepare.elev <- function(elev,
}

## Observed data
prepare.obs <- function(obs.daily, day,
prepare.obs <- function(obs.daily, day, pollutant,
conc.min=10^-6) {
time <- sort(unique(as.POSIXct(as.character(obs.daily$Time),tz="Africa/Algiers")))
if(min(diff.POSIXt(time)) < as.difftime(1,units="days")) {
stop("Cannot deal with sub-daily data.")
}
out <- subset(obs.daily,
subset=(format(time,format="%Y-%m-%d")==
subset=(format(obs.daily$Time,format="%Y-%m-%d")==
format(as.POSIXct(day),format="%Y-%m-%d")))
out <- out[which(!is.na(out[,2])),]
out[,2] <- pmax(out[,2], conc.min)
rownames(out) <- 1:nrow(out)
out <- out[which(!is.na(out[,pollutant])),]
out[,pollutant] <- pmax(out[,pollutant], conc.min, na.rm=T)
if(nrow(out)>0) rownames(out) <- 1:nrow(out)
return(out)
}

Expand All @@ -113,7 +113,7 @@ prepare.day <- function(day,
verbose=FALSE) {
## select the required day from the observations
obs.day <- prepare.obs(obs.daily=obs.daily, day=day)
if(verbose) print(paste("Prepared observations for day ",day,sep=""))
if(verbose) cat(paste("prepare.day: prepared observations for day ",day,"\n",sep=""))

## get the coordinates of the stations with valid data
coords.pnt <- ll2utm(rlat=obs.day$Lat,
Expand All @@ -126,7 +126,7 @@ prepare.day <- function(day,
emis.day <- prepare.emis(emis.winter=emis.winter,
emis.summer=emis.summer,
day=day, x.pnt=x.pnt, y.pnt=y.pnt)
if(verbose) print(paste("Prepared emissions for day ",day,sep=""))
if(verbose) cat(paste("prepare.day: prepared emissions for day ",day,"\n",sep=""))

## get the coordinates of the reference grid
x.grd <- emis.summer$coords$x
Expand All @@ -137,7 +137,7 @@ prepare.day <- function(day,
ctm.day <- prepare.ctm(ctm.daily=ctm.daily, day=day,
x.pnt=x.pnt, y.pnt=y.pnt,
x.grd=x.grd, y.grd=y.grd)
if(verbose) print(paste("Prepared CTM concentrations for day ",day,sep=""))
if(verbose) cat(paste("prepare.day: prepared CTM concentrations for day ",day,"\n",sep=""))

## prepare elevation for the required day
if(is.null(elev)) {
Expand All @@ -146,7 +146,7 @@ prepare.day <- function(day,
elev.day <- prepare.elev(elev=elev,
x.pnt=x.pnt, y.pnt=y.pnt,
z.pnt=obs.day$Elev)
if(verbose) print(paste("Prepared elevation for day ",day,sep=""))
if(verbose) cat(paste("prepare.day: prepared elevation for day ",day,"\n",sep=""))
}

Out <- list(obs.day=obs.day,
Expand Down
10 changes: 7 additions & 3 deletions R/read.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ read.ncdf.arpaer <- function(con=NULL, pollutant="pm10", lev=1,
Time <- as.POSIXct(get.var.ncdf(nc,varid="Times"),
format="%Y-%m-%d_%H:%M:%S", tz=tz.in)
Time <- tz.change(x=Time,tz.in=tz.in,tz.out=tz.out)
value <- get.var.ncdf(nc,varid=pollutant)
opts <- c(pollutant, toupper(pollutant), tolower(pollutant))
vars <- names(nc$var)
pp <- intersect(opts, vars)
if(length(pp)==0) stop(paste(pollutant,"not found in",con))
value <- get.var.ncdf(nc,varid=pp)
if(length(dim(value))==4) {
value <- value[,,lev,]
} else if (length(dim(value))!=3) {
Expand Down Expand Up @@ -175,7 +179,7 @@ read.qaria <- function(file) {
} else {
strTime <- paste(strTime," 00:00",sep="")
}
Time <- as.POSIXct(strTime,tz="BST")
Time <- as.POSIXct(strTime,tz="Africa/Algiers")
out <- data.frame(Time=Time, Value=dat[,ncol(dat)])
names(out)[2] <- names(dat)[ncol(dat)]
return(out)
Expand Down Expand Up @@ -206,7 +210,7 @@ qaria2long <- function(datafiles,
if(is.null(codes)) {
code <- substr(datafiles[i],
rev(gregexpr("_",datafiles[i])[[1]])[1]+1,
rev(gregexpr("\\.",datafiles[i])[[1]][1]-1))
rev(gregexpr("\\.",datafiles[i])[[1]])[1]-1)
} else {
code <- codes[i]
}
Expand Down
3 changes: 2 additions & 1 deletion demo/daily.synthesis.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#' ## Demo: How to prepare daily data for PESCO
#' You can reproduce the following R code with
#' ```demo(daily.sinthesis)``` after loading package ```pesco```.
#' ```demo(daily.synthesis)``` after loading package ```pesco```.

## load package
require(pesco)
Expand Down Expand Up @@ -50,5 +50,6 @@ data(PM10.ctm)
## calculate daily averages
PM10.ctm.ave <- dailyCtm(PM10.ctm, statistic="mean")
rm(PM10.ctm)
library(fields)
filled.contour(PM10.ctm.ave$data[,,1],color.palette=tim.colors)

Binary file modified inst/doc/pesco.pdf
Binary file not shown.
4 changes: 3 additions & 1 deletion man/prepare.functions.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ prepare.emis(emis.winter, emis.summer, day,
prepare.elev(elev, x.pnt, y.pnt,
z.pnt = rep(NA,length(x.pnt)),
x.grd = NULL, y.grd = NULL)
prepare.obs(obs.daily, day, conc.min = 10^-6)
prepare.obs(obs.daily, day, pollutant,
conc.min = 10^-6)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
Expand All @@ -44,6 +45,7 @@ prepare.obs(obs.daily, day, conc.min = 10^-6)
\describe{
\item{coords}{coordinates, a list of 2 numeric vectors x and y}
\item{data}{numeric vector}}}
\item{pollutant}{name of the column with pollutant concentations}
\item{verbose}{logical; if \code{TRUE} some messages are given}
\item{x.pnt}{numeric vector of x coordinates of the stations}
\item{y.pnt}{numeric vector of y coordinates of the stations}
Expand Down
Binary file added tar/pesco_0.3.0.tar.gz
Binary file not shown.

0 comments on commit 1a8dac1

Please sign in to comment.