Skip to content

[raster] problem with large netCDF file

5 messages · Robert J. Hijmans, Tom Roche

#
I'm trying to create an extents object from a large netCDF file on a
linux cluster running RHEL 5.4. I'd try to make the file publicly
available, but

$ ls -alh ./METCRO3D_080101
-r--r--r-- 1 me mygroup 5.3G Jan  8 11:32 ./METCRO3D_080101

# extension used below
$ ln -s ./METCRO3D_080101 ./METCRO3D_080101.nc

# note netCDF-ness of file, and existence of datavar=ZF
$ ncdump -v ZF ./METCRO3D_080101 | head
netcdf METCRO3D_080101 {
dimensions:
        TSTEP = UNLIMITED ; // (25 currently)
        DATE-TIME = 2 ;
        LAY = 24 ;
        VAR = 17 ;
        ROW = 299 ;
        COL = 459 ;
variables:
        int TFLAG(TSTEP, VAR, DATE-TIME) ;
$ ncdump -v ZF ./METCRO3D_080101 | tail
    19116.16, 19112.75, 19128.86, 19171.77, 19206.04, 19224.66, 19247.3, 
    19293.71, 19343.23, 19370.01, 19386.64, 19389.33, 19391.63, 19417.19, 
    19442.12, 19456.19, 19471.03, 19481.76, 19485.71, 19492.51, 19501.67, 
    19511.11, 19499.88, 19470.57, 19464.8,  19466.73, 19467.94, 19481.03, 
    19502.62, 19534.05, 19562.75, 19607.45, 19659.45, 19687.44, 19706.39, 
    19735.43, 19790.02, 19842.22, 19862.31, 19867.04, 19871.75, 19876.44, 
    19881.59, 19882.53, 19838.23, 19772.65, 19724.43, 19754.49, 19824.58, 
    19852.86, 19897.51, 19921.67, 19909.53, 19925.96, 19937.74, 19940.95, 
    19944.61, 19948.7,  19953.03, 19957.13 ;
}

$ R
R version 2.15.2 (2012-10-26) -- "Trick or Treat"
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-unknown-linux-gnu (64-bit)

...
Loading required package: sp
raster 2.0-41 (21-December-2012)
-r--r--r-- 1 me mygroup 5.3G Jan  8 11:32 ./METCRO3D_080101
lrwxrwxrwx 1 me mygroup 17 Feb 10 13:46 ./METCRO3D_080101.nc -> ./METCRO3D_080101
rgdal: version: 0.8-4, (SVN revision 431)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 1.7.3, released 2010/11/10
Path to GDAL shared files: /usr/local/share/gdal
GDAL does not use iconv for recoding strings.
Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
Path to PROJ.4 shared files: (autodetected)
Error in .local(.Object, ...) : 
  `/home/rtd/code/regridding/MOZART_global_to_AQMEII-NA/METCRO3D_080101' not recognised as a supported file format.


Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file.

# Thinking that `raster` might want a supported extension to convince
# it of the file's netCDF-ness, I tried
Error in .local(.Object, ...) : 
  `.../METCRO3D_080101' not recognised as a supported file format.


Error in .rasterObjectFromFile(x, band = band, objecttype = "RasterLayer",  : 
  Cannot create a RasterLayer object from this file.

But plainly `ncdump` thinks METCRO3D_080101 *is* netCDF.
Can I convince `raster`? Either way, how to proceed?

Your assistance is appreciated, Tom Roche <Tom_Roche at pobox.com>
#
Tom Roche Sun, 10 Feb 2013 14:40:05 -0500
...
...
Robert J. Hijmans Sun, 10 Feb 2013 13:53:56 -0800
I was able rename the above file and subsequently load it with
`raster`, but only after copying the above file to my homespace :-(
which is generally unfeasible due to size.
Or perhaps merely add a flag allowing the user to {assert, vouch for}
the file's netCDF-ness? Why I ask:

Files such as the above are generated by a production model of long
standing (~20 years), which moreover generates many other netCDF files
with the same naming convention ("<8 char description/>_<timestamp/>"
with no extension). Hence a request by me for a more appropriate
naming convention seems unlikely to be adopted, and would not help
work with many years of legacy output. Moreover these outputs are
usually quite large (i.e., tens of GB or more), and usually generated
to shared directories with restricted permissions. Hence it would be
quite desirable to enable current `raster` code to either

* respect the extension of a symlink

* take a runtime flag, e.g. 'format=CDF'

If there is somewhere to make a feature request, please let me know.

TIA, Tom Roche <Tom_Roche at pobox.com>
1 day later
#
summary: what are the semantics of 'band', 'level', and 'lvar' in
`raster:::.rasterObjectFromCDF` (et al)?

details:

https://stat.ethz.ch/pipermail/r-sig-geo/2013-February/017441.html
...
https://stat.ethz.ch/pipermail/r-sig-geo/2013-February/017454.html
I'm apparently not understanding the semantics of 'band', and possibly
'level', and 'lvar' (all of which I'm guessing `raster` is designed to
protect me from :-) As noted above, my datavar='ZF' of interest is in
netCDF='./METCRO3D_080101', which is
TSTEP is the time dimension
LAY is the vertical dimension
ROW and COL are the horizontal dimensions
... followed by 10 datavars (none of which are coordinate variables),
then ...
... followed by 7 more datavars (none of which are coordinate
variables), then many global attributes (of which this convention,
IOAPI, is inordinately fond :-) So I tried
+   './METCRO3D_080101', varname='ZF',
+   band=11,  # datavar=ZF is 11th reported by `ncdump -h`
+   level=1,  # "4th dimension variable" in (TSTEP, LAY, ROW, COL)
+   lvar=2,   # "3rd dimension variable" in (TSTEP, LAY, ROW, COL)
+   type='RasterLayer', warn=TRUE)
class       : RasterLayer 
band        : 11 
dimensions  : 299, 459, 137241  (nrow, ncol, ncell)
resolution  : 1, 1  (x, y)
extent      : 0.5, 459.5, 0.5, 299.5  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : ./METCRO3D_080101 
names       : ZF 
z-value     : 11 
zvar        : ZF 
level       : 1 

But if I do

system('mv ./METCRO3D_080101 ./METCRO3D_080101.nc')
raster('./METCRO3D_080101.nc', varname='ZF')

I get

class       : RasterLayer 
band        : 1 
dimensions  : 299, 459, 137241  (nrow, ncol, ncell)
resolution  : 1, 1  (x, y)
extent      : 0.5, 459.5, 0.5, 299.5  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : [...]/METCRO3D_080101.nc 
names       : ZF 
z-value     : 1 
zvar        : ZF 
level       : 1 

which is almost the same, but not quite. It seems my 'band' value is
wrong, so I'd like to know how to determine the appropriate value; I'd
also like to know if my comments above correctly reflect the semantics
of 'level' and 'lvar'. Unfortunately I'm not quite getting this from
raster.pdf, and the source for raster:::.rasterObjectFromCDF seems quite
inscrutable (YMMV :-)

TIA, Tom Roche <Tom_Roche at pobox.com>