Skip to content

Commit

Permalink
Fixed bug where cached parameters were stored as class variables
Browse files Browse the repository at this point in the history
and not being overridden
  • Loading branch information
millen1m committed May 3, 2019
1 parent cf6217e commit d323507
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
27 changes: 7 additions & 20 deletions eqsig/single.py
Expand Up @@ -347,26 +347,6 @@ def running_average(self, width=1):


class AccSignal(Signal):
_cached_response_spectra = False
_cached_disp_and_velo = False
_cached_xi = 0.05
_cached_params = {}
_s_a = None
_s_v = None
_s_d = None
t_b01 = 0.0
t_b05 = 0.0
t_b10 = 0.0
a_rms01 = 0.0
a_rms05 = 0.0
a_rms10 = 0.0
t_595 = 0.0 # significant duration
sd_start = 0.0 # start time of significant duration
sd_end = 0.0 # end time of significant duration
arias_intensity_series = None
arias_intensity = 0.0
cav_series = None
cav = 0.0

def __init__(self, values, dt, label='m1', smooth_freq_range=(0.1, 30), verbose=0, response_times=(0.1, 5), ccbox=0):
"""
Expand Down Expand Up @@ -395,6 +375,13 @@ def __init__(self, values, dt, label='m1', smooth_freq_range=(0.1, 30), verbose=
self.response_times = np.array(response_times)
self._velocity = np.zeros(self.npts)
self._displacement = np.zeros(self.npts)
self._cached_params = {}
self._cached_response_spectra = False
self._cached_disp_and_velo = False
self._cached_xi = 0.05
self._s_a = None
self._s_v = None
self._s_d = None

def clear_cache(self):
self._cached_smooth_fa = False
Expand Down
9 changes: 9 additions & 0 deletions tests/test_acc_signal.py
Expand Up @@ -136,6 +136,15 @@ def test_duration_stats(asig_t1):
assert np.isclose(eqsig.im.calc_brac_dur(asig_t1, 0.05), 15.41) # eqsig==0.5.0
assert np.isclose(eqsig.im.calc_brac_dur(asig_t1, 0.1), 8.41) # eqsig==0.5.0


def test_variables_are_over_writable():
a1 = np.random.rand(100)
asig1 = eqsig.AccSignal(a1, 1)
asig2 = eqsig.AccSignal(a1 * 2, 1)
assert asig2.pga != asig1.pga

#
# if __name__ == '__main__':
# show_response_spectra_at_high_frequencies()

print(np.random.rand(100))

0 comments on commit d323507

Please sign in to comment.