Skip to content

Instantly share code, notes, and snippets.

@MarwanDebbiche
Created October 15, 2020 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarwanDebbiche/c11666369295dca3153ca1bdc0152ff5 to your computer and use it in GitHub Desktop.
Save MarwanDebbiche/c11666369295dca3153ca1bdc0152ff5 to your computer and use it in GitHub Desktop.
import math
import numpy as np # type: ignore
import pandas as pd # type: ignore
from tsgen.time_serie import TimeSerie
def affine(start, end, freq, start_y, end_y) -> TimeSerie:
"""
Generate a linear TimeSerie.
"""
index = pd.date_range(start=start, end=end, freq=freq)
return TimeSerie(
index=index, y_values=np.linspace(start_y, end_y, len(index))
)
def constant(start, end, freq, value) -> TimeSerie:
"""
Generate a constant TimeSerie.
"""
return affine(start, end, freq, value, value)
def cosine(start, end, freq, amp=1, n_periods=1) -> TimeSerie:
"""
Generate a cosine TimeSerie.
"""
index = pd.date_range(start=start, end=end, freq=freq)
return TimeSerie(
index=index,
y_values=amp
* np.cos(np.linspace(0, 2 * math.pi * n_periods, num=len(index))),
)
def sine(start, end, freq, n_periods=1) -> TimeSerie:
"""
Generate a sine TimeSerie.
"""
index = pd.date_range(start=start, end=end, freq=freq)
return TimeSerie(
index=index,
y_values=np.sin(
np.linspace(0, 2 * math.pi * n_periods, num=len(index))
),
)
def randn(start, end, freq, mean=0, std=1) -> TimeSerie:
"""
Generate a random normally distributed TimeSerie.
"""
index = pd.date_range(start=start, end=end, freq=freq)
return TimeSerie(
index=index, y_values=(std * np.random.randn(len(index)) + mean)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment