[update] metadata/inventory management

[bugfix] errors when there were no manual picks using array_map
This commit is contained in:
2018-07-23 14:54:53 +02:00
parent f802f1db58
commit eb07c19c2e
4 changed files with 73 additions and 112 deletions

View File

@@ -23,8 +23,7 @@ class Array_map(QtGui.QWidget):
'''
QtGui.QWidget.__init__(self)
self._parent = parent
self.metadata_type = parent.metadata[0]
self.metadata = parent.metadata[1]
self.metadata = parent.metadata
self.picks = None
self.picks_dict = None
self.autopicks_dict = None
@@ -160,33 +159,7 @@ class Array_map(QtGui.QWidget):
self.main_box.addWidget(self.status_label, 0)
def init_stations(self):
def stat_info_from_parser(parser):
stations_dict = {}
for station in parser.stations:
station_name = station[0].station_call_letters
network_name = station[0].network_code
if not station_name in stations_dict.keys():
st_id = network_name + '.' + station_name
stations_dict[st_id] = {'latitude': station[0].latitude,
'longitude': station[0].longitude}
return stations_dict
def stat_info_from_inventory(inventory):
stations_dict = {}
for network in inventory.networks:
for station in network.stations:
station_name = station.code
network_name = network_name.code
if not station_name in stations_dict.keys():
st_id = network_name + '.' + station_name
stations_dict[st_id] = {'latitude': station[0].latitude,
'longitude': station[0].longitude}
return stations_dict
read_stat = {'xml': stat_info_from_inventory,
'dless': stat_info_from_parser}
self.stations_dict = read_stat[self.metadata_type](self.metadata)
self.stations_dict = self.metadata.get_all_coordinates()
self.latmin = self.get_min_from_stations('latitude')
self.lonmin = self.get_min_from_stations('longitude')
self.latmax = self.get_max_from_stations('latitude')
@@ -195,13 +168,15 @@ class Array_map(QtGui.QWidget):
def init_picks(self):
def get_picks(station_dict):
picks = {}
# selected phase
phase = self.comboBox_phase.currentText()
for st_id in station_dict.keys():
try:
station_name = st_id.split('.')[-1]
# current_picks_dict: auto or manual
pick = self.current_picks_dict()[station_name][phase]
if pick['picker'] == 'auto':
if pick['weight'] > 3:
if not pick['spe']:
continue
picks[st_id] = pick['mpp']
except KeyError:
@@ -216,11 +191,12 @@ class Array_map(QtGui.QWidget):
for pick in picks.values():
if type(pick) is obspy.core.utcdatetime.UTCDateTime:
picks_utc.append(pick)
self._earliest_picktime = min(picks_utc)
for st_id, pick in picks.items():
if type(pick) is obspy.core.utcdatetime.UTCDateTime:
pick -= self._earliest_picktime
picks_rel[st_id] = pick
if picks_utc:
self._earliest_picktime = min(picks_utc)
for st_id, pick in picks.items():
if type(pick) is obspy.core.utcdatetime.UTCDateTime:
pick -= self._earliest_picktime
picks_rel[st_id] = pick
return picks_rel
self.picks = get_picks(self.stations_dict)
@@ -330,6 +306,8 @@ class Array_map(QtGui.QWidget):
def scatter_picked_stations(self):
picks, lats, lons = self.get_picks_lat_lon()
if len(lons) < 1 and len(lats) < 1:
return
# workaround because of an issue with latlon transformation of arrays with len <3
if len(lons) <= 2 and len(lats) <= 2:
self.sc_picked = self.basemap.scatter(lons[0], lats[0], s=50, facecolor='white',
@@ -374,13 +352,16 @@ class Array_map(QtGui.QWidget):
self.draw_everything()
def draw_everything(self):
if self.picks_dict or self.autopicks_dict:
picktype = self.comboBox_am.currentText()
if (self.picks_dict and picktype == 'manual') \
or (self.autopicks_dict and picktype == 'auto'):
self.init_picks()
if len(self.picks) >= 3:
self.init_picksgrid()
self.draw_contour_filled()
self.scatter_all_stations()
if self.picks_dict or self.autopicks_dict:
if (self.picks_dict and picktype == 'manual') \
or (self.autopicks_dict and picktype == 'auto'):
self.scatter_picked_stations()
self.cbar = self.add_cbar(label='Time relative to first onset ({}) [s]'.format(self._earliest_picktime))
self.comboBox_phase.setEnabled(True)

View File

@@ -21,6 +21,7 @@ class Metadata(object):
# saves filenames holding metadata for a seed_id
# seed id as key, path to file as value
self.seed_ids = {}
self.stations_dict = {}
if inventory:
if os.path.isdir(inventory):
self.add_inventory(inventory)
@@ -172,6 +173,37 @@ class Metadata(object):
return
return metadata['data'].get_coordinates(seed_id, time)
def get_all_coordinates(self):
def stat_info_from_parser(parser):
for station in parser.stations:
station_name = station[0].station_call_letters
network_name = station[0].network_code
if not station_name in self.stations_dict.keys():
st_id = network_name + '.' + station_name
self.stations_dict[st_id] = {'latitude': station[0].latitude,
'longitude': station[0].longitude}
def stat_info_from_inventory(inventory):
for network in inventory.networks:
for station in network.stations:
station_name = station.code
network_name = network_name.code
if not station_name in self.stations_dict.keys():
st_id = network_name + '.' + station_name
self.stations_dict[st_id] = {'latitude': station[0].latitude,
'longitude': station[0].longitude}
read_stat = {'xml': stat_info_from_inventory,
'dless': stat_info_from_parser}
self.read_all()
for item in self.inventory_files.values():
inventory = item['data']
invtype = item['invtype']
read_stat[invtype](inventory)
return self.stations_dict
def get_paz(self, seed_id, time):
"""

View File

@@ -145,6 +145,7 @@ class AddMetadataWidget(QWidget):
self.resize(600, 800)
self.metadata = metadata if metadata else Metadata()
self.from_metadata()
self.center()
self.show()
@@ -199,6 +200,9 @@ class AddMetadataWidget(QWidget):
self.close_button.setShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Escape))
self.main_layout.addWidget(self.close_button)
def from_metadata(self):
for inventory_path in self.metadata.inventories:
self.add_item(inventory_path, from_metadata=True)
def refresh_list(self):
self.clear_list()
@@ -223,10 +227,10 @@ class AddMetadataWidget(QWidget):
self.add_item(inventory_path)
self.selection_box.setText('')
def add_item(self, inventory_path):
def add_item(self, inventory_path, from_metadata=False):
if not inventory_path:
return
if inventory_path in self.metadata.inventories:
if inventory_path in self.inventories.keys():
QMessageBox.warning(self, 'Info', 'Path already in list!')
return
if not os.path.isdir(inventory_path):
@@ -237,7 +241,8 @@ class AddMetadataWidget(QWidget):
self.inventories[inventory_path] = item
self.list_model.appendRow(item)
self.metadata.add_inventory(inventory_path)
if not from_metadata:
self.metadata.add_inventory(inventory_path)
def remove_item(self):
for index in reversed(self.list_view.selectionModel().selectedIndexes()):