[SOLVED] Extending the simulated area; creating scale bars

If you have problems using RGeostats package or if you simply need some help on an unlisted subject.

[SOLVED] Extending the simulated area; creating scale bars

Postby Chris » Thu Sep 05, 2013 4:52 am

Hey RGeoS guys,

Great package! It is a really good addition to R. I have been learning how to use RGeoS for a few months now, and have been getting successful results. I have mainly been using your package to create bathymetry maps of a series of lakes that I am working on. I have two questions, that I cannot seem to work out by myself.

The first questions relates to extending the range of simulation in my models so that I can create depth-profile maps which fill the lake boundary. In other words, I want to have a simulated data point for all points within a polygon which is not limited by the extent of my sampling locations. I have attached an image of a map I have created using RGeoS, and the white areas is where I have not collected data, and where I wish to extend the range of modelling to.
pond bathymetry.jpeg
pond bathymetry.jpeg (78.29 KiB) Viewed 3283 times


here is a sample of my code:
Code: Select all
#Create database
z.db <- db.create(DT.z, flag.grid=FALSE, ndim=2, nx=c(n.nodes.x1, n.nodes.x2))
z.db <- db.locate(z.db, c("x","y"), "x")

#Create variogram and model
z.2dir.vario <- vario.calc(z.db, lag=lag.distance, nlag=lag.number, dir=c(45, 135))z.2dir.model <-

model.auto(z.2dir.vario, struct=c("Nugget Effect", "Spherical"), title = "2 directional variogram model")

#Create grid mesh
depth.db <- db.polygon(z.db, polygon)
grid.db.z <- db.grid.init(depth.db, n=c(n.nodes.x1, n.nodes.x2))
grid.poly <- db.polygon(grid.db.z, polygon)

#Kriging
depth.db <- xvalid(depth.db, z.2dir.model, moving.neigh)
depth.db <- db.locate(depth.db, seq(6,7))
depth.db <- db.locate(depth.db, "z", "z")
grid.db.z <- kriging(depth.db, grid.poly, z.2dir.model, unique.neigh, radix="KU.Part")
grid.db.z <- kriging(depth.db, grid.poly, z.2dir.model, moving.neigh, radix="KM.All")
grid.db.z <- neigh.test(depth.db, grid.db.z, z.2dir.model, moving.neigh, radix="Moving")

#Gaussian Transformation
depth.anam <- anam.fit(depth.db, "z")
depth.db <- anam.z2y(depth.db, "z", anam=depth.anam)
depth.g.vario <- vario.calc(depth.db, nlag=lag.number, lag=lag.distance, dir=c(45, 135))
depth.g.model <- model.auto(depth.g.vario, struct=c("Nugget Effect", "Spherical"))

#Simulation
grid.db.z <- simtub(depth.db, grid.db.z, depth.g.model, unique.neigh, nbsimu= 50, nbtuba=100)
grid.db.z <- anam.y2z(grid.db.z, ngrep="Simu.Gaussian.z", anam=depth.anam)
grid.db.z.mean <- db.compare(grid.db.z, ngrep="Raw.Simu.Gaussian.z", fun="mean")
grid.db.z.stdv <- db.compare(grid.db.z, ngrep="Raw.Simu.Gaussian.z", fun="stdv")



My second questions relates to fitting coloured scale bars to the plots. I cannot figure out an easy way to do this. I have noticed on some of the graphs in your demonstration/tutorial packages, that your simulated graphs have coloured scales. Is there a code to easily do this?


Cheers
Chris
Chris
 
Posts: 2
Joined: Mon Sep 02, 2013 4:34 am

Re: Extending the simulated area and creating scale bars

Postby Didier Renard » Fri Sep 06, 2013 8:28 am

Hi Chris

Thanks for your encouragement in continuing developing RGeoS.

I looked at your script. It is slightly difficult to double-check it as I do not have the relevant data.
But I think that we can solve your problem without you having to provide me with them.

The first question is the most tricky.
First remarks:
1)
- you have a polygon which certainly corresponds to the boundary that we can see in your figure
- you applied (twice) this boundary using the db.polygon() facility to your input data as well as your output grid.
- to do so, your used a syntax of the fort:

output_file = db.polygon(input_file,polygon)

Let me tell you that input and output files could be the same. db.polygon() method only add the selection induced
by the polygon as an extra field with the selection locator. This is the same philosophy that db.sel() procedure.

2) More or less similarly, you applied twice the kriging with a syntax of the form:

output_grid = kriging(input_data, input_grid)

The output grid could be the same as the input one. In that case, the results of kriging would simply be added to the list of the already existing fields.
That is the reason why the syntax:
grid.db.z <- kriging(depth.db, grid.poly, z.2dir.model, unique.neigh, radix="KU.Part")
grid.db.z <- kriging(depth.db, grid.poly, z.2dir.model, moving.neigh, radix="KM.All")
grid.db.z <- neigh.test(depth.db, grid.db.z, z.2dir.model, moving.neigh, radix="Moving")
does not make sense to me. As a matter of fact, the resulting grid (grid.db.z) which contains the results of the kriging
performed using a Unique Neighborhood (KU.Part) will immediately be replaced by the one containing
the results of the Moving neighborhood, which itself will be replaced by the results of the neighborhood test.
I would instead recommand the following syntax:

grid.poly <- kriging(depth.db, grid.poly, z.2dir.model, unique.neigh, radix="KU.Part")
grid.poly <- kriging(depth.db, grid.poly, z.2dir.model, moving.neigh, radix="KM.All")
grid.poly <- neigh.test(depth.db, grid.db.z, z.2dir.model, moving.neigh, radix="Moving")
Then output grid file serving as the input grid file for the next operation, all the results would then
be stacked as variables in this unique file.

Now your question:
- you performed first two krigings and a neighborhood test
- did you check the kriging result graphically ?
- dit it fill entirely the polygon or did it leave empty spaces like I can see on the figure ?
- does the figure corresponds to a kriged or simulated result ?

To my opinion, if some space is left blank, this may be linked to:
- either your grid is too small: it has been created so as to cover the data area (using db.grid.init() procedure). So there all depends upon where are the data located with respect to the polygon. Otherwise the grid.db.z file could simply be created (by hands) using the syntax:

grid.db.z = db.create(flag.grid=T,nx=c(xxx,xxx), dx=c(xxx,xxx), x0=c(xxx,xxx))

- either your neighborhood (at least the moving one) has a too small search radius (howvere this is not relevant for the Unique neighborhood)

Question 2:
This is very simple (although not documented correctly I agree). When you use plot on a Db (which means you use in fact the method called db.plot (class mechanism). When checking the arguments of this function, you do not see anything regarding the scale bar (called "legend" in my jargon).
However, you have the opportunity to add extra arguments through the "..." argument.
If you use the argument "pos.legend" there, you trigger the legend option. The syntax should be:

plot(mygrid,pos.legend=xxx)

The argument xxx (as described in all the legend modules) tells you where the legend must be implemented in the figure.
See legend.image documentation for example.

Hope I made the use of the software clearer now.
Didier Renard
 
Posts: 337
Joined: Thu Sep 20, 2012 4:22 pm

Re: Extending the simulated area and creating scale bars

Postby Chris » Mon Sep 16, 2013 7:34 am

Thanks Didier,

It was a problem with the grid being too small. I now understand the concepts much better! Adding the legend was also incredibly simple.

Once I had the grid size corrected, the results from the kriging did not leave empty spaces. The figure I posted was a simulation with 50 simulations and 100 turning bands.


Thanks!
Chris
 
Posts: 2
Joined: Mon Sep 02, 2013 4:34 am


Return to Other Troubleshooting

Who is online

Users browsing this forum: No registered users and 3 guests

cron