Hi all, I have a problem in opening netcdf files. If one netcdf file contains longitude, latitude, and daily precipitation. How to relate each precipitation record to its associated location, and export them as csv files? Thanks. I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks for any ideas. [[alternative HTML version deleted]]
Please show code that allows potential responders to reply meaningfully. -- David> On Jul 25, 2016, at 9:54 PM, lily li <chocold12 at gmail.com> wrote: > > Hi all, > > I have a problem in opening netcdf files. If one netcdf file contains > longitude, latitude, and daily precipitation. How to relate each > precipitation record to its associated location, and export them as csv > files? Thanks. > > I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks for > any ideas. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
You could try with the brick function from the raster package. bvar = brick(netcdfName) This uses the ncdf4 functions for opening and reading the netcdf, but makes it easier to extract data for each day: p1 = rasterToPoints(bvar[[1]]) and write p1 to csv. Best, Jon On 7/26/2016 6:54 AM, lily li wrote:> Hi all, > > I have a problem in opening netcdf files. If one netcdf file contains > longitude, latitude, and daily precipitation. How to relate each > precipitation record to its associated location, and export them as csv > files? Thanks. > > I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks for > any ideas. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Jon Olav Sk?ien Joint Research Centre - European Commission Institute for Space, Security & Migration Disaster Risk Management Unit Via E. Fermi 2749, TP 122, I-21027 Ispra (VA), ITALY jon.skoien at jrc.ec.europa.eu Tel: +39 0332 789205 Disclaimer: Views expressed in this email are those of the individual and do not necessarily represent official views of the European Commission.
Thanks for your reply. But it says "Error in (function (classes, fdef, mtable)): unable to find an inherited method for function 'brick' for signature 'ncdf4' " The dataset is attached. It contains daily precipitation data for 20 years, within a rectangle, so that there are several grid points. I use the code to open it, but don't know how to get csv files, while each file contains continuous daily precipitation data for each grid cell. pre1 = nc_open('sample_precip_daily.nc') pre1 pre1_rd = ncvar_get(pre1, 'precipitation') nc_close(pre1) Thanks for your help. On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien <jon.skoien at jrc.ec.europa.eu> wrote:> You could try with the brick function from the raster package. > > bvar = brick(netcdfName) > > This uses the ncdf4 functions for opening and reading the netcdf, but > makes it easier to extract data for each day: > > p1 = rasterToPoints(bvar[[1]]) > and write p1 to csv. > > Best, > Jon > > > > On 7/26/2016 6:54 AM, lily li wrote: > >> Hi all, >> >> I have a problem in opening netcdf files. If one netcdf file contains >> longitude, latitude, and daily precipitation. How to relate each >> precipitation record to its associated location, and export them as csv >> files? Thanks. >> >> I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks for >> any ideas. >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> >> > -- > Jon Olav Sk?ien > Joint Research Centre - European Commission > Institute for Space, Security & Migration > Disaster Risk Management Unit > > Via E. Fermi 2749, TP 122, I-21027 Ispra (VA), ITALY > > jon.skoien at jrc.ec.europa.eu > Tel: +39 0332 789205 > > Disclaimer: Views expressed in this email are those of the individual and > do not necessarily represent official views of the European Commission. >
You can find many tutorials in internet. For example, I did one here: http://max2.ese.u-psud.fr/epc/conservation/Girondot/Publications/Blog_r/Entrees/2014/4/27_Comparison_between_packages_RnetCDF%2C_ncdf4_and_ncdf.html Without any reproducibl example, it is impossible to help you further. Sincerely Marc