From 4260ec4571e1d7f688a2600f23f1d41c91869d6a Mon Sep 17 00:00:00 2001 From: "M.Rudolf" <mrudolf@gfz-potsdam.de> Date: Wed, 16 Jan 2019 14:35:13 +0100 Subject: [PATCH] Removed unnecessary modules and fixed small bug due to missing ',' --- RSTpicking/RST_Func.py | 37 ++++++++++++++++--------------------- RSTpicking/RST_main.py | 13 ------------- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/RSTpicking/RST_Func.py b/RSTpicking/RST_Func.py index 7fc3e87..f810f69 100644 --- a/RSTpicking/RST_Func.py +++ b/RSTpicking/RST_Func.py @@ -10,16 +10,12 @@ import numpy as np import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec import pandas as pd -import glob -import shutil import codecs import csv -from os.path import isfile, join, basename, splitext import os from nptdms import TdmsFile import matplotlib.pyplot as plt from scipy import signal -from pylab import * from scipy import stats @@ -105,7 +101,6 @@ def eval_shearstress(R, var): # %===================SMOOTHING FUCTION======================================== def savitzky_golay(y, window_size, order, deriv=0, rate=1): - import numpy as np from math import factorial try: @@ -122,7 +117,7 @@ def savitzky_golay(y, window_size, order, deriv=0, rate=1): b = np.mat([[k**i for i in ord_rng] for k in range(-half_w, half_w+1)]) m = np.linalg.pinv(b).A[deriv] * rate**deriv * factorial(deriv) # pad the signal at the extremes with values taken from the signal itself - firstvals = y[0] - np.abs(y[1:half_w+1][::-1] - y[0]) + firstvals = y[0]-np.abs(y[1:half_w+1][::-1] - y[0]) lastvals = y[-1]+np.abs(y[-half_w-1:-1][::-1] - y[-1]) y = np.concatenate((firstvals, y, lastvals)) return np.convolve(m[::-1], y, mode='valid') @@ -141,11 +136,11 @@ def rst_analmut(x, y): M[k, j] = (y[k+j]-y[k])/(x[k+j]-x[k]) # calculate slope/ friction j += 1 k += 1 - M[M == inf] = NaN # set inf to Nan - M[M == -inf] = NaN # set -inf to Nan - M[M == 0] = NaN # set 0 to Nan - M[M < 0] = NaN # set <0 to Nan - M[M > 1] = NaN # set 0 to Nan + M[M == np.inf] = np.nan # set inf to Nan + M[M == -np.inf] = np.nan # set -inf to Nan + M[M == 0] = np.nan # set 0 to Nan + M[M < 0] = np.nan # set <0 to Nan + M[M > 1] = np.nan # set 0 to Nan M_avg, M_std = stats.norm.fit(M[~np.isnan(M)]) # mean and standard deviation for k in range(0, n-1): @@ -154,9 +149,9 @@ def rst_analmut(x, y): j = j+1 k = k+1 # calculation of cohesions (y axis intercept): - C[C == inf] = NaN # set inf to Nan - C[C == -inf] = NaN # set -inf to Nan - C[C == 0.0] = NaN # set 0 to Nan + C[C == np.inf] = np.nan # set inf to Nan + C[C == -np.inf] = np.nan # set -inf to Nan + C[C == 0.0] = np.nan # set 0 to Nan C_avg, C_std = stats.norm.fit(C[~np.isnan(C)]) # mean and standard deviation fric_mut = (M_avg, M_std, C_avg, C_std) data_mut = (M, C) @@ -267,7 +262,7 @@ def plothist(path, name, strength, data_mut): # ==============FRICTION COEFFICIENT======================== axrow[0].hist(coef[~np.isnan(coef)], bins=nbins, - normed=True, + density=True, color='royalblue', edgecolor='black') lnspc = np.linspace(np.nanmin(coef), np.nanmax(coef), len(coef)) @@ -292,7 +287,7 @@ def plothist(path, name, strength, data_mut): # ==============COHESION================================ axrow[1].hist(coh[~np.isnan(coh)], bins=nbins, - normed=True, + density=True, color='royalblue', edgecolor='black') statscoh = stats.norm.fit(coh[~np.isnan(coh)]) @@ -339,12 +334,12 @@ def plotts(path, name, ts, sigma_sort, var): for i in range(0, t): sigma_legend = int(np.sum(sigma_sort[i*3:(i*3)+3])/3) plt.plot(ts.iloc[:, 0], np.zeros(len(ts.iloc[:, 0])), - linewidth=0.5 - color=linecolor[i+1] + linewidth=0.5, + color=linecolor[i+1], label=str(sigma_legend)+' Pa') plt.plot(ts.iloc[:, 0], - ts.iloc[:, i*3+1:(i+1)*3+1] - linewidth=0.5 + ts.iloc[:, i*3+1:(i+1)*3+1], + linewidth=0.5, color=linecolor[i+1]) plt.legend(fontsize=8, facecolor='w', @@ -371,7 +366,7 @@ def saveTS(path, name, ts): index=None, sep='\t', mode='w', - na_rep='NaN') # write to txt file + na_rep='np.nan') # write to txt file def saveStrength(path, name, strength): diff --git a/RSTpicking/RST_main.py b/RSTpicking/RST_main.py index df44665..a201475 100644 --- a/RSTpicking/RST_main.py +++ b/RSTpicking/RST_main.py @@ -8,20 +8,7 @@ Created on Mon Jul 23 14:32:17 2018 # %%===========================IMPORT========================================== import numpy as np import pandas as pd -import matplotlib.pyplot as plt -import matplotlib.gridspec as gridspec -import csv -import pylab -from scipy import stats import os -import fnmatch -import glob -import shutil -import pickle -from nptdms import TdmsFile -import collections -import itertools -from operator import itemgetter import RST_Func # %%==========================NAMES============================================ -- GitLab