Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

""" Tools for generating simulated datasets 

 

The intent of this module is to provide tools for generating simulated data 

that is usefulf for testing, debugging, and learning. This module is inspired 

by the :py:func:`sklearn.datasets.make_classification` and 

:py:func:`sklearn.datasets.make_regression`, among others. 

""" 

import numpy as np 

import pandas as pd 

 

 

# Defaults 

_N_SAMPLES = 1000 

_N_SERIES = 3 

_N_SEGMENT = 2 

_DATE_START = '2000-01-01' 

_DATE_END = '2010-01-01' 

_FREQ = '16D' 

 

 

# ============================================================================= 

# Segments 

def make_segments(date_start=None, date_end=None, date_freq=None, 

n_series=3, n_segments=2, seg_sep=None, 

means=None, stds=None, trends=None, 

amplitudes=None, phases=None): 

""" Simulate data from multiple temporal segments 

 

Parameters 

---------- 

date_start : str, datetime, and more, optional 

Starting date (in a format known to Pandas) 

date_end : str, datetime, and more, optional 

Ending date (in a format known to Pandas) 

date_freq : str, optional 

Date frequency 

n_series : int 

Number of series/spectral bands to simulate 

n_segments : int 

Number of segments to simulate 

seg_sep : Sequence[float] 

Separability of segments (i.e., the size of the disturbance) 

means : Sequence[float] 

The mean value for each series/spectral band (passed to 

:py:func:`make_time_series_mean`) 

stds : Sequence[float] 

The standard deviation for each series/spectral band (passed to 

:py:func:`make_time_series_mean`) 

trends : Sequence[float] 

The time trend for each series/spectral band (passed to 

:py:func:`make_time_series_trend`) 

amplitudes : Sequence[float] 

The harmonic amplitude value for each series/spectral band (passed to 

:py:func:`make_time_series_harmonic`) 

phases : Sequence[float] 

The harmonic phase value for each series/spectral band (passed to 

:py:func:`make_time_series_harmonic`) 

 

Returns 

------- 

xr.DataArray 

Simulated data for ``n_segments`` across ``n_series`` series/spectral 

bands 

np.ndarray 

Array of ``datetime64`` indicating the dates of change 

(size=``n_segments - 1``) 

""" 

assert isinstance(n_series, int) 

assert isinstance(n_segments, int) and n_segments >= 1 

# TODO 

pass 

 

 

# ============================================================================= 

# Time series 

def make_dates(date_start=None, date_end=None, date_freq=None): 

""" Return ``datetime64`` dates 

 

Parameters 

---------- 

date_start : str, datetime, and more, optional 

Starting date (in a format known to Pandas) 

date_end : str, datetime, and more, optional 

Ending date (in a format known to Pandas) 

date_freq : str, optional 

Date frequency 

 

Returns 

------- 

np.ndarray 

Dates as ``np.datetime64`` 

 

See Also 

-------- 

pandas.date_range 

""" 

return pd.date_range(date_start, date_end, freq=date_freq).values 

 

 

def make_time_series_mean(dates, mean=None, std=None): 

pass 

 

 

def make_time_series_trend(dates, trend=None): 

pass 

 

 

def make_time_series_harmonic(dates, amplitude=None, phase=None): 

pass 

 

 

def make_time_series_noise(dates, mean=0., std=1.): 

""" Generate a time series of noise 

""" 

# TODO: implement Gaussian noise with mean/std 

# TODO: add kwarg to parametrize noise from clouds/shadows 

pass