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

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
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 :slight_smile:

(attachments)

test_export_temp.tar.bzip2 (162 KB)

Hi Veronica,
can you please provide the tar.bzip2 file generated by R?

Best regards
Soeren

2015-08-18 13:20 GMT+02:00 Veronica Andreo <veroandreo@gmail.com>:

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 :slight_smile:

_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Hi Veronica,
first note: the attached file is a gzip archive, the suffix is wrong.

However, this seems to be a bug in t.rast.import, since the file names
in the tar archive are listed with a "./" in the path.
I will try to fix this issue.

Best regards
Soeren

2015-08-18 14:58 GMT+02:00 Veronica Andreo <veroandreo@gmail.com>:

Hi Soeren, lists :slight_smile:

2015-08-18 8:34 GMT-03:00 Sören Gebbert <soerengebbert@googlemail.com>:

Hi Veronica,
can you please provide the tar.bzip2 file generated by R

Yes, please attached the tar.bzip2 I get from R
Thanks a lot!

Vero

Hi Soeren,

···

2015-08-18 10:07 GMT-03:00 Sören Gebbert <soerengebbert@googlemail.com>:

Hi Veronica,
first note: the attached file is a gzip archive, the suffix is wrong.

ops! Yes, you are right… write.tgrass creates gzip files, my mistake, I’m sorry…

However, this seems to be a bug in t.rast.import, since the file names
in the tar archive are listed with a “./” in the path.
I will try to fix this issue.

Thanks a lot!

Vero

Hi,
i hopefully fixed the STRDS import so that datasets generated from R
can be imported into GRASS GIS 7.1 in r65967.
Please try this new version. I had to address several issues, but at
least i got your dataset to be correctly imported.

Best regards
Soeren

2015-08-18 15:19 GMT+02:00 Veronica Andreo <veroandreo@gmail.com>:

Hi Soeren,

2015-08-18 10:07 GMT-03:00 Sören Gebbert <soerengebbert@googlemail.com>:

Hi Veronica,
first note: the attached file is a gzip archive, the suffix is wrong.

ops! Yes, you are right... write.tgrass creates gzip files, my mistake, I'm
sorry...

However, this seems to be a bug in t.rast.import, since the file names
in the tar archive are listed with a "./" in the path.
I will try to fix this issue.

Thanks a lot!

Vero

Hi Soeren,

Thanks much! The data is imported now, and it is imported correctly!!

I still think, however, that it would be great to have something like read/writeSTRDS under rgrass7 :slight_smile:

THANKS MUCH again!
Best,

Vero