Merge branch 'feature/metadata_clean_inventory' into develop

This commit is contained in:
Marcel Paffrath 2019-08-12 16:39:12 +02:00
commit 15882ed27e
3 changed files with 19 additions and 3 deletions

View File

@ -2039,10 +2039,11 @@ class MainWindow(QMainWindow):
self.update_obspy_dmt()
def update_obspy_dmt(self):
self.metadata.clear_inventory()
if self.obspy_dmt:
invpath = os.path.join(self.get_current_event_path(), 'resp')
if not invpath in self.metadata.inventories:
self.metadata.add_inventory(invpath)
self.metadata.add_inventory(invpath, obspy_dmt_inv = True)
# check if directory is empty
if os.listdir(invpath):
self.init_map_button.setEnabled(True)
@ -3527,6 +3528,7 @@ class MainWindow(QMainWindow):
'''
Save back project to new pickle file.
'''
self.metadata.clear_inventory()
dlg = QFileDialog(self)
fnm = dlg.getSaveFileName(self, 'Create a new project file...', filter='Pylot project (*.plp)')
filename = fnm[0]
@ -3541,6 +3543,7 @@ class MainWindow(QMainWindow):
self.saveProjectAsAction.setEnabled(True)
self.update_status('Saved new project to {}'.format(filename), duration=5000)
self.add2recentProjects(filename)
self.update_obspy_dmt()
return True
def saveProject(self, new=False):
@ -3553,9 +3556,11 @@ class MainWindow(QMainWindow):
self.setDirty(True)
return False
else:
self.metadata.clear_inventory()
self.project.parameter = self._inputs
self.exportEvents()
self.project.save()
self.update_obspy_dmt()
if not self.project.dirty:
self.setDirty(False)
self.update_status('Saved back project to file:\n{}'.format(self.project.location), duration=5000)

View File

@ -22,6 +22,8 @@ class Metadata(object):
# seed id as key, path to file as value
self.seed_ids = {}
self.stations_dict = {}
# saves which metadata files are from obspy dmt
self.obspy_dmt_invs = []
if inventory:
if os.path.isdir(inventory):
self.add_inventory(inventory)
@ -44,7 +46,7 @@ class Metadata(object):
def __repr__(self):
return self.__str__()
def add_inventory(self, path_to_inventory):
def add_inventory(self, path_to_inventory, obspy_dmt_inv = False):
"""
Add path to list of inventories.
:param path_to_inventory: Path to a folder
@ -54,6 +56,8 @@ class Metadata(object):
assert (os.path.isdir(path_to_inventory)), '{} is no directory'.format(path_to_inventory)
if path_to_inventory not in self.inventories:
self.inventories.append(path_to_inventory)
if obspy_dmt_inv == True:
self.obspy_dmt_invs.append(path_to_inventory)
def add_inventory_file(self, path_to_inventory_file):
"""
@ -89,6 +93,11 @@ class Metadata(object):
# this will be rebuilt for the next init of the arraymap anyway, so just reset it
self.stations_dict = {}
def clear_inventory(self):
for inv in self.obspy_dmt_invs:
self.remove_inventory(inv)
self.obspy_dmt_invs = []
def get_metadata(self, seed_id, time=None):
"""
Get metadata for seed id at time. When time is not specified, metadata for current time is fetched.

View File

@ -206,7 +206,7 @@ class AddMetadataWidget(QWidget):
def init_add_remove_buttons(self):
self.add_remove_layout = QVBoxLayout()
self.add_button = self.init_button("Add", Qt.Key_Insert, "Choose a file to add \n(Ins)")
self.remove_button = self.init_button("Remove", Qt.Key_Delete, "Remove selected file \n(Del)")
self.remove_button = self.init_button("Remove", Qt.Key_Delete, "Remove selected file(s) \n(Del)")
self.add_remove_layout.addWidget(self.add_button, 0, QtCore.Qt.AlignBottom)
self.add_remove_layout.addWidget(self.remove_button, 0, QtCore.Qt.AlignTop)
self.list_buttons_layout.insertLayout(1, self.add_remove_layout, 0)
@ -252,6 +252,8 @@ class AddMetadataWidget(QWidget):
for inventory_path in self.metadata.inventories:
item = QtGui.QStandardItem(inventory_path)
self.list_model.appendRow(item)
if inventory_path in self.metadata.obspy_dmt_invs:
item.setFlags(Qt.NoItemFlags)
def directory_to_lineedit(self):
inventory_path = self.open_directory()