문제

I am using R to work with meteorological data. I proceed in two steps:

  1. convert grib to netcdf using the command line function ncl_convert2nc from ncar command language
  2. use package ncdf in R to import the netcdf data.

I still have one problem:

2- For some particular grib files, the conversion with ncar tool does not work. Is there other ways or trick (other than transcription into netcdf) to read grib files in R ?

Problem Answered by Dirk: 1- I would like to do automatic treatment of many files within R. Can I call ncl_convert2nc within R ? (answered by Dirk Eddelbuettel below )

도움이 되었습니까?

해결책

Regarding question 1, the answer is 'Yes' -- see help(system) and the internal=TRUE option if you want to capture results.

다른 팁

rgdal also can do it, but is less flexible and requires more care and detail than ncdf or RNetCDF - and depends of your GDAL/rgdal built including the GRIB driver.

ncl_convert2nc seems to be the best solution. However, if the structure of data is a little bit more complicated I use GrADS to convert GRIB file to ASCII (e.g. .csv) and then it is possible to create NetCDF file using ncdf4 package dedicated for R. GrADS also provides support for re-writing GRIB to NetCDF, but there is limitation to only 1 variable.

Another solution is to use the wgrib/wgrib2 software (http://www.cpc.ncep.noaa.gov/products/wesley/wgrib2/) and dump your GRIB-1/GRIB-2 file directly to CSV format, e.g.:

/path/to/your/wgrib2 input_file.grb -csv output_file.csv

Then it may be read directly in R...

Another quick and easy command line solution is to use cdo to do the conversion:

cdo -f nc copy file.grb file.nc

If you want to output a netcdf4 file you specify "-f nc4".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top