Skip to content

Commit

Permalink
fix #2266
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers authored and megies committed Feb 14, 2019
1 parent 92843fe commit 7833c50
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions obspy/core/inventory/inventory.py
Expand Up @@ -667,12 +667,14 @@ def remove(self, network='*', station='*', location='*', channel='*',
without child elements (stations/channels) will still be included
in the result.
"""
# Select all objects that are to be removed.
selected = self.select(network=network, station=station,
location=location, channel=channel)
selected_networks = [net for net in selected]
selected_stations = [sta for net in selected_networks for sta in net]
selected_channels = [cha for net in selected_networks
for sta in net for cha in sta]
# Iterate inventory tree and rebuild it excluding selected components.
networks = []
for net in self:
if net in selected_networks and station == '*' and \
Expand All @@ -688,12 +690,14 @@ def remove(self, network='*', station='*', location='*', channel='*',
if cha in selected_channels:
continue
channels.append(cha)
if not channels and not keep_empty:
channels_were_empty = not bool(sta.channels)
if not channels and not (keep_empty or channels_were_empty):
continue
sta = copy.copy(sta)
sta.channels = channels
stations.append(sta)
if not stations and not keep_empty:
stations_were_empty = not bool(net.stations)
if not stations and not (keep_empty or stations_were_empty):
continue
net = copy.copy(net)
net.stations = stations
Expand Down

0 comments on commit 7833c50

Please sign in to comment.