[R-sig-Geo] getting data from an nc file

Michael Sumner md@umner @end|ng |rom gm@||@com
Wed Nov 9 12:54:47 CET 2022


have a look at the output of printing nc_data, you are looking for
dimensions that belong to a 2D (or higher) variable of interest .

They can be called anything, but longitude, lon, x, etc are common. you can
use ncdf4 functions to find them (without reading the output), but it's all
stored in a nested list in nc_data).

See ncmeta package for an alternative way to access the metadata.

Hth, Mike

On Wed, 9 Nov 2022, 21:54 Nick Wray, <nickmwray using gmail.com> wrote:

> Hello
>
> I am trying to get rainfall data from the UK chess-met site
>
>
> https://catalogue.ceh.ac.uk/datastore/eidchub/2ab15bf0-ad08-415c-ba64-831168be7293/precip/
>
> and here there are a large number of nc files eg
>
> "chess-met_precip_gb_1km_daily_20150101-20150131.nc"
>
> I’ve found various sources on the net for opening nc files, and getting the
> data but when I try instructions like
>
> nc_data<-nc_open("chess-met_precip_gb_1km_daily_20150101-20150131.nc")
>
> lon <- ncvar_get(nc_data, "lon")
>
> lon
>
>
>
> the code works but all I get is a series of element numbers and no data:
>
> [,1]     [,2]     [,3]     [,4]     [,5]     [,6]     [,7]     [,8]
>  [,9]
> [,10]    [,11]    [,12]
>
>           [,13]    [,14]    [,15]    [,16]    [,17]    [,18]    [,19]
> [,20]    [,21]    [,22]    [,23]    [,24]
>
>
>
> And similarly for latitude
>
> But if I open the nc file as a raster I get a raster precipitation plot of
> Great Britain, which rather suggests that the lat and long values are in
> there somewhere
>
> Can anyone help with getting the actual data sets out of an nc file?
>
> Thanks Nick Wray
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list