geospatialpython-xarraysatellite-image

Taking differences along time axis for the data with irregular overpass time


I wonder how to take differences along the time axis of data with the irregular overpass time with Xarray.

Data:

What I want to do:

Calculate the difference of the soil moisture data along the time axis, ignoring NaN data. For example, in pandas dataframes, I can achieve it by dropping NaN data and take the diff(). Now I want to do it in Xarray; however, an element-wise drop is not supported in Xarray, so I am at a loss.

What I tried:

I am looking for any algorithms or workaround!


Solution

  • Thanks to @MichaelDelgado here is the answer.

    da.bfill(dim="time").diff(dim="time").where(da.notnull().shift(time=+1))
    

    Another note: I also dug into sparse array, but there was no good solution to it.