Estimate Kappa#
Open the app motion library (no project file) and estimate kappa for one motion, using bounding frequencies and then a constant kappa and Y-intercept.
1"""
2Estimate kappa for one ground motion from the Motion Manager library.
3
4Requires a running RSSeismic scripting server. No project file is needed.
5Motion names are the .txt file names (without extension) in the Motion Manager
6folders from RSSeismic Preferences.
7
8 python examples/example_estimate_kappa.py --motion ChiChi
9 python examples/example_estimate_kappa.py --port 60058 --motion ChiChi
10"""
11
12from __future__ import annotations
13
14import argparse
15import os
16import sys
17
18from rsseismic import RSSeismicApplication
19from rsseismic._client import DEFAULT_SCRIPTING_PORT
20
21
22def _print_kappa(title: str, info) -> None:
23 print(title)
24 print(f" Start frequency {info.startFrequency} Hz")
25 print(f" End frequency {info.endFrequency} Hz")
26 print(f" Kappa {info.kappa}")
27 print(f" Y-intercept {info.yIntercept}")
28 print(f" Start amplitude {info.startAmplitude}")
29 print(f" End amplitude {info.endAmplitude}")
30
31
32def run_estimate_kappa_example(motion_name: str, port: int = DEFAULT_SCRIPTING_PORT) -> None:
33 if not motion_name.strip():
34 raise ValueError("A motion name is required (file name without .txt).")
35
36 app = RSSeismicApplication(port=port)
37 try:
38 app.ping()
39 motion = app.MotionLibrary.getMotion(motion_name.strip())
40 print(f"Using motion: {motion.name}")
41
42 from_bounds = motion.estimateKappaFromBoundingFrequencies(
43 startFrequency=1.0,
44 endFrequency=20.0,
45 )
46 _print_kappa("Bounding frequencies (1–20 Hz)", from_bounds)
47
48 from_constant = motion.estimateKappaFromConstantIntercept(
49 kappa=from_bounds.kappa,
50 yIntercept=from_bounds.yIntercept,
51 )
52 _print_kappa("Constant kappa and intercept (freqs default to 0 and 100 Hz)", from_constant)
53 finally:
54 app.close()
55
56
57def parse_args() -> argparse.Namespace:
58 parser = argparse.ArgumentParser(
59 description="Estimate kappa for one Motion Manager library motion."
60 )
61 parser.add_argument(
62 "--motion",
63 "-m",
64 required=True,
65 help="Motion name (file name without .txt) from Motion Manager folders.",
66 )
67 parser.add_argument(
68 "--port",
69 "-p",
70 type=int,
71 default=int(os.environ.get("RSSEISMIC_SCRIPTING_PORT", DEFAULT_SCRIPTING_PORT)),
72 help=f"gRPC port (default: {DEFAULT_SCRIPTING_PORT}, or RSSEISMIC_SCRIPTING_PORT)",
73 )
74 return parser.parse_args()
75
76
77def main() -> int:
78 args = parse_args()
79 try:
80 run_estimate_kappa_example(args.motion, port=args.port)
81 except Exception as ex:
82 print(f"Example failed: {ex}", file=sys.stderr)
83 return 1
84 print("Estimate Kappa example finished.")
85 return 0
86
87
88if __name__ == "__main__":
89 raise SystemExit(main())