mjwoods / RNetCDF

Read and write netcdf format in R
Other
24 stars 9 forks source link

Search for variables based on standard_name attribute #103

Open mjwoods opened 1 year ago

mjwoods commented 1 year ago

As suggested by @lhmarsden in #102 , var.get.nc would be enhanced by adding an optional argument to search for variables based on the standard_name attribute (instead of the variable name). This would simplify the task of reading datasets created by different people, because standard_name is standardised and consistent, unlike ordinary variable names.

pvanlaake commented 5 months ago

This is going to be a bit more complicated than it may appear at first. Variables (and dimensions) have a unique name in a NetCDF file; the same is not guaranteed for the "standard_name" attribute.

Taking @lhmarsden 's remote file from #143, and using the dev version of the ncdfCF package (https://github.com/pvanlaake/ncdfCF), we get the following:

> devtools::install_github("pvanlaake/ncdfCF")
> library(ncdfCF)

> netcdf_file <- "https://opendap1.nodc.no/opendap/physics/point/cruise/nansen_legacy-single_profile/NMDC_Nansen-Legacy_PR_CT_58US_2021708/CTD_station_P1_NLEG01-1_-_Nansen_Legacy_Cruise_-_2021_Joint_Cruise_2-1.nc"
> x <- open_ncdf(netdcf_file)
> objects_by_standard_name(x, "sea_water_temperature")
[1] "TEMP"   "TEMP-2"

This issue is potentially bigger in DSG-formatted files: there may be many time-series or trajectories using the same physical property in a single file.