Is there a way to index a 3 dimensional array using some form of time index (datetime etc.) on the 3rd dimension?
My problem is that I am doing time series analysis on several thousand radar images and I need to get, for example, monthly averages. However if i simply average over every 31 arrays in the 3rd dimension it becomes inacurate due to shorter months and missing data etc.
答案 0 :(得分:1)
你可以使用pandas模块。它支持按日期/日期时间范围编制索引。它还支持多索引,允许您以2D方式处理多维数据。
>>> rng = pd.date_range('1/1/2016', periods=100, freq='D')
>>> rng[:5]
DatetimeIndex(['2016-01-01', '2016-01-02', '2016-01-03', '2016-01-04', '2016-01-05'], dtype='datetime64[ns]', freq='D')
>>> ts = pd.Series(np.random.randn(len(rng)), index=rng)
>>> ts.head()
2016-01-01 0.119762
2016-01-02 -0.010990
2016-01-03 0.226537
2016-01-04 -0.087559
2016-01-05 0.484426
Freq: D, dtype: float64
>>> ts.resample('M').mean()
2016-01-31 -0.171578
2016-02-29 0.055878
2016-03-31 -0.243225
2016-04-30 -0.015087
Freq: M, dtype: float64
查看以下详细信息:
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DatetimeIndex.html http://pandas.pydata.org/pandas-docs/stable/timeseries.html http://pandas.pydata.org/pandas-docs/stable/advanced.html
答案 1 :(得分:0)
发布我使用的伪造解决方案:
这里的问题是缺乏3d阵列数据(即satillite,雷达)的日期时间索引。虽然pandas中有时间序列函数,但是没有数组(据我所知)。
此解决方案是可行的,因为我使用的数据文件在名称中具有日期时间,例如' 200401010000'是' yyyymmddhhMM'。
使用此功能,您可以将df重新映射到例如1天,取最小值和最大值的' inx'。这为您提供了数组函数的起始位置。
您还可以在mising日期时插入nans数组(即' inx&min;最大值= nan),以便您的3d数组与实际日期时间的长度相匹配。
评论您是否有问题,或者您是否知道此问题的更好解决方案/包。