[refactor] automatic code reformatting (Pycharm)

This commit is contained in:
marcel committed 2022-03-09 14:41:34 +01:00
1 parent 79f3d40714
commit e35d5d6df9
34 files changed
+818 -501

No files matched your search

+12 -16
View File
@@ -1,27 +1,22 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import matplotlib
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import Qt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.patheffects as PathEffects
import traceback
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.feature as cf
from cartopy.mpl.gridliner import LongitudeFormatter, LatitudeFormatter
import traceback
import obspy
import matplotlib
import matplotlib.patheffects as PathEffects
import matplotlib.pyplot as plt
import numpy as np
import obspy
from PySide2 import QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from mpl_toolkits.axes_grid1.inset_locator import inset_axes
from scipy.interpolate import griddata
from pylot.core.util.widgets import PickDlg
from pylot.core.pick.utils import get_quality_class
from pylot.core.util.widgets import PickDlg
matplotlib.use('Qt5Agg')
@@ -173,7 +168,8 @@ class Array_map(QtWidgets.QWidget):
self.canvas.fig.tight_layout()
def add_merid_paral(self):
self.gridlines = self.canvas.axes.gridlines(draw_labels=False, alpha=0.6, color='gray', linewidth=self.linewidth/2, zorder=7)
self.gridlines = self.canvas.axes.gridlines(draw_labels=False, alpha=0.6, color='gray',
linewidth=self.linewidth / 2, zorder=7)
# TODO: current cartopy version does not support label removal. Devs are working on it.
# Should be fixed in coming cartopy versions
# self.gridlines.xformatter = LONGITUDE_FORMATTER
@@ -513,7 +509,7 @@ class Array_map(QtWidgets.QWidget):
levels = np.linspace(self.get_min_from_picks(), self.get_max_from_picks(), nlevel)
self.contourf = self.canvas.axes.contourf(self.longrid, self.latgrid, self.picksgrid_active, levels,
linewidths=self.linewidth*5, transform=ccrs.PlateCarree(),
linewidths=self.linewidth * 5, transform=ccrs.PlateCarree(),
alpha=0.4, zorder=8, cmap=self.get_colormap())
def get_colormap(self):
+5 -2
View File
@@ -2,9 +2,10 @@
# -*- coding: utf-8 -*-
import glob
import numpy as np
import os
import sys
import numpy as np
from obspy import UTCDateTime, read_inventory, read
from obspy.io.xseed import Parser
@@ -46,7 +47,7 @@ class Metadata(object):
def __repr__(self):
return self.__str__()
def add_inventory(self, path_to_inventory, obspy_dmt_inv = False):
def add_inventory(self, path_to_inventory, obspy_dmt_inv=False):
"""
Add path to list of inventories.
:param path_to_inventory: Path to a folder
@@ -211,6 +212,7 @@ class Metadata(object):
self.stations_dict[st_id] = {'latitude': station[0].latitude,
'longitude': station[0].longitude,
'elevation': station[0].elevation}
read_stat = {'xml': stat_info_from_inventory,
'dless': stat_info_from_parser}
@@ -380,6 +382,7 @@ def check_time(datetime):
except ValueError:
return False
# TODO: change root to datapath
def get_file_list(root_dir):
"""
+1
View File
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import os
from obspy import UTCDateTime
from obspy.core.event import Event as ObsPyEvent
from obspy.core.event import Origin, ResourceIdentifier
+4 -2
View File
@@ -3,6 +3,7 @@
# small script that creates array maps for each event within a previously generated PyLoT project
import os
num_thread = "16"
os.environ["OMP_NUM_THREADS"] = num_thread
os.environ["OPENBLAS_NUM_THREADS"] = num_thread
@@ -15,6 +16,7 @@ import multiprocessing
import sys
import glob
import matplotlib
matplotlib.use('Qt5Agg')
sys.path.append(os.path.join('/'.join(sys.argv[0].split('/')[:-1]), '../../..'))
@@ -52,7 +54,8 @@ def array_map_worker(input_dict):
print('Working on event: {} ({}/{})'.format(eventdir, input_dict['index'] + 1, input_dict['nEvents']))
xml_picks = glob.glob(os.path.join(eventdir, f'*{input_dict["f_ext"]}.xml'))
if not len(xml_picks):
print('Event {} does not have any picks associated with event file extension {}'. format(eventdir, input_dict['f_ext']))
print('Event {} does not have any picks associated with event file extension {}'.format(eventdir,
input_dict['f_ext']))
return
# check for picks
manualpicks = event.getPicks()
@@ -92,4 +95,3 @@ if __name__ == '__main__':
for infile in args.infiles:
main(os.path.join(args.dataroot, infile), f_ext='_correlated_0.03-0.1', ncores=args.ncores)
+2 -4
View File
@@ -11,7 +11,6 @@ try:
except Exception as e:
print('Warning: Could not import module QtCore.')
from pylot.core.util.utils import pick_color
@@ -53,7 +52,7 @@ def which(program, parameter):
settings = QSettings()
for key in settings.allKeys():
if 'binPath' in key:
os.environ['PATH'] += ':{0}'.format(settings.value(key))
os.environ['PATH'] += ':{0}'.format(settings.value(key))
nllocpath = ":" + parameter.get('nllocbin')
os.environ['PATH'] += nllocpath
except Exception as e:
@@ -73,7 +72,7 @@ def which(program, parameter):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
exe_file = os.path.join(path, program)
for candidate in ext_candidates(exe_file):
if is_exe(candidate):
return candidate
@@ -101,4 +100,3 @@ def make_pen(picktype, phase, key, quality):
linestyle, width = pick_linestyle_pg(picktype, key)
pen = pg.mkPen(rgba, width=width, style=linestyle)
return pen
+3 -2
View File
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import os
from obspy import UTCDateTime
@@ -36,12 +37,12 @@ def qml_from_obspyDMT(path):
return IOError('Could not find Event at {}'.format(path))
with open(path, 'rb') as infile:
event_dmt = pickle.load(infile)#, fix_imports=True)
event_dmt = pickle.load(infile) # , fix_imports=True)
event_dmt['origin_id'].id = str(event_dmt['origin_id'].id)
ev = Event(resource_id=event_dmt['event_id'])
#small bugfix "unhashable type: 'newstr' "
# small bugfix "unhashable type: 'newstr' "
event_dmt['origin_id'].id = str(event_dmt['origin_id'].id)
origin = Origin(resource_id=event_dmt['origin_id'],
+2 -1
View File
@@ -1,8 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import warnings
import numpy as np
from obspy import UTCDateTime
from pylot.core.util.utils import fit_curve, clims
+6 -3
View File
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*-
import sys, os, traceback
import multiprocessing
import os
import sys
import traceback
from PySide2.QtCore import QThread, Signal, Qt, Slot, QRunnable, QObject
from PySide2.QtWidgets import QDialog, QProgressBar, QLabel, QHBoxLayout, QPushButton
@@ -102,9 +105,9 @@ class Worker(QRunnable):
try:
result = self.fun(self.args)
except:
exctype, value = sys.exc_info ()[:2]
exctype, value = sys.exc_info()[:2]
print(exctype, value, traceback.format_exc())
self.signals.error.emit ((exctype, value, traceback.format_exc ()))
self.signals.error.emit((exctype, value, traceback.format_exc()))
else:
self.signals.result.emit(result)
finally:
+2 -1
View File
@@ -2,12 +2,13 @@
# -*- coding: utf-8 -*-
import hashlib
import numpy as np
import os
import platform
import re
import subprocess
import warnings
import numpy as np
from obspy import UTCDateTime, read
from obspy.core import AttribDict
from obspy.signal.rotate import rotate2zne
+1 -1
View File
@@ -35,9 +35,9 @@ from __future__ import print_function
__all__ = "get_git_version"
import inspect
# NO IMPORTS FROM PYLOT IN THIS FILE! (file gets used at installation time)
import os
import inspect
from subprocess import Popen, PIPE
# NO IMPORTS FROM PYLOT IN THIS FILE! (file gets used at installation time)
+8 -6
View File
@@ -8,15 +8,16 @@ Created on Wed Mar 19 11:27:35 2014
import copy
import datetime
import getpass
import matplotlib
import multiprocessing
import numpy as np
import os
import subprocess
import sys
import time
import traceback
import matplotlib
import numpy as np
matplotlib.use('QT5Agg')
from matplotlib.figure import Figure
@@ -36,7 +37,7 @@ from PySide2.QtWidgets import QAction, QApplication, QCheckBox, QComboBox, \
QGridLayout, QLabel, QLineEdit, QMessageBox, \
QTabWidget, QToolBar, QVBoxLayout, QHBoxLayout, QWidget, \
QPushButton, QFileDialog, QInputDialog
from PySide2.QtCore import QSettings, Qt, QUrl, Signal, Slot
from PySide2.QtCore import QSettings, Qt, QUrl, Signal
from PySide2.QtWebEngineWidgets import QWebEngineView as QWebView
from obspy import Stream, Trace, UTCDateTime
from obspy.core.util import AttribDict
@@ -65,19 +66,20 @@ else:
raise ImportError(f'Python version {sys.version_info.major} of current interpreter not supported.'
f'\nPlease use Python 3+.')
# workaround to prevent PyCharm from deleting icons_rc import when optimizing imports
# icons_rc = icons_rc
icons_rc = icons_rc
class QSpinBox(QtWidgets.QSpinBox):
''' Custom SpinBox, insensitive to Mousewheel (prevents accidental changes when scrolling through parameters) '''
def wheelEvent(self, event):
event.ignore()
class QDoubleSpinBox(QtWidgets.QDoubleSpinBox):
''' Custom DoubleSpinBox, insensitive to Mousewheel (prevents accidental changes when scrolling through parameters) '''
def wheelEvent(self, event):
event.ignore()
@@ -131,7 +133,7 @@ class LogWidget(QtWidgets.QWidget):
def reset_error(self):
# used to make sure that write errors is finished before raising new Message box etc.
self.current_active_error = False
self.stderr.append(60*'#' + '\n\n')
self.stderr.append(60 * '#' + '\n\n')
def getDataType(parent):