dklinges9 / mcera5

mcera5
12 stars 9 forks source link

Error in R_nc4_open: Too many open files #13

Closed lysoifer closed 2 years ago

lysoifer commented 2 years ago

I am trying to extract ERA5 data for a list of coordinates, but when I loop through the list I receive the error "Error in R_nc4_open: Too many open files" after several iterations. I think this error is caused by not closing the nc file somewhere [sneumann/mzR/issues/185]. I tried reinstalling the 'xcms' package as mentioned in the previous thread, but am still receiving the same error. Do you know where the issue might be?

for (i in c(1:length(pai_tiles))) {
  ll = latlongfromraster(pai_tiles[[i]])
  weath = list()
  for (yr in c(1:length(my_nc))) {
    # extract data from ERA5
    nc = my_nc[yr]
    w = extract_clim(nc = nc,
                     long = ll$long, lat = ll$lat,
                     start_time = st_times[[yr]], end_time = en_times[[yr]])
    weath[[yr]] = w
  }
  # bind together weather dataframes for all years
  weath.df = rbindlist(weath)
  weather[[i]] = weath.df
  rm(weath, weath.df)
}

Error in R_nc4_open: Too many open files
Error in nc_open(nc) : 
  Error in nc_open trying to open file C:/Users/lsoif/OneDrive - University of Cambridge/Lydia Soifer/Brazil microclimates/data/ERA5/era5_Brazil_TAL_2011_2020_2014.nc (return_on_error= FALSE )

Thanks.

dklinges9 commented 2 years ago

Hi Lydia, I'm just replying quickly to acknowledge receipt of this issue-- I'm currently working on some other updates to the package and will circle back to this soon. From what you've written it does appear that an nc_close() may be useful somewhere. Would you mind emailing me the netCDF file(s) represented by my_nc in your example, so I can try to reproduce your example?

dklinges9@gmail.com

Thanks, Dave

dklinges9 commented 2 years ago

Address in pull request #15. Closing for now but will re-open if this crops up again. Thanks again @lysoifer !