[change] changed some functions to work with Python 3 and Windows

This commit is contained in:
Marcel Paffrath 2017-07-13 17:27:48 +02:00
parent ac25f9cacb
commit f57aa37d99
11 changed files with 47 additions and 35 deletions

View File

@ -2575,7 +2575,7 @@ class Project(object):
self.setDirty() self.setDirty()
else: else:
print('Skipping event with path {}. Already part of project.'.format(event.path)) print('Skipping event with path {}. Already part of project.'.format(event.path))
self.search_eventfile_info() #self.search_eventfile_info()
def read_eventfile_info(self, filename, separator=','): def read_eventfile_info(self, filename, separator=','):
''' '''

View File

@ -369,18 +369,18 @@ def autoPyLoT(input_dict=None, parameter=None, inputfile=None, fnames=None, even
# HYPOSAT # HYPOSAT
hyposatfile = '%s/PyLoT_%s_HYPOSAT_phases' % (event, evID) hyposatfile = '%s/PyLoT_%s_HYPOSAT_phases' % (event, evID)
hyposat.export(picks, hyposatfile, parameter) hyposat.export(picks, hyposatfile, parameter)
# VELEST # VELEST
velestfile = '%s/PyLoT_%s_VELEST_phases.cnv' % (event, evID) velestfile = '%s/PyLoT_%s_VELEST_phases.cnv' % (event, evID)
velest.export(picks, velestfile, parameter, evt) velest.export(picks, velestfile, parameter, evt)
# hypoDD # hypoDD
hypoddfile = '%s/PyLoT_%s_hypoDD_phases.pha' % (event, evID) hypoddfile = '%s/PyLoT_%s_hypoDD_phases.pha' % (event, evID)
hypodd.export(picks, hypoddfile, parameter, evt) hypodd.export(picks, hypoddfile, parameter, evt)
# FOCMEC # FOCMEC
focmecfile = '%s/PyLoT_%s_FOCMEC.in' % (event, evID) focmecfile = '%s/PyLoT_%s_FOCMEC.in' % (event, evID)
focmec.export(picks, focmecfile, parameter, evt) focmec.export(picks, focmecfile, parameter, evt)
# HASH # HASH
hashfile = '%s/PyLoT_%s_HASH' % (event, evID) hashfile = '%s/PyLoT_%s_HASH' % (event, evID)
hash.export(picks, hashfile, parameter, evt) hash.export(picks, hashfile, parameter, evt)
endsplash = '''------------------------------------------\n' endsplash = '''------------------------------------------\n'
-----Finished event %s!-----\n' -----Finished event %s!-----\n'

View File

@ -6,9 +6,9 @@
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
from PySide import QtCore from PyQt4 import QtCore
qt_resource_data = "\ qt_resource_data = b"\
\x00\x00\x9e\x04\ \x00\x00\x9e\x04\
\x89\ \x89\
\x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\ \x50\x4e\x47\x0d\x0a\x1a\x0a\x00\x00\x00\x0d\x49\x48\x44\x52\x00\
@ -97831,7 +97831,7 @@ qt_resource_data = "\
\x3c\x2f\x68\x74\x6d\x6c\x3e\x0a\ \x3c\x2f\x68\x74\x6d\x6c\x3e\x0a\
" "
qt_resource_name = "\ qt_resource_name = b"\
\x00\x04\ \x00\x04\
\x00\x06\xec\x30\ \x00\x06\xec\x30\
\x00\x68\ \x00\x68\
@ -98033,7 +98033,7 @@ qt_resource_name = "\
\x00\x6e\x00\x64\x00\x65\x00\x78\x00\x2e\x00\x68\x00\x74\x00\x6d\x00\x6c\ \x00\x6e\x00\x64\x00\x65\x00\x78\x00\x2e\x00\x68\x00\x74\x00\x6d\x00\x6c\
" "
qt_resource_struct = "\ qt_resource_struct = b"\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x01\ \x00\x00\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00\x01\
\x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x32\ \x00\x00\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x32\
\x00\x00\x00\x0e\x00\x02\x00\x00\x00\x2d\x00\x00\x00\x05\ \x00\x00\x00\x0e\x00\x02\x00\x00\x00\x2d\x00\x00\x00\x05\

View File

@ -39,7 +39,7 @@ class Data(object):
elif isinstance(evtdata, dict): elif isinstance(evtdata, dict):
evt = readPILOTEvent(**evtdata) evt = readPILOTEvent(**evtdata)
evtdata = evt evtdata = evt
elif isinstance(evtdata, basestring): elif isinstance(evtdata, str):
try: try:
cat = read_events(evtdata) cat = read_events(evtdata)
if len(cat) is not 1: if len(cat) is not 1:

View File

@ -2,7 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from pylot.core.util.errors import ParameterError from pylot.core.util.errors import ParameterError
import default_parameters from pylot.core.io import default_parameters
class PylotParameter(object): class PylotParameter(object):
''' '''

View File

@ -307,7 +307,7 @@ class HOScf(CharacteristicFunction):
class ARZcf(CharacteristicFunction): class ARZcf(CharacteristicFunction):
def calcCF(self, data): def calcCF(self, data):
print 'Calculating AR-prediction error from single trace ...' print('Calculating AR-prediction error from single trace ...')
x = self.getDataArray(self.getCut()) x = self.getDataArray(self.getCut())
xnp = x[0].data xnp = x[0].data
nn = np.isnan(xnp) nn = np.isnan(xnp)
@ -430,7 +430,7 @@ class ARZcf(CharacteristicFunction):
class ARHcf(CharacteristicFunction): class ARHcf(CharacteristicFunction):
def calcCF(self, data): def calcCF(self, data):
print 'Calculating AR-prediction error from both horizontal traces ...' print('Calculating AR-prediction error from both horizontal traces ...')
xnp = self.getDataArray(self.getCut()) xnp = self.getDataArray(self.getCut())
n0 = np.isnan(xnp[0].data) n0 = np.isnan(xnp[0].data)
@ -567,7 +567,7 @@ class ARHcf(CharacteristicFunction):
class AR3Ccf(CharacteristicFunction): class AR3Ccf(CharacteristicFunction):
def calcCF(self, data): def calcCF(self, data):
print 'Calculating AR-prediction error from all 3 components ...' print('Calculating AR-prediction error from all 3 components ...')
xnp = self.getDataArray(self.getCut()) xnp = self.getDataArray(self.getCut())
n0 = np.isnan(xnp[0].data) n0 = np.isnan(xnp[0].data)

View File

@ -480,7 +480,7 @@ def main():
Insheim = PDFstatistics(root_dir) Insheim = PDFstatistics(root_dir)
Insheim.curphase = 'p' Insheim.curphase = 'p'
qdlist = Insheim.get('qdf', 0.2) qdlist = Insheim.get('qdf', 0.2)
print qdlist print(qdlist)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,13 +1,16 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import urllib2 try:
from urllib2 import urlopen
except:
from urllib.request import urlopen
def checkurl(url='https://ariadne.geophysik.rub.de/trac/PyLoT'): def checkurl(url='https://ariadne.geophysik.rub.de/trac/PyLoT'):
try: try:
urllib2.urlopen(url, timeout=1) urlopen(url, timeout=1)
return True return True
except urllib2.URLError: except:
pass pass
return False return False

View File

@ -59,7 +59,7 @@ def exp_parameter(te, tm, tl, eta):
return tm, sig1, sig2, a return tm, sig1, sig2, a
def gauss_branches(k, (mu, sig1, sig2, a1, a2)): def gauss_branches(k, param_tuple):
''' '''
function gauss_branches takes an axes x, a center value mu, two sigma function gauss_branches takes an axes x, a center value mu, two sigma
values sig1 and sig2 and two scaling factors a1 and a2 and return a values sig1 and sig2 and two scaling factors a1 and a2 and return a
@ -79,6 +79,9 @@ def gauss_branches(k, (mu, sig1, sig2, a1, a2)):
:returns fun_vals: list with function values along axes x :returns fun_vals: list with function values along axes x
''' '''
#python 3 workaround
mu, sig1, sig2, a1, a2 = param_tuple
def _func(k, mu, sig1, sig2, a1, a2): def _func(k, mu, sig1, sig2, a1, a2):
if k < mu: if k < mu:
rval = a1 * 1 / (np.sqrt(2 * np.pi) * sig1) * np.exp(-((k - mu) / sig1) ** 2 / 2) rval = a1 * 1 / (np.sqrt(2 * np.pi) * sig1) * np.exp(-((k - mu) / sig1) ** 2 / 2)
@ -93,7 +96,7 @@ def gauss_branches(k, (mu, sig1, sig2, a1, a2)):
return _func(k, mu, sig1, sig2, a1, a2) return _func(k, mu, sig1, sig2, a1, a2)
def exp_branches(k, (mu, sig1, sig2, a)): def exp_branches(k, param_tuple):
''' '''
function exp_branches takes an axes x, a center value mu, two sigma function exp_branches takes an axes x, a center value mu, two sigma
values sig1 and sig2 and a scaling factor a and return a values sig1 and sig2 and a scaling factor a and return a
@ -107,6 +110,9 @@ def exp_branches(k, (mu, sig1, sig2, a)):
:returns fun_vals: list with function values along axes x: :returns fun_vals: list with function values along axes x:
''' '''
#python 3 workaround
mu, sig1, sig2, a = param_tuple
def _func(k, mu, sig1, sig2, a): def _func(k, mu, sig1, sig2, a):
mu = float(mu) mu = float(mu)
if k < mu: if k < mu:

View File

@ -5,7 +5,10 @@ import hashlib
import numpy as np import numpy as np
from scipy.interpolate import splrep, splev from scipy.interpolate import splrep, splev
import os import os
import pwd try:
import pwd
except:
print('Warning: Could not import module pwd')
import re import re
import warnings import warnings
import subprocess import subprocess
@ -258,7 +261,7 @@ def getLogin():
returns the actual user's login ID returns the actual user's login ID
:return: login ID :return: login ID
''' '''
return pwd.getpwuid(os.getuid())[0] return os.getlogin()
def getOwner(fn): def getOwner(fn):

View File

@ -70,9 +70,9 @@ def plot_pdf(_axes, x, y, annotation, bbox_props, xlabel=None, ylabel=None,
title=None): title=None):
# try method or data # try method or data
try: try:
_axes.plot(x, y()) # y provided as method _axes.plot(x, y()) # y provided as method
except: except:
_axes.plot(x, y) # y provided as data _axes.plot(x, y) # y provided as data
if title: if title:
_axes.set_title(title) _axes.set_title(title)
@ -513,7 +513,7 @@ class WaveformWidgetPG(QtGui.QWidget):
stime = trace.stats.starttime - wfstart stime = trace.stats.starttime - wfstart
time_ax = prepTimeAxis(stime, trace) time_ax = prepTimeAxis(stime, trace)
if time_ax is not None: if time_ax is not None:
if not scaleddata: if not scaleddata:
trace.detrend('constant') trace.detrend('constant')
trace.normalize(np.max(np.abs(trace.data)) * 2) trace.normalize(np.max(np.abs(trace.data)) * 2)
times = [time for index, time in enumerate(time_ax) if not index%nth_sample] times = [time for index, time in enumerate(time_ax) if not index%nth_sample]
@ -653,7 +653,7 @@ class WaveformWidget(FigureCanvas):
stime = trace.stats.starttime - wfstart stime = trace.stats.starttime - wfstart
time_ax = prepTimeAxis(stime, trace) time_ax = prepTimeAxis(stime, trace)
if time_ax is not None: if time_ax is not None:
if not scaleddata: if not scaleddata:
trace.detrend('constant') trace.detrend('constant')
trace.normalize(np.max(np.abs(trace.data)) * 2) trace.normalize(np.max(np.abs(trace.data)) * 2)
times = [time for index, time in enumerate(time_ax) if not index%nth_sample] times = [time for index, time in enumerate(time_ax) if not index%nth_sample]
@ -865,7 +865,7 @@ class PickDlg(QDialog):
tip='Delete current picks.') tip='Delete current picks.')
# create other widget elements # create other widget elements
phaseitems = [None] + FILTERDEFAULTS.keys() phaseitems = [None] + list(FILTERDEFAULTS.keys())
# create buttons for P and S filter and picking # create buttons for P and S filter and picking
self.p_button = QPushButton('P', self) self.p_button = QPushButton('P', self)