[SOLVED] Extracting Plurigaussian simulation sample data

If you have problems using RGeostats package or if you simply need some help on an unlisted subject.

[SOLVED] Extracting Plurigaussian simulation sample data

Postby Miorat » Wed Jul 07, 2021 5:16 pm

Hello,

I have created plurigaussian simulation. How can I export the samples data generated into .txt file (as an arrays) in order to manipulate it in Python?

Code: Select all
```{r}
write.table(outgrid2, file = "PGS.txt", sep = "\t",
            row.names = TRUE, col.names = NA)
```



Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class ‘structure("db", package = "RGeostats")’ to a data.frame

Also, I wish to ask if there is an interface of Rgeostats in Python or a way to link it with Jupyter notebook?

Your help will be greatly appreciated, thanks.

Miora
Miorat
 
Posts: 5
Joined: Wed Jul 07, 2021 5:08 pm

Re: Extracting Plurigaussian simulation sample data

Postby Fabien Ors » Thu Jul 08, 2021 9:58 am

Hi Miorat

The outgrid2 is an object of class db. You can access to the underlying R data.frame by using the $items accessor :
Code: Select all
```{r}
write.table(outgrid2$items, file = "PGS.txt", sep = "\t",
            row.names = TRUE, col.names = NA)
```

You can also use [] accessor of db class in order to access a particular line/column/cell of the underlying data.frame.
The list of all accessors is available here (see Methods section) : http://rgeostats.free.fr/html/db-class.html

It is also possible to extract some variables (data.frame's columns) by using the function db.extract (which take into account the active selection, if so)

There is no interface between RGeostats and python. This could be envisaged in the future. So, currently, exporting your data.frame in a text file and import it in python is the best solution.

It is possible to call directly RGeostats from Jupyter Notebooks providing that you install the R kernel. But I never tried to mix Python and R cells in the same jupyter Notebook.
Fabien Ors
Administrateur du site
 
Posts: 226
Joined: Thu Sep 20, 2012 1:07 pm

Re: Extracting Plurigaussian simulation sample data

Postby Miorat » Thu Jul 08, 2021 1:43 pm

Hi Fabien,

Many thanks for your help, it works perfectly for what I need. An interface with Python would really be useful.

Kind regards,
Miora
Miorat
 
Posts: 5
Joined: Wed Jul 07, 2021 5:08 pm


Return to Other Troubleshooting

Who is online

Users browsing this forum: No registered users and 1 guest

cron