r@i@1290 m@iii@g oii @im@com
2019-Mar-16 17:50 UTC
[R] Problems trying to make a time series using NetCDF file
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]]
Jeff Newmiller
2019-Mar-17 01:33 UTC
[R] Problems trying to make a time series using NetCDF file
You might have better luck on the R-sig-spatial mailing list. If you had provided a reproducible example ("reprex") then I might have tried to answer the question but I don't use these tools often enough to grasp the source of your problem based only on diagnostics. And even though they might have a better chance of seeing the issue with only diagnostics, I am sure they would appreciate a reprex too. On March 16, 2019 10:50:46 AM PDT, rain1290--- via R-help <r-help at 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 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.-- Sent from my phone. Please excuse my brevity.
David W. Pierce
2019-Mar-17 02:02 UTC
[R] Problems trying to make a time series using NetCDF file
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 at 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 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. >-- 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 at ucsd.edu [[alternative HTML version deleted]]