Hi everybody. i have 2 datasets : one with a long grid a lat grid and a bathymetry grid the second one only has the long and lat coordinates. So i want to know the bathymetry associated to the second dataset. I thought it was a good idea to do an interpolation between the two datasets. I find a script doing that on matlab but i want to do it on R. Do you how to do it? for ii = 1:length(seal_dive_depth07) seal_bathy_depth07(ii) = interp2(long,latg,A,seal_lon07(ii),seal_lat07(ii)); end Karine HEERAH Master 2 mention "océanographie et environnements marins", parcours océanique 42 rue Salvador Allende 92000 Nanterre 06.61.50.97.47 _________________________________________________________________ [[alternative HTML version deleted]]
Have you considered the "fda" package and the companion book, "Functional Data Analysis with R and Matlab" (Springer, 2009) by Ramsay, Hooker and Graves? This will NOT help you directly with bathymetry = f(long, lat), but will help with b=f(x)+e AND with translations between Matlab and R. To fit z=f(x,y), you may want "thin plate splines". To find R capability for those, you might install the "sos" package and try the following (which requires Internet access): library(sos) tps <- ???'thin plate splines' summary(tps) # 38 help pages found in 9 packages tsp # opens a web browser The "sos" package includes a vignette, which is essentially a copy of an article from the latest issue of The R Journal. Hope this helps. Spencer karine heerah wrote:> Hi everybody. > > > > i have 2 datasets : one with a long grid a lat grid and a bathymetry grid > > the second one only has the long and lat coordinates. > > So i want to know the bathymetry associated to the second dataset. I thought it was a good idea to do an interpolation between the two datasets. I find a script doing that on matlab but i want to do it on R. Do you how to do it? > > > > for ii = 1:length(seal_dive_depth07) > > seal_bathy_depth07(ii) = interp2(long,latg,A,seal_lon07(ii),seal_lat07(ii)); > end > > > > Karine HEERAH > > Master 2 mention "oc?anographie et environnements marins", parcours oc?anique > > 42 rue Salvador Allende > 92000 Nanterre > 06.61.50.97.47 > > > > > _________________________________________________________________ > > > > [[alternative HTML version deleted]] > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Spencer Graves, PE, PhD President and Chief Operating Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San Jos?, CA 95126 ph: 408-655-4567
On Thu, Feb 4, 2010 at 4:03 AM, karine heerah <karine.heerah at hotmail.fr> wrote:> > Hi everybody. > > > > i have 2 datasets : one with a long grid a lat grid and a bathymetry grid > > the second one only has the long and lat coordinates. > > So i want to know the bathymetry associated to the second dataset. I thought it was a good idea to do an interpolation between the two datasets. I find a script doing that on matlab but i want to do it on R. Do you how to do it? > > > > for ii = 1:length(seal_dive_depth07) > > ? ?seal_bathy_depth07(ii) = interp2(long,latg,A,seal_lon07(ii),seal_lat07(ii)); > end > > > > Karine HEERAHThere are several interpolation routines available that will take you between these two grids. The ones I used when preparing bathymetry data for SWAN and ADCIRC models were:>From the fields package:regular grid to regular grid -> interp.surface.grid() regular grid to irregular grid -> interp.surface()>From the akima package:irregular grid to regular grid -> interp() As far as I recall, each of these routines uses either bilinear or bicubic interpolation. The routine as.image() may help you organize your data into the input forms required by these functions. The "sp" package may also help you handle the spatial nature of the data. "sp" contains a routine called as.image.SpatialGridDataFrame() that performs the same function as as.image() on spatially gridded data. There are several other packages available that implement methods other than bilinear/cubic interpolation such as kriging, but I don't have any first hand experience with them. Hope this helps! -Charlie