Skip to content

Commit

Permalink
getPoint provided character instead of numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarperpinan committed Jul 7, 2014
1 parent b154195 commit 8fb5741
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 47 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: meteoForecast
Type: Package
Title: Retrieve meteorological forecast from Meteogalicia and OpenMeteo services
Version: 0.30
Date: 2014-07-06
Version: 0.31
Date: 2014-07-07
Authors@R: c(person("Oscar", "Perpinan Lamigueiro", email="[email protected]", role=c('cre', 'aut')), person("Marcelo", "Almeida", email= "[email protected]", role='ctb'))
Description: Retrieve meteorological forecast from Meteogalicia and OpenMeteo services
URL: http://github.com/oscarperpinan/meteoForecast
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ importFrom(rjson,
fromJSON)

export('getPoint', 'getRaster',
'getRasterDay', 'getRasterDays',
'getRasterDays',
'getPointDays', 'getPointRuns',
'checkDays')
12 changes: 5 additions & 7 deletions R/getPoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ getPoint <- function(point, vars='swflx',
success <- try(suppressWarnings(download.file(completeURL, tmpfile, quiet=TRUE)), silent=TRUE)
if (class(success) == 'try-error')
stop('Data not found. Check the date and variables name.\nURL: ', completeURL)
z <- read.zoo(tmpfile, tz='UTC',
header=TRUE, sep=',', dec='.', fill=TRUE,
format='%Y-%m-%dT%H:%M:%SZ')

lat <- as.numeric(z$lat[1])
lon <- as.numeric(z$lon[1])
z <- z[, -c(1, 2)]
z <- read.csv(tmpfile)
idx <- as.POSIXct(z[,1], format='%Y-%m-%dT%H:%M:%SZ')
lat <- as.numeric(z[1, 2])
lon <- as.numeric(z[1, 3])
z <- zoo(z[, -c(1, 2, 3)], idx)

names(z) <- vars
attr(z, 'lat') <- lat
Expand Down
11 changes: 7 additions & 4 deletions R/getRaster.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ getRaster <-
function(var='swflx',
day=Sys.Date(), run='00',
frames='complete',
box, names, remote=TRUE,
box, names, remote=TRUE,
service='meteogalicia',
dataDir = '.',
...){

service <- match.arg(service, c('meteogalicia', 'openmeteo'))
Expand Down Expand Up @@ -95,9 +96,11 @@ getRaster <-
stop('Data not found. Check the date and variables name')
} else { ## Download Successful!
message('File(s) available at ', tempdir())
}
} ## End of Remote

} ## End of Remote
} else {
old <- setwd(dataDir)
on.exit(setwd(old))
}
## Read files
suppressWarnings(bNC <- stack(ncFile))
## Use frames with local files from meteogalicia
Expand Down
3 changes: 2 additions & 1 deletion R/getRasterDays.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ getRasterDays <- function(var = 'swflx',
lr <- lapply(days, FUN = function(d) {
try(getRaster(var, day = d,
run = '00', frames = 24,
remote = remote, ...))
remote = remote, dataDir = '.',
...))
})
isOK <- sapply(lr, FUN = function(x) class(x)!='try-error')
s <- stack(lr[isOK])
Expand Down
9 changes: 5 additions & 4 deletions man/getPoint.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ temporary folder (as defined by \code{tempdir()}). }
series with a column for each variable included in \code{vars}.

The time series returned by \code{getPoint} starts at 01UTC of
\code{day} if \code{run = '00'} or 13UTC if \code{run = '12'}, and
spans over 4 days (96 hours).
\code{day} if \code{run = '00'} or 13UTC if \code{run = '12'}. It
spans over 4 days (96 hours) if \code{run = '00'} or 84 hours if
\code{run = '12'}.

The time series returned by \code{getPointDays} starts at 01UTC of
\code{start} and finishes at 00UTC of \code{end + 1}. Each day
comprised in the time period is constructed with the forecast outputs
corresponding to that day. Therefore, only the first 24 values
obtained with \code{getPoint} are used for each day.
corresponding to the 00UTC run of that day. Therefore, only the first
24 values obtained with \code{getPoint} are used for each day.

The time series returned by \code{getPointRuns} starts at 01UTC of
\code{start} and finishes at 00UTC of \code{end + 1}. It has 4
Expand Down
42 changes: 18 additions & 24 deletions man/getRaster.Rd
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
\name{getRaster}
\alias{getRaster}
\alias{getRasterDay}
\alias{getRasterDays}
\alias{checkDays}
\encoding{UTF-8}
Expand All @@ -18,11 +17,8 @@

getRaster(var = "swflx", day = Sys.Date(), run = "00",
frames = 'complete', box, names,
remote = TRUE, service = "meteogalicia", ...)

getRasterDay(var = "swflx", day = Sys.Date(),
remote = TRUE, service = "meteogalicia",
dataDir = ".", ...)
remote = TRUE, service = "meteogalicia",
dataDir = ".", ...)

getRasterDays(var = "swflx", start = Sys.Date(), end,
remote = TRUE, dataDir = ".", ...)
Expand Down Expand Up @@ -51,7 +47,7 @@ checkDays(start, end, vars, remote = FALSE, service = 'meteogalicia',
(frames) to retrieve. If \code{frames = 'complete'}, the full set of
frames is downloaded. The meteogalicia service produces 96 hourly
forecasts (frames) with \code{run='00'} and 84 frames with
\code{run='84'}.}
\code{run='12'}.}

\item{box}{The bounding box. A \code{\link{Extent}} or an object that
can be coerced to that class with \code{\link{extent}}: a 2x2 matrix
Expand All @@ -61,7 +57,7 @@ checkDays(start, end, vars, remote = FALSE, service = 'meteogalicia',

\item{names}{Character. Names of the layers of the resulting
\code{RasterBrick}. If missing, a predefined vector is assigned the
a combination of day and hour.}
combination of day and hour.}

\item{remote}{Logical. If \code{TRUE} (default) data is downloaded
from the remote service. If \code{FALSE} the \code{RasterBrick} is
Expand All @@ -87,22 +83,18 @@ checkDays(start, end, vars, remote = FALSE, service = 'meteogalicia',
forecast.

\code{getRasterDays} uses \code{getRaster} to download the results
cast each day comprised between \code{start} and \code{end}, subset
the first 24 frames of each result, and bind them together to produce
a \code{RasterBrick}. Therefore, each frame of this \code{RasterBrick}
is a forecast for an hour of the day when the forecast was cast.

\code{getRasterDay} is a simple wrapper around \code{getRaster} that
downloads only the first frames of each run. It is implemented only
for \code{run = '00'} and \code{service = 'meteogalicia'}, so it
retrieves the first 24 frames corresponding to \code{day}.


\code{checkDays} explores a local folder for NetCDF files
corresponding to a time sequence. It returns a \code{Date} vector
comprising the days corresponding to the available files. If
\code{remote = FALSE} it only checks that \code{start} is after
2008-01-01 (when the historic data of MeteoGalicia begins.)
cast each day comprised between \code{start} and \code{end} using the
00UTC run. Then it subsets the first 24 frames of each result, and
binds them together to produce a \code{RasterBrick}. Therefore, each
frame of this \code{RasterBrick} is a forecast for an hour of the day
when the forecast was cast.

\code{checkDays} explores a local folder looking for NetCDF files
corresponding to a time sequence and a set of variables. It returns a
\code{Date} vector comprising the days with files available for the
requested variables. If \code{remote = TRUE} it only checks that
\code{start} is after 2008-01-01 (first date of the archived forecasts
of MeteoGalicia.)

}

Expand All @@ -123,6 +115,8 @@ checkDays(start, end, vars, remote = FALSE, service = 'meteogalicia',
\url{http://www.meteogalicia.es/web/modelos/threddsIndex.action}

\url{https://openmeteoforecast.org/wiki/Main_Page}

\url{https://openmeteoforecast.org/wiki/OPeNDAP_Server}
}

\author{
Expand Down
9 changes: 5 additions & 4 deletions man/meteo-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@

}

\details{
\code{getRaster}, \code{getRasterDay}, and \code{getRasterDays} get
data inside a bounding box and provide a multilayer raster data using
the \code{RasterBrick} class defined in the package \code{raster}.
\details{

\code{getRaster} and \code{getRasterDays} get data inside a bounding
box and provide a multilayer raster data using the \code{RasterBrick}
class defined in the package \code{raster}.

\code{getPoint}, \code{getPointDays}, and \code{getPointRuns} get data
for a certain location and produce a time series using the \code{zoo}
Expand Down

0 comments on commit 8fb5741

Please sign in to comment.