Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save raw waveforms and metadata in tmp dir #79

Merged
merged 1 commit into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ master
- make reference time given on command line the zero-time on time axis always
(so far if an offset was given the zero time was equal to reference time
plus offset, see #78)
- save raw waveform data and station metadata in current obspyck instance's
temporary directory for easy reuse (see #79)

0.5.1
- fix getting metadata via arclink (see #65)
Expand Down
10 changes: 7 additions & 3 deletions obspyck/obspyck.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ObsPyck(QtGui.QMainWindow):
"""
Main Window with the design loaded from the Qt Designer.
"""
def __init__(self, clients, streams, options, keys, config):
def __init__(self, clients, streams, options, keys, config, inventories):
"""
Standard init.
"""
Expand Down Expand Up @@ -272,8 +272,12 @@ def __init__(self, clients, streams, options, keys, config):
else:
self.test_event_server = None

# save input raw data and metadata for eventual reuse
_save_input_data(streams, inventories, self.tmp_dir)

(warn_msg, merge_msg, streams) = \
merge_check_and_cleanup_streams(streams, options, config)

# if it's not empty show the merge info message now
if merge_msg:
self.info(merge_msg)
Expand Down Expand Up @@ -4782,10 +4786,10 @@ def main():
# TODO: remove KEYS variable and lookup from config directly
KEYS = {key: config.get('keys', key) for key in config.options('keys')}
check_keybinding_conflicts(KEYS)
(clients, streams) = fetch_waveforms_with_metadata(options, args, config)
(clients, streams, inventories) = fetch_waveforms_with_metadata(options, args, config)
# Create the GUI application
qApp = QtGui.QApplication(sys.argv)
obspyck = ObsPyck(clients, streams, options, KEYS, config)
obspyck = ObsPyck(clients, streams, options, KEYS, config, inventories)
qApp.connect(qApp, QtCore.SIGNAL("aboutToQuit()"), obspyck.cleanup)
os._exit(qApp.exec_())

Expand Down
38 changes: 36 additions & 2 deletions obspyck/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ def fetch_waveforms_with_metadata(options, args, config):
"-m overwrite" option.

:returns: (dictionary with clients,
list(:class:`obspy.core.stream.Stream`s))
list(:class:`obspy.core.stream.Stream`s),
list of Inventory)
"""
if not options.station_combinations and not options.seed_ids and not args:
msg = ('No data to use specified. At least use one of option "-s", '
Expand Down Expand Up @@ -395,6 +396,7 @@ def fetch_waveforms_with_metadata(options, args, config):
streams = []
sta_fetched = set()
# Local files:
all_inventories = []
inventories = []
if args:
print "=" * 80
Expand Down Expand Up @@ -444,6 +446,7 @@ def fetch_waveforms_with_metadata(options, args, config):
if net_sta_loc in config.options("rotate_channels"):
rotate_channels(stream_tmp_, net, sta, loc, config)
streams.append(stream_tmp_)
all_inventories += inventories

print "=" * 80
print "Fetching waveforms and metadata from servers:"
Expand Down Expand Up @@ -490,6 +493,7 @@ def fetch_waveforms_with_metadata(options, args, config):
inv = read_inventory(bio, format='XSEED')
inventories.append(inv)
_attach_metadata(st, inventories)
all_inventories += inventories
# ArcLink
elif server_type == "arclink":
st = client.get_waveforms(
Expand All @@ -506,6 +510,7 @@ def fetch_waveforms_with_metadata(options, args, config):
inventories.append(
read_inventory(bio, format='SEED'))
_attach_metadata(st, inventories)
all_inventories += inventories
# FDSN (or JANE)
elif server_type in ("fdsn", "jane"):
st = client.get_waveforms(
Expand All @@ -516,6 +521,7 @@ def fetch_waveforms_with_metadata(options, args, config):
network=net, station=sta, location=loc,
level="response")
_attach_metadata(st, inventory)
all_inventories += [inventory]
# Seedlink
elif server_type == "seedlink":
# XXX I think the wild card checks for net/sta/loc can be
Expand Down Expand Up @@ -547,6 +553,7 @@ def fetch_waveforms_with_metadata(options, args, config):
network=net, station=sta, location=loc,
level="response")
_attach_metadata(st, inventory)
all_inventories += [inventory]
else:
raise NotImplementedError()
# SDS
Expand Down Expand Up @@ -580,6 +587,7 @@ def fetch_waveforms_with_metadata(options, args, config):
network=net, station=sta, location=loc,
level="response")
_attach_metadata(st, inventory)
all_inventories += [inventory]
else:
raise NotImplementedError()
sta_fetched.add(net_sta_loc)
Expand Down Expand Up @@ -621,7 +629,7 @@ def fetch_waveforms_with_metadata(options, args, config):
tr.stats['_format'] = "SDS"
streams.append(st)
print "=" * 80
return (clients, streams)
return (clients, streams, all_inventories)


def rotate_channels(st, net, sta, loc, config):
Expand Down Expand Up @@ -1283,3 +1291,29 @@ def set_matplotlib_defaults(config):
if config.has_section('matplotlibrc'):
for key, value in config.items('matplotlibrc'):
mpl.rcParams[key] = value


def _save_input_data(streams, inventories, directory):
"""
:type streams: list of Stream
:type inventories: list of Inventory
:type directory: str
"""
if not os.path.isdir(directory):
raise OSError('Not a directory: ' + str(directory))
if isinstance(streams, (list, tuple)):
pass
elif isinstance(streams, Stream):
streams = [streams]
else:
raise TypeError
# write raw waveforms
st = Stream()
for st_ in streams:
st += st_
st.write(os.path.join(directory, 'waveforms.mseed'), format='MSEED')
# write inventories
inv = Inventory(networks=[], source='')
for inv_ in inventories:
inv += inv_
inv.write(os.path.join(directory, 'inventory.xml'), format='STATIONXML')