Skip to content

Commit

Permalink
Rename download to fetchdata
Browse files Browse the repository at this point in the history
Also, move ObsPy mass downloader code to a separate file.
  • Loading branch information
claudiodsf committed Dec 2, 2024
1 parent 4b800e4 commit 374d219
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Copyright (c) 2022-2024 Claudio Satriano <[email protected]>

## unreleased

- `seiscat download` renamed to `seiscat fetchdata`
- New option for `seiscat initdb` and `seiscat updatedb`: `--fromfile` to
initialize or update the database from a CSV file

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
from ..utils import ExceptionExit


def download_event_details(config):
def fetch_event_details(config):
"""
Download event details from FDSN web services
Fetch event details from FDSN web services
and store them to local files.
:param config: config object
Expand Down
30 changes: 30 additions & 0 deletions seiscat/fetchdata/event_waveforms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf8 -*-
# SPDX-License-Identifier: GPL-3.0-or-later
"""
Fetch event waveforms from FDSN web services or from a local SDS archive.
:copyright:
2022-2024 Claudio Satriano <[email protected]>
:license:
GNU General Public License v3.0 or later
(https://www.gnu.org/licenses/gpl-3.0-standalone.html)
"""
import pathlib
from .mass_downloader import mass_download_waveforms
from ..database.dbfunctions import read_events_from_db
from ..utils import ExceptionExit


def fetch_event_waveforms(config):
"""
Fetch event waveforms from FDSN web services
or from a local SDS archive.
:param config: config object
"""
with ExceptionExit():
events = read_events_from_db(config)
event_dir = pathlib.Path(config['event_dir'])
event_dir.mkdir(parents=True, exist_ok=True)
for event in events:
mass_download_waveforms(config, event)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import pathlib
from obspy.clients.fdsn.mass_downloader import CircularDomain, \
Restrictions, MassDownloader
from ..database.dbfunctions import read_events_from_db
from ..utils import ExceptionExit


Expand Down Expand Up @@ -41,7 +40,7 @@ def _check_fdsn_providers(fdsn_providers):
print('Please answer y or n:', end=' ')


def _download_waveforms(config, event):
def mass_download_waveforms(config, event):
"""
Download waveforms for a single event using ObsPy mass downloader.
Expand Down Expand Up @@ -99,18 +98,3 @@ def _download_waveforms(config, event):
f'\n{evid}: waveforms and station metadata saved to '
f'{evid_dir}\n\n'
)


def download_event_waveforms(config):
"""
Uses ObsPy mass downloader to download event waveforms from FDSN
web services.
:param config: config object
"""
with ExceptionExit():
events = read_events_from_db(config)
event_dir = pathlib.Path(config['event_dir'])
event_dir.mkdir(parents=True, exist_ok=True)
for event in events:
_download_waveforms(config, event)
18 changes: 9 additions & 9 deletions seiscat/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def run():
elif args.action == 'editdb':
from .database.editdb import editdb
editdb(config)
elif args.action == 'download':
download_event = args.event or args.both
download_data = args.data or args.both
if download_event:
from .download.event_details import download_event_details
download_event_details(config)
if download_data:
from .download.event_waveforms import download_event_waveforms
download_event_waveforms(config)
elif args.action == 'fetchdata':
fetch_event = args.event or args.both
fetch_data = args.data or args.both
if fetch_event:
from .fetchdata.event_details import fetch_event_details
fetch_event_details(config)
if fetch_data:
from .fetchdata.event_waveforms import fetch_event_waveforms
fetch_event_waveforms(config)
elif args.action == 'print':
from .print import print_catalog
print_catalog(config)
Expand Down
12 changes: 6 additions & 6 deletions seiscat/parse_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,16 @@ def parse_arguments():
'Note that the comparison operators must be quoted to avoid\n'
'interpretation by the shell.\n'
)
download_parser = subparser.add_parser(
'download', parents=[versions_parser, where_parser],
help='download full event details and/or waveform data and metadata',
fetchdata_parser = subparser.add_parser(
'fetchdata', parents=[versions_parser, where_parser],
help='fetch full event details and/or waveform data and metadata',
formatter_class=NewlineHelpFormatter
)
download_parser.add_argument(
fetchdata_parser.add_argument(
'eventid', nargs='?',
help='event ID to download (default: all events)'
).completer = _evid_completer
group = download_parser.add_mutually_exclusive_group(required=True)
group = fetchdata_parser.add_mutually_exclusive_group(required=True)
group.add_argument(
'-e',
'--event',
Expand All @@ -220,7 +220,7 @@ def parse_arguments():
default=False,
help='download both event details and waveform data and metadata'
)
download_parser.add_argument(
fetchdata_parser.add_argument(
'-o',
'--overwrite_existing',
action='store_true',
Expand Down

0 comments on commit 374d219

Please sign in to comment.