Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need methods to store objects #172

Closed
courtiol opened this issue Oct 16, 2023 · 2 comments
Closed

Need methods to store objects #172

courtiol opened this issue Oct 16, 2023 · 2 comments
Assignees
Milestone

Comments

@courtiol
Copy link
Owner

courtiol commented Oct 16, 2023

Problem

It is no longer possible to directly save objects created by IsoriX onto the hard drive with terra.

Context

When relying on raster it was possible to save objects created by IsoriX onto the hard drive as *.rda or *.rds.

Objects created by IsoriX are composite in the sense that they may contain rasters, spatial vectors, and non-spatial info all bundled together as a list.

Those list cannot be saved with terra since this package has functions designed to save rasters or vectors specifically and no function to store any kinds of composite.

This matters for users because spatial objects created by IsoriX can be very slow to create.
This also matters to me for editing the bookdown.

Solution

Turning files into binaries ("serialisation") does not seem to be a recommended practice for spatial objects, and even with raster it led to issues if the values were not stored in memory.

So the solution seems to implement methods to save specific classes of IsoriX-created objects.
These methods would create a folder with a particular structure within which the different parts of the objects would be saved separately.

We would also have methods to read these folders so as to recreate the IsoriX objects.

Objects created in IsoriX containing spatial data

  • objects of class ISOFIT: a list storing various info and no spatial data.
  • objects of class MULTIISOFIT: a list storing various info and no spatial data.
  • objects of class CALIBFIT: a list storing various info as well as 0 or 1 SpatVector and no SpatRaster.
  • objects of class ISOSCAPE: a list storing 1 SpatRaster and 1 SpatVector.
  • objects of class ISOFIND: a list of 3 lists, one containing 4 SpatRaster, one containing 1 SpatRaster, one containing (up to?) 3 SpatVector.

Open questions

  • Could there be a simpler way for us to avoid having to create IsoriX-specific methods?
  • Revise the internal structure of ISOFIND to make it simpler (e.g. single brick)? (I need to check if various sets of points can be combined within a single SpatVector)
@courtiol courtiol self-assigned this Oct 16, 2023
@courtiol courtiol added this to the version 0.9.2 milestone Oct 16, 2023
@courtiol
Copy link
Owner Author

@rhijmans, if you have thoughts, please share them with us :-)

@rhijmans
Copy link

rhijmans commented Oct 16, 2023

I think you can define a saveRDS method for these objects. These can then call terra::wrap for SpatRaster/SpatVector objects before calling base::saveRDS. That is what terra does for saveRDS<SpatVector> and saveRDS<SpatRaster>. And do the inverse for readRDS.

courtiol added a commit that referenced this issue Nov 12, 2023
* Edits

* Fix typos and outdated URLs

* First saveRDS & readRDS methods (#172)

* PrecipBrickDE: raster -> terra

* isomultiscape was broken

* Methods for saveRDS and readRDS

* Remove pdf after test

* Add bookdown link

* Adapt to new IsoriX

* Omnibus saveRDS fn

* Omnibus saveRDS fn

* Use distinct Rproj for bookdown and package

* Add comment on terra

* `terra::aggregate()` does not na.rm by default (unlike `raster::aggregate`)

* Minor edits for consistency

* Fix typo(s)

* NEWS moved to md

* Update spelling

* Fix typo(s)

* Reoxygenise

* Minor edit

* Reformatting

* Update README

* Fix wrong index in tests

* Capture spaMM warnings and messages

* New IsoriX options for reviving spaMM warnings and messages

* Fix typo(s)

* Better handle NAs in predictions

* `terra::aggregate()` does not na.rm by default (unlike `raster::aggregate`)

* Outdated?

* Reformating

* Add local tests

* Update README

* Better handle NAs

* Add info origin def

* Add bullet points to issue template

* Add missing namespace

* `styler:::style_active_pkg()` and `lintr::lint_package()`

* Add path in example

* Revise spacing

* Local test for RDS

* Solve S3/S4 remaining issues

* Complete NEWS

* Polish links

* Update URL

* `usethis::use_spell_check(lang = "en-GB")`

* `styler:::style_active_pkg()`

* `usethis::use_cran_comments()`

* Add steps

* Update CRAN comment

* More steps

* Bump version number
courtiol added a commit that referenced this issue Nov 12, 2023
* Edits

* Fix typos and outdated URLs

* First saveRDS & readRDS methods (#172)

* PrecipBrickDE: raster -> terra

* isomultiscape was broken

* Methods for saveRDS and readRDS

* Remove pdf after test

* Add bookdown link

* Adapt to new IsoriX

* Omnibus saveRDS fn

* Omnibus saveRDS fn

* Use distinct Rproj for bookdown and package

* Add comment on terra

* `terra::aggregate()` does not na.rm by default (unlike `raster::aggregate`)

* Minor edits for consistency

* Fix typo(s)

* NEWS moved to md

* Update spelling

* Fix typo(s)

* Reoxygenise

* Minor edit

* Reformatting

* Update README

* Fix wrong index in tests

* Capture spaMM warnings and messages

* New IsoriX options for reviving spaMM warnings and messages

* Fix typo(s)

* Better handle NAs in predictions

* `terra::aggregate()` does not na.rm by default (unlike `raster::aggregate`)

* Outdated?

* Reformating

* Add local tests

* Update README

* Better handle NAs

* Add info origin def

* Add bullet points to issue template

* Add missing namespace

* `styler:::style_active_pkg()` and `lintr::lint_package()`

* Add path in example

* Revise spacing

* Local test for RDS

* Solve S3/S4 remaining issues

* Complete NEWS

* Polish links

* Update URL

* `usethis::use_spell_check(lang = "en-GB")`

* `styler:::style_active_pkg()`

* `usethis::use_cran_comments()`

* Add steps

* Update CRAN comment

* More steps

* Bump version number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants