[R-sig-Geo] netCDF header info in R

Michael Sumner mdsumner at gmail.com
Tue Mar 2 21:49:25 CET 2010


Sorry, one correction - the ncdf package does use the class system to
remove the need for ".nc" on print and close.


On Wed, Mar 3, 2010 at 7:47 AM, Michael Sumner <mdsumner at gmail.com> wrote:
> You could use
>
> shell("ncdump -h netCDF.nc", intern = TRUE)
>
> In the ncdf package you can print a connection and it gives you a
> summary, for example:
>
> library(ncdf)
>  nc <- open.ncdf("sst.wkmean.1990-present.nc")
> print.ncdf(nc)
> [1] "file sst.wkmean.1990-present.nc has 4 dimensions:"
> [1] "lon   Size: 360"
> [1] "lat   Size: 180"
> [1] "nbnds   Size: 2"
> [1] "time   Size: 1046"
> [1] "------------------------"
> [1] "file sst.wkmean.1990-present.nc has 2 variables:"
> [1] "double time_bnds[nbnds,time]  Longname:Time Boundaries Missval:1e+30"
> [1] "short sst[lon,lat,time]  Longname:Weekly Mean of Sea Surface
> Temperature Missval:32767"
>
> close.ncdf(nc)
>
>
> The RNetCDF package does the same, but the summary is more "ncdump-alike":
>
> library(RNetCDF)
> nc <- open.nc("sst.wkmean.1990-present.nc")
> print.nc(nc)
> dimensions:
>        lon = 360 ;
>        lat = 180 ;
>        nbnds = 2 ;
>        time = UNLIMITED ; // (1046 currently)
> variables:
>        float lat(lat) ;
>                lat:units = "degrees_north" ;
>                lat:long_name = "Latitude" ;
>                lat:actual_range = 89.5-89.5 ;
>                lat:standard_name = "latitude_north" ;
>                lat:axis = "y" ;
>                lat:coordinate_defines = "center" ;
>        float lon(lon) ;
>                lon:units = "degrees_east" ;
>                lon:long_name = "Longitude" ;
>                lon:actual_range = 0.5359.5 ;
>                lon:standard_name = "longitude_east" ;
>                lon:axis = "x" ;
>                lon:coordinate_defines = "center" ;
>        double time(time) ;
>                time:units = "days since 1800-1-1 00:00:00" ;
>                time:long_name = "Time" ;
>                time:actual_range = 6939576710 ;
>                time:delta_t = "0000-00-07 00:00:00" ;
>                time:avg_period = "0000-00-07 00:00:00" ;
>                time:standard_name = "time" ;
>                time:axis = "t" ;
>        double time_bnds(nbnds, time) ;
>                time_bnds:long_name = "Time Boundaries" ;
>        short sst(lon, lat, time) ;
>                sst:long_name = "Weekly Mean of Sea Surface Temperature" ;
>                sst:valid_range = -540 ;
>                sst:actual_range = -1.835.63 ;
>                sst:units = "degC" ;
>                sst:add_offset = 0 ;
>                sst:scale_factor = 0.01 ;
>                sst:missing_value = 32767 ;
>                sst:precision = 2 ;
>                sst:least_significant_digit = 2 ;
>                sst:var_desc = "Sea Surface Temperature" ;
>                sst:dataset = "NOAA Optimum Interpolation (OI) SST V2" ;
>                sst:level_desc = "Surface" ;
>                sst:statistic = "Weekly Mean" ;
>                sst:parent_stat = "Individual obs" ;
>                sst:standard_name = "sea_surface_temperature" ;
>
> // global attributes:
>                :title = "NOAA Optimum Interpolation (OI) SST V2" ;
>                :Conventions = "CF-1.0" ;
>                :history = "Created 10/2002 by RHS" ;
>                :comments = "Data described in  Reynolds, R.W., N.A.
> Rayner, T.M.
> Smith, D.C. Stokes, and W. Wang, 2002: An Improved In Situ and Satellite
> SST Analysis for Climate, J. Climate" ;
>                :platform = "Model" ;
>                :source = "NCEP Climate Modeling Branch" ;
>                :institution = "National Centers for Environmental Prediction" ;
>                :references =
> "http://www.emc.ncep.noaa.gov/research/cmb/sst_analysis/
> http://www.cdc.noaa.gov/cdc/data.ncep.oisst.v2.html" ;
>
>
> Unfortunately, neither package provides the metadata as an R object
> and they do not use the class system to (for example) remove the need
> for the ".nc" on print() and close(). The functions are not that
> complicated at the R level thought, so modifying them to suit is quite
> simple.
>
> Cheers, Mike.
>
>
>
>
> On Tue, Mar 2, 2010 at 11:43 PM, Ian McCallum <mccallum at iiasa.ac.at> wrote:
>> Greetings,
>>
>> I am importing netCDF files into R using library(ncdf)
>> I would like to see the header info of these files directly in R if
>> possible (i.e. units, full description, etc)
>> It is possible to use "ncdump -h netCDF.nc" from the unix prompt,
>> but I was wondering is it possible to access all info in the header
>> directly in R?
>>
>> Many thanks
>> Ian
>>
>>
>> ___________________________________________
>>
>> Ian McCallum
>> Forestry Program
>> International Institute for Applied Systems Analysis
>> Schlossplatz 1, A-2361 Laxenburg, Austria
>> Phone: +43 2236 807-328
>> Fax: +43 2236 807-599 or 71313
>> E-mail: mccallum at iiasa.ac.at
>> Web: http://www.iiasa.ac.at/Research/FOR/
>> ___________________________________________
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>



More information about the R-sig-Geo mailing list