[updates] generate_array_maps multiprocessing, added extension '_autopylot' to picks generated by autopylot to prevent overwriting on auto-save

This commit is contained in:
Marcel Paffrath 2019-11-26 11:10:06 +01:00
parent 3be78ec576
commit be1e49fa57
3 changed files with 48 additions and 33 deletions

View File

@ -483,7 +483,7 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
saveEvtPath = eventpath saveEvtPath = eventpath
else: else:
saveEvtPath = savepath saveEvtPath = savepath
fnqml = '%s/PyLoT_%s' % (saveEvtPath, evID) fnqml = '%s/PyLoT_%s_autopylot' % (saveEvtPath, evID)
data.exportEvent(fnqml, fnext='.xml', fcheck=['auto', 'magnitude', 'origin']) data.exportEvent(fnqml, fnext='.xml', fcheck=['auto', 'magnitude', 'origin'])
if locflag == 1: if locflag == 1:
# HYPO71 # HYPO71

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os import os
import multiprocessing
from PyLoT import Project from PyLoT import Project
from pylot.core.util.dataprocessing import Metadata from pylot.core.util.dataprocessing import Metadata
@ -9,44 +10,58 @@ from pylot.core.util.array_map import Array_map
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
def main(project_file_path, manual=False, auto=True, file_format='png', f_ext=''): def main(project_file_path, manual=False, auto=True, file_format='png', f_ext='', ncores=None):
project = Project.load(project_file_path) project = Project.load(project_file_path)
nEvents = len(project.eventlist) nEvents = len(project.eventlist)
input_list = []
for index, event in enumerate(project.eventlist): for index, event in enumerate(project.eventlist):
eventdir = event.path
# MP MP TESTING +++ # MP MP TESTING +++
#if not eventdir.endswith('20170908_044946.a'): #if not eventdir.endswith('20170908_044946.a'):
# continue # continue
# MP MP ---- # MP MP ----
print('Working on event: {} ({}/{})'.format(eventdir, index + 1, nEvents)) kwargs = dict(event=event, nEvents=nEvents, index=index, manual=manual, auto=auto, file_format=file_format,
# check for picks f_ext=f_ext)
manualpicks = event.getPicks() input_list.append(kwargs)
autopicks = event.getAutopicks()
# prepare event and get metadata if ncores == 1:
metadata_path = os.path.join(eventdir, 'resp') for item in input_list:
metadata = Metadata(inventory=metadata_path, verbosity=0) array_map_worker(item)
for pick_type in ['manual', 'auto']: else:
if pick_type == 'manual' and (not manualpicks or not manual): pool = multiprocessing.Pool(ncores)
continue result = pool.map(array_map_worker, input_list)
if pick_type == 'auto' and (not autopicks or not auto): pool.close()
continue pool.join()
# create figure to plot on
fig = plt.figure(figsize=(16,9)) def array_map_worker(input_dict):
# create array map object event = input_dict['event']
map = Array_map(None, metadata, figure=fig, width=2.13e6, height=1.2e6, pointsize=15., linewidth=1.0) eventdir = event.path
# set combobox to auto/manual to plot correct pick type print('Working on event: {} ({}/{})'.format(eventdir, input_dict['index'] + 1, input_dict['nEvents']))
map.comboBox_am.setCurrentIndex(map.comboBox_am.findText(pick_type)) # check for picks
# add picks to map and save file manualpicks = event.getPicks()
map.refresh_drawings(manualpicks, autopicks) autopicks = event.getAutopicks()
fpath_out = os.path.join(eventdir, 'array_map_{}_{}{}.{}'.format(event.pylot_id, pick_type, f_ext, # prepare event and get metadata
file_format)) metadata_path = os.path.join(eventdir, 'resp')
fig.savefig(fpath_out, dpi=300.) metadata = Metadata(inventory=metadata_path, verbosity=0)
print('Wrote file: {}'.format(fpath_out)) for pick_type in ['manual', 'auto']:
if pick_type == 'manual' and (not manualpicks or not input_dict['manual']):
continue
if pick_type == 'auto' and (not autopicks or not input_dict['auto']):
continue
# create figure to plot on
fig = plt.figure(figsize=(16,9))
# create array map object
map = Array_map(None, metadata, figure=fig, width=2.13e6, height=1.2e6, pointsize=15., linewidth=1.0)
# set combobox to auto/manual to plot correct pick type
map.comboBox_am.setCurrentIndex(map.comboBox_am.findText(pick_type))
# add picks to map and save file
map.refresh_drawings(manualpicks, autopicks)
fpath_out = os.path.join(eventdir, 'array_map_{}_{}{}.{}'.format(event.pylot_id, pick_type, input_dict['f_ext'],
input_dict['file_format']))
fig.savefig(fpath_out, dpi=300.)
print('Wrote file: {}'.format(fpath_out))
if __name__ == '__main__': if __name__ == '__main__':
#main('/home/marcel/pylot_m7_mantle_correlated_ORIG_AUTOPYLOT.plp') #main('/home/marcel/pylot_m7_mantle_correlated.plp', f_ext='_0.5Hz')
#main('/home/marcel/test_project_obs_highf.plp', f_ext='_highf') main('/home/marcel/alparray_m7_mantle_correlated_v3.plp', f_ext='_correlated_0.5Hz')
#main('/home/marcel/test_project_obs_lowf.plp', f_ext='_lowf') #main('/home/marcel/alparray_m6.5-6.9_mantle_correlated_v3.plp', f_ext='_correlated_0.5Hz')
#main('/home/marcel/test_project_obs_hybrid.plp', f_ext='_hybrid')
main('/home/marcel/test_project_obs_uhf.plp', f_ext='_uhf')

View File

@ -3793,7 +3793,7 @@ class TuneAutopicker(QWidget):
'savexml': False, 'savexml': False,
'obspyDMT_wfpath': wfpath} 'obspyDMT_wfpath': wfpath}
event = self.get_current_event() event = self.get_current_event()
self.parent().saveData(event, event.path, '.xml') #self.parent().saveData(event, event.path, '.xml') MP MP uncommented because overwriting pick files in tune mode
for key in self.fig_dict.keys(): for key in self.fig_dict.keys():
if not key == 'plot_style': if not key == 'plot_style':
self.fig_dict[key].clear() self.fig_dict[key].clear()