[GRASS-dev] support for raster time series in rgrass7?

Veronica Andreo veroandreo at gmail.com
Tue Aug 18 04:20:24 PDT 2015


Hello list,

I'm just trying to use GRASS along with R for raster time series
processing.
I'm using GRASS temporal modules (t.rast.export/t.rast.import) along with
the functions available in spacetime package (read.tgrass and write.tgrass)
to complete workflow... However, after finally being able of getting
write.tgrass to work, t.rast.import does not do the job... So, I don't know
where exactly the problem is...

The workflow I'm following is more or less like this:

# GRASS (where I have my raster time series)
t.rast.export input=temperature output=test_export_temp.tar.bzip2
# extract data to check it's fine
tar xvf test_export_temp.tar.bzip2
# check text files
cat list.txt ; cat proj.txt ; cat init.txt ; cat metadata.txt

(if i import it back into GRASS with
t.rast.import in=test_export_temp.tar.bzip2 out=test_import_temp
base=t_test directory=/tmp it works smoothly)

but, let's say I want to import it into R, do something there and get it
back into GRASS. So,

# In R
library(spacetime)
tgrass_test <- read.tgrass("test_export_temp.tar.bzip2")

dim(tgrass_test)
#[1] 135 150  12

class(tgrass_test)
#[1] "RasterStack"
#attr(,"package")
#[1] "raster"

when, trying to follow the example in the "spacetime package" manual,

> write.tgrass(tgrass_test, "myfile.tar.bzip2")
Error in .local(x, filename, ...) :
  filenames of source and target should be different

# I changed map names (dunno if it makes sense) because of the previous
error message
for (i in c(1:12)) name_tgrass[i]<-paste("layer_",i,sep="")
names(tgrass_test)<-name_tgrass

> write.tgrass(tgrass_test, "myfile.tar.bzip2")
tar: .: file changed as we read it

> getwd()
[1] "/tmp/RtmplJyK2L"

# the file is created anyway... but when i try to import the created
.tar.bzip2 into GRASS again, I get:

GRASS 7.1.svn (nc_spm_08_grass7):~ > t.rast.import
input=/tmp/RtmplJyK2L/myfile.tar.bzip2 out=tgrass_import basename=t_test_2
directory=/tmp/RtmplJyK2L
Traceback (most recent call last):
  File
"/home/veroandreo/software/grass-7.1.svn/dist.x86_64-unknown-linux-gnu/scripts/t.rast.import",
line 123, in <module>
    main()
  File
"/home/veroandreo/software/grass-7.1.svn/dist.x86_64-unknown-linux-gnu/scripts/t.rast.import",
line 119, in main
    set_current_region)
  File
"/home/veroandreo/software/grass-7.1.svn/dist.x86_64-unknown-linux-gnu/etc/python/grass/temporal/stds_import.py",
line 216, in import_stds
    gscript.fatal(_("Unable to find init file <%s>") % init_file_name)
  File
"/home/veroandreo/software/grass-7.1.svn/dist.x86_64-unknown-linux-gnu/etc/python/grass/script/core.py",
line 643, in fatal
    raise ScriptError(msg)
grass.exceptions.ScriptError: Unable to find init file <init.txt>

When I check the .tar.bzip2 file, the init.txt file is in fact there, but
also the original maps... Can anybody explain how it is supposed to work??
Or what I'm doing wrong? I attach the .tar.bzip2 file I get with
t.rast.export

I was wondering if there was any chance to include support for
reading/writing spatio-temporal data sets in rgrass7, and make this kind of
workflows a bit smoother, besides saving time and disk space... A somehow
equivalent structure for GRASS raster data sets, but in R might be STFDF
from spacetime package, "A class for spatio-temporal data with full
space-time grid; for n spatial locations and m times, n x m observations
are available", maybe it can be recycled??

I'm using GRASS GIS 7.1 r65947 and R 3.2.1 under Fedora 21.

Thanks a lot!!!

Cheers,
Vero

ps: sorry for double posting :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20150818/c104599b/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_export_temp.tar.bzip2
Type: application/octet-stream
Size: 165769 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20150818/c104599b/attachment-0001.obj>


More information about the grass-dev mailing list