ErikKusch / KrigR

An R Package for downloading, preprocessing, and statistical downscaling of the European Centre for Medium-range Weather Forecasts ReAnalysis 5 (ERA5) family provided by the European Centre for Medium‐Range Weather Forecasts (ECMWF).
MIT License
103 stars 24 forks source link

Error in R_nc4_create: NetCDF: Invalid argument (creation mode was 0) #54

Closed mankouhi closed 1 year ago

mankouhi commented 1 year ago

hi I am going to use KrigR. As the first step, I tried to download ERA5-Land temperature data via the download_ERA() function. However, I have received this error:

Checking for known data issues. Loading downloaded data for masking and aggregation. Masking according to shape/buffer polygon | | 0%Aggregating to temporal resolution of choice | | 0%Error in R_nc4_create: NetCDF: Invalid argument (creation mode was 0) Error in ncdf4::nc_create(filename, ncvars, force_v4 = force_v4, verbose = verbose) : Error in nc_create!

Maybe I know what I should do? Thank you for your kind help.

ErikKusch commented 1 year ago

Please ensure you are running the latest version of KrigR by reinstalling. If the error persists, please provide a minimal working example script that produces the error.

ErikKusch commented 1 year ago

I imagine this might be related to the same issue mentioned in #29. So I imagine reinstalling is the best option to start troubleshooting. Please let me know if that fixes it.

mankouhi commented 1 year ago

thanks a lot . Of course I will

mankouhi commented 1 year ago

I have installed Rstudio and KrigR packages again using this code.

Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS="true") devtools::install_github("https://github.com/ErikKusch/KrigR") library(KrigR)

i run this I run this code, FirstDL <- download_ERA( Variable = "2m_temperature", # the variable we want to obtain data for DataSet = "era5-land", # the data set we want to obtain data from DateStart = "1995-01-01", # the starting date of our time-window DateStop = "1995-01-31", # the final date of our time-window Extent = Extent_ext, # the spatial preference we are after Dir = Dir.Data, # where to store the downloaded data FileName = "FirstDL", # a name for our downloaded file API_User = API_User, # your API User Number API_Key = API_Key # your API User Key )

however the same error occurred again.

"Checking for known data issues. Loading downloaded data for masking and aggregation. Aggregating to temporal resolution of choice Error in R_nc4_create: NetCDF: Invalid argument (creation mode was 0) Error in ncdf4::nc_create(filename, ncvars, force_v4 = force_v4, verbose = verbose) : Error in nc_create!"

Thank you for your unwavering support,

ErikKusch commented 1 year ago

Heyo - I am afraid this code executes without a hitch for me:

image

Could you provide how you specified Extent_ext? For me, this extent extent(-78.83, -77.87, -0.73, 0.34) worked just fine. You may have to update your ncdf4 library, I reckon. Here is my environment in which the code compiles:

image

Let me know how you get on - I am sure we will find a solution ;-)

mankouhi commented 1 year ago

This is the environment in which the code has been run: R version 4.2.1 (2022-06-23 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

attached base packages: [1] parallel stats graphics grDevices utils datasets methods base

other attached packages: [1] KrigR_0.1.3 terra_1.6-7 httr_1.4.6 stars_0.5-6 abind_1.4-5
[6] fasterize_1.0.4 sf_1.0-8 lubridate_1.9.2 automap_1.1-9 doSNOW_1.0.20
[11] snow_0.4-4 doParallel_1.0.17 iterators_1.0.14 foreach_1.5.2 rgdal_1.5-32
[16] raster_3.5-29 sp_1.5-0 stringr_1.5.0 keyring_1.3.1 ecmwfr_1.5.0
[21] ncdf4_1.21

loaded via a namespace (and not attached): [1] pkgload_1.3.0 jsonlite_1.8.7 shiny_1.7.2 assertthat_0.2.1
[5] remotes_2.4.2 sessioninfo_1.2.2 pillar_1.9.0 lattice_0.20-45
[9] glue_1.6.2 digest_0.6.29 promises_1.2.0.1 colorspace_2.1-0
[13] plyr_1.8.8 htmltools_0.5.3 httpuv_1.6.5 pkgconfig_2.0.3
[17] devtools_2.4.4 purrr_1.0.1 xtable_1.8-4 scales_1.2.1
[21] intervals_0.15.2 processx_3.7.0 later_1.3.0 gstat_2.0-9
[25] timechange_0.2.0 tibble_3.2.1 proxy_0.4-27 ggplot2_3.4.2
[29] generics_0.1.3 usethis_2.1.6 ellipsis_0.3.2 cachem_1.0.6
[33] withr_2.5.0 cli_3.4.1 magrittr_2.0.3 crayon_1.5.1
[37] mime_0.12 memoise_2.0.1 ps_1.7.1 fs_1.5.2
[41] fansi_1.0.3 xts_0.12.1 lwgeom_0.2-8 class_7.3-20
[45] FNN_1.1.3.1 pkgbuild_1.3.1 profvis_0.3.7 tools_4.2.1
[49] prettyunits_1.1.1 lifecycle_1.0.3 munsell_0.5.0 callr_3.7.2
[53] compiler_4.2.1 e1071_1.7-11 spacetime_1.3-0 rlang_1.1.1
[57] classInt_0.4-7 units_0.8-0 grid_4.2.1 rstudioapi_0.15.0 [61] htmlwidgets_1.5.4 miniUI_0.1.1.1 gtable_0.3.3 codetools_0.2-18
[65] reshape_0.8.9 DBI_1.1.3 curl_4.3.2 R6_2.5.1
[69] zoo_1.8-10 dplyr_1.1.2 fastmap_1.1.0 utf8_1.2.2
[73] KernSmooth_2.23-20 stringi_1.7.8 Rcpp_1.0.8.3 vctrs_0.6.3
[77] tidyselect_1.2.0 urlchecker_1.0.1

ErikKusch commented 1 year ago

Right - I am afraid I don't think me putting in the time to compare everyone of your package versions would be a good use of a Sunday. Instead, I notice that some of the packages here are of an earlier version than what I am using. Particularly, you are working with an old R version. Could I trouble you to update your R version and then install KrigR and all its dependencies again from scratch?

ErikKusch commented 1 year ago

Update: here is the session info for a windows server environment in which the code compiles without any issue for me:

image

If you prefer not to install a newer version of R (which I would recommend), this may help you narrow done which dependency causes the issue. The netcdf saving is done via the terra package, so updating this might be your next best bet.

mankouhi commented 1 year ago

Dear Erik Thank you so much for your kind help. I will check them again and ask you later. Have a good holiday.

Best regards, Masoureh

mankouhi commented 1 year ago

Dear Erik, I have updated my R version. It works correctly. Thanks a lot All the best, Mansoureh

mankouhi commented 1 year ago

dear Erik I am going to download the maximum and minimum temperature of Era5-land. Since I know the Copernicus website does not have these parameters. Maybe I know what you suggest. thank you

ErikKusch commented 1 year ago

Hi,

happy to hear the package is now working for you as intended. To obtain maximum and minimum temperature for any given temporal aggregation, you will simply need to set the fun argument to the desired metric (like max and min).