seismic-response 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. seismic_response-0.1.0/.gitignore +33 -0
  2. seismic_response-0.1.0/LICENSE +165 -0
  3. seismic_response-0.1.0/PKG-INFO +226 -0
  4. seismic_response-0.1.0/README.md +193 -0
  5. seismic_response-0.1.0/pyproject.toml +68 -0
  6. seismic_response-0.1.0/src/seismic_response/__init__.py +121 -0
  7. seismic_response-0.1.0/src/seismic_response/__main__.py +8 -0
  8. seismic_response-0.1.0/src/seismic_response/cli.py +543 -0
  9. seismic_response-0.1.0/src/seismic_response/errors.py +33 -0
  10. seismic_response-0.1.0/src/seismic_response/evaluate.py +1094 -0
  11. seismic_response-0.1.0/src/seismic_response/gui/__init__.py +1 -0
  12. seismic_response-0.1.0/src/seismic_response/gui/__main__.py +23 -0
  13. seismic_response-0.1.0/src/seismic_response/gui/server.py +194 -0
  14. seismic_response-0.1.0/src/seismic_response/gui/static/app.js +1165 -0
  15. seismic_response-0.1.0/src/seismic_response/gui/static/favicon.svg +5 -0
  16. seismic_response-0.1.0/src/seismic_response/gui/static/icon.svg +5 -0
  17. seismic_response-0.1.0/src/seismic_response/gui/static/index.html +253 -0
  18. seismic_response-0.1.0/src/seismic_response/gui/static/style.css +242 -0
  19. seismic_response-0.1.0/src/seismic_response/model.py +258 -0
  20. seismic_response-0.1.0/src/seismic_response/output.py +120 -0
  21. seismic_response-0.1.0/src/seismic_response/py.typed +0 -0
  22. seismic_response-0.1.0/src/seismic_response/resp.py +421 -0
  23. seismic_response-0.1.0/src/seismic_response/sacpz.py +250 -0
  24. seismic_response-0.1.0/src/seismic_response/selection.py +170 -0
  25. seismic_response-0.1.0/src/seismic_response/stationxml.py +329 -0
  26. seismic_response-0.1.0/src/seismic_response/timeutil.py +61 -0
  27. seismic_response-0.1.0/src/seismic_response/units.py +110 -0
  28. seismic_response-0.1.0/src/seismic_response/web_api.py +247 -0
  29. seismic_response-0.1.0/tests/conftest.py +26 -0
  30. seismic_response-0.1.0/tests/data/README.md +14 -0
  31. seismic_response-0.1.0/tests/data/evalresp/README +12 -0
  32. seismic_response-0.1.0/tests/data/evalresp/RESP.UW.LON9.T1.HAX +31 -0
  33. seismic_response-0.1.0/tests/data/evalresp/RESP.XX.GAINFIRST..BHZ +37 -0
  34. seismic_response-0.1.0/tests/data/evalresp/RESP.XX.NYQ.00.ZZZ +42 -0
  35. seismic_response-0.1.0/tests/data/evalresp/station-gain-only.xml +33 -0
  36. seismic_response-0.1.0/tests/data/evalresp/station-list-stage2.xml +134 -0
  37. seismic_response-0.1.0/tests/data/evalresp/station-list.xml +59 -0
  38. seismic_response-0.1.0/tests/data/evalresp/station-polynomial-negative.xml +62 -0
  39. seismic_response-0.1.0/tests/data/evalresp/station-polynomial-zero.xml +97 -0
  40. seismic_response-0.1.0/tests/data/evalresp/station-polynomial.xml +572 -0
  41. seismic_response-0.1.0/tests/data/evalresp/station-precision.xml +99 -0
  42. seismic_response-0.1.0/tests/data/evalresp/station-pz-excess-pole.xml +75 -0
  43. seismic_response-0.1.0/tests/data/evalresp/station-pz-zero-freq.xml +186 -0
  44. seismic_response-0.1.0/tests/data/golden/golden.json +1 -0
  45. seismic_response-0.1.0/tests/data/real/RESP.IM.ATTU..BHE +228 -0
  46. seismic_response-0.1.0/tests/data/real/RESP.IU.ANMO.00.BHZ +958 -0
  47. seismic_response-0.1.0/tests/data/real/RESP.Z.CGV..HYZ +648 -0
  48. seismic_response-0.1.0/tests/data/real/station-3.xml +607 -0
  49. seismic_response-0.1.0/tests/data/real/station-3.xml2resp.resp +704 -0
  50. seismic_response-0.1.0/tests/data/synthetic/fir_asym.resp +48 -0
  51. seismic_response-0.1.0/tests/data/synthetic/fir_continuation.resp +57 -0
  52. seismic_response-0.1.0/tests/data/synthetic/gain_freq_mismatch.resp +47 -0
  53. seismic_response-0.1.0/tests/data/synthetic/gain_only_stage.resp +47 -0
  54. seismic_response-0.1.0/tests/data/synthetic/iir_coeff.resp +49 -0
  55. seismic_response-0.1.0/tests/data/synthetic/iir_pz.resp +48 -0
  56. seismic_response-0.1.0/tests/data/synthetic/pz_cancel.resp +23 -0
  57. seismic_response-0.1.0/tests/data/synthetic/pz_hz_fir_odd.resp +63 -0
  58. seismic_response-0.1.0/tests/data/synthetic/pz_pole_only.resp +23 -0
  59. seismic_response-0.1.0/tests/data/synthetic/sacpz_II_PFO_BHZ.pz +36 -0
  60. seismic_response-0.1.0/tests/data/synthetic/single_stage.resp +23 -0
  61. seismic_response-0.1.0/tests/data/synthetic/units_acc.resp +41 -0
  62. seismic_response-0.1.0/tests/data/synthetic/units_dis.resp +41 -0
  63. seismic_response-0.1.0/tests/data/synthetic/units_nm_acc.resp +41 -0
  64. seismic_response-0.1.0/tests/pyodide/package.json +9 -0
  65. seismic_response-0.1.0/tests/pyodide/smoke.mjs +59 -0
  66. seismic_response-0.1.0/tests/test_cli.py +176 -0
  67. seismic_response-0.1.0/tests/test_evaluate.py +536 -0
  68. seismic_response-0.1.0/tests/test_golden.py +90 -0
  69. seismic_response-0.1.0/tests/test_gui.py +175 -0
  70. seismic_response-0.1.0/tests/test_output.py +76 -0
  71. seismic_response-0.1.0/tests/test_parsers.py +277 -0
  72. seismic_response-0.1.0/tests/test_review_regressions.py +121 -0
  73. seismic_response-0.1.0/tests/test_sacpz.py +147 -0
  74. seismic_response-0.1.0/tests/test_selection.py +94 -0
  75. seismic_response-0.1.0/tests/test_units.py +43 -0
  76. seismic_response-0.1.0/tools/compare_evalresp.py +508 -0
  77. seismic_response-0.1.0/tools/make_golden.py +56 -0
  78. seismic_response-0.1.0/tools/make_synthetic.py +258 -0
  79. seismic_response-0.1.0/tools/release_notes.py +63 -0
@@ -0,0 +1,33 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .pytest_cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ .coverage
12
+ htmlcov/
13
+ .tox/
14
+
15
+ # Virtual environments
16
+ venv/
17
+ .venv/
18
+ env/
19
+
20
+ # Editors / OS
21
+ .vscode/
22
+ .idea/
23
+ .DS_Store
24
+
25
+ # Generated web build output
26
+ /web-dist/
27
+ /pyodide-test/
28
+
29
+ # evalresp output files produced by running the CLI in the repo root
30
+ /AMP.*
31
+ /PHASE.*
32
+ /FAP.*
33
+ /SPECTRA.*
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
@@ -0,0 +1,226 @@
1
+ Metadata-Version: 2.5
2
+ Name: seismic-response
3
+ Version: 0.1.0
4
+ Summary: Evaluate seismological instrument responses (StationXML, SEED RESP) with evalresp-compatible output
5
+ Author: EarthScope Consortium
6
+ License-Expression: LGPL-3.0-only
7
+ License-File: LICENSE
8
+ Keywords: FDSN,RESP,SEED,StationXML,evalresp,instrument response,seismology
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
12
+ Classifier: Operating System :: MacOS
13
+ Classifier: Operating System :: Microsoft :: Windows
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: 3.15
21
+ Classifier: Topic :: Scientific/Engineering :: Physics
22
+ Requires-Python: >=3.11
23
+ Provides-Extra: desktop
24
+ Requires-Dist: pywebview>=6.2; extra == 'desktop'
25
+ Provides-Extra: dev
26
+ Requires-Dist: build>=1.6; extra == 'dev'
27
+ Requires-Dist: pytest>=9; extra == 'dev'
28
+ Requires-Dist: ruff>=0.17; extra == 'dev'
29
+ Requires-Dist: twine>=7; extra == 'dev'
30
+ Provides-Extra: test
31
+ Requires-Dist: pytest>=9; extra == 'test'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # seismic-response
35
+
36
+
37
+
38
+ Evaluate seismological instrument responses specified as **StationXML**, **SEED RESP** or **SAC poles-and-zeros**
39
+ as selected frequencies to get complex-spectra or frequency-amplitude-phase results. This package is a
40
+ superset of the capability of the legacy [evalresp](https://github.com/EarthScope/evalresp) program.
41
+
42
+ * **Python library**: pure Python, no dependencies, runs unchanged under [Pyodide](https://pyodide.org) (WebAssembly)
43
+ * **evalresp-compatible command line**: `pyevalresp` (with a few [deliberate differences](#deliberate-differences-from-evalresp))
44
+ * **interactive GUI**: a web app (plots amplitude and phase, per-stage curves, FDSN fetch, export) that runs
45
+ locally, as a desktop window, or entirely in the browser with no server ([try it](https://earthscope-labs.github.io/seismic-response/app/))
46
+
47
+ Requires Python 3.11 or newer (Linux, macOS and Windows).
48
+
49
+ ## Install
50
+
51
+ ```sh
52
+ pip install seismic-response # library + CLI + GUI
53
+ pip install "seismic-response[desktop]" # also a native window for the GUI (pywebview)
54
+ ```
55
+
56
+ ## Library
57
+
58
+ ```python
59
+ from datetime import datetime, timezone
60
+ import seismic_response as sr
61
+
62
+ channels = sr.read_response("RESP.IU.ANMO.00.BHZ") # StationXML, RESP or SAC PZ, auto-detected
63
+ chan = sr.select_channel(channels, "FDSN:IU_ANMO_00_B_H_Z",
64
+ time=datetime(2000, 1, 1, tzinfo=timezone.utc))
65
+
66
+ freqs = sr.generate_frequencies(0.001, 50, 200) # log spaced; linear=True for linear
67
+ result = chan.evaluate(freqs, unit="vel") # "def" (default, as documented), "vel", "dis" or "acc"
68
+
69
+ result.frequencies # Hz
70
+ result.values # complex response, counts per unit of the requested ground motion
71
+ result.amplitudes
72
+ result.phases(unwrap=True) # degrees
73
+ result.info # sensitivity, per-stage gains, warnings, ...
74
+ ```
75
+
76
+ Useful options of `evaluate`: `stages=(first, last)`, `use_total_sensitivity=True`,
77
+ `use_estimated_delay=True` (asymmetric FIR), `b62_x=...` (polynomial responses) and `per_stage=True`
78
+ (each stage's contribution in `result.stage_values`; their product is the total response).
79
+
80
+ Channel selection follows evalresp: patterns are globs, and when several epochs of a channel overlap the
81
+ shortest one containing the requested time wins (the latest one when no time is given):
82
+
83
+ ```python
84
+ sr.select_channels(channels, network="IU", station="ANMO", location="00,10", channel="BH?", time=t)
85
+ ```
86
+
87
+ Errors derive from `SeismicResponseError` (`ResponseParseError`, `ResponseValueError`,
88
+ `ChannelNotFoundError`, `UnsupportedFeatureError`).
89
+
90
+ ## Command line
91
+
92
+ `pyevalresp` takes the same arguments and options as the C `evalresp` and writes the same files
93
+ (`AMP.*`/`PHASE.*`, `FAP.*` or `SPECTRA.*`, or the `-stdio` form):
94
+
95
+ ```sh
96
+ pyevalresp ANMO BHZ 2000 100 0.001 50 200 -f RESP.IU.ANMO.00.BHZ -u vel -r fap
97
+ pyevalresp KONO BHN,BHE 1992 1 0.001 10 100 -f resp_dir -t 12:31:04 -v
98
+ cat station.xml | pyevalresp '*' 'BH?' 2020 5 0.01 10 50 -stdio -x
99
+ ```
100
+
101
+ Run `pyevalresp` without arguments for the full option list. Differences from the C program:
102
+ messages go to stderr and a request matching no channel prints a warning. Also, `-u` defaults to `def`
103
+ (the units documented in the response) rather than evalresp's `vel`; pass `-u vel` to get evalresp's
104
+ behavior. A response whose input units are not ground motion (pressure, counts, none documented, ...)
105
+ therefore evaluates with no `-u`, where evalresp fails and asks for `-u def`.
106
+
107
+ `seismic-response` is the umbrella command: `seismic-response info FILE [-s]` lists channels and stages,
108
+ `seismic-response evalresp ...` is `pyevalresp`, and `seismic-response gui [FILE ...]` starts the GUI.
109
+
110
+ ## User Interface - Seismological Response Explorer
111
+
112
+ ```sh
113
+ seismic-response gui RESP.IU.ANMO.00.BHZ # opens your browser on a local server
114
+ seismic-response gui --app # native window (needs the [desktop] extra)
115
+ python -m seismic_response.gui --build site/ # static copy: host it anywhere, no Python server needed
116
+ ```
117
+
118
+ The browser version of each release is published to GitHub Pages at
119
+ <https://earthscope-labs.github.io/seismic-response/app/>. A static copy has to be served over HTTP
120
+ (for example `python -m http.server -d site/`); opening `index.html` from disk does not work.
121
+
122
+ Load files by dropping them on the page, enter a file URL, or fetch from an FDSN station web service. Choose
123
+ an epoch of an FDSN Source ID from the list, then set the
124
+ frequency range, output unit and options, and tick the stages to include in the stage table. The plot shows
125
+ amplitude and phase with a hover read-out; individual stages can be overlaid; tick several epochs, of the same
126
+ or different Source IDs, to overlay them for comparison; results export as evalresp text
127
+ (FAP, AP, complex), SVG or PNG.
128
+
129
+ A link can open the page with files already loaded using the `url` parameter (repeatable, percent-encoded),
130
+ for example `.../app/?url=https%3A%2F%2Fexample.org%2Fresponse.xml`. The file server must allow cross-origin
131
+ requests.
132
+
133
+ The page talks to the same Python through a small JSON API (`seismic_response.web_api`). With the local
134
+ server that is plain HTTP on the loopback interface (requests with a foreign `Host` or `Origin` are
135
+ refused). On a static host it loads Pyodide from a CDN and runs the package in the browser.
136
+
137
+ ### Deliberate differences from evalresp
138
+
139
+ * **Default output unit.** With no unit requested, responses are evaluated in the units documented in the
140
+ response (equivalent to `def` in evalresp): counts per m/s for a velocity sensor, counts per m/s² for
141
+ an accelerometer, counts per pascal for a pressure sensor, and so on. Any documented unit, or none, is
142
+ accepted. This applies to the library (`evaluate()`), `pyevalresp`, the web API and the GUI. evalresp
143
+ defaults to `vel`; pass `-u vel` (or `unit="vel"`) for that.
144
+
145
+ Because evalresp 5.1.0 refuses `dis`, `vel` and `acc` for a response whose input units are not ground
146
+ motion, its default fails on pressure, tesla, degrees C, counts or volts inputs and on responses with no
147
+ documented input units; this package evaluates them as documented. Requesting `dis`, `vel` or `acc`
148
+ explicitly fails here too. These require the first stage that documents input units to use a
149
+ ground-motion unit: `M`, `M/S`, `M/SEC`, or an acceleration form (`M/S**2`, `M/S^2`, `M/S2`, `M/S/S` and
150
+ their `SEC` equivalents), each with an optional `N`, `M` or `C` prefix. The unit symbol is the text
151
+ before the first space, hyphen, comma or parenthesis, so a description is optional. Any other input
152
+ unit, or none, is an error; use `def` for those responses.
153
+
154
+ ## Limitations
155
+
156
+ * **Polynomial responses (blockette 62)** are evaluated at `b62_x` (default 0, any value allowed) as the
157
+ first derivative of the MacLaurin polynomial; a negative slope is a negative real response, as in
158
+ evalresp 5.1.0 and later.
159
+ * **Response-list interpolation** (`-il`, or `interpolate_list=True`) resamples a blockette 55 response
160
+ at the requested frequencies with a natural cubic spline in log10(frequency), interpolating
161
+ log10(amplitude) and the unwrapped phase. If any listed frequency or amplitude, or any requested
162
+ frequency, is not positive it falls back to linear space with a warning. Requested frequencies outside
163
+ the list's range are dropped with a warning, and the list frequencies must be strictly increasing.
164
+ A response list may be in any stage. Without interpolation the output is at the listed frequencies, and
165
+ several lists must share them; with it, every evaluated list is interpolated and only the range common to
166
+ all of them is kept. `-ii` is accepted as an alias. This matches evalresp releases that include the spline fixes; evalresp
167
+ 5.0.1 and earlier give different values for requested frequencies that are not listed, because they
168
+ swap two spline coefficients (the result is not smooth on unevenly spaced frequencies) and interpolate in
169
+ linear space, where steep roll-offs can overshoot or go negative.
170
+ * **RESP dictionary references** (blockette 60 and the blockette 4x lookups) are not supported and raise
171
+ `ResponseParseError`.
172
+ * Analog (non-Z) coefficient filters are rejected, as in evalresp.
173
+
174
+ ## How closely does it match evalresp?
175
+
176
+ The numerical code is a port of evalresp's own logic (stage consistency checks, gain/normalization
177
+ handling, FIR/IIR/pole-zero evaluation, unit conversion, phase unwrapping) rather than a re-derivation.
178
+ It is checked against a built evalresp in two ways:
179
+
180
+ * **Golden tests** (`tests/test_golden.py`, run everywhere): 377 results captured from the C program
181
+ (evalresp 5.1.0) for real and synthetic responses and a selection of evalresp's own test responses, over a
182
+ matrix of options (units, `-ts`, estimated delay, stage ranges, `-il`, `-b62_x`), matched to within the
183
+ 7 digits it prints. Each point may also differ by up to 1e-14 of the response's peak (floating-point
184
+ cancellation near a stopband), and points where both values are below 1e-9 of the peak (such as a FIR
185
+ response above Nyquist) are numerical noise and are not compared.
186
+ * **Live comparison** (`tools/compare_evalresp.py BINARY FILES...`, needs a built C evalresp, 5.1.0):
187
+ 2,850 complex-spectrum comparisons over every response in evalresp's own test data and 389 over this
188
+ repository's fixtures, and 952 FAP/AP text comparisons on evalresp's test data (`--formats`, which
189
+ includes phase unwrapping), with no mismatches. Points above the Nyquist frequency of the evaluated
190
+ decimation stages, where FIRs alias and the response is ill-conditioned, are compared to 1e-4
191
+ (`--rtol-above-nyquist`) instead of 2e-6.
192
+
193
+ Confirmed matching: Laplace (rad/s and Hz) and Z-transform poles/zeros, asymmetric/even/odd-symmetric
194
+ FIR (including continuation blockettes and delay correction), IIR coefficients, response lists, gain-only
195
+ stages, sensitivity-frequency renormalization, `dis`/`vel`/`acc`/`def` conversion including nm/mm/cm
196
+ inputs, `-ts`, `-use-estimated-delay` and stage ranges.
197
+
198
+ ## References
199
+
200
+ * **SEED**: [SEED Reference Manual, SEED Format Version 2.4](https://www.fdsn.org/pdf/SEEDManual_V2.4.pdf)
201
+ (FDSN), which defines the response blockettes that RESP files carry, and the
202
+ [FDSN publications](https://www.fdsn.org/publications/) page.
203
+ * **evalresp**: the [evalresp repository](https://github.com/EarthScope/evalresp) and the
204
+ [5.1.0 development version](https://github.com/EarthScope/evalresp/tree/develop) this package is validated against.
205
+ * **SAC poles and zeros**: Goldstein, P., Dodge, D., Firpo, M., and Minner, L. (2003). SAC2000: Signal
206
+ processing and analysis tools for seismologists and engineers. In W. H. K. Lee, H. Kanamori, P. C. Jennings,
207
+ and C. Kisslinger (Eds.), *International Handbook of Earthquake and Engineering Seismology*, Part B, ch. 85.5,
208
+ pp. 1613–1614. Academic Press, London.
209
+ [doi:10.1016/S0074-6142(03)80284-X](https://doi.org/10.1016/S0074-6142(03)80284-X)
210
+ * **Related FDSN standards** used by this package: [StationXML](https://docs.fdsn.org/projects/stationxml/en/latest/)
211
+ and [Source Identifiers](https://docs.fdsn.org/projects/source-identifiers/en/latest/).
212
+
213
+ ## Development
214
+
215
+ ```sh
216
+ python -m venv .venv && . .venv/bin/activate
217
+ pip install -e ".[dev]"
218
+ pytest # ~550 tests, ~2 s
219
+ ruff check src tests tools
220
+ ```
221
+
222
+ `tools/make_synthetic.py` and `tools/make_golden.py` regenerate the synthetic fixtures and the golden
223
+ reference results (the latter needs a built C evalresp). `tests/pyodide/` holds the WebAssembly smoke
224
+ test run in CI; see `.github/workflows/tests.yml`.
225
+
226
+ The package is distributed under the GNU Lesser General Public License, version 3 (see `LICENSE`), the same license as evalresp.
@@ -0,0 +1,193 @@
1
+ # seismic-response
2
+
3
+
4
+
5
+ Evaluate seismological instrument responses specified as **StationXML**, **SEED RESP** or **SAC poles-and-zeros**
6
+ as selected frequencies to get complex-spectra or frequency-amplitude-phase results. This package is a
7
+ superset of the capability of the legacy [evalresp](https://github.com/EarthScope/evalresp) program.
8
+
9
+ * **Python library**: pure Python, no dependencies, runs unchanged under [Pyodide](https://pyodide.org) (WebAssembly)
10
+ * **evalresp-compatible command line**: `pyevalresp` (with a few [deliberate differences](#deliberate-differences-from-evalresp))
11
+ * **interactive GUI**: a web app (plots amplitude and phase, per-stage curves, FDSN fetch, export) that runs
12
+ locally, as a desktop window, or entirely in the browser with no server ([try it](https://earthscope-labs.github.io/seismic-response/app/))
13
+
14
+ Requires Python 3.11 or newer (Linux, macOS and Windows).
15
+
16
+ ## Install
17
+
18
+ ```sh
19
+ pip install seismic-response # library + CLI + GUI
20
+ pip install "seismic-response[desktop]" # also a native window for the GUI (pywebview)
21
+ ```
22
+
23
+ ## Library
24
+
25
+ ```python
26
+ from datetime import datetime, timezone
27
+ import seismic_response as sr
28
+
29
+ channels = sr.read_response("RESP.IU.ANMO.00.BHZ") # StationXML, RESP or SAC PZ, auto-detected
30
+ chan = sr.select_channel(channels, "FDSN:IU_ANMO_00_B_H_Z",
31
+ time=datetime(2000, 1, 1, tzinfo=timezone.utc))
32
+
33
+ freqs = sr.generate_frequencies(0.001, 50, 200) # log spaced; linear=True for linear
34
+ result = chan.evaluate(freqs, unit="vel") # "def" (default, as documented), "vel", "dis" or "acc"
35
+
36
+ result.frequencies # Hz
37
+ result.values # complex response, counts per unit of the requested ground motion
38
+ result.amplitudes
39
+ result.phases(unwrap=True) # degrees
40
+ result.info # sensitivity, per-stage gains, warnings, ...
41
+ ```
42
+
43
+ Useful options of `evaluate`: `stages=(first, last)`, `use_total_sensitivity=True`,
44
+ `use_estimated_delay=True` (asymmetric FIR), `b62_x=...` (polynomial responses) and `per_stage=True`
45
+ (each stage's contribution in `result.stage_values`; their product is the total response).
46
+
47
+ Channel selection follows evalresp: patterns are globs, and when several epochs of a channel overlap the
48
+ shortest one containing the requested time wins (the latest one when no time is given):
49
+
50
+ ```python
51
+ sr.select_channels(channels, network="IU", station="ANMO", location="00,10", channel="BH?", time=t)
52
+ ```
53
+
54
+ Errors derive from `SeismicResponseError` (`ResponseParseError`, `ResponseValueError`,
55
+ `ChannelNotFoundError`, `UnsupportedFeatureError`).
56
+
57
+ ## Command line
58
+
59
+ `pyevalresp` takes the same arguments and options as the C `evalresp` and writes the same files
60
+ (`AMP.*`/`PHASE.*`, `FAP.*` or `SPECTRA.*`, or the `-stdio` form):
61
+
62
+ ```sh
63
+ pyevalresp ANMO BHZ 2000 100 0.001 50 200 -f RESP.IU.ANMO.00.BHZ -u vel -r fap
64
+ pyevalresp KONO BHN,BHE 1992 1 0.001 10 100 -f resp_dir -t 12:31:04 -v
65
+ cat station.xml | pyevalresp '*' 'BH?' 2020 5 0.01 10 50 -stdio -x
66
+ ```
67
+
68
+ Run `pyevalresp` without arguments for the full option list. Differences from the C program:
69
+ messages go to stderr and a request matching no channel prints a warning. Also, `-u` defaults to `def`
70
+ (the units documented in the response) rather than evalresp's `vel`; pass `-u vel` to get evalresp's
71
+ behavior. A response whose input units are not ground motion (pressure, counts, none documented, ...)
72
+ therefore evaluates with no `-u`, where evalresp fails and asks for `-u def`.
73
+
74
+ `seismic-response` is the umbrella command: `seismic-response info FILE [-s]` lists channels and stages,
75
+ `seismic-response evalresp ...` is `pyevalresp`, and `seismic-response gui [FILE ...]` starts the GUI.
76
+
77
+ ## User Interface - Seismological Response Explorer
78
+
79
+ ```sh
80
+ seismic-response gui RESP.IU.ANMO.00.BHZ # opens your browser on a local server
81
+ seismic-response gui --app # native window (needs the [desktop] extra)
82
+ python -m seismic_response.gui --build site/ # static copy: host it anywhere, no Python server needed
83
+ ```
84
+
85
+ The browser version of each release is published to GitHub Pages at
86
+ <https://earthscope-labs.github.io/seismic-response/app/>. A static copy has to be served over HTTP
87
+ (for example `python -m http.server -d site/`); opening `index.html` from disk does not work.
88
+
89
+ Load files by dropping them on the page, enter a file URL, or fetch from an FDSN station web service. Choose
90
+ an epoch of an FDSN Source ID from the list, then set the
91
+ frequency range, output unit and options, and tick the stages to include in the stage table. The plot shows
92
+ amplitude and phase with a hover read-out; individual stages can be overlaid; tick several epochs, of the same
93
+ or different Source IDs, to overlay them for comparison; results export as evalresp text
94
+ (FAP, AP, complex), SVG or PNG.
95
+
96
+ A link can open the page with files already loaded using the `url` parameter (repeatable, percent-encoded),
97
+ for example `.../app/?url=https%3A%2F%2Fexample.org%2Fresponse.xml`. The file server must allow cross-origin
98
+ requests.
99
+
100
+ The page talks to the same Python through a small JSON API (`seismic_response.web_api`). With the local
101
+ server that is plain HTTP on the loopback interface (requests with a foreign `Host` or `Origin` are
102
+ refused). On a static host it loads Pyodide from a CDN and runs the package in the browser.
103
+
104
+ ### Deliberate differences from evalresp
105
+
106
+ * **Default output unit.** With no unit requested, responses are evaluated in the units documented in the
107
+ response (equivalent to `def` in evalresp): counts per m/s for a velocity sensor, counts per m/s² for
108
+ an accelerometer, counts per pascal for a pressure sensor, and so on. Any documented unit, or none, is
109
+ accepted. This applies to the library (`evaluate()`), `pyevalresp`, the web API and the GUI. evalresp
110
+ defaults to `vel`; pass `-u vel` (or `unit="vel"`) for that.
111
+
112
+ Because evalresp 5.1.0 refuses `dis`, `vel` and `acc` for a response whose input units are not ground
113
+ motion, its default fails on pressure, tesla, degrees C, counts or volts inputs and on responses with no
114
+ documented input units; this package evaluates them as documented. Requesting `dis`, `vel` or `acc`
115
+ explicitly fails here too. These require the first stage that documents input units to use a
116
+ ground-motion unit: `M`, `M/S`, `M/SEC`, or an acceleration form (`M/S**2`, `M/S^2`, `M/S2`, `M/S/S` and
117
+ their `SEC` equivalents), each with an optional `N`, `M` or `C` prefix. The unit symbol is the text
118
+ before the first space, hyphen, comma or parenthesis, so a description is optional. Any other input
119
+ unit, or none, is an error; use `def` for those responses.
120
+
121
+ ## Limitations
122
+
123
+ * **Polynomial responses (blockette 62)** are evaluated at `b62_x` (default 0, any value allowed) as the
124
+ first derivative of the MacLaurin polynomial; a negative slope is a negative real response, as in
125
+ evalresp 5.1.0 and later.
126
+ * **Response-list interpolation** (`-il`, or `interpolate_list=True`) resamples a blockette 55 response
127
+ at the requested frequencies with a natural cubic spline in log10(frequency), interpolating
128
+ log10(amplitude) and the unwrapped phase. If any listed frequency or amplitude, or any requested
129
+ frequency, is not positive it falls back to linear space with a warning. Requested frequencies outside
130
+ the list's range are dropped with a warning, and the list frequencies must be strictly increasing.
131
+ A response list may be in any stage. Without interpolation the output is at the listed frequencies, and
132
+ several lists must share them; with it, every evaluated list is interpolated and only the range common to
133
+ all of them is kept. `-ii` is accepted as an alias. This matches evalresp releases that include the spline fixes; evalresp
134
+ 5.0.1 and earlier give different values for requested frequencies that are not listed, because they
135
+ swap two spline coefficients (the result is not smooth on unevenly spaced frequencies) and interpolate in
136
+ linear space, where steep roll-offs can overshoot or go negative.
137
+ * **RESP dictionary references** (blockette 60 and the blockette 4x lookups) are not supported and raise
138
+ `ResponseParseError`.
139
+ * Analog (non-Z) coefficient filters are rejected, as in evalresp.
140
+
141
+ ## How closely does it match evalresp?
142
+
143
+ The numerical code is a port of evalresp's own logic (stage consistency checks, gain/normalization
144
+ handling, FIR/IIR/pole-zero evaluation, unit conversion, phase unwrapping) rather than a re-derivation.
145
+ It is checked against a built evalresp in two ways:
146
+
147
+ * **Golden tests** (`tests/test_golden.py`, run everywhere): 377 results captured from the C program
148
+ (evalresp 5.1.0) for real and synthetic responses and a selection of evalresp's own test responses, over a
149
+ matrix of options (units, `-ts`, estimated delay, stage ranges, `-il`, `-b62_x`), matched to within the
150
+ 7 digits it prints. Each point may also differ by up to 1e-14 of the response's peak (floating-point
151
+ cancellation near a stopband), and points where both values are below 1e-9 of the peak (such as a FIR
152
+ response above Nyquist) are numerical noise and are not compared.
153
+ * **Live comparison** (`tools/compare_evalresp.py BINARY FILES...`, needs a built C evalresp, 5.1.0):
154
+ 2,850 complex-spectrum comparisons over every response in evalresp's own test data and 389 over this
155
+ repository's fixtures, and 952 FAP/AP text comparisons on evalresp's test data (`--formats`, which
156
+ includes phase unwrapping), with no mismatches. Points above the Nyquist frequency of the evaluated
157
+ decimation stages, where FIRs alias and the response is ill-conditioned, are compared to 1e-4
158
+ (`--rtol-above-nyquist`) instead of 2e-6.
159
+
160
+ Confirmed matching: Laplace (rad/s and Hz) and Z-transform poles/zeros, asymmetric/even/odd-symmetric
161
+ FIR (including continuation blockettes and delay correction), IIR coefficients, response lists, gain-only
162
+ stages, sensitivity-frequency renormalization, `dis`/`vel`/`acc`/`def` conversion including nm/mm/cm
163
+ inputs, `-ts`, `-use-estimated-delay` and stage ranges.
164
+
165
+ ## References
166
+
167
+ * **SEED**: [SEED Reference Manual, SEED Format Version 2.4](https://www.fdsn.org/pdf/SEEDManual_V2.4.pdf)
168
+ (FDSN), which defines the response blockettes that RESP files carry, and the
169
+ [FDSN publications](https://www.fdsn.org/publications/) page.
170
+ * **evalresp**: the [evalresp repository](https://github.com/EarthScope/evalresp) and the
171
+ [5.1.0 development version](https://github.com/EarthScope/evalresp/tree/develop) this package is validated against.
172
+ * **SAC poles and zeros**: Goldstein, P., Dodge, D., Firpo, M., and Minner, L. (2003). SAC2000: Signal
173
+ processing and analysis tools for seismologists and engineers. In W. H. K. Lee, H. Kanamori, P. C. Jennings,
174
+ and C. Kisslinger (Eds.), *International Handbook of Earthquake and Engineering Seismology*, Part B, ch. 85.5,
175
+ pp. 1613–1614. Academic Press, London.
176
+ [doi:10.1016/S0074-6142(03)80284-X](https://doi.org/10.1016/S0074-6142(03)80284-X)
177
+ * **Related FDSN standards** used by this package: [StationXML](https://docs.fdsn.org/projects/stationxml/en/latest/)
178
+ and [Source Identifiers](https://docs.fdsn.org/projects/source-identifiers/en/latest/).
179
+
180
+ ## Development
181
+
182
+ ```sh
183
+ python -m venv .venv && . .venv/bin/activate
184
+ pip install -e ".[dev]"
185
+ pytest # ~550 tests, ~2 s
186
+ ruff check src tests tools
187
+ ```
188
+
189
+ `tools/make_synthetic.py` and `tools/make_golden.py` regenerate the synthetic fixtures and the golden
190
+ reference results (the latter needs a built C evalresp). `tests/pyodide/` holds the WebAssembly smoke
191
+ test run in CI; see `.github/workflows/tests.yml`.
192
+
193
+ The package is distributed under the GNU Lesser General Public License, version 3 (see `LICENSE`), the same license as evalresp.