Commit dc779628 authored by Michael Rudolf's avatar Michael Rudolf
Browse files

Formatting, Spelling, minor fixes

* Changed the format of the code to more or less comply with PEP8 
standard (e.g. 80 chars per line, whitespaces around operators, etc.). 
Some too long lines still remain, maybe changed later.
* Removed spelling errors where found
* Fixed #1
parent abe8c8f9
This diff is collapsed.
......@@ -5,17 +5,18 @@ Created on Mon Jul 23 14:32:17 2018
@author: Michael Warsitzka
"""
# *************************************************************************
#%%===========================IMPORT==========================================
# %%===========================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
from scipy import stats
import os
import fnmatch
import glob, shutil
import glob
import shutil
import pickle
from nptdms import TdmsFile
import collections
......@@ -23,112 +24,136 @@ import itertools
from operator import itemgetter
import RST_Func
#%%==========================NAMES==============================================
projectname = 'example'
path_in = 'input/'
path_out = 'output/'
name_ts= projectname+'_ts'
name_rst = [projectname+'_peak', projectname+'_dynamic', projectname+'_reactivation']
name_rst2 = projectname+'_RSTstd'
#%%==========================PARAMETERS & VARIABLES==============================================
plot_ts = 1 # if 1: time series data is plotted, if 0: no plots are produced
save_ts = 1 # if 1: time series data is stored in .txt files, if 0: data is not stored
rst = 1 # if 1: atomatic picking of peak, dynamic and reactivation strength conducted
prec_Sigma = 500 #Define preccision to what normal stress is rounded (affects the analaysis!)
Vars = {'A': 0.022619, # area of shear zone (= surface area of lid) (m^2)
'li': 0.0776, # inner lever (center cell to center of shear zone)
'lo': 0.1250, # outer lever (center cell to hinge point)
'vel': 30, #shear velocity (mm/min)
'prec': prec_Sigma, # rounding precision for normal stress in file names
# %%==========================NAMES============================================
projectname = 'example'
path_in = 'input/'
path_out = 'output/'
name_ts = projectname+'_ts'
name_rst = [projectname+'_peak',
projectname+'_dynamic',
projectname+'_reactivation']
name_rst2 = projectname+'_RSTstd'
# %%=====================PARAMETERS & VARIABLES================================
plot_ts = 1 # if 1: time series data is plotted, if 0: no plots are produced
save_ts = 1 # if 1: time series data is stored in .txt files, if 0: not
rst = 1 # if 1: automatic picking of peak, dynamic and reactivation strength
prec_Sigma = 500 # Define preccision of normal stress (affects the analysis!)
Vars = {'A': 0.022619, # area of shear zone (= surface area of lid) (m^2)
'li': 0.0776, # inner lever (center cell to center shear zone)
'lo': 0.1250, # outer lever (center cell to hinge point)
'vel': 30, # shear velocity (mm/min)
'prec': prec_Sigma, # precision for normal stress in filenames
'velnoise': 1e-2,
'stressnoise': 0.025,
'smoothwindow': 51} # define window for smooth shear stress curve
#%%============================VARIABLES=======================================================
'smoothwindow': 51} # define window for smooth shear stress curve
# %%============================VARIABLES======================================
N = len(os.listdir(path_in))
len_df = np.zeros(N)
TS = pd.DataFrame()
Sigma = np.zeros(N)
Sigma_avg = np.zeros(N)
Peakstress = np.zeros((N,2))
Dynstress = np.zeros((N,2))
Reactstress = np.zeros((N,2))
Peakstress = np.zeros((N, 2))
Dynstress = np.zeros((N, 2))
Reactstress = np.zeros((N, 2))
Dilation = np.zeros(N)
Weak = np.zeros(N)
Weak_p = np.zeros(N)
#%%==========================READ, CONVERT & EVALUATE DATA==============================================
for i in range(0,N):
current_set= RST_Func.convert(path_in, os.listdir(path_in)[i], Vars)
# %%=====================READ, CONVERT & EVALUATE DATA=========================
for i in range(0, N):
current_set = RST_Func.convert(path_in, os.listdir(path_in)[i], Vars)
Sigma_avg[i] = round(np.mean(current_set['normalstress'])/Vars['prec'])*Vars['prec'] # only for the file name
len_df[i] = len(current_set['time'])
TS = pd.concat([TS, pd.Series((current_set.shearforce).values)], ignore_index=True, axis=1)
len_df[i] = len(current_set['time'])
TS = pd.concat([TS, pd.Series((current_set.shearforce).values)],
ignore_index=True, axis=1)
if rst == 1:
RST_var = RST_Func.eval_shearstress(current_set, Vars)
Sigma[i],Peakstress[i,:], Dynstress[i,:],Reactstress[i,:] = RST_var[0],RST_var[1],RST_var[2],RST_var[3]
Dilation[i], Weak[i], Weak_p[i] = RST_var[4], RST_var[5], RST_var[5]
RST_var = RST_Func.eval_shearstress(current_set, Vars)
Sigma[i] = RST_var[0]
Peakstress[i, :] = RST_var[1]
Dynstress[i, :] = RST_var[2]
Reactstress[i, :] = RST_var[3]
Dilation[i] = RST_var[4]
Weak[i] = RST_var[5]
Weak_p[i] = RST_var[6]
else:
RST_var = []
pos_dfmax = int(np.where(len_df == len_df.max())[0][0]) # position of longest measurement
RST_var = []
# position of longest measurement
pos_dfmax = int(np.where(len_df == len_df.max())[0][0])
time_max = RST_Func.convert(path_in, os.listdir(path_in)[pos_dfmax], Vars)['time']
#data drame of sorted time series for pdf plot:
TS_sort=TS.iloc[:, TS.max().sort_values(ascending=True).index] # sort according to max values
Sigma_avg_sort = Sigma_avg[TS_sort.columns] # sort Sigma avg according to columns
TS_sort = pd.concat([time_max,TS_sort], axis=1)
TS_sort = pd.DataFrame(TS_sort.values,
columns=['Time [s]'] + [str(i) for i in Sigma_avg_sort]) #combine ts data and new header
#data drame of time series for export to txt file:
TS = pd.concat([time_max,TS], axis=1) # add time column to data frame
TS = pd.DataFrame(TS.values,
columns=['Time [s]'] + [str(i) for i in Sigma_avg]) #combine ts data and new header
#%%==================ANALYSIS OF FRICTION COEFFICIENTS AND COHESIONS=====================================
if rst == 1:
peakstress = [Peakstress[i][1] for i in range(0,N)]
dynstress = [Dynstress[i][1] for i in range(0,N)]
reactstress = [Reactstress[i][1] for i in range(0,N)]
#%===========Analysis 1: Mutual linear regression==================================
# data frame of sorted time series for pdf plot:
# sort according to max values
TS_sort = TS.iloc[:, TS.max().sort_values(ascending=True).index]
# sort Sigma avg according to columns
Sigma_avg_sort = Sigma_avg[TS_sort.columns]
TS_sort = pd.concat([time_max, TS_sort], axis=1)
# combine ts data and new header
TS_sort = pd.DataFrame(TS_sort.values,
columns=['Time [s]'] + [str(i) for i in Sigma_avg_sort])
# data frame of time series for export to txt file:
TS = pd.concat([time_max, TS], axis=1) # add time column to data frame
# combine ts data and new header
TS = pd.DataFrame(TS.values,
columns=['Time [s]'] + [str(i) for i in Sigma_avg])
# %%==================ANALYSIS OF FRICTION COEFFICIENTS AND COHESIONS==========
if rst == 1:
peakstress = [Peakstress[i][1] for i in range(0, N)]
dynstress = [Dynstress[i][1] for i in range(0, N)]
reactstress = [Reactstress[i][1] for i in range(0, N)]
# %%===========Analysis 1: Mutual linear regression========================
peakfric_mut, peakdata_mut = RST_Func.rst_analmut(Sigma_avg, peakstress)
dynfric_mut, dyndata_mut = RST_Func.rst_analmut(Sigma_avg, dynstress)
reactfric_mut, reactdata_mut = RST_Func.rst_analmut(Sigma_avg, reactstress)
#%%==============ANALYSIS 2: Standard regression of all data pairs ==========================
# %%===========ANALYSIS 2: Standard regression of all data pairs ==========
peakfric_std = RST_Func.rst_analstd(Sigma_avg, peakstress)
dynfric_std = RST_Func.rst_analstd(Sigma_avg, dynstress)
reactfric_std = RST_Func.rst_analstd(Sigma_avg, reactstress)
#%%==============MERGE DATA================================================
# %%==========MERGE DATA===================================================
Strength = (Sigma_avg, peakstress, dynstress, reactstress, 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)
print('=====================================================================')
print('==================================================================')
print('RST analysis successful')
print('=====================================================================')
print('==================================================================')
else:
print('=====================================================================')
print('==================================================================')
print('RST analysis skipped')
print('=====================================================================')
#%%====================PLOT DATA=====================================================
if rst == 1:
print('==================================================================')
# %%====================PLOT DATA==============================================
if rst == 1:
RST_Func.plotstd(path_out, projectname, Strength, Fric_std)
RST_Func.plothist(path_out, projectname, Strength, Data_mut)
print('=====================================================================')
print('==================================================================')
print('>>> Fiction data plotted')
print('=====================================================================')
print('==================================================================')
if plot_ts == 1:
RST_Func.plotts(path_out, projectname, TS_sort, Sigma_avg_sort, Vars)
print('=====================================================================')
print('>>> Time series data plotted')
print('=====================================================================')
print('==================================================================')
print('>>> Time series data plotted')
print('==================================================================')
#%%====================Save DATA=====================================================
# %%====================Save DATA==============================================
if rst == 1:
RST_Func.saveStrength(path_out, projectname, Strength)
RST_Func.saveFric(path_out, projectname, Fric_mut, Fric_std)
#RST_Funct.RST_plotstd(path_out, name_rst2, RST2)
print('=====================================================================')
# RST_Funct.RST_plotstd(path_out, name_rst2, RST2)
print('==================================================================')
print('>>> Friction data saved')
print('=====================================================================')
print('==================================================================')
if save_ts == 1:
RST_Func.saveTS(path_out, projectname, TS)
print('=====================================================================')
print('==================================================================')
print('>>> Time series data saved')
print('=====================================================================')
print('==================================================================')
Supports Markdown
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