| Conditions | 2 |
| Total Lines | 20 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import obspy |
||
| 9 | def process(self, data): |
||
| 10 | # Create a Stream object from the incoming data |
||
| 11 | st = obspy.Stream(obspy.Trace(data)) |
||
| 12 | # Remove mean and linear trends |
||
| 13 | st.detrend("demean") |
||
| 14 | st.detrend("linear") |
||
| 15 | # Apply bandpass filter to isolate frequencies of interest |
||
| 16 | st.filter("bandpass", freqmin=0.1, freqmax=20.0) |
||
| 17 | # Integrate to convert displacement to velocity |
||
| 18 | st.integrate() |
||
| 19 | # Find Peak Ground Velocity (PGV) |
||
| 20 | pgv = max(abs(st[0].data)) |
||
| 21 | # Convert PGV from m/s to cm/s |
||
| 22 | pgv_cm_s = pgv * 100 |
||
| 23 | # Estimate Richter magnitude using the empirical relationship |
||
| 24 | magnitude = np.log10(pgv_cm_s) + 2.4 |
||
| 25 | |||
| 26 | # Trigger alert if magnitude exceeds threshold |
||
| 27 | if magnitude >= self.threshold: |
||
| 28 | self.trigger_alert(magnitude) |
||
| 29 | |||
| 38 |