Skip to content

Commit

Permalink
Fixed SciPy compatibility issue in the arias_duration module.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiolsilva committed Nov 13, 2024
1 parent 2f1f3f0 commit 076851d
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions bbp/comps/arias_duration.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3
"""
BSD 3-Clause License
Copyright (c) 2021, University of Southern California
Copyright (c) 2024, University of Southern California
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -40,6 +41,12 @@
import math
import scipy.integrate

# Compatible with SciPy 1.4
try:
cumulative_trapezoid = scipy.integrate.cumulative_trapezoid
except AttributeError:
cumulative_trapezoid = scipy.integrate.cumtrapz

# Converting to cm units. Use approximation to g
G_TO_CMS = 981.0 # %(cm/s)

Expand Down Expand Up @@ -97,9 +104,9 @@ def ad_from_acc(a_in_peer_file, a_out_ad):
# Integrate and calculate vel and disp arrays
#
acc_cms = [value * G_TO_CMS for value in acc]
velo = list(dt * scipy.integrate.cumtrapz(acc_cms))
velo = list(dt * cumulative_trapezoid(acc_cms))
velo.insert(0, 0)
disp = list(dt * scipy.integrate.cumtrapz(velo))
disp = list(dt * cumulative_trapezoid(velo))
disp.insert(0, 0)

#
Expand Down Expand Up @@ -138,7 +145,7 @@ def ad_from_acc(a_in_peer_file, a_out_ad):
# Arias Intensities
# Using the trapezoidal integration
arias_intensity = [pow((value * G_TO_CMS), 2) for value in acc]
tsum = list(scipy.integrate.cumtrapz(arias_intensity) * dt)
tsum = list(cumulative_trapezoid(arias_intensity) * dt)
tsum.insert(0, 0)

arias_intensity = [num * math.pi / (2 * G_TO_CMS) for num in tsum]
Expand Down

0 comments on commit 076851d

Please sign in to comment.