Commit b686ed7c authored by dhomm's avatar dhomm
Browse files

change thesis code part 1

parent 21c59e5b
# Bachelor Thesis - Sensor Localization
All files and folders exist in on the master branch.
The finished systmes can be found on the main and on the master branch.
Scripts for the feature evaluation and tests are only on the master branch.
The Folder with thesis-code includes my result systems.
To run my systems the main branch should be used.
PLOE-Adaption:
To run only the PLOE-Adaption go to the Wrist-Distinction
and run
python3 PLOE_combined.py
If you clone the repo the Proband3.mkv file will be available.
The result should then be:
Using a timespan of: 0.9 and a threshold of: (9, 3.5) the placement: ('Position L1, X -> Elbow, Y -> Thumb, Z -> Palm', 1.0) was chosen
To change the file change the needed properties
below the if __name__ == "__main__" clause accordingly.
Placement Finder:
The PLOE-Adaption is also included in the edited imustat.
All systems need the av.io module from https://github.com/pscholl/PyAV
all other requirements are easy installable with pip.
......@@ -82,44 +82,31 @@ def ploe_adaption_max(acc_stream, gyro_stream, sit1=[], sit2=[], stand=[], sub_s
if __name__ == "__main__":
"""
# one test case
res20 = []
import os
#for file in os.listdir("../../../data/2020-Handwashing"):
parent = "../../../data/My_Recordings/Daily_Living"
for file in os.listdir(parent):
f1 = file
file = parent+ "/"+ f1
#audio = read("a:", file=file)
#sub = read("s:", file=file)
#acc_stream = audio[1]
#gyro_stream = audio[2]
#sub_stream = sub
f = np.load(file)
acc_stream = [i[:3] for i in f]
gyro_stream = [i[3:] for i in f]
# needed properties
# the path to the file
file = "../Proband3.mkv"
# the orientations which should occur if the placement is placed like L1
l1_prop = "--+"
# frequency is only important if it cannot be read from the mkv file from the audio streams
frequency = 100
audios = read("a:", file=file)
acc = "not set"
gyro = "not set"
for a in audios:
if "wrist" in a.info.metadata["BODY_POSITION"].lower() or "forearm" in a.info.metadata["BODY_POSITION"].lower():
if "acc" in a.info.metadata["NAME"].lower():
acc = a
elif "gyr" in a.info.metadata["NAME"].lower():
gyro = a
if not isinstance(acc, str) and not isinstance(gyro, str):
break
# checking if both acceleration and angular velocity data is available
if isinstance(acc, str) or isinstance(gyro, str):
raise Exception("There are no acceleration or gyroscope recordings for the wrist or the forearm available")
res20.append((f1, ploe_adaption_max(acc_stream, gyro_stream, l1_prop="--+")))
print(res20)
res = res20
# in res2020 or res are all data stored for handwashing 2020
r2 = [i for i in res if "Position R2" in i[1][0][0]]
r = [i for i in res if "Position R" in i[1][0][0]]
l = [i for i in res if "Position L" in i[1][0][0]]
al = [i for i in res if "Position L" in i[1][0][0] or "Position R" in i[1][0][0]]
print("R2: ", len(r2))
print("R: ", len(r))
print("L: ", len(l))
print("Al: ", len(al))
print(len(res))
#print(l)
print([i[1][2] for i in al])
print("Timespan:", sum([i[1][1] for i in res])/len(res))
print("Tr high:", sum([i[1][2][0] for i in al])/len(al))
print("Tr low:",sum([i[1][2][1] for i in al])/len(al))
# output: ts = 15sec, t0-1: 9, 3"""
"""
placement, timespan, thresholds, i = ploe_adaption_max(acc_stream=acc, gyro_stream=gyro, sit1=[], sit2=[], stand=[], sub_stream=0, l1_prop=l1_prop, thresholds=(9, 3.5), frequency=frequency)
print("Using a timespan of: ", timespan, "and a threshold of: ", thresholds, "the placement: \t", placement, "was chosen for the file: ", file)
......@@ -5,8 +5,10 @@ placement different characteristics, which result in thresholds for different
features. Depending on the actual values of these features the linter estimates
the placement and
"""
from av.io import read
import numpy as np
def placement_decider(walking_acc, walking_gyro, freq=100, walking_mag=0):
def placement_finder(walking_acc, walking_gyro, freq=100):
"""
This placement decider takes some statistical moments
to decide which body_part is the most probably
......@@ -87,4 +89,62 @@ def placement_decider(walking_acc, walking_gyro, freq=100, walking_mag=0):
else:
if pps_gyr > 0.0005:
pass
return "chest"
return "chest"
def get_walking_sequences(sub, freq):
"""
"""
for act in sub[0]:
# since labels can vary, decision that the probability of sit and stand in
# sitting or standing
if "walk" in act[2].lower():
return int(act[0]/(1000/freq)), int(act[1]/(1000/freq))
return 0, -1
def paired_acc_gyr(sensor_list, position_key):
"""
This function takes a list with sensors and combines every accelerometer
with it's gyroscope, paired by same metadata[position_key]
:args:
sensor_list: List with accelerometer and gyrsocope sensor streams
:return:
List with tuples of accelerometer and gyroscope streams
"""
# print("paired")
for s in sensor_list:
if s.info.metadata["NAME"].lower() in "accelerometer":
acc = s
for s2 in sensor_list:
if s2.info.metadata["NAME"].lower() in "gyroscope" and \
s2.info.metadata[position_key] == acc.info.metadata[position_key]:
gyr = s2
yield acc, gyr
def placement_finder_one_file(file, position_key):
sub = read("s:", file=file)
audio = read("a:", file=file)
paired_list = list(paired_acc_gyr(audio, position_key))
freq = paired_list[0][0].info.sample_rate
start, end = get_walking_sequences(sub, freq)
for acc, gyr in paired_list:
if len(acc) < end or len(gyr) < end:
print("For the ", acc.info.metadata[position_key], "is no walking sequence available")
else:
walking_acc = acc[start:end]
walking_gyro = gyr[start:end]
placement = placement_finder(walking_acc, walking_gyro, freq=freq)
print("For the metadata palcement:\t", acc.info.metadata[position_key], "was the:\t", placement, "chosen")
if __name__ == "__main__":
#set path to file
file = "../Proband3.mkv"
position_key = "BODY_POSITION"
placement_finder_one_file(file, position_key)
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