Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Code for Analabs
RST Evaluation
Commits
1a8913ce
Commit
1a8913ce
authored
Jan 22, 2021
by
Michael Rudolf
Browse files
Support for stress based ascii files.
Changed manual picking procedure.
parent
98802c67
Changes
1
Hide whitespace changes
Inline
Side-by-side
RSTpicking/RST_Func.py
View file @
1a8913ce
...
...
@@ -18,9 +18,9 @@ import matplotlib.gridspec as gridspec
import
matplotlib.pyplot
as
plt
import
nptdms
import
numpy
as
np
from
scipy.optimize
import
least_squares
,
curve_fit
from
scipy.stats
import
norm
from
scipy.optimize
import
curve_fit
,
least_squares
from
scipy.signal
import
medfilt
,
resample
from
scipy.stats
import
norm
# %%==============CONVERSION===================================================
...
...
@@ -42,10 +42,17 @@ def convert(path, file_in, var):
'.dat'
:
_readdat
,
'.tdms'
:
_readtdms
}
(
_
,
ext
)
=
os
.
path
.
splitext
(
path
+
file_in
)
(
_
,
ext
)
=
os
.
path
.
splitext
(
os
.
path
.
join
(
path
,
file_in
)
)
data
=
file_convert
[
ext
](
path
,
file_in
)
# data contains basic content
nsamples
=
int
(
var
[
'nsamples'
])
# check if stress data was imported instead of force
if
'normalstress'
in
data
.
keys
():
data
[
'normalforce'
]
=
data
[
'normalstress'
]
*
var
[
'A'
]
data
[
'shearforce'
]
=
(
(
data
[
'shearstress'
]
*
(
var
[
'li'
]
*
var
[
'A'
]))
/
var
[
'lo'
]
)
if
len
(
data
[
'time'
])
>
nsamples
:
data
[
'time'
]
=
np
.
linspace
(
0
,
data
[
'time'
][
-
1
],
nsamples
)
data
[
'velocity'
]
=
downsample
(
...
...
@@ -72,6 +79,8 @@ def convert(path, file_in, var):
data
[
'normalstress'
]
=
data
[
'normalforce'
]
/
var
[
'A'
]
data
[
'displacement'
]
=
np
.
cumsum
(
data
[
'time'
][
1
]
*
data
[
'velocity'
])
data
[
'name'
]
=
file_in
print
(
file_in
+
' read'
)
return
data
...
...
@@ -359,10 +368,20 @@ def eval_shearstress(cur_dat, var, review=None):
closest
=
prednorms
[
np
.
argmin
(
np
.
abs
(
differences
))]
return
closest
print
(
'Picking %s'
%
cur_dat
[
'name'
])
if
not
review
:
picks
=
_auto_pick
(
cur_dat
,
var
)
try
:
picks
=
_auto_pick
(
cur_dat
,
var
)
except
IndexError
as
_
:
print
(
'Auto picking failed ... starting manual pick'
)
picks
=
_manual_pick
(
cur_dat
,
var
)
elif
review
==
'auto'
:
picks
=
_auto_pick
(
cur_dat
,
var
)
try
:
picks
=
_auto_pick
(
cur_dat
,
var
)
except
IndexError
as
_
:
print
(
'Auto picking failed ... starting manual pick'
)
picks
=
_manual_pick
(
cur_dat
,
var
)
(
fig
,
ax
)
=
_pick_base_plot
(
cur_dat
,
var
)
(
fig
,
ax
)
=
_review_picks
(
fig
,
ax
,
picks
)
plt
.
close
()
...
...
@@ -995,9 +1014,32 @@ def dilation(path, name, lid_pos, exp_data, prop_file, cfg):
plt
.
close
()
def
_check_for_type
(
filepath
):
"""
Checks what kind of dat file we have.
Returns:
0: if it is unkown
1: if data is in Newton
2: if data is in Pascal
"""
with
open
(
filepath
,
'rt'
)
as
fhandle
:
for
i
,
row
in
enumerate
(
csv
.
reader
(
fhandle
)):
if
i
==
2
:
row
=
row
[
0
]
if
'[N]'
in
row
:
return
1
elif
'[Pa]'
in
row
:
return
2
else
:
return
0
elif
i
>
2
:
break
def
_readasc
(
path
,
file_in
):
""" Helper function to read *.asc file """
with
codecs
.
open
(
path
+
file_in
,
encoding
=
'utf-8-sig'
)
as
f
:
with
codecs
.
open
(
os
.
path
.
join
(
path
,
file_in
)
,
encoding
=
'utf-8-sig'
)
as
f
:
data_load
=
np
.
loadtxt
(
f
)
# load file for further calculations
# extract data and convert to SI-units
...
...
@@ -1017,33 +1059,84 @@ 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
]}
def
standardload
(
f
):
"""
Standard loading
"""
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
]
}
return
data
def
alternativeload
(
f
):
"""
Loads data in a slightly different way to ensure backwards
compatability
"""
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
def
pascalload
(
f
):
"""
Loads a file with Pascal as main units
"""
data_load
=
np
.
loadtxt
(
f
,
delimiter
=
';'
,
skiprows
=
3
)
time
=
data_load
[:,
0
]
# in s
normalforce
=
data_load
[:,
1
]
# in Pa
shearforce
=
data_load
[:,
2
]
# in Pa
liddispl
=
data_load
[:,
3
]
# in mm
velocity
=
data_load
[:,
4
]
# in mm/s
data
=
{
'time'
:
time
,
'velocity'
:
velocity
,
'normalstress'
:
normalforce
,
'shearstress'
:
shearforce
,
'liddispl'
:
liddispl
,
'name'
:
file_in
.
split
(
'.'
)[
0
]
}
return
data
load_fun
=
[
alternativeload
,
standardload
,
pascalload
]
filetype
=
_check_for_type
(
os
.
path
.
join
(
path
,
file_in
))
print
(
'%s of type: %s'
%
(
file_in
,
filetype
))
if
filetype
:
# if filetype is non zero:
with
codecs
.
open
(
os
.
path
.
join
(
path
,
file_in
),
encoding
=
'utf-8-sig'
)
as
f
:
try
:
data
=
load_fun
[
filetype
](
f
)
except
ValueError
as
_
:
data
=
alternativeload
(
f
)
return
data
...
...
@@ -1051,7 +1144,7 @@ def _readtdms(path, file_in):
""" Helper function to read *.tdms file """
try
:
f
=
nptdms
.
TdmsFile
(
path
+
file_in
)
f
=
nptdms
.
TdmsFile
(
os
.
path
.
join
(
path
,
file_in
)
)
time
=
f
.
group_channels
(
'Untitled'
)[
0
].
time_track
()
# in [s]
df_raw
=
dict
()
for
channel
in
f
.
group_channels
(
'Untitled'
):
...
...
@@ -1062,7 +1155,7 @@ def _readtdms(path, file_in):
liddispl
=
df_raw
[
'Lid Displacement'
]
# in [mm]
velocity
=
df_raw
[
'Velocity'
]
# in [mm/s]
except
AttributeError
as
_
:
with
nptdms
.
TdmsFile
.
open
(
path
+
file_in
)
as
f
:
with
nptdms
.
TdmsFile
.
open
(
os
.
path
.
join
(
path
,
file_in
)
)
as
f
:
time
=
f
[
'Untitled'
][
'Shear Force'
].
time_track
()
# in [s]
shearforce
=
f
[
'Untitled'
][
'Shear Force'
][:]
# in [N]
normalforce
=
f
[
'Untitled'
][
'Normal Force'
][:]
# in [N]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment