Skip to content

produce_Darendeli_curves() raises TypeError when called with its default strain_in_pct=None #87

Open

Description

@jsh9

Found while reviewing #74. Pre-existing on main (b764057); #74 does not change the behavior.

Problem

produce_Darendeli_curves() documents strain_in_pct=None as "use numpy.geomspace(1e-4, 10, 400)". It does build that array as gamma, but later it takes len(strain_in_pct) instead of len(gamma). With the default, that is len(None), which raises TypeError. The two callers in the package (produce_HH_G_param() and Damping_Calibration.get_damping_curves()) and the tests always pass strain_in_pct, so the default is never run.

strain_in_pct : np.ndarray | None, default=None
The strain values at which to calculate G/Gmax and damping values. If
``None``, numpy.geomspace(1e-4, 10, 400) will be used. Unit: percent.

if strain_in_pct is None:
gamma = np.geomspace(1e-4, 10, 400)
else:
gamma = strain_in_pct.copy()

n_strain_pts = len(strain_in_pct)

import numpy as np

import PySeismoSoil.helper_hh_calibration as hhc

sigma_v0 = np.array([3000.0, 6000.0, 9000.0])

GGmax, xi, gamma_r = hhc.produce_Darendeli_curves(
    sigma_v0, strain_in_pct=np.geomspace(1e-4, 10, 400)
)
print(GGmax.shape)
# (400, 3)

hhc.produce_Darendeli_curves(sigma_v0)  # default: strain_in_pct=None
# TypeError: object of type 'NoneType' has no len()
# (expected the same result as the call above)

Fix

  1. Change line 1025 to n_strain_pts = len(gamma). With that change, produce_Darendeli_curves(sigma_v0) returns the same three arrays as produce_Darendeli_curves(sigma_v0, strain_in_pct=np.geomspace(1e-4, 10, 400)).
  2. Add a test that calls produce_Darendeli_curves() without strain_in_pct and compares it with the explicit call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions