Repository navigation
fit_HH_x_single_layer() and fit_H4_x_single_layer() subtract the initial damping in place, changing the Damping_Curve's data and the caller's array #84
Description
Found while reviewing #74. Pre-existing on main (b764057); #74 does not change the behavior.
Problem
fit_HH_x_single_layer() and fit_H4_x_single_layer() offset the damping curve with damping_data_in_pct[:, 1] -= init_damping. This writes into the array that the caller passed in.
PySeismoSoil/PySeismoSoil/helper_hh_model.py
Lines 246 to 248 in b764057
| init_damping = damping_data_in_pct[0, 1] # small-strain damping | |
| damping_data_in_pct[:, 1] -= init_damping # offset all dampings | |
| damping_data_in_unit_1 = damping_data_in_pct / 100 # unit: percent --> 1 |
PySeismoSoil/PySeismoSoil/helper_mkz_model.py
Lines 138 to 140 in b764057
| init_damping = damping_data_in_pct[0, 1] # small-strain damping | |
| damping_data_in_pct[:, 1] -= init_damping # offset all dampings | |
| damping_data_in_unit_1 = damping_data_in_pct / 100 # unit: percent --> 1 |
Damping_Curve.get_HH_x_param() and get_H4_x_param() pass self.raw_data. Multiple_Damping_Curves.get_all_HH_x_params() and get_all_H4_x_params() pass each curve's raw_data through fit_all_damping_curves(), which uses the arrays as is.
PySeismoSoil/PySeismoSoil/class_curves.py
Lines 453 to 455 in b764057
| HH_x_param = hh.fit_HH_x_single_layer( | |
| self.raw_data, | |
| use_scipy=use_scipy, |
PySeismoSoil/PySeismoSoil/class_curves.py
Lines 536 to 538 in b764057
| H4_x_param = mkz.fit_H4_x_single_layer( | |
| self.raw_data, | |
| use_scipy=use_scipy, |
PySeismoSoil/PySeismoSoil/class_curves.py
Line 1101 in b764057
| list_of_np_array = [_.raw_data for _ in self.curves] |
PySeismoSoil/PySeismoSoil/class_curves.py
Line 1220 in b764057
| list_of_np_array = [_.raw_data for _ in self.curves] |
PySeismoSoil/PySeismoSoil/helper_site_response.py
Line 2558 in b764057
| curves_list = curves |
When the curve is not interpolated, Curve.__init__() stores raw_data as the caller's array, and damping is a view of its second column. So after a fit, the curve's damping, its raw_data, the caller's array, and get_curve_matrix() are all shifted down by the initial damping.
PySeismoSoil/PySeismoSoil/class_curves.py
Lines 116 to 117 in b764057
| else: | |
| strain, values = data[:, 0], data[:, 1] |
PySeismoSoil/PySeismoSoil/class_curves.py
Line 125 in b764057
| self.raw_data = data |
PySeismoSoil/PySeismoSoil/class_curves.py
Line 371 in b764057
| self.damping = self.values |
import numpy as np
from PySeismoSoil.class_curves import Damping_Curve, Multiple_Damping_Curves
data = np.genfromtxt('tests/files/curve_FKSH14.txt')[:, 2:4] # strain [%], damping [%]
user_array = data.copy()
curve = Damping_Curve(user_array)
print(curve.damping[:3], user_array[:3, 1])
# [1.6683 1.8386 2.4095] [1.6683 1.8386 2.4095]
curve.get_HH_x_param(pop_size=1, n_gen=1)
print(curve.damping[:3], curve.raw_data[:3, 1], user_array[:3, 1])
# [0. 0.1703 0.7412] [0. 0.1703 0.7412] [0. 0.1703 0.7412]
# (expected [1.6683 1.8386 2.4095] for all three)
curve_2 = Damping_Curve(data.copy())
curve_2.get_H4_x_param(pop_size=1, n_gen=1)
print(curve_2.damping[:3])
# [0. 0.1703 0.7412]
mdc = Multiple_Damping_Curves('tests/files/curve_FKSH14.txt')[:2]
mdc.get_all_HH_x_params(pop_size=1, n_gen=1)
print(mdc[0].damping[:3], mdc.get_curve_matrix()[:3, 3])
# [0. 0.1703 0.7412] [0. 0.1703 0.7412]
mdc_2 = Multiple_Damping_Curves('tests/files/curve_FKSH14.txt')[:2]
mdc_2.get_all_H4_x_params(pop_size=1, n_gen=1)
print(mdc_2[0].damping[:3])
# [0. 0.1703 0.7412]Fix
- In
fit_HH_x_single_layer()andfit_H4_x_single_layer(), work on a float copy: for exampledamping_data_in_pct = np.array(damping_data_in_pct, dtype=float)before the offset. This keeps the caller's array, and so the curve objects, unchanged. - Add tests that
Damping_Curve.get_HH_x_param()/get_H4_x_param()andMultiple_Damping_Curves.get_all_HH_x_params()/get_all_H4_x_params()leavecurve.damping,curve.raw_dataand the input array unchanged.
Activity