Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in executing randomization of modulus reduction and damping ratio curves #19

Open
AniketSanjayDesai opened this issue Apr 15, 2023 · 6 comments

Comments

@AniketSanjayDesai
Copy link

Hello.
I have been using PYSTRATA for a long time and it worked very well. However, I just downloaded the latest version of PYSTRATA and Python both. During an equivalent linear analysis based on one of your examples, I executed the following command to implement the randomization of modulus reduction and damping ratio curves:

var_soiltypes = pystrata.variation.DarendeliVariation(-0.5)
count = 4
for geopsy_profile in iter_geopsy_profiles(fname):
for profile in pystrata.variation.iter_varied_profiles(
profile,
count,
var_thickness=None,
var_velocity=None,
var_soiltypes=var_soiltypes
):
calc(ts, profile, profile.location('outcrop', index=-1))
outputs(calc)

In earlier versions, it used to show only this message:
C:\Users\ADMIN\anaconda3\lib\site-packages\pystrata\site.py:741: RuntimeWarning: divide by zero encountered in divide
err = 100.0 * np.max((self.previous - self.value) / self.value)
C:\Users\ADMIN\anaconda3\lib\site-packages\pystrata\site.py:741: RuntimeWarning: invalid value encountered in divide
err = 100.0 * np.max((self.previous - self.value) / self.value)

But, it used to work well and provided the results properly.

However, with the latest version, It showed this message:
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\site.py:804: RuntimeWarning: divide by zero encountered in divide
err = 100.0 * np.max((self.previous - self.value) / self.value)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\site.py:804: RuntimeWarning: invalid value encountered in divide
err = 100.0 * np.max((self.previous - self.value) / self.value)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:327: RuntimeWarning: overflow encountered in multiply
waves_a[i + 1, :] = 0.5 * waves_a[i] * (1 + cimped) * np.exp(
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:327: RuntimeWarning: invalid value encountered in multiply
waves_a[i + 1, :] = 0.5 * waves_a[i] * (1 + cimped) * np.exp(
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:329: RuntimeWarning: overflow encountered in multiply
) + 0.5 * waves_b[i] * (1 - cimped) * np.exp(-cterm)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:327: RuntimeWarning: invalid value encountered in add
waves_a[i + 1, :] = 0.5 * waves_a[i] * (1 + cimped) * np.exp(
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:330: RuntimeWarning: overflow encountered in multiply
waves_b[i + 1, :] = 0.5 * waves_a[i] * (1 - cimped) * np.exp(
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:330: RuntimeWarning: invalid value encountered in multiply
waves_b[i + 1, :] = 0.5 * waves_a[i] * (1 - cimped) * np.exp(
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:332: RuntimeWarning: overflow encountered in multiply
) + 0.5 * waves_b[i] * (1 + cimped) * np.exp(-cterm)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:330: RuntimeWarning: invalid value encountered in add
waves_b[i + 1, :] = 0.5 * waves_a[i] * (1 - cimped) * np.exp(
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:369: RuntimeWarning: overflow encountered in multiply
return 2 * self._waves_a[l.index] * np.exp(cterm)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:369: RuntimeWarning: invalid value encountered in multiply
return 2 * self._waves_a[l.index] * np.exp(cterm)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:455: RuntimeWarning: overflow encountered in multiply
denom = -(ang_freqs2) * self.wave_at_location(lin)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:455: RuntimeWarning: invalid value encountered in multiply
denom = -(ang_freqs
2) * self.wave_at_location(lin)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:461: RuntimeWarning: invalid value encountered in divide
tf[mask] = GRAVITY * numer[mask] / denom[mask]
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:461: RuntimeWarning: overflow encountered in multiply
tf[mask] = GRAVITY * numer[mask] / denom[mask]
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:309: RuntimeWarning: invalid value encountered in divide
wave_nums[i, :] = angular_freqs / l.comp_shear_vel
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:329: RuntimeWarning: invalid value encountered in multiply
) + 0.5 * waves_b[i] * (1 - cimped) * np.exp(-cterm)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:332: RuntimeWarning: invalid value encountered in multiply
) + 0.5 * waves_b[i] * (1 + cimped) * np.exp(-cterm)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:451: RuntimeWarning: overflow encountered in multiply
self._waves_a[lout.index, :] * np.exp(cterm)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:451: RuntimeWarning: invalid value encountered in multiply
self._waves_a[lout.index, :] * np.exp(cterm)
C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:452: RuntimeWarning: invalid value encountered in multiply

  • self._waves_b[lout.index, :] * np.exp(-cterm)
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:448: RuntimeWarning: overflow encountered in multiply
    1j
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:461: RuntimeWarning: invalid value encountered in multiply
    tf[mask] = GRAVITY * numer[mask] / denom[mask]
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:327: RuntimeWarning: overflow encountered in exp
    waves_a[i + 1, :] = 0.5 * waves_a[i] * (1 + cimped) * np.exp(
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:330: RuntimeWarning: overflow encountered in exp
    waves_b[i + 1, :] = 0.5 * waves_a[i] * (1 - cimped) * np.exp(
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:448: RuntimeWarning: invalid value encountered in multiply
    1j
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:451: RuntimeWarning: invalid value encountered in subtract
    self._waves_a[lout.index, :] * np.exp(cterm)
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:451: RuntimeWarning: overflow encountered in subtract
    self._waves_a[lout.index, :] * np.exp(cterm)
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:309: RuntimeWarning: divide by zero encountered in divide
    wave_nums[i, :] = angular_freqs / l.comp_shear_vel
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:362: RuntimeWarning: invalid value encountered in multiply
    cterm = 1j * self._wave_nums[l.index] * l.depth_within
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\site.py:804: RuntimeWarning: divide by zero encountered in double_scalars
    err = 100.0 * np.max((self.previous - self.value) / self.value)
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:387: RuntimeWarning: invalid value encountered in divide
    tf = self.wave_at_location(lout) / self.wave_at_location(lin)
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\propagation.py:561: RuntimeWarning: divide by zero encountered in double_scalars
    l.strain = self._motion.pgv / l.initial_shear_vel
    C:\Users\ADMIN\miniconda3\lib\site-packages\pystrata\site.py:804: RuntimeWarning: invalid value encountered in double_scalars
    err = 100.0 * np.max((self.previous - self.value) / self.value)

After that, it generated results, but in the output, the majority of the values are shown as 'NaN' and therefore, in the plots also, very few output curves are shown (Figure attached(Previous version and current)). I request you to kindly let me know how to rectify this error.

PreviousVersion
LatestVersion

@arkottke
Copy link
Owner

Can you provide the complete script that causes this problem?

@AniketSanjayDesai
Copy link
Author

Sure Here is the script:

import numba
import re
import matplotlib.pyplot as plt
import numpy as np
import pystrata
%matplotlib inline

Increased figure sizes

plt.rcParams['figure.dpi'] = 120

def iter_geopsy_profiles(fname):
"""Read a Geopsy formatted text file created by gpdcreport."""
with open(fname) as fp:
next(fp)
while True:
try:
line = next(fp)
except StopIteration:
break

        m = re.search(r'Layered model (\d+): value=([0-9.]+)', line)
        id, score = m.groups()
        count = int(next(fp))
        d = {
            'id': id,
            'score': score,
            'layers': [],
        }
        cols = ['thickness', 'vel_comp', 'vel_shear', 'density']
        for _ in range(count):
            values = [float(p) for p in next(fp).split()]
            d['layers'].append(dict(zip(cols, values)))
        yield d

fname = 'data/ChamoliAftershock.AT2'
ts = pystrata.motion.TimeSeriesMotion.load_at2_file(fname)
ts.accels

calc = pystrata.propagation.EquivalentLinearCalculator()

freqs = np.logspace(-1, 2, num=500)

outputs = pystrata.output.OutputCollection([
pystrata.output.ResponseSpectrumOutput(
# Frequency
freqs,
# Location of the output
pystrata.output.OutputLocation('outcrop', index=0),
# Damping
0.05),
pystrata.output.ResponseSpectrumRatioOutput(
# Frequency
freqs,
# Location in (denominator),
pystrata.output.OutputLocation('outcrop', index=-1),
# Location out (numerator)
pystrata.output.OutputLocation('outcrop', index=0),
# Damping
0.05),
pystrata.output.FourierAmplitudeSpectrumOutput(
# Frequency
freqs,
# Location of the output
pystrata.output.OutputLocation('outcrop', index=0),
# Bandwidth for Konno-Omachi smoothing window
ko_bandwidth=30),
pystrata.output.AccelTransferFunctionOutput(
# Frequency
freqs,
# Location in (denominator),
pystrata.output.OutputLocation('outcrop', index=-1),
# Location out (numerator)
pystrata.output.OutputLocation('outcrop', index=0)
)
])

fname = 'data/EQD_NoAPAll.txt'
for geopsy_profile in iter_geopsy_profiles(fname):
profile = pystrata.site.Profile([
pystrata.site.Layer(
pystrata.site.DarendeliSoilType(
l['density'] * 9.81/1000, plas_index=0, ocr=1, stress_mean=200),
l['thickness'], l['vel_shear'])
for i, l in enumerate(geopsy_profile['layers'])
])
profile[-1].soil_type.damping = 0.02

var_soiltypes = pystrata.variation.DarendeliVariation(-0.5)
count = 4
for geopsy_profile in iter_geopsy_profiles(fname):
for profile in pystrata.variation.iter_varied_profiles(
profile,
count,
var_thickness=None,
var_velocity=None,
var_soiltypes=var_soiltypes
):
calc(ts, profile, profile.location('outcrop', index=-1))
outputs(calc)

for o in outputs:
fig, ax = plt.subplots()
ax.plot(o.refs, o.values)
ax.set(xlabel=o.xlabel, xscale='log', ylabel=o.ylabel)
fig.tight_layout();

The required input files are attached herewith.
data.zip

@arkottke
Copy link
Owner

Please attach the actual file as the formatting is lost when you just paste the code as a comment.

@AniketSanjayDesai
Copy link
Author

Ex6_MRDR_final-Copy5.zip

@arkottke
Copy link
Owner

arkottke commented Apr 18, 2023

A few comments.

In this cell:

var_soiltypes = pystrata.variation.DarendeliVariation(-0.5)
count = 4
for geopsy_profile in iter_geopsy_profiles(fname):
    for profile in pystrata.variation.iter_varied_profiles(
            profile,
            count,
            var_thickness=None,
            var_velocity=None,
            var_soiltypes=var_soiltypes
        ):
            calc(ts, profile, profile.location('outcrop', index=-1))
            outputs(calc)

You are only varying the last created profile. The for loop that loop[s over iter_geopsy_profile(fname) is never used.
More importantly, you are using the variable named profile multiple times and they are overwriting each other. It works if you change it to something like this:

var_soiltypes = pystrata.variation.DarendeliVariation(-0.5)
count = 4
for geopsy_profile in iter_geopsy_profiles(fname):
    for p in pystrata.variation.iter_varied_profiles(
            profile,
            count,
            var_thickness=None,
            var_velocity=None,
            var_soiltypes=var_soiltypes
        ):
            calc(ts, p, p.location('outcrop', index=-1))
            outputs(calc)

@AniketSanjayDesai
Copy link
Author

It is working now.
Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants