[GRASS-user] About Spatial PCA in GRASS

I am interested to run the spatial-mode PCA on raster time series. In R it is implemented as an ‘EOF’ function in spacetime Package. The function transposes the raster stack and applies ‘prcomp’ function. I would like to know if there is any possible way to implement i.pca similar to this approach.

Interestingly, I found a very good tutorial on GRASS raster time series at https://grasswiki.osgeo.org/wiki/Temporal_data_processing/GRASS_R_raster_time_series_processing This includes the example using spacetime package to read GRASS raster time series into R.

I would very much appreciate any support on this.

Thank you.

Shiva

Shiva Khanal

University of Western Sydney, Australia

Hi Shiva,

El jue., 12 jul. 2018 a las 2:45, Shiva Khanal (<shiva_khanal@hotmail.com>) escribió:

Hi,

I am interested to run the spatial-mode PCA on raster time series. In R it is implemented as an ‘EOF’ function in spacetime Package. The function transposes the raster stack and applies ‘prcomp’ function. I would like to know if there is any possible way to implement i.pca similar to this approach.

Interestingly, I found a very good tutorial on GRASS raster time series at https://grasswiki.osgeo.org/wiki/Temporal_data_processing/GRASS_R_raster_time_series_processing This includes the example using spacetime package to read GRASS raster time series into R.

there’s also an alternative way to export raster time series from GRASS that was not there at the moment of creating the wiki: the add-on t.rast.out.xyz [0] that produces a table with xy coordinates and all dates in columns. You can then import that into R, transpose and run prcomp, EOF or others. Do you want it for gap-filling?

If you dare to implement EOF in GRASS, please go ahead!! I will be very happy to test and provide feedback, I’ve been wishing for such a thing (and also DINEOF) for a while :slight_smile:

Maybe the devs can provide hints and advice on how to address it.

Best,

Vero

[0] https://grass.osgeo.org/grass74/manuals/addons/t.rast.out.xyz.html

Hi Vero,

Thank you for your response. The only issue I have running the EOF in R is the data size.

My raster stack is a MODIS time series.

stk

class : RasterStack

dimensions : 2423, 2470, 5984810, 690 (nrow, ncol, ncell, nlayers)

resolution : 499.9339, 499.9718 (x, y)

extent : -85163.44, 1149673, 5656775, 6868207 (xmin, xmax, ymin, ymax)

coord. ref. : NA

names : X2001.01.01, X2001.01.09, X2001.01.17, X2001.01.25, X2001.02.02, X2001.02.10, X2001.02.18, X2001.02.26, X2001.03.06, X2001.03.14, X2001.03.22, X2001.03.30, X2001.04.07, X2001.04.15, X2001.04.23, …

min values : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …

max values : 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, …

The size of raster stack is ~8 mb.

object.size(stk)

8699416 bytes

But, when I try to export it to a table, it becomes several GBs, which is too much for my desktop. (Though, my desktop has ~32 GB RAM with 8 cores)

Therefore, I am looking for the possibility of running i.pca but on transposed raster time series stack.

I am motivated by the nice grasswiki on PCA which compares the i.pca outputs against the R equivalent functions.

https://grasswiki.osgeo.org/wiki/Principal_Components_Analysis

I would appreciate any help on this.

Cheers,

Shiva

···

Hi Shiva,

El jue., 12 jul. 2018 a las 2:45, Shiva Khanal (<shiva_khanal@hotmail.com>) escribió:

Hi,

I am interested to run the spatial-mode PCA on raster time series. In R it is implemented as an ‘EOF’ function in spacetime Package. The function transposes the raster stack and applies ‘prcomp’ function. I would like to know if there is any possible way to implement i.pca similar to this approach.

Interestingly, I found a very good tutorial on GRASS raster time series at https://grasswiki.osgeo.org/wiki/Temporal_data_processing/GRASS_R_raster_time_series_processing This includes the example using spacetime package to read GRASS raster time series into R.

there’s also an alternative way to export raster time series from GRASS that was not there at the moment of creating the wiki: the add-on t.rast.out.xyz [0] that produces a table with xy coordinates and all dates in columns. You can then import that into R, transpose and run prcomp, EOF or others. Do you want it for gap-filling?

If you dare to implement EOF in GRASS, please go ahead!! I will be very happy to test and provide feedback, I’ve been wishing for such a thing (and also DINEOF) for a while :slight_smile:

Maybe the devs can provide hints and advice on how to address it.

Best,

Vero

[0] https://grass.osgeo.org/grass74/manuals/addons/t.rast.out.xyz.html