WIP: Simplify data structure #39

Draft
sebastianw wants to merge 31 commits from 38-simplify-data-structure into develop
4 changed files with 28 additions and 38 deletions
Showing only changes of commit db976e5ea9 - Show all commits

View File

@ -25,6 +25,7 @@ https://www.iconfinder.com/iconsets/flavour
import argparse import argparse
import json import json
import logging
import os import os
import platform import platform
import shutil import shutil
@ -113,11 +114,7 @@ class MainWindow(QMainWindow):
def __init__(self, parent=None, infile=None, reset_qsettings=False): def __init__(self, parent=None, infile=None, reset_qsettings=False):
super(MainWindow, self).__init__(parent) super(MainWindow, self).__init__(parent)
# check for default pylot.in-file if infile and os.path.isfile(infile) is False:
if not infile:
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
print('Using default input file {}'.format(infile))
if os.path.isfile(infile) is False:
infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file')[0] infile = QFileDialog().getOpenFileName(caption='Choose PyLoT-input file')[0]
if not os.path.exists(infile): if not os.path.exists(infile):
@ -253,7 +250,7 @@ class MainWindow(QMainWindow):
self._inputs.reset_defaults() self._inputs.reset_defaults()
# check for default pylot.in-file # check for default pylot.in-file
infile = os.path.join(pylot_config_dir, '.pylot.in') infile = os.path.join(pylot_config_dir, '.pylot.in')
print('Using default input file {}'.format(infile)) logging.warning('Using default input file {}'.format(infile))
self._inputs.export2File(infile) self._inputs.export2File(infile)
self.infile = infile self.infile = infile

View File

@ -119,13 +119,9 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
obspyDMT_wfpath = input_dict['obspyDMT_wfpath'] obspyDMT_wfpath = input_dict['obspyDMT_wfpath']
if not parameter: if not parameter:
if inputfile: if not inputfile:
parameter = PylotParameter(inputfile) print('Using default input parameter')
# iplot = parameter['iplot'] parameter = PylotParameter(inputfile)
else:
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in')
print('Using default input file {}'.format(infile))
parameter = PylotParameter(infile)
else: else:
if not type(parameter) == PylotParameter: if not type(parameter) == PylotParameter:
print('Wrong input type for parameter: {}'.format(type(parameter))) print('Wrong input type for parameter: {}'.format(type(parameter)))

View File

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import copy import copy
import logging
import os import os
from PySide2.QtWidgets import QMessageBox from PySide2.QtWidgets import QMessageBox
@ -408,18 +409,16 @@ class Data(object):
not implemented: {1}'''.format(evtformat, e)) not implemented: {1}'''.format(evtformat, e))
if fnext == '_focmec.in': if fnext == '_focmec.in':
try: try:
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in') parameter = PylotParameter()
print('Using default input file {}'.format(infile)) logging.warning('Using default input parameter')
parameter = PylotParameter(infile)
focmec.export(picks_copy, fnout + fnext, parameter, eventinfo=self.get_evt_data()) focmec.export(picks_copy, fnout + fnext, parameter, eventinfo=self.get_evt_data())
except KeyError as e: except KeyError as e:
raise KeyError('''{0} export format raise KeyError('''{0} export format
not implemented: {1}'''.format(evtformat, e)) not implemented: {1}'''.format(evtformat, e))
if fnext == '.pha': if fnext == '.pha':
try: try:
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in') parameter = PylotParameter()
print('Using default input file {}'.format(infile)) logging.warning('Using default input parameter')
parameter = PylotParameter(infile)
hypodd.export(picks_copy, fnout + fnext, parameter, eventinfo=self.get_evt_data()) hypodd.export(picks_copy, fnout + fnext, parameter, eventinfo=self.get_evt_data())
except KeyError as e: except KeyError as e:
raise KeyError('''{0} export format raise KeyError('''{0} export format

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import glob import glob
import logging
import os import os
import warnings import warnings
@ -217,7 +218,7 @@ def picksdict_from_obs(fn):
return picks return picks
def picksdict_from_picks(evt): def picksdict_from_picks(evt, parameter=None):
""" """
Takes an Event object and return the pick dictionary commonly used within Takes an Event object and return the pick dictionary commonly used within
PyLoT PyLoT
@ -230,6 +231,7 @@ def picksdict_from_picks(evt):
'auto': {} 'auto': {}
} }
for pick in evt.picks: for pick in evt.picks:
errors = None
phase = {} phase = {}
station = pick.waveform_id.station_code station = pick.waveform_id.station_code
if pick.waveform_id.channel_code is None: if pick.waveform_id.channel_code is None:
@ -273,32 +275,28 @@ def picksdict_from_picks(evt):
phase['epp'] = epp phase['epp'] = epp
phase['lpp'] = lpp phase['lpp'] = lpp
phase['spe'] = spe phase['spe'] = spe
try: weight = phase.get('weight')
phase['weight'] = weight if not weight:
except: if not parameter:
# get onset weight from uncertainty logging.warning('Using ')
infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in') logging.warning('Using default input parameter')
print('Using default input file {}'.format(infile)) parameter = PylotParameter()
parameter = PylotParameter(infile)
pick.phase_hint = identifyPhase(pick.phase_hint) pick.phase_hint = identifyPhase(pick.phase_hint)
if pick.phase_hint == 'P': if pick.phase_hint == 'P':
errors = parameter['timeerrorsP'] errors = parameter['timeerrorsP']
elif pick.phase_hint == 'S': elif pick.phase_hint == 'S':
errors = parameter['timeerrorsS'] errors = parameter['timeerrorsS']
weight = get_quality_class(spe, errors) if errors:
phase['weight'] = weight weight = get_quality_class(spe, errors)
phase['weight'] = weight
phase['channel'] = channel phase['channel'] = channel
phase['network'] = network phase['network'] = network
phase['picker'] = pick_method phase['picker'] = pick_method
try: if pick.polarity == 'positive':
if pick.polarity == 'positive': phase['fm'] = 'U'
phase['fm'] = 'U' elif pick.polarity == 'negative':
elif pick.polarity == 'negative': phase['fm'] = 'D'
phase['fm'] = 'D' else:
else:
phase['fm'] = 'N'
except:
print("No FM info available!")
phase['fm'] = 'N' phase['fm'] = 'N'
phase['filter_id'] = filter_id if filter_id is not None else '' phase['filter_id'] = filter_id if filter_id is not None else ''