Commit 3babe1c1 authored by Michael Rudolf's avatar Michael Rudolf
Browse files

Included VST-Analysis in GUI-Version

parent 116f452d
...@@ -5,23 +5,22 @@ Created on Mon Jul 23 11:41:01 2018 ...@@ -5,23 +5,22 @@ Created on Mon Jul 23 11:41:01 2018
@author: Michael Warsitzka, Michael Rudolf @author: Michael Warsitzka, Michael Rudolf
""" """
# %%=================FUNCTION================================================
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import codecs import codecs
import collections
import csv import csv
import os import os
import nptdms
from scipy import stats
from scipy import optimize
from scipy.signal import medfilt
import time
import sys import sys
import collections import time
from operator import itemgetter from operator import itemgetter
import matplotlib as mpl
import matplotlib.gridspec as gridspec
import matplotlib.pyplot as plt
import nptdms
import numpy as np
from scipy import optimize, stats
from scipy.signal import medfilt
# %%==============CONVERSION=================================================== # %%==============CONVERSION===================================================
def convert(path, file_in, var): def convert(path, file_in, var):
...@@ -390,6 +389,27 @@ def rst_analstd(x, y): ...@@ -390,6 +389,27 @@ def rst_analstd(x, y):
out_var = (slope, std_slope, intercept, std_intercept, y_fit) out_var = (slope, std_slope, intercept, std_intercept, y_fit)
return out_var return out_var
def fitfric(x, a, b):
return a*x+b
# %%=====================VELOCITY STEPPING ANALYSIS============================
def vst_analysis(data):
mu_app = data['shearstress']/data['normalstress'] # Apparent friction
pfit, perr = fit_bootstrap(
[-.1, .5],
np.log10(data['velocity']),
mu_app,
function=fitfric
)
name_fit = (
r'y = ({:.4f}$\pm${:.5f})log10(x) +' +
'\n\t\t' +
r'({:.4f}$\pm${:.5f})').format(pfit[0],
perr[0],
pfit[1],
perr[1])
return pfit, perr, name_fit
# %%======================BOOTSTRAP LINEAR REGRESSION========================== # %%======================BOOTSTRAP LINEAR REGRESSION==========================
def fit_bootstrap(p0, datax, datay, function=None, def fit_bootstrap(p0, datax, datay, function=None,
...@@ -406,7 +426,7 @@ def fit_bootstrap(p0, datax, datay, function=None, ...@@ -406,7 +426,7 @@ def fit_bootstrap(p0, datax, datay, function=None,
"""Linear Function""" """Linear Function"""
return (a*x+b) return (a*x+b)
if ~function: if not function:
function = _poly1 function = _poly1
# Error function producing residuals # Error function producing residuals
...@@ -643,6 +663,61 @@ def plotts(path, name, exp_data, normal_stress): ...@@ -643,6 +663,61 @@ def plotts(path, name, exp_data, normal_stress):
edgecolor='w') edgecolor='w')
plt.close() plt.close()
# %%=================PLOT VST ANALYSIS=========================================
def plotVST(path, data, pfit, perr, name_fit):
""" Plots VST analysis data """
plt.rcParams['savefig.format'] = 'pdf'
plt.rcParams['font.size'] = 10
plt.rcParams['font.family'] = 'Arial Unicode MS'
plt.rcParams['savefig.dpi'] = 300
plt.rcParams['figure.figsize'] = (16, 5)
fig = plt.figure()
gs = gridspec.GridSpec(1, 3, wspace=0.4, hspace=0.3)
ax1 = fig.add_subplot(gs[0, :2])
ax2 = ax1.twinx()
ax3 = fig.add_subplot(gs[0, 2])
# Displacement vs. friction:
displ = data['displacement']
fric = data['shearstress'] / data['normalstress']
vel = data['velocity']
ax1.plot(displ, fric, 'royalblue', lw=.2)
ax1.set_xlabel('Shear displacement $d$ [mm]')
ax1.set_ylabel('Friction', color='royalblue')
ax1.spines['left'].set_color('royalblue')
ax1.tick_params('y', which='both', colors='royalblue')
ax1.set_xlim(0, max(displ)+max(displ)/100)
# Displacement vs. shear velocity:
ax2.plot(displ, vel, 'r', lw=1)
ax2.set_xlabel('Shear displacement $d$ [mm]')
ax2.set_ylabel('Shear velocity $v$ [$\mathregular{mm s^{-1}}$]', color='r')
ax2.set_yscale('log')
ax2.spines['right'].set_color('r')
ax2.spines['left'].set_color('royalblue')
ax2.tick_params('y', which='both', colors='r')
ax2.set_xlim(0, max(displ)+max(displ)/100)
# shear velocity vs. fricton:
ax3.plot(vel, fric, 'k.', ms=2)
ax3.plot(vel, fitfric(np.log10(vel), *pfit), 'g-', label='curve fit: '+ name_fit)
ax3.set_xscale('log')
ax3.set_xlabel('Shear velocity $v$ [$\mathregular{mm s^{-1}}$]')
ax3.set_ylabel('Friction')
ax3.set_xlim(min(vel)-(min(vel)/5), max(vel)+max(vel)/5)
ax3.legend(fontsize=8,
facecolor='w',
edgecolor='k',
loc='upper right',
framealpha=0.5)
fig.suptitle(data['name'], fontsize=14, y=0.95)
plt.savefig(path + data['name'],
bbox_inches='tight',
edgecolor='w')
plt.close()
print(data['name']+' processed.')
# %%========================SAVE=============================================== # %%========================SAVE===============================================
def saveTS(path, name, exp_data): def saveTS(path, name, exp_data):
...@@ -887,18 +962,32 @@ def _readasc(path, file_in): ...@@ -887,18 +962,32 @@ def _readasc(path, file_in):
def _readdat(path, file_in): def _readdat(path, file_in):
""" Helper function to read *.dat file """ """ Helper function to read *.dat file """
with codecs.open(path+file_in, encoding='utf-8-sig') as f: with codecs.open(path+file_in, encoding='utf-8-sig') as f:
data_load = np.loadtxt(f, delimiter=';', skiprows=3) try:
time = data_load[:, 0] # in s data_load = np.loadtxt(f, delimiter=';', skiprows=3)
normalforce = data_load[:, 1] # in N time = data_load[:, 0] # in s
shearforce = data_load[:, 2] # in N normalforce = data_load[:, 1] # in N
liddispl = data_load[:, 3] # in mm shearforce = data_load[:, 2] # in N
velocity = data_load[:, 4] # in mm/s liddispl = data_load[:, 3] # in mm
data = {'time': time, velocity = data_load[:, 4] # in mm/s
'velocity': velocity,
'normalforce': normalforce, data = {'time': time,
'shearforce': shearforce, 'velocity': velocity,
'liddispl': liddispl, 'normalforce': normalforce,
'name': file_in.split('.')[0]} 'shearforce': shearforce,
'liddispl': liddispl,
'name': file_in.split('.')[0]}
except ValueError as _:
data_load = np.loadtxt(f, delimiter='\t', skiprows=1)
time = data_load[:, 0] # in s
velocity = data_load[:, 1] # in mm/s
normalforce = data_load[:, 2] # in N
shearforce = data_load[:, 3] # in N
data = {'time': time,
'velocity': velocity,
'normalforce': normalforce,
'shearforce': shearforce,
'name': file_in.split('.')[0]}
return data return data
......
#!/usr/bin/env python3 #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# @Author: M. Rudolf, M. Warsitzka
# @Date: 2019-02-20 12:00:00
# @Last Modified by: M. Rudolf
# @Last Modified time: 2020-05-06 14:46:03
""" """
RST_pick_GUI.py RST_pick_GUI.py
GUI based approach for RSTpicking GUI based approach for RSTpicking
__AUTHOR__: Michael Rudolf
__DATE__: 20-Feb-2019
""" """
import configparser import configparser
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
import re
import os
import logging import logging
import RST_Func as rfnc import os
import warnings import re
import sys import sys
import tkinter as tk
import warnings
from tkinter import filedialog, messagebox
import RST_Func as rfnc
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
log = logging.getLogger() log = logging.getLogger()
...@@ -42,6 +43,7 @@ class RST_pick_GUI(tk.Tk): ...@@ -42,6 +43,7 @@ class RST_pick_GUI(tk.Tk):
self.plot_ts = tk.IntVar() self.plot_ts = tk.IntVar()
self.save_ts = tk.IntVar() self.save_ts = tk.IntVar()
self.rev_pick = tk.IntVar() self.rev_pick = tk.IntVar()
self.is_VST = tk.IntVar()
self.quit_onprc = tk.IntVar() self.quit_onprc = tk.IntVar()
self.rst = tk.IntVar() self.rst = tk.IntVar()
self.cfg = configparser.ConfigParser() self.cfg = configparser.ConfigParser()
...@@ -125,16 +127,23 @@ class RST_pick_GUI(tk.Tk): ...@@ -125,16 +127,23 @@ class RST_pick_GUI(tk.Tk):
anchor='w', anchor='w',
variable=self.rev_pick) variable=self.rev_pick)
self.opt_revpick.grid(column=1, row=4, sticky='EW') self.opt_revpick.grid(column=1, row=4, sticky='EW')
# Review Picking # Is a VST-Test
self.opt_revpick = tk.Checkbutton(self,
text='VST-Test',
anchor='w',
variable=self.is_VST)
self.opt_revpick.grid(column=1, row=5, sticky='EW')
# Quit after processing
self.opt_quit = tk.Checkbutton(self, self.opt_quit = tk.Checkbutton(self,
text='Quit after processing', text='Quit after processing',
anchor='w', anchor='w',
variable=self.quit_onprc) variable=self.quit_onprc)
self.opt_quit.grid(column=1, row=5, sticky='EW') self.opt_quit.grid(column=1, row=6, sticky='EW')
# More Options # More Options
self.button_options = tk.Button(self, self.button_options = tk.Button(self,
text='More options...') text='More options...')
self.button_options.grid(column=1, row=6, sticky='w') self.button_options.grid(column=1, row=7, sticky='w')
self.button_options.bind('<ButtonRelease-1>', self.more_options) self.button_options.bind('<ButtonRelease-1>', self.more_options)
# Start processing # Start processing
...@@ -247,79 +256,92 @@ class RST_pick_GUI(tk.Tk): ...@@ -247,79 +256,92 @@ class RST_pick_GUI(tk.Tk):
# Data is stored as a list of dictionaries containing the data # Data is stored as a list of dictionaries containing the data
exp_data = [rfnc.convert(path_in, f, Vars) for f in file_list] exp_data = [rfnc.convert(path_in, f, Vars) for f in file_list]
if self.rst.get() == 1: if self.is_VST.get() == 0:
# Evaluate all data sets and store results in a list if self.rst.get() == 1:
if self.rev_pick.get() == 1: # Evaluate all data sets and store results in a list
eval_data = [rfnc.eval_shearstress(cur_dat, Vars, if self.rev_pick.get() == 1:
review='auto') eval_data = [rfnc.eval_shearstress(cur_dat, Vars,
for cur_dat in exp_data] review='auto')
for cur_dat in exp_data]
else:
eval_data = [rfnc.eval_shearstress(cur_dat, Vars)
for cur_dat in exp_data]
print('Automatic analysis successful')
else: else:
eval_data = [rfnc.eval_shearstress(cur_dat, Vars) print('Automatic analysis skipped, initiating manual picking')
for cur_dat in exp_data] eval_data = [rfnc.eval_shearstress(cur_dat, Vars, review='manual')
print('Automatic analysis successful') for cur_dat in exp_data]
# Create lists of parameters for analysis
normal_stress = [ev[0] for ev in eval_data]
peak_stress = [ev[1][1] for ev in eval_data]
dyn_stress = [ev[2][1] for ev in eval_data]
stat_stress = [ev[3][1] for ev in eval_data]
dilation = [ev[4] for ev in eval_data]
weak = [ev[5] for ev in eval_data]
weak_p = [ev[6] for ev in eval_data]
p_ind = [ev[7] for ev in eval_data]
# ==========ANALYSIS OF FRICTION COEFFICIENTS AND COHESIONS=======
# ===========Analysis 1: Mutual linear regression=================
peakfric_mut, peakdata_mut = rfnc.rst_analmut(
normal_stress,
peak_stress
)
dynfric_mut, dyndata_mut = rfnc.rst_analmut(
normal_stress,
dyn_stress
)
reactfric_mut, reactdata_mut = rfnc.rst_analmut(
normal_stress,
stat_stress
)
# ===========ANALYSIS 2: Standard regression of all data pairs ==
peakfric_std = rfnc.rst_analstd(normal_stress, peak_stress)
dynfric_std = rfnc.rst_analstd(normal_stress, dyn_stress)
reactfric_std = rfnc.rst_analstd(normal_stress, stat_stress)
# ==========MERGE DATA===========================================
strength = (normal_stress, peak_stress, dyn_stress,
stat_stress, weak, weak_p)
fric_mut = (peakfric_mut, dynfric_mut, reactfric_mut)
data_mut = (peakdata_mut, dyndata_mut, reactdata_mut)
fric_std = (peakfric_std, dynfric_std, reactfric_std)
# ===================PLOT DATA======================================
rfnc.plotstd(path_out, projectname, strength, fric_std)
rfnc.plothist(path_out, projectname, strength, data_mut)
print('>>> Friction data plotted')
if self.plot_ts.get() == 1:
rfnc.plotts(path_out, projectname, exp_data, normal_stress)
print('>>> Time series data plotted')
# ====================Save DATA======================================
if self.rst.get() == 1:
rfnc.saveStrength(path_out, projectname, strength)
rfnc.saveFric(path_out, projectname, fric_mut, fric_std)
lid_pos = rfnc.savelidpos(path_out, projectname, p_ind, exp_data)
print('>>> Friction data saved')
prop_file = [path_in+f for f in os.listdir(path_in)
if f.endswith('csv')]
if prop_file:
print('>>> Prop file detected! Starting dilation analysis...')
rfnc.dilation(path_out, projectname, lid_pos, exp_data,
prop_file[0], self.cfg)
else:
print('>>> There is no prop file! Going on as usual.')
if self.save_ts.get() == 1:
rfnc.saveTS(path_out, projectname, exp_data)
print('>>> Time series data saved')
else: else:
print('Automatic analysis skipped, initiating manual picking') print('Velocity Stepping Test')
eval_data = [rfnc.eval_shearstress(cur_dat, Vars, review='manual') for exp in exp_data:
for cur_dat in exp_data] pfit, perr, name_fit = rfnc.vst_analysis(exp)
rfnc.plotVST(path_out, exp, pfit, perr, name_fit)
# Create lists of parameters for analysis
normal_stress = [ev[0] for ev in eval_data]
peak_stress = [ev[1][1] for ev in eval_data]
dyn_stress = [ev[2][1] for ev in eval_data]
stat_stress = [ev[3][1] for ev in eval_data]
dilation = [ev[4] for ev in eval_data]
weak = [ev[5] for ev in eval_data]
weak_p = [ev[6] for ev in eval_data]
p_ind = [ev[7] for ev in eval_data]
# ==========ANALYSIS OF FRICTION COEFFICIENTS AND COHESIONS=======
# ===========Analysis 1: Mutual linear regression=================
peakfric_mut, peakdata_mut = rfnc.rst_analmut(normal_stress,
peak_stress)
dynfric_mut, dyndata_mut = rfnc.rst_analmut(normal_stress,
dyn_stress)
reactfric_mut, reactdata_mut = rfnc.rst_analmut(normal_stress,
stat_stress)
# ===========ANALYSIS 2: Standard regression of all data pairs ==
peakfric_std = rfnc.rst_analstd(normal_stress, peak_stress)
dynfric_std = rfnc.rst_analstd(normal_stress, dyn_stress)
reactfric_std = rfnc.rst_analstd(normal_stress, stat_stress)
# ==========MERGE DATA===========================================
strength = (normal_stress, peak_stress, dyn_stress,
stat_stress, weak, weak_p)
fric_mut = (peakfric_mut, dynfric_mut, reactfric_mut)
data_mut = (peakdata_mut, dyndata_mut, reactdata_mut)
fric_std = (peakfric_std, dynfric_std, reactfric_std)
# ====================PLOT DATA======================================
rfnc.plotstd(path_out, projectname, strength, fric_std)
rfnc.plothist(path_out, projectname, strength, data_mut)
print('>>> Friction data plotted')
if self.plot_ts.get() == 1:
rfnc.plotts(path_out, projectname, exp_data, normal_stress)
print('>>> Time series data plotted')
# ====================Save DATA======================================
if self.rst.get() == 1:
rfnc.saveStrength(path_out, projectname, strength)
rfnc.saveFric(path_out, projectname, fric_mut, fric_std)
lid_pos = rfnc.savelidpos(path_out, projectname, p_ind, exp_data)
print('>>> Friction data saved')
prop_file = [path_in+f for f in os.listdir(path_in)
if f.endswith('csv')]
if prop_file:
print('>>> Prop file detected! Starting dilation analysis...')
rfnc.dilation(path_out, projectname, lid_pos, exp_data,
prop_file[0], self.cfg)
else:
print('>>> There is no prop file! Going on as usual.')
if self.save_ts.get() == 1:
rfnc.saveTS(path_out, projectname, exp_data)
print('>>> Time series data saved')
# ======= Exit if 'exit on processing' is selected ===== # ======= Exit if 'exit on processing' is selected =====
if self.quit_onprc.get() == 1: if self.quit_onprc.get() == 1:
...@@ -371,6 +393,7 @@ class RST_pick_GUI(tk.Tk): ...@@ -371,6 +393,7 @@ class RST_pick_GUI(tk.Tk):
self.save_ts.set(self.cfg.getint('options', 'save_ts')) self.save_ts.set(self.cfg.getint('options', 'save_ts'))
self.rst.set(self.cfg.getint('options', 'rst')) self.rst.set(self.cfg.getint('options', 'rst'))
self.rev_pick.set(self.cfg.getint('options', 'rev_pick')) self.rev_pick.set(self.cfg.getint('options', 'rev_pick'))
self.is_VST.set(self.cfg.getint('options', 'is_VST'))
self.quit_onprc.set(self.cfg.getint('options', 'quit_onprc')) self.quit_onprc.set(self.cfg.getint('options', 'quit_onprc'))
# Read parameters and store them as a dictionary of StringVars # Read parameters and store them as a dictionary of StringVars
# This automatically links them to changes made in the Options dialog. # This automatically links them to changes made in the Options dialog.
...@@ -394,6 +417,7 @@ class RST_pick_GUI(tk.Tk): ...@@ -394,6 +417,7 @@ class RST_pick_GUI(tk.Tk):
'save_ts': 1, # if 1: data stored in .txt files, if 0: not 'save_ts': 1, # if 1: data stored in .txt files, if 0: not
'rst': 1, # if 1: automatic picking 'rst': 1, # if 1: automatic picking
'rev_pick': 0, # if 1: the user can review the picked peaks 'rev_pick': 0, # if 1: the user can review the picked peaks
'is_VST': 0, # if 1: the file is a VST-Test file
'quit_onprc': 0, # if 1: automatically quits after processing 'quit_onprc': 0, # if 1: automatically quits after processing
} }
......
...@@ -8,16 +8,18 @@ plot_ts = 1 ...@@ -8,16 +8,18 @@ plot_ts = 1
save_ts = 1 save_ts = 1
rst = 1 rst = 1
rev_pick = 0 rev_pick = 0
is_VST = 0
quit_onprc = 0 quit_onprc = 0
[parameters] [parameters]
A = 0.022619 A = 0.022619
li = 0.0776 li = 0.0776
lo = 0.125 lo = 0.125
vel = 6 vel = 30
prec = 250 prec = 500
velnoise = 0.01 velnoise = 0.01
stressnoise = 0.025 stressnoise = 0.025
cellweight = 2185.3
smoothwindow = 51 smoothwindow = 51
[units] [units]
...@@ -28,5 +30,6 @@ vel = mm/min ...@@ -28,5 +30,6 @@ vel = mm/min
prec = Pa prec = Pa
velnoise = mm/min velnoise = mm/min
stressnoise = Pa stressnoise = Pa
cellweight = g
smoothwindow = samples smoothwindow = samples
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment