使用 Python 生成日和年波动的时间序列



我想生成一个时间序列,y轴为温度,x轴为一年中的小时数。我在想两个正弦波:1 -一个周期设置为1天(模拟夜间低温和白天高温)。振幅也可以是简单的,即1,并使vertical_shift = 25。2 -第一波是"嵌入";在更大的季节性波浪中。

用python模拟这个的正确方法是什么?

包含了一个可能的实现。它利用了cos(2* *t/t)的周期为t的事实,使t =24和t =24*365分别产生一天和一年变化的余弦波。负号类似于从冬至午夜开始的观测情况。

import numpy as np
import matplotlib.pyplot as plt
# parameters
MeanTemp = 15           # Average temperature in the country
DailyAmpl = 10          # Amplitude of the daily cycle
YearlyAmpl = 1          # Amplitude of the yearly cycle
NoiseStd = 0.1          # Standard deviation of normally distributed error term
# Total hours in year
TotalHours = 24*365
# Generate the frequency components of the data
x = np.arange(0, TotalHours)
DailyCycle = -DailyAmpl*np.cos( (2*np.pi)*x/24 )
YearlyCycle = -YearlyAmpl*np.cos( (2*np.pi)*x/TotalHours )
Noise = np.random.normal(0, NoiseStd, TotalHours)
# Final series
y = MeanTemp + DailyCycle + YearlyCycle + Noise
# Visualise result
fig, axs = plt.subplots(2, 1)
axs[0].plot(y)
axs[0].set_title('Complete series')
axs[1].plot(y[0:(10*24)])
axs[1].set_title('First ten days')
plt.show()

最新更新