0

How can I simply access the information on raster "global attributes" (e.g., Title or Sensor - see the data structure bellow)?

Is it possible to get those information as the same as I got the extent and date infos (see bellow)?

ext <- raster[[1]]@extent    # 1st day extent area

date = as.Date(as.numeric(raster[[1]]@z), origin = "1960-01-01", tz = "GMT", format = "%Y-%m-%d")     # 1st day Date

Bellows is how my raster list is structured:

> raster[[1]]

class       : RasterLayer 
band        : 1  (of  31  bands)
dimensions  : 110, 74, 8140  (nrow, ncol, ncell)
resolution  : 1, 1  (x, y)
extent      : -42, 32, -55, 55  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : /data/input/raster.nc 
names       : var1 
z-value     : 20667.5 
zvar        : var1 


> raster[1]

[[1]]
File /data/input/raster.nc (NC_FORMAT_CLASSIC):

 2 variables (excluding dimension variables):
    int var1[longitude,latitude,time]   
        units: nodimension
    int var2[longitude,latitude,time]   
        units: nodimension

 3 dimensions:
    longitude  Size:74
        units: degrees east
        long_name: Longitude
    latitude  Size:110
        units: degrees north
        long_name: Latitude
    time  Size:31
        units: Julian days since 1960-1-01

6 global attributes:
    Title: Rain Rate every 1 degree
    Date Beg: 2016-08-01 00:00:00
    Date End: 2016-08-31 23:59:59
    Author: LastName, FirstName
    Sensor: GEO
    Conventions: CF-1.0
Val
  • 6,585
  • 5
  • 22
  • 52
romaug
  • 1
  • 2
  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick May 16 '18 at 16:56

1 Answers1

0

read in the .nc file with the ncdf4 package and explore

# open nc connection
my.nc <- nc_open("./path/thedata.nc")

# names of variables
names(my.nc$var)

# names of attributes of a variable
ncatt_get(my.nc,attributes(my.nc$var)$names[1])

# check the names of dimensions
length(my.nc$dim)
names(my.nc$dim)

# check time dimension of file
my.nc$dim$time
my.nc$dim$time$vals

# global attributes
ncatt_get(my.nc, 0)

# attributes of specific variable
ncatt_get(my.nc, "some_variable")

and others and more.

Sam
  • 1,400
  • 13
  • 29