Last active
January 27, 2023 15:35
-
-
Save hrzn/dd81ce4770626527a33dd3308cc02827 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# First, some imports: | |
import numpy as np | |
from darts.utils import timeseries_generation as tg | |
np.random.seed(42) | |
LENGTH = 3 * 365 # 3 years of daily data | |
# Melting: a sine with yearly periodicity and additive white noise | |
melting = (tg.sine_timeseries(length=LENGTH, | |
value_frequency=(1/365), | |
freq='D', | |
column_name='melting') | |
+ 0.15 * tg.gaussian_timeseries(length=LENGTH, freq='D')) | |
# Rainfalls: a sine with bi-weekly periodicity and additive white noise | |
rainfalls = (tg.sine_timeseries(length=LENGTH, | |
value_frequency=(1/14), | |
freq='D', | |
column_name='rainfall') | |
+ 0.3 * tg.gaussian_timeseries(length=LENGTH, freq='D')) | |
# We scale and shift the melting by 5 days; giving us the melting contribution | |
melting_contribution = 0.5 * melting.shift(5) | |
# We compute similar contribution from the rainfalls | |
all_contributions = [melting_contribution] + [0.1 * rainfalls.shift(lag) for lag in range(5)] | |
# We compute the final flow as the sum of everything, | |
# trimming series so they all have the same start time | |
flow = sum([series[melting_contribution.start_time():][:melting.end_time()] | |
for series in all_contributions]).with_columns_renamed('melting', 'flow') | |
# add some white noise | |
flow += 0.1 * tg.gaussian_timeseries(length=len(flow)) | |
melting.plot() | |
rainfalls.plot() | |
flow.plot(lw=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment