Coverage for bilby/core/series.py: 100%

62 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-05-06 04:57 +0000

1from . import utils 

2 

3 

4class CoupledTimeAndFrequencySeries(object): 

5 

6 def __init__(self, duration=None, sampling_frequency=None, start_time=0): 

7 """ A waveform generator 

8 

9 Parameters 

10 ========== 

11 sampling_frequency: float, optional 

12 The sampling frequency 

13 duration: float, optional 

14 Time duration of data 

15 start_time: float, optional 

16 Starting time of the time array 

17 """ 

18 self._duration = duration 

19 self._sampling_frequency = sampling_frequency 

20 self.start_time = start_time 

21 self._frequency_array_updated = False 

22 self._time_array_updated = False 

23 self._frequency_array = None 

24 self._time_array = None 

25 

26 def __repr__(self): 

27 return self.__class__.__name__ + '(duration={}, sampling_frequency={}, start_time={})'\ 

28 .format(self.duration, self.sampling_frequency, self.start_time) 

29 

30 @property 

31 def frequency_array(self): 

32 """ Frequency array for the waveforms. Automatically updates if sampling_frequency or duration are updated. 

33 

34 Returns 

35 ======= 

36 array_like: The frequency array 

37 """ 

38 if not self._frequency_array_updated: 

39 if self.sampling_frequency and self.duration: 

40 self._frequency_array = utils.create_frequency_series( 

41 sampling_frequency=self.sampling_frequency, 

42 duration=self.duration) 

43 else: 

44 raise ValueError('Can not calculate a frequency series without a ' 

45 'legitimate sampling_frequency ({}) or duration ({})' 

46 .format(self.sampling_frequency, self.duration)) 

47 

48 self._frequency_array_updated = True 

49 return self._frequency_array 

50 

51 @frequency_array.setter 

52 def frequency_array(self, frequency_array): 

53 self._frequency_array = frequency_array 

54 self._sampling_frequency, self._duration = \ 

55 utils.get_sampling_frequency_and_duration_from_frequency_array(frequency_array) 

56 self._frequency_array_updated = True 

57 

58 @property 

59 def time_array(self): 

60 """ Time array for the waveforms. Automatically updates if sampling_frequency or duration are updated. 

61 

62 Returns 

63 ======= 

64 array_like: The time array 

65 """ 

66 

67 if not self._time_array_updated: 

68 if self.sampling_frequency and self.duration: 

69 self._time_array = utils.create_time_series( 

70 sampling_frequency=self.sampling_frequency, 

71 duration=self.duration, 

72 starting_time=self.start_time) 

73 else: 

74 raise ValueError('Can not calculate a time series without a ' 

75 'legitimate sampling_frequency ({}) or duration ({})' 

76 .format(self.sampling_frequency, self.duration)) 

77 

78 self._time_array_updated = True 

79 return self._time_array 

80 

81 @time_array.setter 

82 def time_array(self, time_array): 

83 self._time_array = time_array 

84 self._sampling_frequency, self._duration = \ 

85 utils.get_sampling_frequency_and_duration_from_time_array(time_array) 

86 self._start_time = time_array[0] 

87 self._time_array_updated = True 

88 

89 @property 

90 def duration(self): 

91 """ Allows one to set the time duration and automatically updates the frequency and time array. 

92 

93 Returns 

94 ======= 

95 float: The time duration. 

96 

97 """ 

98 return self._duration 

99 

100 @duration.setter 

101 def duration(self, duration): 

102 self._duration = duration 

103 self._frequency_array_updated = False 

104 self._time_array_updated = False 

105 

106 @property 

107 def sampling_frequency(self): 

108 """ Allows one to set the sampling frequency and automatically updates the frequency and time array. 

109 

110 Returns 

111 ======= 

112 float: The sampling frequency. 

113 

114 """ 

115 return self._sampling_frequency 

116 

117 @sampling_frequency.setter 

118 def sampling_frequency(self, sampling_frequency): 

119 self._sampling_frequency = sampling_frequency 

120 self._frequency_array_updated = False 

121 self._time_array_updated = False 

122 

123 @property 

124 def start_time(self): 

125 return self._start_time 

126 

127 @start_time.setter 

128 def start_time(self, start_time): 

129 self._start_time = start_time 

130 self._time_array_updated = False