I have a really long dataset in Xarray that I must resample using both a custom function and the mean function to create a new dataset with both data.
To do this, I do
ds_res = ds.resample(time=freq)
ds_mean = ds_res.mean('time')
aux_time = [] ; aux_custom = []
for time,data in ds_res:
aux_time.append(time)
aux_custom.append( custom_function(data) )
new_ds = xarray.Dataset( ... ) #Merge both ds_mean and aux_custom over the coord time
This works well ALMOST every time, but sometimes the length of the aux lists are smaller than the length of the resample:
len(ds_res) > len(aux_time)
So when I try to create the new dataframe it gives me the error of "ValueError: conflicting sizes for dimensions ..."
Any idea why this happens?? I checked the for loop and it really does less iterations than the length of the resampled dataset.
Maybe it is because of NaN values or something, I have no idea.
For the
Dataset
parameterdata_vars
, each dimension must have the same length in all variables in which it appears, as described here.Are you specifying
dims
as aset
instead of alist
?Maybe the example from this answer might help you: https://stackoverflow.com/a/60529275/16116707