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
@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 collections
import csv
import os
import nptdms
from scipy import stats
from scipy import optimize
from scipy.signal import medfilt
import time
import sys
import collections
import time
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===================================================
def convert(path, file_in, var):
......@@ -390,6 +389,27 @@ def rst_analstd(x, y):
out_var = (slope, std_slope, intercept, std_intercept, y_fit)
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==========================
def fit_bootstrap(p0, datax, datay, function=None,
......@@ -406,7 +426,7 @@ def fit_bootstrap(p0, datax, datay, function=None,
"""Linear Function"""
return (a*x+b)
if ~function:
if not function:
function = _poly1
# Error function producing residuals
......@@ -643,6 +663,61 @@ def plotts(path, name, exp_data, normal_stress):
edgecolor='w')
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===============================================
def saveTS(path, name, exp_data):
......@@ -887,18 +962,32 @@ def _readasc(path, file_in):
def _readdat(path, file_in):
""" Helper function to read *.dat file """
with codecs.open(path+file_in, encoding='utf-8-sig') as f:
try:
data_load = np.loadtxt(f, delimiter=';', skiprows=3)
time = data_load[:, 0] # in s
normalforce = data_load[:, 1] # in N
shearforce = data_load[:, 2] # in N
liddispl = data_load[:, 3] # in mm
velocity = data_load[:, 4] # in mm/s
data = {'time': time,
'velocity': velocity,
'normalforce': normalforce,
'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
......
#!/usr/bin/env python3
# -*- 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
GUI based approach for RSTpicking
__AUTHOR__: Michael Rudolf
__DATE__: 20-Feb-2019
"""
import configparser
import tkinter as tk
from tkinter import filedialog
from tkinter import messagebox
import re
import os
import logging
import RST_Func as rfnc
import warnings
import os
import re
import sys
import tkinter as tk
import warnings
from tkinter import filedialog, messagebox
import RST_Func as rfnc
warnings.filterwarnings("ignore")
log = logging.getLogger()
......@@ -42,6 +43,7 @@ class RST_pick_GUI(tk.Tk):
self.plot_ts = tk.IntVar()
self.save_ts = tk.IntVar()
self.rev_pick = tk.IntVar()
self.is_VST = tk.IntVar()
self.quit_onprc = tk.IntVar()
self.rst = tk.IntVar()
self.cfg = configparser.ConfigParser()
......@@ -125,16 +127,23 @@ class RST_pick_GUI(tk.Tk):
anchor='w',
variable=self.rev_pick)
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,
text='Quit after processing',
anchor='w',
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
self.button_options = tk.Button(self,
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)
# Start processing
......@@ -247,6 +256,7 @@ class RST_pick_GUI(tk.Tk):
# Data is stored as a list of dictionaries containing the data
exp_data = [rfnc.convert(path_in, f, Vars) for f in file_list]
if self.is_VST.get() == 0:
if self.rst.get() == 1:
# Evaluate all data sets and store results in a list
if self.rev_pick.get() == 1:
......@@ -274,12 +284,18 @@ class RST_pick_GUI(tk.Tk):
# ==========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)
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)
......@@ -293,7 +309,7 @@ class RST_pick_GUI(tk.Tk):
data_mut = (peakdata_mut, dyndata_mut, reactdata_mut)
fric_std = (peakfric_std, dynfric_std, reactfric_std)
# ====================PLOT DATA======================================
# ===================PLOT DATA======================================
rfnc.plotstd(path_out, projectname, strength, fric_std)
rfnc.plothist(path_out, projectname, strength, data_mut)
print('>>> Friction data plotted')
......@@ -320,6 +336,12 @@ class RST_pick_GUI(tk.Tk):
if self.save_ts.get() == 1:
rfnc.saveTS(path_out, projectname, exp_data)
print('>>> Time series data saved')
else:
print('Velocity Stepping Test')
for exp in exp_data:
pfit, perr, name_fit = rfnc.vst_analysis(exp)
rfnc.plotVST(path_out, exp, pfit, perr, name_fit)
# ======= Exit if 'exit on processing' is selected =====
if self.quit_onprc.get() == 1:
......@@ -371,6 +393,7 @@ class RST_pick_GUI(tk.Tk):
self.save_ts.set(self.cfg.getint('options', 'save_ts'))
self.rst.set(self.cfg.getint('options', 'rst'))
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'))
# Read parameters and store them as a dictionary of StringVars
# This automatically links them to changes made in the Options dialog.
......@@ -394,6 +417,7 @@ class RST_pick_GUI(tk.Tk):
'save_ts': 1, # if 1: data stored in .txt files, if 0: not
'rst': 1, # if 1: automatic picking
'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
}
......
......@@ -8,16 +8,18 @@ plot_ts = 1
save_ts = 1
rst = 1
rev_pick = 0
is_VST = 0
quit_onprc = 0
[parameters]
A = 0.022619
li = 0.0776
lo = 0.125
vel = 6
prec = 250
vel = 30
prec = 500
velnoise = 0.01
stressnoise = 0.025
cellweight = 2185.3
smoothwindow = 51
[units]
......@@ -28,5 +30,6 @@ vel = mm/min
prec = Pa
velnoise = mm/min
stressnoise = Pa
cellweight = g
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