### Verify PyStrata installation Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Imports PyStrata, prints its version, and runs a simple example to confirm the installation works. ```python import pystrata print(pystrata.__version__) # Run a simple example motion = pystrata.motion.SourceTheoryRvtMotion(6.5, 20, "wna") print("Installation successful!") ``` -------------------------------- ### Development installation from source Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Clones the PyStrata repository and installs it in editable mode for development. ```bash git clone https://github.com/arkottke/pystrata.git cd pystrata pip install -e . ``` -------------------------------- ### Development setup using UV Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Clones the repository, syncs dependencies with UV, and runs tests. ```bash git clone https://github.com/arkottke/pystrata.git cd pystrata uv sync uv run pytest # Run tests ``` -------------------------------- ### Set up local development environment Source: https://github.com/arkottke/pystrata/blob/main/CONTRIBUTING.md Create a virtual environment, navigate into the project directory, and install the package in development mode. ```bash $ mkvirtualenv pystrata $ cd pystrata/ $ python setup.py develop ``` -------------------------------- ### Install optional dependencies Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Installs PyStrata with optional dependencies for testing and documentation. ```bash pip install pystrata[test,docs] ``` -------------------------------- ### Create and use a virtual environment Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Creates a virtual environment, activates it, and installs PyStrata to avoid environment conflicts. ```bash python -m venv pystrata-env source pystrata-env/bin/activate # On Windows: pystrata-env\Scripts\activate pip install pystrata ``` -------------------------------- ### Visualization Example Source: https://github.com/arkottke/pystrata/blob/main/docs/quickstart.rst Complete example that sets up a motion and profile, runs a linear elastic analysis, and plots response spectrum and transfer function using matplotlib. ```python import matplotlib.pyplot as plt import pystrata # Setup motion = pystrata.motion.SourceTheoryRvtMotion(6.5, 20, "wna") profile = pystrata.site.Profile([ pystrata.site.Layer(pystrata.site.SoilType("Soil", 18.0, None, 0.05), 30, 400), pystrata.site.Layer(pystrata.site.SoilType("Rock", 24.0, None, 0.01), 0, 1200), ]) outputs = pystrata.output.OutputCollection([ pystrata.output.ResponseSpectrumOutput(), pystrata.output.AccelTransferFunctionOutput(), ]) # Run analysis calc = pystrata.propagation.LinearElasticCalculator() calc(motion, profile, profile.location("outcrop", index=-1)) # Plot results fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 5)) # Response spectrum rs_output = outputs[0] ax1.loglog(rs_output.periods, rs_output.values) ax1.set_xlabel("Period (s)") ax1.set_ylabel("Spectral Acceleration (g)") ax1.set_title("Surface Response Spectrum") ax1.grid(True) # Transfer function tf_output = outputs[1] ax2.semilogx(tf_output.freqs, abs(tf_output.values)) ax2.set_xlabel("Frequency (Hz)") ax2.set_ylabel("Amplification Factor") ax2.set_title("Acceleration Transfer Function") ax2.grid(True) plt.tight_layout() plt.show() ``` -------------------------------- ### Install pyStrata with pip Source: https://github.com/arkottke/pystrata/blob/main/docs/index.rst Install the pyStrata library using pip. This command is executed in a shell and installs the package from PyPI. ```bash $ python -m pip install pyStrata ``` -------------------------------- ### Initialize quarter-wavelength calculator Source: https://github.com/arkottke/pystrata/blob/main/examples/example-09.ipynb Creates a QuarterWaveLenCalculator with site attenuation 0.04 and gets the input location at the outcrop. ```python calc = pystrata.propagation.QuarterWaveLenCalculator(site_atten=0.04) input_loc = profile.location("outcrop", index=-1) ``` -------------------------------- ### Install PyStrata with --user flag Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Installs PyStrata for the current user to avoid permission errors. ```bash pip install --user pystrata ``` -------------------------------- ### Development installation with optional dependencies Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Clones the repository and installs PyStrata in editable mode with test and documentation dependencies. ```bash git clone https://github.com/arkottke/pystrata.git cd pystrata pip install -e ".[test,docs]" ``` -------------------------------- ### nbsphinx-link .nblink file example Source: https://github.com/arkottke/pystrata/blob/main/DOC_PROMPT.md Example of a .nblink file to link a notebook from outside the docs directory. ```json { "path": "../../examples/my_notebook.ipynb" } ``` -------------------------------- ### Import libraries for PyStrata example Source: https://github.com/arkottke/pystrata/blob/main/examples/example-15.ipynb Imports matplotlib, numpy, pandas, and pystrata for the example. ```python import matplotlib.pyplot as plt import numpy as np import pandas as pd import pystrata ``` -------------------------------- ### pip install pystrata Source: https://github.com/arkottke/pystrata/blob/main/README.md Use to install the latest release of pyStrata from PyPI. ```bash pip install pystrata ``` -------------------------------- ### Environment management commands with UV Source: https://github.com/arkottke/pystrata/blob/main/docs/developer/contributing.rst Commands for installing dependencies, running tests, linting, formatting, and type checking using UV. ```bash # Install all dependencies including dev tools uv sync ``` ```bash # Run tests uv run pytest ``` ```bash # Run linting uv run ruff check src/ tests/ uv run ruff format src/ tests/ ``` ```bash # Run type checking uv run mypy src/ ``` -------------------------------- ### Install or upgrade pyrvt and pystrata with pip Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Installs or upgrades pyrvt and pystrata using pip after dependencies are installed. ```default pip install --upgrade pyrvt pystrata ``` -------------------------------- ### Install PyStrata with conda Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Installs PyStrata from the conda-forge channel using conda. ```bash conda install -c conda-forge pystrata ``` -------------------------------- ### Example commit message for PyStrata contributions Source: https://github.com/arkottke/pystrata/blob/main/docs/developer/contributing.rst A sample commit message following the project's guidelines, including a summary and bullet points. ```text Add support for frequency-dependent damping in RVT motions - Implement FDDampingMixin class - Add tests for frequency-dependent behavior - Update documentation with new damping options Closes #123 ``` -------------------------------- ### Import PyStrata and dependencies for logic tree example Source: https://github.com/arkottke/pystrata/blob/main/examples/example-16.ipynb Imports required libraries including json, matplotlib, numpy, pandas, and PyStrata's logic tree components. Sets matplotlib inline and figure DPI. ```python import json import matplotlib.pyplot as plt import numpy as np import pandas as pd import pystrata from pystrata.logic_tree import Alternative, LogicTree, Node %matplotlib inline plt.rcParams["figure.dpi"] = 120 ``` -------------------------------- ### Logic Tree Structure Example Source: https://github.com/arkottke/pystrata/blob/main/docs/theory/uncertainty.rst Shows a logic tree with weighted alternatives for site response methods and modulus reduction curves. Weights are assigned to each branch (e.g., Equivalent Linear 0.7, Darendeli Curves 0.8). ```default Site Response Method ├── Equivalent Linear (0.7) │ ├── Darendeli Curves (0.8) │ └── Zhang Curves (0.2) └── Frequency Domain (0.3) ├── Darendeli Curves (0.8) └── Zhang Curves (0.2) ``` -------------------------------- ### Install dependencies with conda Source: https://github.com/arkottke/pystrata/blob/main/docs/install.rst Installs required dependencies (setuptools, numpy, scipy, matplotlib, pytest) using conda. ```default conda install --yes setuptools numpy scipy matplotlib pytest ``` -------------------------------- ### Call equivalent linear calculator Source: https://github.com/arkottke/pystrata/blob/main/docs/api/index.rst All propagation calculators implement the same calling interface. This example creates an EquivalentLinearCalculator and invokes it with motion, profile, and output location. ```python calc = pystrata.propagation.EquivalentLinearCalculator() calc(motion, profile, output_location) ``` -------------------------------- ### Clone and set up PyStrata development environment Source: https://github.com/arkottke/pystrata/blob/main/docs/developer/contributing.rst Commands to clone the repository and set up the development environment using UV and pre-commit hooks. ```bash git clone https://github.com/yourusername/pystrata.git cd pystrata ``` ```bash uv sync uv run pre-commit install ``` ```bash git checkout -b feature-name ``` -------------------------------- ### Initialize calculators Source: https://github.com/arkottke/pystrata/blob/main/examples/example-12.ipynb Creates a FrequencyDependentEqlCalculator with method='raw' and an EquivalentLinearCalculator with strain_ratio=0.65 for the analyses. ```python calc_fdm = pystrata.propagation.FrequencyDependentEqlCalculator(method="raw") calc_eql = pystrata.propagation.EquivalentLinearCalculator(strain_ratio=0.65) ``` -------------------------------- ### Creating nonlinear soil types with PyStrata Source: https://github.com/arkottke/pystrata/blob/main/docs/theory/nonlinear_models.rst Shows how to instantiate different nonlinear soil models (Darendeli, Menq, Wang, Alemu et al.) using the pystrata.site module. Each model requires specific parameters such as plasticity index, mean stress, unit weight, and others. ```python # Darendeli model for clay soil_type = pystrata.site.DarendeliSoilType( plas_index=30, stress_mean=100, # kPa unit_wt=18.0, ) # Menq model for gravel soil_type = pystrata.site.MenqSoilType( unit_wt=20.0, coef_unif=10, diam_mean=5, # mm stress_mean=101.3, # kPa ) # Wang and Stokoe model for clean sand soil_type = pystrata.site.WangSoilType( soil_group="clean_sand_and_gravel", unit_wt=19.0, stress_mean=100, # kPa void_ratio=0.6, ) # Alemu et al. model for transitional silt soil_type = pystrata.site.AlemuEtAlSoilType( unit_wt=18.0, plas_index=15, ocr=1.5, stress_mean=50, # kPa ) ``` -------------------------------- ### Create a simple logic tree with three parameters Source: https://github.com/arkottke/pystrata/blob/main/examples/example-16.ipynb Constructs a LogicTree with nodes for site class, shear wave velocity factor, and damping model. Each node has alternatives with weights. Prints the number of valid branches and the first five branches with their weights. ```python # Create a simple logic tree with three parameters simple_tree = LogicTree( [ # Site classification with equal weights Node( "site_class", [Alternative("C", weight=0.4), Alternative("D", weight=0.6)] ), # Shear wave velocity uncertainty Node( "vs_factor", [ Alternative(0.8, weight=0.2), # Lower bound Alternative(1.0, weight=0.6), # Best estimate Alternative(1.2, weight=0.2), # Upper bound ], ), # Damping model choice Node( "damping_model", [ Alternative("darendeli", weight=0.7), Alternative("seed_idriss", weight=0.3), ], ), ] ) print(f"Logic tree has {len(list(simple_tree))} valid branches") # Display first few branches for i, branch in enumerate(simple_tree): if i < 5: print(f"Branch {i + 1}: {branch.as_dict()}, weight: {branch.weight:.3f}") ``` -------------------------------- ### Create a simple site profile Source: https://github.com/arkottke/pystrata/blob/main/examples/example-04.ipynb Creates a simple site profile with three layers: two soil layers and a rock half-space, specifying unit weight, damping, thickness, and shear-wave velocity. ```python profile = pystrata.site.Profile( [ pystrata.site.Layer( pystrata.site.SoilType("Soil-1", 18.0, None, 0.05), 30, 400 ), pystrata.site.Layer( pystrata.site.SoilType("Soil-2", 19.0, None, 0.05), 20, 600 ), pystrata.site.Layer(pystrata.site.SoilType("Rock", 24.0, None, 0.01), 0, 1200), ] ) ``` -------------------------------- ### Create site profile with layers Source: https://github.com/arkottke/pystrata/blob/main/docs/user_guide/index.rst Creates a site profile by defining a list of layers, each with soil type, thickness, and shear wave velocity. Additional layers can be added as needed. ```python profile = pystrata.site.Profile([ pystrata.site.Layer(soil_type, thickness, vs), # ... additional layers ]) ``` -------------------------------- ### Migration: Profile creation from 0.4.x to 0.5.x Source: https://github.com/arkottke/pystrata/blob/main/docs/changelog.rst Shows the old and new ways to create a Profile object. The old method uses `Profile(layers)`, while the new method uses `pystrata.site.Profile(layers)`. ```python # Old profile = Profile(layers) # New profile = pystrata.site.Profile(layers) ``` -------------------------------- ### Define velocity distribution parameters Source: https://github.com/arkottke/pystrata/blob/main/examples/example-04.ipynb Defines a dictionary of velocity distribution parameters for the 'USGS B' model, consistent with the earlier example. ```python # Parameters for distribution of velocities PARAMS = { "USGS B": { # To be consistent with example above "ln_std": 0.27, "rho_0": 0.97, "delta": 3.8, "rho_200": 1.00, "h_0": 0.0, "b": 0.293, } } ``` -------------------------------- ### Access read-only properties Source: https://github.com/arkottke/pystrata/blob/main/docs/api/index.rst Read-only properties provide computed values. This example shows accessing vs30, duration, and output values. ```python profile.vs30 # Time-averaged shear wave velocity motion.duration # Motion duration output.values # Computed output values ``` -------------------------------- ### Import libraries and set up plotting Source: https://github.com/arkottke/pystrata/blob/main/examples/example-17.ipynb Imports matplotlib, numpy, and pystrata, and loads the NCM profile function. Sets the matplotlib inline backend and figure DPI. ```python import matplotlib.pyplot as plt import numpy as np import pystrata from pystrata.generic import load_ncm_profile %matplotlib inline plt.rcParams["figure.dpi"] = 120 ``` -------------------------------- ### Create site profile with published nonlinear curves Source: https://github.com/arkottke/pystrata/blob/main/examples/example-15.ipynb Builds a three-layer sand profile using SoilType.from_published with the 'Seed & Idriss, Sand Mean' model, then auto-discretizes it. The profile is used as input for the equivalent-linear analysis. ```python profile = pystrata.site.Profile( [ pystrata.site.Layer( pystrata.site.SoilType.from_published( unit_wt=18.0, model="Seed & Idriss, Sand Mean" ), 10, 400, ), pystrata.site.Layer( pystrata.site.SoilType.from_published( unit_wt=18.0, model="Seed & Idriss, Sand Mean" ), 10, 450, ), pystrata.site.Layer( pystrata.site.SoilType.from_published( unit_wt=18.0, model="Seed & Idriss, Sand Mean" ), 30, 600, ), pystrata.site.Layer(pystrata.site.SoilType("Rock", 24.0, None, 0.01), 0, 1200), ] ).auto_discretize() ``` -------------------------------- ### Monte Carlo Simulation for Shear Wave Velocity Source: https://github.com/arkottke/pystrata/blob/main/docs/theory/uncertainty.rst Python example generating 1000 random shear wave velocity samples from a normal distribution with mean 400 m/s and standard deviation 50 m/s. The loop is intended to run site response analysis and store results for each sample. ```python # Example: Uncertain shear wave velocity vs_mean = 400 # m/s vs_std = 50 # m/s for i in range(1000): vs_sample = np.random.normal(vs_mean, vs_std) # Run site response analysis # Store results ``` -------------------------------- ### Create site profile Source: https://github.com/arkottke/pystrata/blob/main/examples/example-08.ipynb Defines a simple profile with three Darendeli soil layers and a rock layer, using linear-elastic soil types. ```python profile = pystrata.site.Profile( [ pystrata.site.Layer( pystrata.site.DarendeliSoilType(18.0, plas_index=0, ocr=1, stress_mean=100), 10, 400, ), pystrata.site.Layer( pystrata.site.DarendeliSoilType(18.0, plas_index=0, ocr=1, stress_mean=200), 10, 450, ), pystrata.site.Layer( pystrata.site.DarendeliSoilType(18.0, plas_index=0, ocr=1, stress_mean=400), 30, 600, ), pystrata.site.Layer(pystrata.site.SoilType("Rock", 24.0, None, 0.01), 0, 1200), ] ) ``` -------------------------------- ### Define logic tree and run site response Source: https://github.com/arkottke/pystrata/blob/main/examples/example-16.ipynb Creates a source-theory RVT motion, defines a logic tree with nodes for shear-wave velocity factor and damping model, then runs equivalent-linear site response for each branch, printing branch parameters and weights. ```python # Create a simple input motion motion = pystrata.motion.SourceTheoryRvtMotion(magnitude=6.5, distance=20, region="wna") # Define a logic tree for site response uncertainty site_response_tree = LogicTree( [ Node( "vs_factor", [ Alternative(0.8, weight=0.2), Alternative(1.0, weight=0.6), Alternative(1.2, weight=0.2), ], ), Node( "damping_model", [ Alternative("darendeli", weight=0.7), Alternative("wang", weight=0.3), ], ), ] ) # Run site response calculation calc = pystrata.propagation.EquivalentLinearCalculator() # Output at surface outputs = pystrata.output.OutputCollection( [ pystrata.output.ResponseSpectrumOutput( # Frequencies for response spectrum freqs=np.logspace(-1, 2, 91), location=pystrata.output.OutputLocation("outcrop", depth=0), osc_damping=0.05, ), ] ) print("Computing site response for each logic tree branch...") for i, branch in enumerate(site_response_tree): vs_factor = branch.value("vs_factor") damping_model = branch.value("damping_model") print( f" Branch {i + 1}: vs_factor={vs_factor:.1f}, damping={damping_model}, weight={branch.weight:.1f}" ) # Create profile for this branch profile = create_site_profile(vs_factor, damping_model).auto_discretize() calc(motion, profile, profile.location("outcrop", index=-1)) outputs(calc, name=branch) ``` ```text Output: Computing site response for each logic tree branch... Branch 1: vs_factor=0.8, damping=darendeli, weight=0.1 Branch 2: vs_factor=0.8, damping=wang, weight=0.1 Branch 3: vs_factor=1.0, damping=darendeli, weight=0.4 Branch 2: vs_factor=0.8, damping=wang, weight=0.1 Branch 3: vs_factor=1.0, damping=darendeli, weight=0.4 Branch 4: vs_factor=1.0, damping=wang, weight=0.2 Branch 5: vs_factor=1.2, damping=darendeli, weight=0.1 Branch 4: vs_factor=1.0, damping=wang, weight=0.2 Branch 5: vs_factor=1.2, damping=darendeli, weight=0.1 Branch 6: vs_factor=1.2, damping=wang, weight=0.1 Branch 6: vs_factor=1.2, damping=wang, weight=0.1 ``` -------------------------------- ### Save and Load Logic Tree from JSON Source: https://github.com/arkottke/pystrata/blob/main/examples/example-16.ipynb Creates a logic tree definition with site classification, kappa, and randomization method alternatives, saves it to a JSON file, loads it using LogicTree.from_json, and prints the valid branches with their weights. ```python # Create a complex logic tree definition logic_tree_definition = [ { "name": "site_classification", "alts": [ {"value": "C", "weight": 0.3, "params": {"vs30_range": [360, 760]}}, {"value": "D", "weight": 0.6, "params": {"vs30_range": [180, 360]}}, {"value": "E", "weight": 0.1, "params": {"vs30_range": [0, 180]}}, ], }, { "name": "kappa", "alts": [ {"value": 0.02, "weight": 0.2, "requires": {"site_classification": "C"}}, {"value": 0.03, "weight": 0.6, "requires": {"site_classification": "C"}}, {"value": 0.04, "weight": 0.2, "requires": {"site_classification": "C"}}, {"value": 0.03, "weight": 0.2, "requires": {"site_classification": "D"}}, {"value": 0.04, "weight": 0.6, "requires": {"site_classification": "D"}}, {"value": 0.05, "weight": 0.2, "requires": {"site_classification": "D"}}, {"value": 0.05, "weight": 0.4, "requires": {"site_classification": "E"}}, {"value": 0.06, "weight": 0.6, "requires": {"site_classification": "E"}}, ], }, { "name": "randomization_method", "alts": [ {"value": "monte_carlo", "weight": 0.4, "params": {"n_realizations": 1000}}, { "value": "latin_hypercube", "weight": 0.4, "params": {"n_realizations": 100}, }, {"value": "deterministic", "weight": 0.2, "params": {"n_realizations": 1}}, ], }, ] # Save to JSON file json_filename = "site_response_logic_tree.json" with open(json_filename, "w") as f: json.dump(logic_tree_definition, f, indent=2) print(f"Saved logic tree definition to {json_filename}") # Load from JSON loaded_tree = LogicTree.from_json(json_filename) print(f"\nLoaded logic tree with {len(list(loaded_tree))} valid branches") # Display the loaded tree structure print("\nBranches from JSON logic tree:") for i, branch in enumerate(loaded_tree): branch_info = { "site": branch.value("site_classification"), "kappa": branch.value("kappa"), "method": branch.value("randomization_method"), "weight": branch.weight, } print(f" {i + 1:2d}: {branch_info}") ``` ```text Saved logic tree definition to site_response_logic_tree.json Loaded logic tree with 24 valid branches Branches from JSON logic tree: 1: {'site': 'C', 'kappa': 0.02, 'method': 'monte_carlo', 'weight': np.float64(0.024)} 2: {'site': 'C', 'kappa': 0.02, 'method': 'latin_hypercube', 'weight': np.float64(0.024)} 3: {'site': 'C', 'kappa': 0.02, 'method': 'deterministic', 'weight': np.float64(0.012)} 4: {'site': 'C', 'kappa': 0.03, 'method': 'monte_carlo', 'weight': np.float64(0.072)} 5: {'site': 'C', 'kappa': 0.03, 'method': 'latin_hypercube', 'weight': np.float64(0.072)} 6: {'site': 'C', 'kappa': 0.03, 'method': 'deterministic', 'weight': np.float64(0.036)} 7: {'site': 'C', 'kappa': 0.04, 'method': 'monte_carlo', 'weight': np.float64(0.024)} 8: {'site': 'C', 'kappa': 0.04, 'method': 'latin_hypercube', 'weight': np.float64(0.024)} 9: {'site': 'C', 'kappa': 0.04, 'method': 'deterministic', 'weight': np.float64(0.012)} 10: {'site': 'D', 'kappa': 0.03, 'method': 'monte_carlo', 'weight': np.float64(0.144)} 11: {'site': 'D', 'kappa': 0.03, 'method': 'latin_hypercube', 'weight': np.float64(0.144)} 12: {'site': 'D', 'kappa': 0.03, 'method': 'deterministic', 'weight': np.float64(0.072)} 13: {'site': 'D', 'kappa': 0.04, 'method': 'monte_carlo', 'weight': np.float64(0.048)} 14: {'site': 'D', 'kappa': 0.04, 'method': 'latin_hypercube', 'weight': np.float64(0.048)} 15: {'site': 'D', 'kappa': 0.04, 'method': 'deterministic', 'weight': np.float64(0.024)} 16: {'site': 'D', 'kappa': 0.05, 'method': 'monte_carlo', 'weight': np.float64(0.048)} 17: {'site': 'D', 'kappa': 0.05, 'method': 'latin_hypercube', 'weight': np.float64(0.048)} 18: {'site': 'D', 'kappa': 0.05, 'method': 'deterministic', 'weight': np.float64(0.024)} 19: {'site': 'E', 'kappa': 0.05, 'method': 'monte_carlo', 'weight': np.float64(0.008000000000000002)} 20: {'site': 'E', 'kappa': 0.05, 'method': 'latin_hypercube', 'weight': np.float64(0.008000000000000002)} 21: {'site': 'E', 'kappa': 0.05, 'method': 'deterministic', 'weight': np.float64(0.004000000000000001)} 22: {'site': 'E', 'kappa': 0.06, 'method': 'monte_carlo', 'weight': np.float64(0.024)} 23: {'site': 'E', 'kappa': 0.06, 'method': 'latin_hypercube', 'weight': np.float64(0.024)} 24: {'site': 'E', 'kappa': 0.06, 'method': 'deterministic', 'weight': np.float64(0.012)} ``` -------------------------------- ### Import libraries and set up plotting Source: https://github.com/arkottke/pystrata/blob/main/examples/example-14.ipynb Imports matplotlib, numpy, pandas, and pystrata, and enables inline plotting. Also increases figure DPI for better resolution. ```python import matplotlib.pyplot as plt import numpy as np import pandas as pd import pystrata %matplotlib inline ``` ```python # Increased figure sizes plt.rcParams["figure.dpi"] = 120 ``` -------------------------------- ### Create a simple site profile Source: https://github.com/arkottke/pystrata/blob/main/examples/example-02.ipynb Defines a two-layer profile: a 30 m soil layer (unit weight 18.0, damping 0.05) over a rock half-space (unit weight 24.0, damping 0.01). ```python profile = pystrata.site.Profile( [ pystrata.site.Layer(pystrata.site.SoilType("Soil", 18.0, None, 0.05), 30, 400), pystrata.site.Layer(pystrata.site.SoilType("Rock", 24.0, None, 0.01), 0, 1200), ] ) ``` -------------------------------- ### SourceTheoryRvtMotion.__init__ Source: https://github.com/arkottke/pystrata/blob/main/docs/usage.rst Initializes a SourceTheoryRvtMotion instance with earthquake scenario parameters such as magnitude, distance, region, and optional settings for peak calculation and site amplification. ```APIDOC ## SourceTheoryRvtMotion.__init__ ### Description Initializes a SourceTheoryRvtMotion instance with earthquake scenario parameters such as magnitude, distance, region, and optional settings for peak calculation and site amplification. ### Method Constructor ### Signature `__init__(magnitude: float, distance: float, region: str | None = None, depth: float | None = 8, peak_calculator: str | Calculator | None = None, calc_kwds: dict | None = None, freqs: ndarray | None = None, disable_site_amp: bool = False, **kwargs)` ### Parameters - **magnitude** (float) - Required - Moment magnitude of the event. - **distance** (float) - Required - Epicentral distance (km). - **region** (str) - Optional - Region for the parameters. Either 'cena' for Central and Eastern North America, or 'wna' for Western North America. - **stress_drop** (float, optional) - Optional - Stress drop of the event (bars). If None, the default value is used. For region 'cena', the default is computed by the model; for 'wna', the default is 100 bars. - **depth** (float, optional) - Optional - Hypocenter depth (km). The depth is combined with the distance to compute the hypocentral distance. - **peak_calculator** (Calculator, optional) - Optional - Peak calculator to use. If None, the default peak calculator is used. May be specified by a pyrvt.peak_calculators.Calculator object or by the initials of the calculator using pyrvt.peak_calculators.get_peak_calculator. - **calc_kwds** (dict, optional) - Optional - Keywords to be passed during the creation of the peak calculator. Only required for some peak calculators. - **freqs** (array_like) - Optional - Frequencies for which the Fourier amplitude spectrum should be computed. Defaults to np.geomspace(0.05, 200, 512). - **disable_site_amp** (bool, optional) - Optional - If the crustal site amplification should be disabled. Defaults to False. ### Returns None ``` -------------------------------- ### Load WNA profile from JSON Source: https://github.com/arkottke/pystrata/blob/main/examples/example-09.ipynb Loads a site profile from a JSON file, constructs a pystrata Profile with layers, and updates the profile. ```python with open("../tests/data/qwl_tests.json") as fp: data = json.load(fp)[1] thickness = np.diff(data["site"]["depth"]) profile = pystrata.site.Profile() for i, (thick, vel_shear, density) in enumerate( zip(thickness, data["site"]["velocity"], data["site"]["density"]) ): profile.append( pystrata.site.Layer( pystrata.site.SoilType(f"{i}", density * pystrata.motion.GRAVITY), thick * 1000, vel_shear * 1000, ) ) profile.update_layers(0) ``` -------------------------------- ### Simple Linear Analysis with PyStrata Source: https://github.com/arkottke/pystrata/blob/main/docs/quickstart.rst Performs a basic linear elastic site response analysis. Loads a time series motion from an AT2 file, creates a two-layer profile (soil and bedrock), defines output collection (response spectrum, transfer function, max acceleration profile), runs the analysis using LinearElasticCalculator, and prints the output values. ```python import pystrata # Load an input motion motion = pystrata.motion.TimeSeriesMotion.load_at2_file("path/to/motion.at2") # Create a simple two-layer profile profile = pystrata.site.Profile([ # Soil layer: 30m thick, Vs=400 m/s, damping=5% pystrata.site.Layer( pystrata.site.SoilType("Soil", 18.0, None, 0.05), 30, 400 ), # Bedrock: half-space, Vs=1200 m/s, damping=1% pystrata.site.Layer( pystrata.site.SoilType("Rock", 24.0, None, 0.01), 0, 1200 ), ]) # Define outputs of interest outputs = pystrata.output.OutputCollection([ pystrata.output.ResponseSpectrumOutput(), pystrata.output.AccelTransferFunctionOutput(), pystrata.output.MaxAccelProfile(), ]) # Create calculator and run analysis calc = pystrata.propagation.LinearElasticCalculator() calc(motion, profile, profile.location("outcrop", index=-1)) # Access results for output in outputs: print(f"{output.name}: {output.values}") ``` -------------------------------- ### Build pystrata.site.Profile from NCM data with nonlinear and linear layers Source: https://github.com/arkottke/pystrata/blob/main/examples/example-17.ipynb Constructs a pystrata.site.Profile from a DataFrame 'df' containing NCM data. Layers above 300 m use DarendeliSoilType with mean effective stress floored at 1/8 atmosphere; deeper layers use linear SoilType with 1% damping. The last layer is a halfspace with zero thickness. The profile is created with a specified water table depth. ```python # Floor mean effective stress at 1/8 atmosphere to avoid near-zero values stress_mean = np.maximum(df["mean_eff_stress"].values, 101.3 / 8) # Layer thicknesses (last layer = halfspace with 0 thickness) thicknesses = df["thickness"].values # Depth threshold for nonlinear layers NONLINEAR_DEPTH = 300 # m # Build layers layers = [] for i, row in df.iterrows(): if row["depth"] < NONLINEAR_DEPTH: soil_type = pystrata.site.DarendeliSoilType( unit_wt=row["unit_wt"], plas_index=0, ocr=1, stress_mean=stress_mean[i], ) else: soil_type = pystrata.site.SoilType( unit_wt=row["unit_wt"], mod_reduc=None, damping=0.01, ) layers.append(pystrata.site.Layer(soil_type, thicknesses[i], row["vel_shear"])) profile = pystrata.site.Profile(layers, wt_depth=wt_depth) profile ``` ```text Result: ``` -------------------------------- ### Create site profile Source: https://github.com/arkottke/pystrata/blob/main/examples/example-07.ipynb Creates a simple two-layer soil profile: a 300 m soil layer with nonlinear properties (Darendeli model) over a 0 m rock layer. The soil type uses a density of 18.0 and damping 0.02, while rock uses 24.0 and 0.01. ```python profile = pystrata.site.Profile( [ pystrata.site.Layer(pystrata.site.SoilType("Soil", 18.0, None, 0.02), 300, 600), pystrata.site.Layer(pystrata.site.SoilType("Rock", 24.0, None, 0.01), 0, 2000), ] ) ``` -------------------------------- ### Set up output collection Source: https://github.com/arkottke/pystrata/blob/main/examples/example-14.ipynb Defines frequency range from 0.1 to 100 Hz (log-spaced) and creates an OutputCollection with response spectrum, response spectrum ratio, initial velocity profile, and maximum acceleration profile outputs. The response spectrum is at the outcrop surface (index 0) and the ratio uses the outcrop at the base (index -1) as denominator. ```python 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.InitialVelProfile(), pystrata.output.MaxAccelProfile(), ] ) ``` -------------------------------- ### Define output collection Source: https://github.com/arkottke/pystrata/blob/main/examples/example-08.ipynb Sets up an OutputCollection with a response spectrum, a spectral ratio, and an initial velocity profile output. ```python 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.InitialVelProfile(), ] ) ``` -------------------------------- ### Create site response calculator and variations Source: https://github.com/arkottke/pystrata/blob/main/examples/example-08.ipynb Instantiates an EquivalentLinearCalculator and defines variations for thickness, velocity, and soil types using Toro and Spid models. ```python calc = pystrata.propagation.EquivalentLinearCalculator() ``` ```python var_thickness = pystrata.variation.ToroThicknessVariation() var_velocity = pystrata.variation.ToroVelocityVariation.generic_model("USGS C") var_soiltypes = pystrata.variation.SpidVariation( -0.5, std_mod_reduc=0.15, std_damping=0.30 ) ``` -------------------------------- ### Create site response calculators (EQL, FDM variants) Source: https://github.com/arkottke/pystrata/blob/main/examples/example-11.ipynb Defines a list of PyStrata calculators: EquivalentLinearCalculator and FrequencyDependentEqlCalculator with different methods (ka02, zr15, ko:20) and a strain ratio of 0.65 for the first FDM. These are used to compute site response. ```python calcs = [ ("EQL", pystrata.propagation.EquivalentLinearCalculator()), ( "FDM (KA)", pystrata.propagation.FrequencyDependentEqlCalculator( strain_ratio=0.65, method="ka02" ), ), ( "FDM (ZR)", pystrata.propagation.FrequencyDependentEqlCalculator(method="zr15"), ), ( "FDM (KO 0.3)", pystrata.propagation.FrequencyDependentEqlCalculator(method="ko:20"), ), ] ``` -------------------------------- ### Create a logic tree with conditional dependencies Source: https://github.com/arkottke/pystrata/blob/main/examples/example-16.ipynb Builds a LogicTree with nodes for soil type, plasticity index, relative density, and nonlinear model. Alternatives use 'requires' and 'excludes' to enforce conditions, e.g., plasticity index only for clay, relative density only for sand, and gq_h model excluded for clay. The tree is iterated to print the number of valid branches and each branch's dictionary and weight. ```python # Create a logic tree with conditional dependencies conditional_tree = LogicTree( [ # Soil type classification Node( "soil_type", [Alternative("clay", weight=0.4), Alternative("sand", weight=0.6)], ), # Plasticity index (only relevant for clay) Node( "plasticity_index", [ Alternative("low", weight=0.3, requires={"soil_type": "clay"}), Alternative("medium", weight=0.4, requires={"soil_type": "clay"}), Alternative("high", weight=0.3, requires={"soil_type": "clay"}), Alternative( "not_applicable", weight=1.0, requires={"soil_type": "sand"} ), ], ), # Relative density (only relevant for sand) Node( "relative_density", [ Alternative("loose", weight=0.2, requires={"soil_type": "sand"}), Alternative("medium", weight=0.6, requires={"soil_type": "sand"}), Alternative("dense", weight=0.2, requires={"soil_type": "sand"}), Alternative( "not_applicable", weight=1.0, requires={"soil_type": "clay"} ), ], ), # Nonlinear model selection with exclusions Node( "nonlinear_model", [ Alternative("hyperbolic", weight=0.5), Alternative( "gq_h", weight=0.3, excludes={"soil_type": "clay"} ), # Only for sand Alternative( "pressurized", weight=0.2, requires={"soil_type": "clay"} ), # Only for clay ], ), ] ) print(f"Conditional tree has {len(list(conditional_tree))} valid branches") print("\nValid branches:") for i, branch in enumerate(conditional_tree): print(f"{i + 1:2d}: {branch.as_dict()}, weight: {branch.weight:.3f}") ``` ```text Output: Conditional tree has 12 valid branches Valid branches: 1: {'soil_type': 'clay', 'plasticity_index': 'low', 'relative_density': 'not_applicable', 'nonlinear_model': 'hyperbolic'}, weight: 0.060 2: {'soil_type': 'clay', 'plasticity_index': 'low', 'relative_density': 'not_applicable', 'nonlinear_model': 'pressurized'}, weight: 0.024 3: {'soil_type': 'clay', 'plasticity_index': 'medium', 'relative_density': 'not_applicable', 'nonlinear_model': 'hyperbolic'}, weight: 0.080 4: {'soil_type': 'clay', 'plasticity_index': 'medium', 'relative_density': 'not_applicable', 'nonlinear_model': 'pressurized'}, weight: 0.032 5: {'soil_type': 'clay', 'plasticity_index': 'high', 'relative_density': 'not_applicable', 'nonlinear_model': 'hyperbolic'}, weight: 0.060 6: {'soil_type': 'clay', 'plasticity_index': 'high', 'relative_density': 'not_applicable', 'nonlinear_model': 'pressurized'}, weight: 0.024 7: {'soil_type': 'sand', 'plasticity_index': 'not_applicable', 'relative_density': 'loose', 'nonlinear_model': 'hyperbolic'}, weight: 0.060 8: {'soil_type': 'sand', 'plasticity_index': 'not_applicable', 'relative_density': 'loose', 'nonlinear_model': 'gq_h'}, weight: 0.036 9: {'soil_type': 'sand', 'plasticity_index': 'not_applicable', 'relative_density': 'medium', 'nonlinear_model': 'hyperbolic'}, weight: 0.180 10: {'soil_type': 'sand', 'plasticity_index': 'not_applicable', 'relative_density': 'medium', 'nonlinear_model': 'gq_h'}, weight: 0.108 11: {'soil_type': 'sand', 'plasticity_index': 'not_applicable', 'relative_density': 'dense', 'nonlinear_model': 'hyperbolic'}, weight: 0.060 12: {'soil_type': 'sand', 'plasticity_index': 'not_applicable', 'relative_density': 'dense', 'nonlinear_model': 'gq_h'}, weight: 0.036 ``` -------------------------------- ### Linear Elastic Calculator Source: https://github.com/arkottke/pystrata/blob/main/docs/quickstart.rst Creates a LinearElasticCalculator instance, the fastest analysis method assuming constant soil properties. ```python calc = pystrata.propagation.LinearElasticCalculator() ```