Re: [R] about netcdf files

2016-08-02 Thread Marc Girondot via R-help

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

__
R-help@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.


Re: [R] about netcdf files

2016-08-01 Thread lily li
Thanks, Roy. I will do a search. In addition, how to look at spatial
patterns from this netcdf file? Thanks again.

On Mon, Aug 1, 2016 at 11:46 AM, Roy Mendelssohn - NOAA Federal <
roy.mendelss...@noaa.gov> wrote:

> Hi Lily:
>
> If you download the vignette to my xtractomatic package  (
> http://coastwatch.pfeg.noaa.gov/xtracto/index.html) there are any number
> of examples using ggplot2 to make maps from netcdf data,
>
> HTH,
>
> -Roy
>
> > On Aug 1, 2016, at 10:35 AM, lily li  wrote:
> >
> > Hi all,
> >
> > I can read the data, but how to plot it using ggplot or something? In
> this
> > case, x-axis should be longitude, and y-axis should be latitude. I tried
> to
> > plot using raster function, but the x and y axes are from 0 to 1.
> > Thanks again.
> >
> > The code is like this:
> > pre1 = nc_open('sample_precip_daily.nc')
> > pre.3d = ncvar_get(pre1, 'precipitation')
> >
> > require(raster)
> > rplot = t(pre.3d[, , 1])
> > r = raster(rplot[nrow(rplot):1, ]
> > plot(r)
> >
> >
> > On Tue, Jul 26, 2016 at 1:07 PM, lily li  wrote:
> >
> >> 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.sko...@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@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.sko...@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.
> >>>
> >>
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@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.
>
> **
> "The contents of this message do not reflect any position of the U.S.
> Government or NOAA."
> **
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new address and phone***
> 110 Shaffer Road
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK
> Jr.
>
>

[[alternative HTML version deleted]]

__
R-help@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.

Re: [R] about netcdf files

2016-08-01 Thread Roy Mendelssohn - NOAA Federal
Hi Lily:

If you download the vignette to my xtractomatic package  
(http://coastwatch.pfeg.noaa.gov/xtracto/index.html) there are any number of 
examples using ggplot2 to make maps from netcdf data,

HTH,

-Roy

> On Aug 1, 2016, at 10:35 AM, lily li  wrote:
> 
> Hi all,
> 
> I can read the data, but how to plot it using ggplot or something? In this
> case, x-axis should be longitude, and y-axis should be latitude. I tried to
> plot using raster function, but the x and y axes are from 0 to 1.
> Thanks again.
> 
> The code is like this:
> pre1 = nc_open('sample_precip_daily.nc')
> pre.3d = ncvar_get(pre1, 'precipitation')
> 
> require(raster)
> rplot = t(pre.3d[, , 1])
> r = raster(rplot[nrow(rplot):1, ]
> plot(r)
> 
> 
> On Tue, Jul 26, 2016 at 1:07 PM, lily li  wrote:
> 
>> 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 
>> 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@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.sko...@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.
>>> 
>> 
>> 
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@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.

**
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new address and phone***
110 Shaffer Road
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

__
R-help@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.

Re: [R] about netcdf files

2016-08-01 Thread lily li
Hi all,

I can read the data, but how to plot it using ggplot or something? In this
case, x-axis should be longitude, and y-axis should be latitude. I tried to
plot using raster function, but the x and y axes are from 0 to 1.
Thanks again.

The code is like this:
pre1 = nc_open('sample_precip_daily.nc')
pre.3d = ncvar_get(pre1, 'precipitation')

require(raster)
rplot = t(pre.3d[, , 1])
r = raster(rplot[nrow(rplot):1, ]
plot(r)


On Tue, Jul 26, 2016 at 1:07 PM, lily li  wrote:

> 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 
> 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@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.sko...@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.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@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.

Re: [R] about netcdf files

2016-07-27 Thread lily li
Hi Jon,

The versions are: raster_2.5-2 sp_1.2-3


On Wed, Jul 27, 2016 at 9:31 AM, Jon Skoien 
wrote:

> Hi Lily,
>
> You can ignore the first three lines, they are just for information.
> Which version of raster do you have? I see that the attempt to read the
> crs-variable was not wrapped in a try-call in earlier versions. Upgrading
> might help.
>
> Best,
> Jon
>
>
>
> On 7/27/2016 5:13 PM, lily li wrote:
>
> Hi Jon,
>
> I still have problems. The brick function does not work well and I don't
> know where to check the problem. I put the error message below, thanks.
>
> > pre = brick("~/Downloads/sample_precip_daily.nc")
> [1] "vobjtovarid4: error #F: I could not find the requsted var (or dimvar)
> in the file!"
> [1] "var (or dimvar) name: crs"
> [1] "file name: /.../Downloads/sample_precip_daily.nc"
> Error in vobjtovarid4(nc, varid, allowdimvar = TRUE, verbose = verbose) :
>   Variable not found
>
>
> On Wed, Jul 27, 2016 at 1:10 AM, Jon Skoien 
> wrote:
>
>> I think you get the error because you passed the object from nc_open(),
>> you should rather pass the filename of the netCDF, so:
>>
>> pre = brick("sample_precip_daily.nc")
>> From the test-file, this gives you a RasterBrick-object with 5*9 pixels
>> and 7305 layers.
>> Then you can extract data.frames of each layer with:
>> dframe = rasterToPoints(pre[[1]])
>> where 1 is the first layer, or time series with:
>> tseries = pre[3,4]
>> where 3 and 4 are the pixels in x and y-direction.
>>
>> To write dframe to csv:
>> write.csv(dframe, filename = "csvfile.csv")
>> Check the function for more options.
>>
>> Hope this helps you a bit further.
>> Jon
>>
>>
>> On 7/26/2016 9:07 PM, lily li wrote:
>>
>> 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.sko...@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@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.sko...@jrc.ec.europa.eu
>>> Tel:  +39 0332 789205 <%2B39%200332%20789205>
>>>
>>> Disclaimer: Views expressed in this email are those of the individual
>>> and do not necessarily represent official views of the European Commission.
>>>
>>
>>
>> --
>> 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.sko...@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.
>>
>>
>
> --
> 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.sko...@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.
>
>


Re: [R] about netcdf files

2016-07-27 Thread Jon Skoien
Hi Lily,

You can ignore the first three lines, they are just for information.
Which version of raster do you have? I see that the attempt to read the 
crs-variable was not wrapped in a try-call in earlier versions. 
Upgrading might help.

Best,
Jon


On 7/27/2016 5:13 PM, lily li wrote:
> Hi Jon,
>
> I still have problems. The brick function does not work well and I 
> don't know where to check the problem. I put the error message below, 
> thanks.
>
> > pre = brick("~/Downloads/sample_precip_daily.nc 
> ")
> [1] "vobjtovarid4: error #F: I could not find the requsted var (or 
> dimvar) in the file!"
> [1] "var (or dimvar) name: crs"
> [1] "file name: /.../Downloads/sample_precip_daily.nc 
> "
> Error in vobjtovarid4(nc, varid, allowdimvar = TRUE, verbose = verbose) :
>   Variable not found
>
>
> On Wed, Jul 27, 2016 at 1:10 AM, Jon Skoien 
> > wrote:
>
> I think you get the error because you passed the object from
> nc_open(), you should rather pass the filename of the netCDF, so:
>
> pre = brick("sample_precip_daily.nc ")
> From the test-file, this gives you a RasterBrick-object with 5*9
> pixels and 7305 layers.
> Then you can extract data.frames of each layer with:
> dframe = rasterToPoints(pre[[1]])
> where 1 is the first layer, or time series with:
> tseries = pre[3,4]
> where 3 and 4 are the pixels in x and y-direction.
>
> To write dframe to csv:
> write.csv(dframe, filename = "csvfile.csv")
> Check the function for more options.
>
> Hope this helps you a bit further.
> Jon
>
>
> On 7/26/2016 9:07 PM, lily li wrote:
>> 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
>> > > 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@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.sko...@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.
>>
>>
>
> -- 
> 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.sko...@jrc.ec.europa.eu 
> Tel:+39 0332 789205 

Re: [R] about netcdf files

2016-07-27 Thread Jon Skoien
I think you get the error because you passed the object from nc_open(), 
you should rather pass the filename of the netCDF, so:

pre = brick("sample_precip_daily.nc")
 From the test-file, this gives you a RasterBrick-object with 5*9 pixels 
and 7305 layers.
Then you can extract data.frames of each layer with:
dframe = rasterToPoints(pre[[1]])
where 1 is the first layer, or time series with:
tseries = pre[3,4]
where 3 and 4 are the pixels in x and y-direction.

To write dframe to csv:
write.csv(dframe, filename = "csvfile.csv")
Check the function for more options.

Hope this helps you a bit further.
Jon

On 7/26/2016 9:07 PM, lily li wrote:
> 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 
> > 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@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.sko...@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.
>
>

-- 
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.sko...@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.


[[alternative HTML version deleted]]

__
R-help@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.

Re: [R] about netcdf files

2016-07-26 Thread Roy Mendelssohn - NOAA Federal
Hi Lily:

> On Jul 26, 2016, at 2:00 PM, lily li  wrote:
> 
> Here are the results. Yes, I tried to read netcdf files, but cannot grasp the 
> contents. Thanks for helping out.
> 
> > str(pre1)

A guide to netcdf files and R can be found at 
https://www.image.ucar.edu/GSP/Software/Netcdf/, it would be worth your time to 
read through it.  Not certain why you want .csv files,  but I can give you a 
rough idea of how to read a slice into a variable in R,  it is then up to you 
to save the result as a .csv.

netcdf files have parameters, precipitation in this case, defined on a grid, in 
your case (lon, lat, time).  The file contains dimensions,  which gives the 
number of points in each dimension of the grid, and coordinate variables,  
which give the values of that coordinate variable at each grid point.  So if I 
wanted to to subset at a certain lat, lon - I would first need to get those 
values

> lat <- ncvar_get(pre1, "lat")
> lon <- ncvar_get(pre1, "lon")
> 

I have no idea of contents of your file, but let's say you know there is a lat 
of 30, and a lon of 120, so I would have to find where they occur:

> myLat <- which(lat == 30)
> myLon <- which(lon == 120)

then you get the slice at that lat-lon for all time by telling ncvar_get where 
to start on the grid, and how many steps to take:

> myPrecip <- ncvar_get(pre1,"precipitation", start = c(myLat, myLon,1), count 
> = c(1, 1, -1))

where the -1 value tells it to get all the values along the time dimension.  
You now have that slice of the data stored in myPrecip.  I hope this gets you 
started, but i strongly urge you to read through the link above.

-Roy

> 
> On Tue, Jul 26, 2016 at 2:52 PM, Roy Mendelssohn - NOAA Federal 
>  wrote:
> Hi Lily:
> 
> I doubt the mail-list would pass through the netcdf file. Instead, could you 
> do the following, and post the results:
> 
> library(ncdf4
> pre1 = nc_open('sample_precip_daily.nc')
> str(pre1)
> nc_close(pre1)
> 
> I have a feeling you haven't worked much with netcdf files. I will try to 
> find a tutorial also to help you along.
> 
> Thanks,
> 
> -Roy
> 
> > On Jul 26, 2016, at 12:07 PM, lily li  wrote:
> >
> > 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 
> > 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@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.sko...@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.
> >>
> > __
> > R-help@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.
> 
> **
> "The contents of this message do not reflect any position of the U.S. 
> 

Re: [R] about netcdf files

2016-07-26 Thread lily li
How to read continuous daily precipitation at each grid cell, and then
export to a csv file? Later, there should be several csv files, each
represents daily precipitation data for one grid cell. Thanks a lot.

On Tue, Jul 26, 2016 at 2:52 PM, Roy Mendelssohn - NOAA Federal <
roy.mendelss...@noaa.gov> wrote:

> Hi Lily:
>
> I doubt the mail-list would pass through the netcdf file. Instead, could
> you do the following, and post the results:
>
> library(ncdf4
> pre1 = nc_open('sample_precip_daily.nc')
> str(pre1)
> nc_close(pre1)
>
> I have a feeling you haven't worked much with netcdf files. I will try to
> find a tutorial also to help you along.
>
> Thanks,
>
> -Roy
>
> > On Jul 26, 2016, at 12:07 PM, lily li  wrote:
> >
> > 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  >
> > 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@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.sko...@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.
> >>
> > __
> > R-help@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.
>
> **
> "The contents of this message do not reflect any position of the U.S.
> Government or NOAA."
> **
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new address and phone***
> 110 Shaffer Road
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK
> Jr.
>
>

[[alternative HTML version deleted]]

__
R-help@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.

Re: [R] about netcdf files

2016-07-26 Thread lily li
Here are the results. Yes, I tried to read netcdf files, but cannot grasp
the contents. Thanks for helping out.

> str(pre1)
List of 14
 $ filename   : chr "~/Downloads/sample_precip_daily.nc"
 $ writable   : logi FALSE
 $ id : int 262144
 $ safemode   : logi FALSE
 $ format : chr "NC_FORMAT_CLASSIC"
 $ is_GMT : logi FALSE
 $ groups :List of 1
  ..$ :List of 7
  .. ..$ id   : int 262144
  .. ..$ name : chr ""
  .. ..$ ndims: int 3
  .. ..$ nvars: int 4
  .. ..$ natts: int 48
  .. ..$ dimid: int [1:3(1d)] 0 1 2
  .. ..$ fqgn : chr ""
  .. ..- attr(*, "class")= chr "ncgroup4"
 $ fqgn2Rindex:List of 1
  ..$ : int 1
 $ ndims  : num 3
 $ natts  : num 48
 $ dim:List of 3
  ..$ time:List of 11
  .. ..$ name : chr "time"
  .. ..$ len  : int 7305
  .. ..$ unlim: logi FALSE
  .. ..$ group_index  : int 1
  .. ..$ group_id : int 262144
  .. ..$ id   : int 0
  .. ..$ dimvarid :List of 5
  .. .. ..$ id : int 1
  .. .. ..$ group_index: int 1
  .. .. ..$ group_id   : int 262144
  .. .. ..$ list_index : num -1
  .. .. ..$ isdimvar   : logi TRUE
  .. .. ..- attr(*, "class")= chr "ncid4"
  .. ..$ units: chr "days since 1900-01-01 00:00:00"
  .. ..$ calendar : chr "gregorian"
  .. ..$ vals : num [1:7305(1d)] 38716 38717 38718 38719 38720 ...
  .. ..$ create_dimvar: logi TRUE
  .. ..- attr(*, "class")= chr "ncdim4"
  ..$ lat :List of 10
  .. ..$ name : chr "lat"
  .. ..$ len  : int 5
  .. ..$ unlim: logi FALSE
  .. ..$ group_index  : int 1
  .. ..$ group_id : int 262144
  .. ..$ id   : int 1
  .. ..$ dimvarid :List of 5
  .. .. ..$ id : int 2
  .. .. ..$ group_index: int 1
  .. .. ..$ group_id   : int 262144
  .. .. ..$ list_index : num -1
  .. .. ..$ isdimvar   : logi TRUE
  .. .. ..- attr(*, "class")= chr "ncid4"
  .. ..$ units: chr "degrees_north"
  .. ..$ vals : num [1:5(1d)] 39.8 39.9 40 40 40.1
  .. ..$ create_dimvar: logi TRUE
  .. ..- attr(*, "class")= chr "ncdim4"
  ..$ lon :List of 10
  .. ..$ name : chr "lon"
  .. ..$ len  : int 9
  .. ..$ unlim: logi FALSE
  .. ..$ group_index  : int 1
  .. ..$ group_id : int 262144
  .. ..$ id   : int 2
  .. ..$ dimvarid :List of 5
  .. .. ..$ id : int 3
  .. .. ..$ group_index: int 1
  .. .. ..$ group_id   : int 262144
  .. .. ..$ list_index : num -1
  .. .. ..$ isdimvar   : logi TRUE
  .. .. ..- attr(*, "class")= chr "ncid4"
  .. ..$ units: chr "degrees_east"
  .. ..$ vals : num [1:9(1d)] 254 254 254 254 255 ...
  .. ..$ create_dimvar: logi TRUE
  .. ..- attr(*, "class")= chr "ncdim4"
 $ unlimdimid : num -1
 $ nvars  : num 1
 $ var:List of 1
  ..$ precipitation:List of 22
  .. ..$ id:List of 5
  .. .. ..$ id : num 0
  .. .. ..$ group_index: num -1
  .. .. ..$ group_id   : int 262144
  .. .. ..$ list_index : num 1
  .. .. ..$ isdimvar   : logi FALSE
  .. .. ..- attr(*, "class")= chr "ncid4"
  .. ..$ name  : chr "precipitation"
  .. ..$ ndims : int 3
  .. ..$ natts : int 9
  .. ..$ size  : int [1:3] 9 5 7305
  .. ..$ dimids: int [1:3] 2 1 0
  .. ..$ prec  : chr "float"
  .. ..$ units : chr "mm"
  .. ..$ longname  : chr "Precipitation"
  .. ..$ group_index   : int 1
  .. ..$ chunksizes: logi NA
  .. ..$ storage   : num 1
  .. ..$ shuffle   : logi FALSE
  .. ..$ compression   : logi NA
  .. ..$ dims  : list()
  .. ..$ dim   :List of 3
  .. .. ..$ :List of 10
  .. .. .. ..$ name : chr "lon"
  .. .. .. ..$ len  : int 9
  .. .. .. ..$ unlim: logi FALSE
  .. .. .. ..$ group_index  : int 1
  .. .. .. ..$ group_id : int 262144
  .. .. .. ..$ id   : int 2
  .. .. .. ..$ dimvarid :List of 5
  .. .. .. .. ..$ id : int 3
  .. .. .. .. ..$ group_index: int 1
  .. .. .. .. ..$ group_id   : int 262144
  .. .. .. .. ..$ list_index : num -1
  .. .. .. .. ..$ isdimvar   : logi TRUE
  .. .. .. .. ..- attr(*, "class")= chr "ncid4"
  .. .. .. ..$ units: chr "degrees_east"
  .. .. .. ..$ vals : num [1:9(1d)] 254 254 254 254 255 ...
  .. .. .. ..$ create_dimvar: logi TRUE
  .. .. .. ..- attr(*, "class")= chr "ncdim4"
  .. .. ..$ :List of 10
  .. .. .. ..$ name : chr "lat"
  .. .. .. ..$ len  : int 5
  .. .. .. ..$ unlim: logi FALSE
  .. .. .. ..$ group_index  : int 1
  .. .. .. ..$ group_id : int 262144
  .. .. .. ..$ id   : int 1
  .. .. .. ..$ dimvarid :List of 5
  .. .. .. .. ..$ id : int 2
  .. .. .. .. ..$ group_index: int 1
  .. .. .. .. ..$ group_id   : int 262144
  .. .. .. .. ..$ list_index : num -1
  .. .. .. .. ..$ isdimvar   : logi TRUE
  .. .. .. .. ..- attr(*, "class")= chr "ncid4"
  .. .. .. ..$ units: chr "degrees_north"
  .. .. .. ..$ vals : num 

Re: [R] about netcdf files

2016-07-26 Thread Roy Mendelssohn - NOAA Federal
Hi Lily:

I doubt the mail-list would pass through the netcdf file. Instead, could you do 
the following, and post the results:

library(ncdf4
pre1 = nc_open('sample_precip_daily.nc')
str(pre1)
nc_close(pre1)

I have a feeling you haven't worked much with netcdf files. I will try to find 
a tutorial also to help you along.

Thanks,

-Roy

> On Jul 26, 2016, at 12:07 PM, lily li  wrote:
> 
> 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 
> 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@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.sko...@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.
>> 
> __
> R-help@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.

**
"The contents of this message do not reflect any position of the U.S. 
Government or NOAA."
**
Roy Mendelssohn
Supervisory Operations Research Analyst
NOAA/NMFS
Environmental Research Division
Southwest Fisheries Science Center
***Note new address and phone***
110 Shaffer Road
Santa Cruz, CA 95060
Phone: (831)-420-3666
Fax: (831) 420-3980
e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/

"Old age and treachery will overcome youth and skill."
"From those who have been given much, much will be expected" 
"the arc of the moral universe is long, but it bends toward justice" -MLK Jr.

__
R-help@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.

Re: [R] about netcdf files

2016-07-26 Thread lily li
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 
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@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.sko...@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.
>
__
R-help@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.

Re: [R] about netcdf files

2016-07-26 Thread Jon Skoien

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@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.sko...@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.


__
R-help@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.


Re: [R] about netcdf files

2016-07-26 Thread David Winsemius
Please show code that allows potential responders to reply meaningfully.

-- 
David

> On Jul 25, 2016, at 9:54 PM, 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@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.

__
R-help@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.


[R] about netcdf files

2016-07-25 Thread lily li
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@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.