Dear list,
I am going to build a spacetime::STFDF object where the "n" spatial
locations hold "h" different values (different fields) over the "m" times.
Along the documentation (spacetime vignette, ?stConstruct, ?STFDF, ?reshape)
I only found examples with layout of {n?m?1} observations, and not {n?m?h}
as in my case.
[I might as well have missed such examples, so please forgive me in that
case]
I am writing here to have a confirmation that I am doing things correctly.
This is a toy-example of my workflow (letting out CRS or ending-times
details):
-----------------------------------
library(gstat)
library(spacetime)
data(meuse)
# subset
meuse <- meuse[c("cadmium", "copper", "x", "y")][1:10,]
coordinates(meuse) <- ~x+y
#
ds <- slot(meuse, "data")
meuse <- as(meuse, "SpatialPoints")
# append hypothetical values to match cardinality of data required
ds <- rbind(ds, ds+1)
# Assign dates
dts <- as.Date(c(1:2))
ds <- cbind(ds, time=sort(rep(dts,10)), id=1:nrow(ds))
# Rename field variables to avoid conflict
#names(ds) <- c("cadmiums", "coppers", "time", "id")
# Build the spacetime object: n=10, m=2, h=2
stMeuse = STFDF(meuse, dts, ds)
str(stMeuse)
-----------------------------------
Thanks for any comment.
Piero
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/STFDF-with-n-variables-tp7581966.html
Sent from the R-sig-geo mailing list archive at Nabble.com.
STFDF with n variables
6 messages · piero campa, Piero Campalani, Edzer Pebesma
On 12/16/2012 06:32 PM, piero campa wrote:
Dear list,
I am going to build a spacetime::STFDF object where the "n" spatial
locations hold "h" different values (different fields) over the "m" times.
Along the documentation (spacetime vignette, ?stConstruct, ?STFDF, ?reshape)
I only found examples with layout of {n?m?1} observations, and not {n?m?h}
as in my case.
[I might as well have missed such examples, so please forgive me in that
case]
I am writing here to have a confirmation that I am doing things correctly.
This is a toy-example of my workflow (letting out CRS or ending-times
details):
-----------------------------------
library(gstat)
library(spacetime)
data(meuse)
# subset
meuse <- meuse[c("cadmium", "copper", "x", "y")][1:10,]
coordinates(meuse) <- ~x+y
#
ds <- slot(meuse, "data")
meuse <- as(meuse, "SpatialPoints")
# append hypothetical values to match cardinality of data required
ds <- rbind(ds, ds+1)
# Assign dates
dts <- as.Date(c(1:2))
ds <- cbind(ds, time=sort(rep(dts,10)), id=1:nrow(ds))
# Rename field variables to avoid conflict
#names(ds) <- c("cadmiums", "coppers", "time", "id")
# Build the spacetime object: n=10, m=2, h=2
stMeuse = STFDF(meuse, dts, ds)
str(stMeuse)
-----------------------------------
Thanks for any comment.
Piero
Yes, that works:
class(stMeuse)
[1] "STFDF" attr(,"package") [1] "spacetime"
dim(stMeuse)
space time variables
10 2 4
stConstruct would need extension to be help here, it tries to build
STFDF objects from time- or space-wide tables -- with multiple
attributes, the organization of such tables is not unambiguous.
(also note that with the CRAN version of spacetime, you'd need to load
package zoo first in order to run your script)
-- View this message in context: http://r-sig-geo.2731867.n2.nabble.com/STFDF-with-n-variables-tp7581966.html Sent from the R-sig-geo mailing list archive at Nabble.com.
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20121216/69d7081e/attachment.pl>
Piero, in your case id is simply an attribute, so it can have any value, as you can see from: stplot(stMeuse[,,1:4], mode = 'ts') what is the special purpose of your IDs, what should they identify?
On 12/16/2012 07:42 PM, Piero Campalani wrote:
Thank you Edzer, comments inline On 16 December 2012 19:19, Edzer Pebesma <edzer.pebesma at uni-muenster.de>wrote:
Yes, that works:
class(stMeuse)
[1] "STFDF" attr(,"package") [1] "spacetime"
dim(stMeuse)
space time variables
10 2 4
I could see that a STFDF object was created, but I still have some concern with regard to the "id" which need to be attached to the data.frame . With regards to my example, I tried as well with reverse-order IDs:
ds <- cbind(ds, time=sort(rep(dts,10)), id=nrow(ds):1)
...or with duplicated IDs like:
ds <- cbind(ds, time=sort(rep(dts,10)), id=rep(1:10,2))
and the final stMeuse object still seemed the same by looking at stplot(stMeuse). I guess they are not bound to the locations of the spatial object (points in `meuse` in this case).
(also note that with the CRAN version of spacetime, you'd need to load
package zoo first in order to run your script)
Got it, thanks ;) Piero
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20121216/8a2d2edf/attachment.pl>
On 12/16/2012 08:28 PM, Piero Campalani wrote:
Oh, right, I actually can see that things work fine even with no "id" attribute in the data.frame. I started it all by following an example of Roger with NDVI images of Gambia, where the initial wide-format dataframe was `reshape`d to long-format to eventually create a STFDF: the ids were used there. Afaics, one can keep trace of the spatial location of each row with the IDs when going from a time-wide format to a long one, otherwise the spatial dimension gets flattened with no chance of reverting to time-wide format.
Piero, there is a chance: if the layout is complete (full: STFDF) you can recreate space and time ID from row order,
((1:prod(dim(stMeuse)[1:2])-1) %% dim(stMeuse)[1] + 1)
[1] 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10
((1:prod(dim(stMeuse)[1:2])-1) %/% dim(stMeuse)[1] + 1)
[1] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 For an irregular layout, STIDF, the IDs are kept in the index slot. Indeed, you need to know that space cycles fastest, and so it is easy to make mistakes.
Thought they were used by STFDF to link the locations in the spatial object and the values in the data.frame. Thanks again Edzer. Cheers, Piero On 16 December 2012 19:53, Edzer Pebesma <edzer.pebesma at uni-muenster.de>wrote:
Piero, in your case id is simply an attribute, so it can have any value, as you can see from: stplot(stMeuse[,,1:4], mode = 'ts') what is the special purpose of your IDs, what should they identify? On 12/16/2012 07:42 PM, Piero Campalani wrote:
Thank you Edzer, comments inline On 16 December 2012 19:19, Edzer Pebesma <edzer.pebesma at uni-muenster.de wrote:
Yes, that works:
class(stMeuse)
[1] "STFDF" attr(,"package") [1] "spacetime"
dim(stMeuse)
space time variables
10 2 4
I could see that a STFDF object was created, but I still have some
concern
with regard to the "id" which need to be attached to the data.frame . With regards to my example, I tried as well with reverse-order IDs:
ds <- cbind(ds, time=sort(rep(dts,10)), id=nrow(ds):1)
...or with duplicated IDs like:
ds <- cbind(ds, time=sort(rep(dts,10)), id=rep(1:10,2))
and the final stMeuse object still seemed the same by looking at stplot(stMeuse). I guess they are not bound to the locations of the spatial object (points in `meuse` in this case).
(also note that with the CRAN version of spacetime, you'd need to load
package zoo first in order to run your script)
Got it, thanks ;) Piero
-- Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de
[[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de