今年12月至1月的平均日数 [英] Average day of the year across December-January
问题描述
dt1
或 dt2
中显示的日期。我需要计算这些最大值的一年的平均日期(DOY)。 问题是,对于 dt1
(211)和 dt2
(356)。原因很明显,一些 dt1
的元素是在1月份,所以相应的DOY非常小,并导致平均下降。
我最初使用另外一个月作为起点来计算DOY,但是这产生了其他时间序列的问题,在新的起点附近达到顶峰。
这个问题有一般的,全年的 解决方案吗?
dt1 = [datetime(2000,12,15),datetime(2001,12,16 ),datetime(2002,12,20),datetime(2004,1,2),datetime(2005,1,1)]
dt2 = [datetime(2000,12,15),datetime(2001,12 ,16),datetime(2002,12,20),datetime(2003,12,31),datetime(2004,12,30)]
doys1 = np.array([dt.timetuple()。tm_yday for dt in dt1])$ b $ b doys2 = np.array([dt.timetuple()。tm_yday for dt in dt2])
print doys1.mean()
print doys2.mean()
谢谢!
经过一番谷歌搜索,我发现你正在寻找的是一种计算一个循环数量的意思。更多的谷歌搜索显示,这是在 scipy
图书馆。我发现感谢这个答案,但是我尝试找到一些关于功能的正确文档失败了本身并恢复检查源代码,以便了解如何调用它。
>>>导入numpy为np
>>>>来自scipy import stats
>>>> from datetime import datetime
>>>>
>>> dt1 = [datetime(2000,12,15),datetime(2001,12,16),datetime(2002,12,20),datetime(2004,1,2),datetime(2005,1,1)]
>>>> dt2 = [datetime(2000,12,15),datetime(2001,12,16),datetime(2002,12,20),datetime(2003,12,31),datetime(2004,12,30)]
>>>> doys1 = np.array(dttupuple().tm_yday for dt in dt1])$ b $ b>>>> doys2 = np.array(dttupuple().tm_yday for dt in dt2])
>>>>
>>> stats.circmean(doys1,high = 365)
357.39332727199502
>>> stats.circmean(doys2,high = 365)
356.79551148217894
Imagine a time series that peaks cyclically around end-December/early-January. The maxima of the series will then have dates like those showed in dt1
or dt2
below. I need to compute the average day of the year (DOY) of those maxima.
The problem is that a normal average would give very different results for dt1
(211) and dt2
(356). The cause is obviously that some elements of dt1
are in January, so the corresponding DOYs are very small and bring the resulting average down.
I originally worked this around using another month as the origin to calculate the DOYs, but this created problems with other time series peaked around the new origin.
Is there a general, all-year-round solution to this problem?
dt1 = [datetime(2000, 12, 15), datetime(2001, 12, 16), datetime(2002,12,20), datetime(2004,1,2) , datetime(2005,1,1)]
dt2 = [datetime(2000, 12, 15), datetime(2001, 12, 16), datetime(2002,12,20), datetime(2003,12,31), datetime(2004,12,30)]
doys1 = np.array([dt.timetuple().tm_yday for dt in dt1])
doys2 = np.array([dt.timetuple().tm_yday for dt in dt2])
print doys1.mean()
print doys2.mean()
Thanks!
After a bit of googling, I've found that what you're looking for is a way to calculate a mean of circular quantities. Some more googling revealed that this is implemented in the scipy
library. I've found it thanks to this answer, however I've failed in my attempts to locate some proper documentation on the function itself and reverted to inspecting the source code in order to find out how it should be invoked.
>>> import numpy as np
>>> from scipy import stats
>>> from datetime import datetime
>>>
>>> dt1 = [datetime(2000, 12, 15), datetime(2001, 12, 16), datetime(2002,12,20), datetime(2004,1,2) , datetime(2005,1,1)]
>>> dt2 = [datetime(2000, 12, 15), datetime(2001, 12, 16), datetime(2002,12,20), datetime(2003,12,31), datetime(2004,12,30)]
>>> doys1 = np.array([dt.timetuple().tm_yday for dt in dt1])
>>> doys2 = np.array([dt.timetuple().tm_yday for dt in dt2])
>>>
>>> stats.circmean(doys1, high=365)
357.39332727199502
>>> stats.circmean(doys2, high=365)
356.79551148217894
这篇关于今年12月至1月的平均日数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!