Dear Thiago,

Sorry for the late response.

It would seem that the problem is here:

*> r<-raster(cmorph$datancfile)*
*
*
I assume that *cmorph$datancfile *is a matrix. You can make a RasterLayer
this way, but its geo-reference is unlikely to be correct.

perhaps something like this will work (you need to adjust the values for
xmin, xmax, ymin, and ymax):

r <- raster(ncol = 126, nrow=98, xmin=0, xmax=10, ymin=0, ymax=10)
r <- setValues(r, as.vector(*cmorph$datancfile))*
# or perhaps
# r <- setValues(r, as.vector(t (*cmorph$datancfile)))*
*
*
*Best, Robert*
*
*

On Mon, Jul 5, 2010 at 7:13 AM, Thiago Veloso <thi_vel...@yahoo.com.br>wrote:

>   Dear Dr. Hijmans,
>
>   Thank you very much for the advice. According to the poor results I
> received from interpolating gauge data, your approach really seems to be
> more promising.
>
>   I'm trying to perform the sattelite data interpolation as you suggested.
> However, I'm facing an error. My satellite data consists of thousands of raw
> binary hourly files which I converted to netcdf monthly values and loaded
> into a variable:
>
> *>summary(cmorph)*
> *           Length Class  Mode   *
> *lonncfile    126  -none- numeric*
> *latncfile     98  -none- numeric*
> *datancfile 12348  -none- numeric*
> *
> *
>   The 'cmorph' variable contains rainfall estimates to the southern most
> Brazilian state for january 2009. Everything goes fine when I create the
> raster object and extract the coordinates. The 'gauge' variable contains
> lon, lat and rainfall station values for the same january 2009:
>
> *> r<-raster(cmorph$datancfile)*
> *> res<-xyValues(r,gauge[,1:2],method='bilinear')*
>
>   However, when trying to plot:
>
> *> plot(res,gauge[,3])*
> *Error in plot.window(...) : need finite 'xlim' values*
> *In addition: Warning messages:*
> *1: In min(x) : no non-missing arguments to min; returning Inf*
> *2: In max(x) : no non-missing arguments to max; returning -Inf*
>
>   This error is certainly caused by the contents of 'res' variable:
>
> > res
>   [1] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> NA NA
>  [26] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> NA NA
>  [51] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> NA NA
>  [76] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> NA NA
> [101] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> NA NA
> [126] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
>
>   Could you figure out what I'm doing wrong??
>
>   Best regards,
>
>   Thiago Veloso.
>
> --- On *Tue, 29/6/10, Robert J. Hijmans <r.hijm...@gmail.com>* wrote:
>
>
> From: Robert J. Hijmans <r.hijm...@gmail.com>
>
> Subject: Re: [R-sig-Geo] Spatial data interpolation on R
> To: "Thiago Veloso" <thi_vel...@yahoo.com.br>
> Cc: r-sig-geo@stat.math.ethz.ch
> Date: Tuesday, 29 June, 2010, 15:15
>
>
> Thiago,
>
> I think a better approach would be to estimate the value for the sat
> images at the stations' locations; and not the other way around, as
> your are proposing.
>
> A simple way to do that is bilinear interpolation of the sat image
> values for the weather station locations.
>
> If 'xyv' is your lon/lat/prec matrix and 'f' is a filename for one of
> your sat images.
>
> library(raster)
> r <- raster(f)
> res <- xyValues(r, xyv[,1:2], method='bilinear')
> plot(res, xyv[,3])
>
>
> ..... and now analyze the difference between res and xyv[,3]  data
> taking spatial autocorrelation into account
>
>
>
> Nevertheless, if you insist on interpolating the weather station data,
> you could do that with a spline
>
> library(fields)
> tps <- Tps(xyv[,1:2], xyv[,3])
> p <- raster(r)
> p <- interpolate(p, tps)
> plot(p, r)
>
>
> In the end, the best approach to obtaining a raster of the rainfall
> data, if that is what you are after, would probably be a hybrid where
> the sat image is use as an independent variable (covariate) in the
> spline (or other interpolation method).
>
> Robert
>
>
> On Tue, Jun 29, 2010 at 8:59 AM, Don MacQueen 
> <m...@llnl.gov<http://mc/compose?to=m...@llnl.gov>>
> wrote:
> > If you are willing to do simple interpolation, i.e., ignoring any spatial
> > correlation, you could look at the interp() function, which is in the
> akima
> > package.  Even if you need to incorporate spatial correlation, starting
> with
> > the interp() function would probably serve as a good way to get started
> > learning R. The help page for interp() has some examples.
> >
> > Here's an excerpt from the help page for the interp() function:
> >
> > interp                  package:akima                  R Documentation
> >
> > Gridded Bivariate Interpolation for Irregular Data
> >
> > Description:
> >
> >     These functions implement bivariate interpolation onto a grid for
> >     irregularly spaced input data.  Bilinear or bicubic spline
> >     interpolation is applied using different versions of algorithms
> >     from Akima.
> >
> >
> > Install the akima package using the R console GUI (Mac or Windows) or the
> > install.packages() function (linux).
> >
> > Then there's the question of coordinate systems. interp() assumes
> cartesian
> > coordinates, but lat/long is not cartesian. If your site is too large,
> you
> > shouldn't ignore this, so you will have to learn how to project from
> > lat/long to UTM or other appropriate local coordinate  system. For this,
> I
> > use the spTransform() function in the rgdal package. Looking on the CRAN
> > website, it appears there is a Windows binary for rgdal; for the other
> > platforms (I use Mac), it can be more challenging. Converting your data
> into
> > a "spatial" class object, so that it can be projected, will be a
> challenge
> > at first.
> >
> > Gettng the book that Mark Connolly mentioned would help a lot.
> >
> > -Don
> >
> >
> > At 10:20 AM -0700 6/2/10, Thiago Veloso wrote:
> >>
> >> Content-Type: text/plain
> >> Content-Disposition: inline
> >> Content-length: 937
> >>
> >> Dear R colleagues!
> >>  I´d like to start my participation in this list by describing my
> current
> >> problem: inside my area of study I need to compare precipitation data
> from
> >> two different sources: both station (total of 86) and a grid (at 8km) of
> >> satellite estimates.
> >>  My specific objective is to interpolate the station data into a regular
> >> grid in the same resolution of the satellite estimates, preferentially
> >> having control of the spatial domain (lat/lon coordinates). As far as I
> know
> >> this is the correct way of making such comparison.
> >>  Could anybody please point directions to perform this task using R? I´m
> >> such a beginner that I don´t even know if
> >>  there´s a package designed to create regular grids from "random" data
> >> (interpolating by kriging or other technique). Usage examples would be
> >> welcomed as well!
> >> Thanks in advance,
> >>  Thiago.
> >>
> >>
> >>
> >>        [[alternative HTML version deleted]]
> >>
> >>
> >> _______________________________________________
> >> R-sig-Geo mailing list
> >> R-sig-Geo@stat.math.ethz.ch<http://mc/compose?to=r-sig-...@stat.math.ethz.ch>
> >> https://*stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
> >
> > --
> > --------------------------------------
> > Don MacQueen
> > Environmental Protection Department
> > Lawrence Livermore National Laboratory
> > Livermore, CA, USA
> > 925-423-1062
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@stat.math.ethz.ch<http://mc/compose?to=r-sig-...@stat.math.ethz.ch>
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> >
>
>
>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Reply via email to