diff --git a/PyLoT.py b/PyLoT.py index f972c73a..7e6160ff 100755 --- a/PyLoT.py +++ b/PyLoT.py @@ -200,7 +200,7 @@ class MainWindow(QMainWindow): settings.setValue('useGuiFilter', False) if settings.value('output/Format', None) is None: outformat = QInputDialog.getText(self, - "Enter output format (*.xml, *.cnv, *.obs, *.focmec):", + "Enter output format (*.xml, *.cnv, *.obs, *.focmec, *.pha):", "Format") settings.setValue("output/Format", outformat) if settings.value('autoFilter', None) is None: @@ -1481,7 +1481,7 @@ class MainWindow(QMainWindow): self.set_fname(self.get_data().getEventFileName(), type) return self.get_fnames(type) - def saveData(self, event=None, directory=None, outformats=['.xml', '.cnv', '.obs', '.focmec']): + def saveData(self, event=None, directory=None, outformats=['.xml', '.cnv', '.obs', '.focmec', '.pha']): ''' Save event data to directory with specified output formats. :param event: PyLoT Event, if not set current event will be used diff --git a/pylot/core/io/data.py b/pylot/core/io/data.py index b472ad8c..76f5e0c6 100644 --- a/pylot/core/io/data.py +++ b/pylot/core/io/data.py @@ -12,6 +12,7 @@ from PySide.QtGui import QMessageBox import pylot.core.loc.velest as velest import pylot.core.loc.focmec as focmec +import pylot.core.loc.hypodd as hypodd from pylot.core.io.phases import readPILOTEvent, picks_from_picksdict, \ picksdict_from_pilot, merge_picks, PylotParameter from pylot.core.util.errors import FormatError, OverwriteError @@ -232,22 +233,27 @@ class Data(object): picks = event.picks # remove existing picks for j, pick in reversed(list(enumerate(picks))): - if picktype in str(pick.method_id.id): - picks.pop(j) - checkflag = 1 + try: + if picktype in str(pick.method_id.id): + picks.pop(j) + checkflag = 1 + except AttributeError as e: + msg = '{}'.format(e) + print(e) + checkflag = 0 if checkflag: print("Found %s pick(s), remove them and append new picks to catalog." % picktype) - # append new picks - for pick in self.get_evt_data().picks: - if picktype in str(pick.method_id.id): - picks.append(pick) + # append new picks + for pick in self.get_evt_data().picks: + if picktype in str(pick.method_id.id): + picks.append(pick) def exportEvent(self, fnout, fnext='.xml', fcheck='auto', upperErrors=None): """ Export event to file :param fnout: basename of file - :param fnext: file extension, xml, cnv, obs, focmec + :param fnext: file extensions xml, cnv, obs, focmec, or/and pha :param fcheck: check and delete existing information can be a str or a list of strings of ['manual', 'auto', 'origin', 'magnitude'] """ @@ -369,6 +375,15 @@ class Data(object): except KeyError as e: raise KeyError('''{0} export format not implemented: {1}'''.format(evtformat, e)) + if fnext == '.pha': + try: + infile = os.path.join(os.path.expanduser('~'), '.pylot', 'pylot.in') + print('Using default input file {}'.format(infile)) + parameter = PylotParameter(infile) + hypodd.export(picks_copy, fnout + fnext, parameter, eventinfo=self.get_evt_data()) + except KeyError as e: + raise KeyError('''{0} export format + not implemented: {1}'''.format(evtformat, e)) def getComp(self): """ diff --git a/pylot/core/io/phases.py b/pylot/core/io/phases.py index d2735ad5..f657bea4 100644 --- a/pylot/core/io/phases.py +++ b/pylot/core/io/phases.py @@ -291,7 +291,6 @@ def picksdict_from_picks(evt): phase['filter_id'] = filter_id if filter_id is not None else '' onsets[pick.phase_hint] = phase.copy() - #picksdict[picker][station] = onsets.copy() picksdict[station] = onsets.copy() return picksdict @@ -757,7 +756,7 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None): fid.write('%-4sS%d%6.2f\n' % (stat, Sweight, Srt)) fid.close() - elif fformat == 'hypoDD': + elif fformat == 'HYPODD': print("Writing phases to %s for hypoDD" % filename) fid = open("%s" % filename, 'w') # get event information needed for hypoDD-phase file @@ -770,6 +769,12 @@ def writephases(arrivals, fformat, filename, parameter=None, eventinfo=None): stime.year, stime.month, stime.day, stime.hour, stime.minute, stime.second, eventsource['latitude'], eventsource['longitude'], eventsource['depth'] / 1000, eventinfo.magnitudes[0]['mag'], eventsource['quality']['standard_error'], hddID)) + # check whether arrivals are dictionaries (autoPyLoT) or pick object (PyLoT) + if isinstance(arrivals, dict) == False: + # convert pick object (PyLoT) into dictionary + evt = ope.Event(resource_id=eventinfo['resource_id']) + evt.picks = arrivals + arrivals = picksdict_from_picks(evt) for key in arrivals: if arrivals[key].has_key('P'): # P onsets diff --git a/pylot/core/loc/hypodd.py b/pylot/core/loc/hypodd.py index 1280ad99..c194ed90 100644 --- a/pylot/core/loc/hypodd.py +++ b/pylot/core/loc/hypodd.py @@ -25,4 +25,4 @@ def export(picks, fnout, parameter, eventinfo): :type eventinfo: list object ''' # write phases to hypoDD-phase file - writephases(picks, 'hypoDD', fnout, parameter, eventinfo) + writephases(picks, 'HYPODD', fnout, parameter, eventinfo) diff --git a/pylot/core/util/defaults.py b/pylot/core/util/defaults.py index 457b0bcd..ce195b23 100644 --- a/pylot/core/util/defaults.py +++ b/pylot/core/util/defaults.py @@ -37,6 +37,7 @@ TIMEERROR_DEFAULTS = os.path.join(os.path.expanduser('~'), OUTPUTFORMATS = {'.xml': 'QUAKEML', '.cnv': 'CNV', '.obs': 'NLLOC_OBS', - '.focmec': 'FOCMEC'} + '.focmec': 'FOCMEC', + '.pha': 'HYPODD'} LOCTOOLS = dict(nll=nll, hyposat=hyposat, velest=velest, hypo71=hypo71, hypodd=hypodd)