今年12月至1月的平均日数 [英] Average day of the year across December-January

查看:184
本文介绍了今年12月至1月的平均日数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下,在12月底和1月初期间,周期性地出现了一个时间序列。该系列的最大值将具有如下所示的日期: 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆