spacetime : the challenge of image time series containing holes

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

spacetime : the challenge of image time series containing holes

scizmeli
Greetings to all,

I have monthly mean satellite image time series that come in a 4-column
text file each.  I have dozens of such files. Every line correspond to a
pixel that is projected onto a regular ISIN grid. The first column is
the ISIN grid number (same coordinates for a given grid number in every
file), the second column is the latitude, the third column is the
longitude and the last column is the value of the satellite measurement.
Every file contain a varying number of lines (no NAs), although the lat
and lon associated for a given ISIN grid number is the same in every file.

I read the examples related with the STFDF class and understood it.
However this is not a good solution for me as I have a lot of holes in
my data. I would therefore like to place these time series into an
irregular STSDF spacetime format. I could not find any information on
how to achieve that. I would appreciate it very much if you could help
me construct the irregular STSDF (or STIDF?) object. How to instruct the
STSDF function so that it understands what goes where?

Below is a sample code that involves 3 image files, each containing
different pixels. I do not have handy a complete list of a list of all
grid numbers for which there is at least one pixel. But I could easily
generate it by reading in every image in a same data frame and producing
a list of the unique values of the first column. For now I construct a
SpatialPoints object but eventually I will be working with SpatialPixels.

thanks a lot for your kindly help.
Best
Servet

library(sp)
library(spacetime)
img200206 <- data.frame(rbind(
c(10849178, -4.979167,      -19.99302,      1.1542897E-03),
c(10849179, -4.979167,      -19.95120,      1.3418309E-03),
c(10849180, -4.979167,      -19.90937,      1.3988283E-03)))

img200207 <- data.frame(rbind(
c(10849178,  -4.979167,      -19.99302,      1.2843144E-03),
c(10849179,  -4.979167,      -19.95120,      1.1260216E-03)))

img200208 <- data.frame(rbind(
c(10849179,  -4.979167,      -19.95120,      1.5001300E-03),
c(10849180,  -4.979167,      -19.90937,      1.4793734E-03)))

coordinates(img200206)=c("X3","X2")
coordinates(img200207)=c("X3","X2")
coordinates(img200208)=c("X3","X2")

time = xts(1:3, as.POSIXct(c("2002-06-01","2002-07-01","2002-08-01")))

#This is where I am stuck at
mySTSDF = STSDF(  ... )

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: spacetime : the challenge of image time series containing holes

Tom Gottfried
Hi,

see below

Am 09.04.2011 02:26, schrieb servet cizmeli:

> Greetings to all,
>
> I have monthly mean satellite image time series that come in a 4-column
> text file each.  I have dozens of such files. Every line correspond to a
> pixel that is projected onto a regular ISIN grid. The first column is
> the ISIN grid number (same coordinates for a given grid number in every
> file), the second column is the latitude, the third column is the
> longitude and the last column is the value of the satellite measurement.
> Every file contain a varying number of lines (no NAs), although the lat
> and lon associated for a given ISIN grid number is the same in every file.
>
> I read the examples related with the STFDF class and understood it.
> However this is not a good solution for me as I have a lot of holes in
> my data. I would therefore like to place these time series into an
> irregular STSDF spacetime format. I could not find any information on
> how to achieve that. I would appreciate it very much if you could help
> me construct the irregular STSDF (or STIDF?) object. How to instruct the
> STSDF function so that it understands what goes where?

> Below is a sample code that involves 3 image files, each containing
> different pixels. I do not have handy a complete list of a list of all
> grid numbers for which there is at least one pixel. But I could easily
> generate it by reading in every image in a same data frame and producing
> a list of the unique values of the first column. For now I construct a
> SpatialPoints object but eventually I will be working with SpatialPixels.
>
> thanks a lot for your kindly help.
> Best
> Servet
>
> library(sp)
> library(spacetime)
> img200206<- data.frame(rbind(
> c(10849178, -4.979167,      -19.99302,      1.1542897E-03),
> c(10849179, -4.979167,      -19.95120,      1.3418309E-03),
> c(10849180, -4.979167,      -19.90937,      1.3988283E-03)))
>
> img200207<- data.frame(rbind(
> c(10849178,  -4.979167,      -19.99302,      1.2843144E-03),
> c(10849179,  -4.979167,      -19.95120,      1.1260216E-03)))
>
> img200208<- data.frame(rbind(
> c(10849179,  -4.979167,      -19.95120,      1.5001300E-03),
> c(10849180,  -4.979167,      -19.90937,      1.4793734E-03)))
>
> coordinates(img200206)=c("X3","X2")
> coordinates(img200207)=c("X3","X2")
> coordinates(img200208)=c("X3","X2")
>
> time = xts(1:3, as.POSIXct(c("2002-06-01","2002-07-01","2002-08-01")))
>
> #This is where I am stuck at
> mySTSDF = STSDF(  ... )

there's surely a better way for constructing the index (depending on how
you organise your input data), but for the example this should work:

sp <- SpatialPoints(unique(rbind(coordinates(img200206),
coordinates(img200207), coordinates(img200208))))
data <- rbind(img200206, img200207, img200208)@data
index <- matrix(c(1:3, 1:2, 2:3, rep(1, 3), rep(2,2), rep(3,2)),
nrow=nrow(data))
mySTSDF = STSDF(sp, time, data, index)

regards,
Tom

>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: spacetime : the challenge of image time series containing holes

scizmeli
Hi Tom,

Thanks a million for your fast, accurate reply. I did not apply that to my imagery yet but the test I did show that it seems to work...

thank you!
Servet
Reply | Threaded
Open this post in threaded view
|

Re: spacetime : the challenge of image time series containing holes

edzer
Servet,

For the solution below to work, you'll need spacetime package version
0.3-1, which I just submitted to CRAN (misnamed as
spacetime_0.3-2.tar.gz; I had to use passive ftp for some reason)

I added a solution to your problem that does not require the manual
create of an index to construct a sparse space time lattice (STSDF), as
was required in Tom's solution. Combined script below.

library(sp)
library(spacetime)
img200206 <- data.frame(rbind(
c(10849178, -4.979167,      -19.99302,      1.1542897E-03),
c(10849179, -4.979167,      -19.95120,      1.3418309E-03),
c(10849180, -4.979167,      -19.90937,      1.3988283E-03)))

img200207 <- data.frame(rbind(
c(10849178,  -4.979167,      -19.99302,      1.2843144E-03),
c(10849179,  -4.979167,      -19.95120,      1.1260216E-03)))

img200208 <- data.frame(rbind(
c(10849179,  -4.979167,      -19.95120,      1.5001300E-03),
c(10849180,  -4.979167,      -19.90937,      1.4793734E-03)))

coordinates(img200206)=c("X3","X2")
coordinates(img200207)=c("X3","X2")
coordinates(img200208)=c("X3","X2")

time = xts(1:3, as.POSIXct(c("2002-06-01","2002-07-01","2002-08-01")))

# solution one: spacetime creates index:
sp.list = list(img200206, img200207, img200208)
times = time[rep(1:length(sp.list), unlist(lapply(sp.list, length)))]
sp.all = do.call(rbind, sp.list)
stidf = STIDF(sp.all, times, sp.all@data)
stsdf = as(stidf, "STSDF")

# solution two: Tom creates index:
sp <- SpatialPoints(unique(rbind(coordinates(img200206),
coordinates(img200207), coordinates(img200208))))
data <- rbind(img200206, img200207, img200208)@data
index <- matrix(c(1:3, 1:2, 2:3, rep(1, 3), rep(2,2), rep(3,2)),
nrow=nrow(data))
mySTSDF = STSDF(sp, time, data, index)

# check they're equal:
all.equal(mySTSDF, stsdf, check.attributes)

On 04/12/2011 05:20 PM, scizmeli wrote:

> Hi Tom,
>
> Thanks a million for your fast, accurate reply. I did not apply that to my
> imagery yet but the test I did show that it seems to work...
>
> thank you!
> Servet
>
> --
> View this message in context: http://r-sig-geo.2731867.n2.nabble.com/spacetime-the-challenge-of-image-time-series-containing-holes-tp6255766p6265557.html
> Sent from the R-sig-geo mailing list archive at Nabble.com.
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> 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      [hidden email]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: spacetime : the challenge of image time series containing holes

scizmeli
dear Edzer,

Thanks a lot for the wonderful improvement. It certainly makes it easier.

Servet