Motion Pair View#
Open the app motion library (no project file), print one H1/H2 pair’s properties, geometric-mean Sa, and EAS, then save scaled copies of both horizontals. Scaled files are not added to the motion library.
1"""
2Inspect one H1/H2 motion pair (Motion Pair View) and write scaled copies to disk.
3
4Requires a running RSSeismic scripting server. No project file is needed.
5``pairId`` is the shared name prefix of the horizontal components in Motion Manager
6folders (for example ``Event`` for ``Event_EW.txt`` + ``Event_NS.txt``).
7
8 python examples/example_motion_pair_view.py --pair Event
9 python examples/example_motion_pair_view.py --port 60058 --pair Event --output-dir "D:\\out"
10
11Scaling writes two .txt files. It does not add them to the motion library.
12"""
13
14from __future__ import annotations
15
16import argparse
17import os
18import sys
19
20from rsseismic import (
21 EAS_BANDWIDTH_PEER_2018,
22 GeometricMeanSpectralType,
23 RSSeismicApplication,
24)
25from rsseismic._client import DEFAULT_SCRIPTING_PORT
26
27
28def _print_properties(title: str, properties) -> None:
29 print(title)
30 print(f" Time step {properties.timeStep} {properties.timeStepUnit}")
31 print(f" Nyquist frequency {properties.nyquistFrequency} {properties.frequencyUnit}")
32 print(f" PGA {properties.pga} {properties.accelerationUnit}")
33 print(f" PGV {properties.pgv} {properties.velocityUnit}")
34 print(f" PGD {properties.pgd} {properties.displacementUnit}")
35 print(f" Number of points {properties.numPoints}")
36
37
38def run_motion_pair_view_example(
39 pair_id: str,
40 port: int = DEFAULT_SCRIPTING_PORT,
41 output_dir: str = "",
42) -> None:
43 if not pair_id.strip():
44 raise ValueError("A pair id is required (shared H1/H2 name prefix).")
45
46 app = RSSeismicApplication(port=port)
47 try:
48 app.ping()
49 pair = app.MotionLibrary.getMotionPair(pair_id.strip())
50
51 props = pair.getProperties()
52 print(f"Using pair: {props.pairId} ({props.motionH1Name}, {props.motionH2Name})")
53 _print_properties("H1 properties", props.h1)
54 _print_properties("H2 properties", props.h2)
55
56 geo = pair.getGeometricMeanSpectrum(GeometricMeanSpectralType.FREQUENCY_DOMAIN)
57 print("Geometric-mean columns:", list(geo.columns))
58 print(geo.head())
59
60 eas = pair.getEffectiveAmplitudeSpectrum()
61 print(f"EAS columns (bandwidth default {EAS_BANDWIDTH_PEER_2018}):", list(eas.columns))
62 print(eas.head())
63
64 if not output_dir:
65 output_dir = os.path.join(os.getcwd(), "scaled_motion_pairs_example")
66 output_dir = os.path.abspath(output_dir)
67 os.makedirs(output_dir, exist_ok=True)
68
69 h1_path = os.path.join(output_dir, f"{props.motionH1Name}_to_0p30g.txt")
70 h2_path = os.path.join(output_dir, f"{props.motionH2Name}_to_0p30g.txt")
71 scaled = pair.scaleToG(0.30, h1_path, h2_path, overwrite=True)
72 print(f"\nSaved H1: {scaled.h1FilePath} (factor {scaled.h1AppliedScaleFactor})")
73 print(f"Saved H2: {scaled.h2FilePath} (factor {scaled.h2AppliedScaleFactor})")
74
75 if not os.path.isfile(scaled.h1FilePath) or not os.path.isfile(scaled.h2FilePath):
76 raise RuntimeError("Expected scaled motion pair files were not written.")
77
78 print("\nOriginal library motions are unchanged.")
79 print("Scaled files are on disk only; they are not in the motion library.")
80 finally:
81 app.close()
82
83
84def parse_args() -> argparse.Namespace:
85 parser = argparse.ArgumentParser(
86 description="Print Motion Pair View properties and spectra, then save scaled copies."
87 )
88 parser.add_argument(
89 "--pair",
90 "-p",
91 required=True,
92 help="Pair id (shared H1/H2 file-name prefix) from Motion Manager folders.",
93 )
94 parser.add_argument(
95 "--port",
96 type=int,
97 default=DEFAULT_SCRIPTING_PORT,
98 help=f"Scripting server port (default {DEFAULT_SCRIPTING_PORT}).",
99 )
100 parser.add_argument(
101 "--output-dir",
102 default="",
103 help="Directory for scaled H1/H2 files (default: ./scaled_motion_pairs_example).",
104 )
105 return parser.parse_args()
106
107
108def main() -> int:
109 args = parse_args()
110 try:
111 run_motion_pair_view_example(args.pair, port=args.port, output_dir=args.output_dir)
112 except Exception as exc:
113 print(f"Error: {exc}", file=sys.stderr)
114 return 1
115 return 0
116
117
118if __name__ == "__main__":
119 raise SystemExit(main())