[R] Problems trying to make a time series using NetCDF file

David W. Pierce dp|erce @end|ng |rom uc@d@edu
Sun Mar 17 03:02:50 CET 2019


Hi there,

the reason it's doing this is because there is no variable named "time" in
the file. Obviously I need to patch the ncdf4 package so that it issues an/
understandable error message in this case instead of dying with a weird R
error message. That is probably happening because there is a dimension
named "time", but no variable name "time".

Perhaps what you meant to do instead is get the "Year" variable, which is,
indeed, a variable in the file:

Year <- ncvar_get( Model, "Year" )

Regards,

--Dave


On Sat, Mar 16, 2019 at 5:08 PM rain1290--- via R-help <r-help using r-project.org>
wrote:

> Hi there,
> I am using climate model data in attempt to create a time series for a
> specific location. Getting longitude and latitude is fine. However, I am
> receiving the following error when using the "ncvar_get" function in trying
> to derive the "time" dimension:
> Error in nc$dim[[idobj$list_index]] :
>   attempt to select more than one element in get1index <real>
> What could be causing this?
> -This is what I have done so far:
> #CanESM2 plotting for specified yearncfname<-"MaxPrecCCCMACanESM2rcp45.nc"
> Prec<-raster(ncfname)
> print(Prec)
> Model<-nc_open(ncfname)longitude<-ncvar_get(Model, "lon") #Works fine
> latitude<-ncvar_get(Model, "lat") #Works fine
> time<-ncvar_get(Model, "time") #Error in nc$dim[[idobj$list_index]] :
> attempt to select more than one element in get1index <real>
>
>
> Here is the structure of the file after using "nc_open":
> File MaxPrecCCCMACanESM2rcp45.nc (NC_FORMAT_NETCDF4):
>
>      3 variables (excluding dimension variables):
>         double onedaymax[lon,lat,time]   (Contiguous storage)
>             units: mm/day
>         double fivedaymax[lon,lat,time]   (Contiguous storage)
>             units: mm/day
>         short Year[time]   (Contiguous storage)
>
>      3 dimensions:
>         time  Size:95
>         lat  Size:64
>             units: degree North
>         lon  Size:128
>             units: degree East
> What could be causing this error?
> Thanks in advance, and I look forward to your response!
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using 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.
>


-- 
David W. Pierce
Division of Climate, Atmospheric Science, and Physical Oceanography
Mail Stop 0230
Scripps Institution of Oceanography, La Jolla, California, USA
(858) 534-8276 (voice)  /  (858) 534-8561 (fax)    dpierce using ucsd.edu

	[[alternative HTML version deleted]]



More information about the R-help mailing list