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

Vlad Amihaesei v|@d@@m|h@e@e|95 @end|ng |rom gm@||@com
Thu Nov 10 04:25:18 CET 2022


Hi,

Or you can try witty terra library :

library(terra)

r <- terra::rast("chess-met_precip_gb_1km_daily_20150101-20150131.nc")
if the nc file has more than one parameters like precipitation,
temperature, humidity etc, try this:
r.sub <- terra::rast("chess-met_precip_gb_1km_daily_20150101-20150131.nc",
subds = "yourvarname")

or with raster library:
r1 <- raster::brick("chess-met_precip_gb_1km_daily_20150101-20150131.nc")
same,
r1.sub <- raster::brick("chess-met_precip_gb_1km_daily_20150101-20150131.nc",
varname  = "yourvarname")

I hope this helps.
Best,
Vlad Amihaesei



On Wed, Nov 9, 2022 at 6:49 PM ani jaya <gaaauul using gmail.com> wrote:

> Maybe you are looking for something like this:
>
> nc_data<-nc_open("chess-met_precip_gb_1km_daily_20150101-20150131.nc")
> lon<-lon<-nc_data$dim$LON$vals
> lat<-nc_data$dim$LAT$vals
>
> or
>
> lon<-ncvar_get(nc_data,nc_data$dim$LON)
> lat<-ncvar_get(nc_data,nc_data$dim$LAT)
>
> Note that the LON and LAT can be anything as Mike said. Hope it's helps.
>
> Ani
>
> On Wed, Nov 9, 2022 at 7:54 PM 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
>
> _______________________________________________
> 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