在数据中,对不规则的通过时间沿时间轴进行差异化处理。

huangapple go评论117阅读模式
英文:

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

问题

我想知道如何使用Xarray在具有不规则过境时间的数据的时间轴上计算差异。

数据:

  • NASA SMAP L3土壤湿度数据,规则网格
  • 不规则的过境时间。每两天或三天一次,取决于过境情况。缺少的每日数值用NaN填充。

我想做的事情:

计算土壤湿度数据在时间轴上的差异,忽略NaN数据。例如,在pandas数据框中,我可以通过删除NaN数据并使用diff()来实现。现在我想在Xarray中做同样的事情;然而,Xarray不支持逐元素删除,所以我不知道该怎么办。

我尝试过的方法:

  • 简单地使用diff()。由于缺少的每日数值被NaN填充,结果值最终充满NaN。
  • 向前填充NaN数据并使用diff()。这成功地计算了我想要的差异。但我失去了时间信息;与数据对应的原始时间变得不清楚,而这是我下一步需要的。
  • 查看稀疏数组包... 但我没有找到任何有助于计算diff()的东西。

我正在寻找任何算法或解决方法!

英文:

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

Data:

  • NASA SMAP L3 soil moisture data, regularly gridded
  • Irregular overpass time. Two- or three-daily, depending on the overpass. Missing daily values are filled with NaNl.

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:

  • Simply taking diff(). The resulting values end up in full of NaN because missing daily values are filled with NaN.
  • Forward-filling the NaN data and taking diff(). This successfully calculates the differences that I want. However, I lose time information; the original time corresponding to the data becomes unclear, which I need for the next step.
  • Looking into Sparse Array package ... but I didn't find anything helpful to calculate diff().

I am looking for any algorithms or workaround!

答案1

得分: 1

感谢 @MichaelDelgado,以下是答案。

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

另外一点:我也研究了稀疏数组,但没有找到好的解决方案。

英文:

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.

huangapple
  • 本文由 发表于 2023年3月7日 04:57:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75655781.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定