Skip to content

dimensions point attribute changed by writing to disk #742

@btupper

Description

@btupper

Hi,

When writing and then reading a regular grid to/from disk, the dimensions point attribute changes from NA to FALSE. The two (original and from-disk) versions cannot be concatenated then because, of course, the dimensional attributes don't match.

I assume that I could get/modify/set the dimension attributes so that they match, but I am hopeful that there exists a cleaner way to manage that by controlling read_stars or write_stars. Perhaps there magic gdal arguments? I have looked at gdal's geotiff specifications, but nothing jumps out at me.

Below is a small example.

Thanks so much!
Ben

ofile = tempfile(fileext = ".tif")

a = stars::read_stars(system.file("nc/reduced.nc", package = "stars")) |> 
  dplyr::slice("time",1) |>
  dplyr::select("sst") |>
  sf::st_set_crs(4326) |>
  stars::write_stars(ofile)
#> sst, anom, err, ice,

b = stars::read_stars(ofile)

da = stars::st_dimensions(a)
db = stars::st_dimensions(b)
cat("point in a:", da$x$point, "\n")
#> point in a: NA
cat("point in b:", db$x$point, "\n")
#> point in b: FALSE

c = c(a, b, along = NA_integer_)
#> Error in c.stars(a, b, along = NA_integer_): don't know how to merge arrays: please specify parameter along

sessionInfo()
#> R version 4.4.2 (2024-10-31)
#> Platform: x86_64-apple-darwin20
#> Running under: macOS Sequoia 15.3.2
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib 
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.12.0
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> time zone: America/New_York
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] vctrs_0.6.5        cli_3.6.4          knitr_1.48         rlang_1.1.5       
#>  [5] xfun_0.48          DBI_1.2.3          KernSmooth_2.23-24 generics_0.1.3    
#>  [9] sf_1.0-19          glue_1.8.0         htmltools_0.5.8.1  e1071_1.7-16      
#> [13] rmarkdown_2.28     grid_4.4.2         tibble_3.2.1       evaluate_1.0.0    
#> [17] classInt_0.4-11    abind_1.4-8        fastmap_1.2.0      yaml_2.3.10       
#> [21] lifecycle_1.0.4    compiler_4.4.2     dplyr_1.1.4        fs_1.6.4          
#> [25] pkgconfig_2.0.3    Rcpp_1.0.14        rstudioapi_0.17.0  digest_0.6.37     
#> [29] R6_2.6.1           tidyselect_1.2.1   class_7.3-22       reprex_2.1.1      
#> [33] pillar_1.10.1      parallel_4.4.2     magrittr_2.0.3     tools_4.4.2       
#> [37] withr_3.0.2        proxy_0.4-27       stars_0.6-8        units_0.8-5

Created on 2025-04-07 with reprex v2.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions