# -*- coding: utf8 -*-
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Fetch event waveforms from a local SDS archive.
:copyright:
2022-2026 Claudio Satriano <satriano@ipgp.fr>
:license:
GNU General Public License v3.0 or later
(https://www.gnu.org/licenses/gpl-3.0-standalone.html)
"""
import pathlib
import re
from obspy.clients.filesystem.sds import Client
from .event_waveforms_utils import prefer_high_sampling_rate
[docs]
def get_sds_client(sds_root):
"""
Get an SDS client.
:param sds_root: path to SDS archive
:type sds_root: str
:return: SDS client
:rtype: obspy.clients.filesystem.sds.Client
"""
client = Client(sds_root)
# Ensure the archive has at least one NSLC entry before accepting it.
if client.get_all_nslc():
return client
else:
raise FileNotFoundError(
f'No SDS archive found in {sds_root}')
def _check_channel(channel, channel_codes):
"""
Check if a channel matches the specified channel codes.
The channel codes can contain wildcards:
- '*' matches any number of characters
- '?' matches a single character
:param channel: channel code
:type channel: str
:param channel_codes: string with channel codes separated by commas
:type channel_codes: str
:return: True if the channel is in the list of channel priorities
:rtype: bool
"""
# Escape dots, replace `?` with `.`, replace `*` with `.*`,
# and split by comma
regex_parts = [
code.replace('.', r'\.') # Escape dots if any
.replace('?', '.') # Single-character wildcard
.replace('*', '.*') # Multi-character wildcard
for code in channel_codes.split(',')
]
# Join with `|` to create an OR pattern
regex = f"^({'|'.join(regex_parts)})$"
return bool(re.match(regex, channel))