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

tar_terra_rast() doesn't save units or varnames #58

Open
Aariq opened this issue Apr 25, 2024 · 4 comments
Open

tar_terra_rast() doesn't save units or varnames #58

Aariq opened this issue Apr 25, 2024 · 4 comments
Labels
bug Something isn't working priority: high terra related to compatibility with `terra`

Comments

@Aariq
Copy link
Collaborator

Aariq commented Apr 25, 2024

I suspect this is because those metadata are stored in a "sidecar file" when filetype = "GeoTIFF", but I haven't investigated further.

library(targets)
tar_script({
    make_rast <- function() {
        x <- terra::rast(system.file("ex/elev.tif", package = "terra"))
        terra::units(x) <- "m"
        terra::varnames(x) <- "elev"
        x
    }
    list(
        geotargets::tar_terra_rast(
            rast,
            make_rast()
        )
    )
})
tar_make()
#> ▶ dispatched target rast
#> ● completed target rast [0.017 seconds]
#> ▶ ended pipeline [0.148 seconds]
tar_load(rast)
terra::units(rast)
#> [1] ""
terra::varnames(rast)
#> [1] "rast"
terra::names(rast)
#> [1] "elevation"

Created on 2024-04-25 with reprex v2.1.0

@Aariq Aariq added the bug Something isn't working label Apr 25, 2024
@Aariq
Copy link
Collaborator Author

Aariq commented Apr 25, 2024

Yeah, looks like units are store in an aux.json file. varnames() aren't read back in by rast() so I guess that one isn't our problem. Related to #37

@Aariq
Copy link
Collaborator Author

Aariq commented Apr 25, 2024

I've tried a half dozen or so differente GDAL drivers and they all create an aux.json file when a SpatRaster has units. Ideas:

  1. always zip files after writing and use vsizip to read back in (cons to this approach in comments on Generalization of compression for spatial targets with GDAL #37)
  2. have tar_terra_rast(my_map) create two targets: my_map_rast and my_map_meta. Not sure how reading this back in would work though
  3. don't support units???

@Aariq
Copy link
Collaborator Author

Aariq commented Apr 25, 2024

Found this: https://github.com/rspatial/terra/blob/master/NEWS.md#new-18
aux.json file is written for all drivers except when using writeCDF()

@Aariq Aariq added the terra related to compatibility with `terra` label Apr 26, 2024
@njtierney
Copy link
Owner

Thanks for this! I'll take a look later this week on my geotargets day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority: high terra related to compatibility with `terra`
Projects
None yet
Development

No branches or pull requests

2 participants