I've been trying to replace the value of a cell (meaning, a point with an specific latitude and longitude) in a xarray dataset. The coordinares of my Dataset are lon, lat and time. I want to replace the value of certain lat and lon with the mean of the adjacent cells across time.
So far I've managed to replace it with an scalar (e.g. ds.loc[{'lon': long, 'lat': lat}]['qtot'] = 1
, but when I try to replace it with an array or dataarray it seems ok but it does not update the value in the original dataset. I've tried the following expressions:
ds.loc[{'lon': lon, 'lat': lat}]['qtot'] = ds.loc[{'lon': slice(lon-0.5, lon+0.5), 'lat': slice(lat+0.5, lat-0.5)}]['qtot'].mean(['lat', 'lon'])
ds.loc[{'lon': lon, 'lat': lat}]['qtot'].values = ds.loc[{'lon': slice(lon-0.5, lon+0.5), 'lat': slice(lat+0.5, lat-0.5)}]['qtot'].mean(['lat', 'lon']).values
Any ideas would be much appreciated.