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

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

View File

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

View File

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

View File

@@ -307,7 +307,7 @@ class HOScf(CharacteristicFunction):
class ARZcf(CharacteristicFunction):
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())
xnp = x[0].data
nn = np.isnan(xnp)
@@ -430,7 +430,7 @@ class ARZcf(CharacteristicFunction):
class ARHcf(CharacteristicFunction):
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())
n0 = np.isnan(xnp[0].data)
@@ -567,7 +567,7 @@ class ARHcf(CharacteristicFunction):
class AR3Ccf(CharacteristicFunction):
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())
n0 = np.isnan(xnp[0].data)

View File

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

View File

@@ -1,13 +1,16 @@
#!/usr/bin/env python
# -*- 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'):
try:
urllib2.urlopen(url, timeout=1)
urlopen(url, timeout=1)
return True
except urllib2.URLError:
except:
pass
return False

View File

@@ -59,7 +59,7 @@ def exp_parameter(te, tm, tl, eta):
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
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
'''
#python 3 workaround
mu, sig1, sig2, a1, a2 = param_tuple
def _func(k, mu, sig1, sig2, a1, a2):
if k < mu:
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)
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
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:
'''
#python 3 workaround
mu, sig1, sig2, a = param_tuple
def _func(k, mu, sig1, sig2, a):
mu = float(mu)
if k < mu:

View File

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

View File

@@ -70,9 +70,9 @@ def plot_pdf(_axes, x, y, annotation, bbox_props, xlabel=None, ylabel=None,
title=None):
# try method or data
try:
_axes.plot(x, y()) # y provided as method
_axes.plot(x, y()) # y provided as method
except:
_axes.plot(x, y) # y provided as data
_axes.plot(x, y) # y provided as data
if title:
_axes.set_title(title)
@@ -513,7 +513,7 @@ class WaveformWidgetPG(QtGui.QWidget):
stime = trace.stats.starttime - wfstart
time_ax = prepTimeAxis(stime, trace)
if time_ax is not None:
if not scaleddata:
if not scaleddata:
trace.detrend('constant')
trace.normalize(np.max(np.abs(trace.data)) * 2)
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
time_ax = prepTimeAxis(stime, trace)
if time_ax is not None:
if not scaleddata:
if not scaleddata:
trace.detrend('constant')
trace.normalize(np.max(np.abs(trace.data)) * 2)
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.')
# create other widget elements
phaseitems = [None] + FILTERDEFAULTS.keys()
phaseitems = [None] + list(FILTERDEFAULTS.keys())
# create buttons for P and S filter and picking
self.p_button = QPushButton('P', self)