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).
Other
97 stars 23 forks source link

BioClim Aggregation Issues: Temporal aggregation: "Error in .local(x, ...): not a valid subset" #35

Closed japilo closed 1 year ago

japilo commented 1 year ago

Hello again! I have an issue that has come up at the temporal aggregation step of download_ERA. Here is a MWE with the BioClim function calling on download_ERA:

BioClim(Water_Var = "total_precipitation", Y_start = "1940", Y_end = "1941", T_res = 'day', Extent = bbox, DataSet = 'era5', API_User = user, API_Key = key, verbose = TRUE, FileName = 'BioClim_1940_1941.nc', Cores = 1)

I think this may be some issue that arises while indexing the raster stack for the precipitation fix starting at the year 1940.

ErikKusch commented 1 year ago

At a conference all week. I will be slow troubleshooting this.

ErikKusch commented 1 year ago

Nevermind, the opening session allowed me to get some coding and troubleshooting in.

I believe this error may be caused by the first six hours of 01-01-1940 not being available for total precipitation. You can see this when selecting this specific data and the total precipitation variable here. NOTE: this does not affect other water-availability variables like soil moisture levels which I would recommend using over total precipitation anyways (more reliably interpolated and arguably more informative for all plant life).

Instead of coding in a fix for that at this point. I recommend, you forego BioClim computation including 1940. With the development on issue #25, my plans for metadata implementation should take care of such issues.

To summarise, you can "resolve" this problem in two ways:

1. Swap your Water_Var

This runs just fine on my end:

BioClim(Water_Var = "volumetric_soil_water_layer_1", 
Y_start = "1940", 
Y_end = "1941", 
T_res = 'day', 
Extent = bbox, 
DataSet = 'era5', 
API_User = user, 
API_Key = key, 
verbose = TRUE, 
FileName = 'BioClim_1940_1941.nc', 
Cores = 1)

2. Forego Y_start = "1940" until ECMWF makes available Total Precipitation data for the whole year

This works:

BioClim(Water_Var = "total_precipitation", 
Y_start = "1941", 
Y_end = "1942", 
T_res = 'day', 
Extent = bbox, 
DataSet = 'era5', 
API_User = user, 
API_Key = key, 
verbose = TRUE, 
FileName = 'BioClim_1941_1942.nc', 
Cores = 1)