Skip to content

NetCDF Variable Naming: File Name vs. Metadata Name (NETCDF_VARNAME) Inconsistency #744

@alexyshr

Description

@alexyshr

When reading a NetCDF file that contains only one variable, the variable in the stars object is automatically named after the file itself. However, the actual name of the variable in the metadata is different—for example, NETCDF_VARNAME=tp.

Wouldn't it be more accurate or helpful if the default variable name used matched the actual metadata-defined variable name (tp in this case), rather than defaulting to the file name?

Also, when I use gdal_utils(util = "info", ...), the output is extremely long. Is this expected behavior (e.g., due to the structure of my file), or could this be an issue in how the metadata is being parsed or displayed?

If the URL in the reprex doen't work, please download the file idalia_2024_accum.nc from here
https://drive.google.com/file/d/1A6cK-TDGalR8DC-6_WVL_zHU6_XR0fio/view?usp=sharing

or here
https://github.com/alexyshr/sof

myurl <- "https://geocorp.co/wind/idalia_2024_accum.nc"
filename <- "idalia_2024_accum.nc"
download.file(myurl, filename, mode = "wb")
library(stars)
#> Loading required package: abind
#> Loading required package: sf
#> Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
gdalinfo_a <- gdal_utils(util = "info", "idalia_2024_accum.nc")
#> Driver: netCDF/Network Common Data Format
#> Files: idalia_2024_accum.nc
#> Size is 35, 29
#> Origin = (-88.125000000000000,31.625000000000000)
#> Pixel Size = (0.250000000000000,-0.250000000000000)
#> Metadata:
..
#>     long_name=Total precipitation
#>     NETCDF_DIM_valid_time=1690848000
#>     NETCDF_VARNAME=tp
#>     standard_name=unknown
#>     units=m
..
long_name=Total precipitation\n    NETCDF_DIM_valid_time=1696114800\n    NETCDF_VARNAME=tp\n    standard_name=unknown\n    units=m\n    _FillValue=nan\n"
a <- read_stars("idalia_2024_accum.nc")
a
#> stars object with 3 dimensions and 1 attribute
#> attribute(s), summary of first 1e+05 cells:
#>                          Min. 1st Qu.       Median         Mean      3rd Qu.
#> idalia_2024_accum.nc [m]    0       0 4.768372e-07 8.301466e-05 2.002716e-05
#>                                Max.
#> idalia_2024_accum.nc [m] 0.02074099
#> dimension(s):
#>            from   to                               offset
#> x             1   35                               -88.12
#> y             1   29                                31.62
#> valid_time    1 1464 1.691e+09 [seconds since 1970-01-01]
#>                                      delta x/y
#> x                                     0.25 [x]
#> y                                    -0.25 [y]
#> valid_time 3600 [seconds since 1970-01-01]

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

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.3 (2025-02-28 ucrt)
#>  os       Windows 10 x64 (build 19045)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language (EN)
#>  collate  English_United States.utf8
#>  ctype    English_United States.utf8
#>  tz       America/New_York
#>  date     2025-04-12
#>  pandoc   3.2 @ C:/Program Files/RStudio/resources/app/bin/quarto/bin/tools/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date (UTC) lib source
#>  abind       * 1.4-8   2024-09-12 [1] CRAN (R 4.4.1)
#>  class         7.3-23  2025-01-01 [1] CRAN (R 4.4.2)
#>  classInt      0.4-11  2025-01-08 [1] CRAN (R 4.4.2)
#>  cli           3.6.3   2024-06-21 [1] CRAN (R 4.4.1)
#>  DBI           1.2.3   2024-06-02 [1] CRAN (R 4.4.0)
#>  digest        0.6.37  2024-08-19 [1] CRAN (R 4.4.2)
#>  e1071         1.7-16  2024-09-16 [1] CRAN (R 4.4.2)
#>  evaluate      1.0.3   2025-01-10 [1] CRAN (R 4.4.2)
#>  fastmap       1.2.0   2024-05-15 [1] CRAN (R 4.4.1)
#>  fs            1.6.5   2024-10-30 [1] CRAN (R 4.4.2)
#>  glue          1.8.0   2024-09-30 [1] CRAN (R 4.4.2)
#>  htmltools     0.5.8.1 2024-04-04 [1] CRAN (R 4.4.1)
#>  KernSmooth    2.23-26 2025-01-01 [1] CRAN (R 4.4.2)
#>  knitr         1.49    2024-11-08 [1] CRAN (R 4.4.2)
#>  lifecycle     1.0.4   2023-11-07 [1] CRAN (R 4.4.1)
#>  magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.4.1)
#>  proxy         0.4-27  2022-06-09 [1] CRAN (R 4.4.1)
#>  purrr         1.0.2   2023-08-10 [1] CRAN (R 4.4.1)
#>  R.cache       0.16.0  2022-07-21 [1] CRAN (R 4.4.1)
#>  R.methodsS3   1.8.2   2022-06-13 [1] CRAN (R 4.4.0)
#>  R.oo          1.27.0  2024-11-01 [1] CRAN (R 4.4.1)
#>  R.utils       2.13.0  2025-02-24 [1] CRAN (R 4.4.3)
#>  Rcpp          1.0.14  2025-01-12 [1] CRAN (R 4.4.2)
#>  reprex        2.1.1   2024-07-06 [1] CRAN (R 4.4.3)
#>  rlang         1.1.5   2025-01-17 [1] CRAN (R 4.4.2)
#>  rmarkdown     2.29    2024-11-04 [1] CRAN (R 4.4.2)
#>  rstudioapi    0.17.1  2024-10-22 [1] CRAN (R 4.4.2)
#>  sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.4.1)
#>  sf          * 1.0-21  2025-04-10 [1] Github (r-spatial/sf@ac49ec2)
#>  stars       * 0.6-9   2025-04-09 [1] Github (r-spatial/stars@cee007f)
#>  styler        1.10.3  2024-04-07 [1] CRAN (R 4.4.1)
#>  units         0.8-7   2025-03-11 [1] CRAN (R 4.4.3)
#>  vctrs         0.6.5   2023-12-01 [1] CRAN (R 4.4.1)
#>  withr         3.0.2   2024-10-28 [1] CRAN (R 4.4.2)
#>  xfun          0.49    2024-10-31 [1] CRAN (R 4.4.2)
#>  yaml          2.3.10  2024-07-26 [1] CRAN (R 4.4.1)
#> 
#>  [1] C:/Users/500596972/AppData/Local/R/win-library/4.4
#>  [2] C:/Program Files/R/R-4.4.3/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

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