Commit f9ecd67b authored by dhomm's avatar dhomm
Browse files

combined sensor finder changes

parent 477ea2cc
......@@ -27,7 +27,7 @@ Using a timespan of: 0.9 and a threshold of: (9, 3.5) the placement: ('Posit
Placement Finder:
To run only the Placement Finder for one file go to the placement_finder
and run
python3 placement_finder
python3 placement_finder.py
The result should be:
For the metadata palcement: chest was the: chest chosen
For the metadata palcement: forearm was the: forearm chosen
......@@ -38,7 +38,23 @@ For the metadata palcement: upperarm was the: upper arm chosen
For the metadata palcement: waist was the: waist chosen
Sensor
Sensor Finder:
To run only the Sensor Finder for one file go to the sensor_finder
and run:
python3 sensor_finder.py
The result should be:
For the wanted placement: forearm the sensor with the metadata placement: forearm was chosen.
All available metadata placements were: ['chest', 'forearm', 'head', 'shin', 'thigh', 'upperarm', 'waist']
Combined Sensor Finder:
To run only the Sensor Finder for one file go to the combined-sensor-finder
and run:
python3 combined-sensor-finder.py
The result should be:
For the wanted placement: forearm the sensor with the metadata placement: forearm was chosen.
All available metadata placements were: ['chest', 'forearm', 'head', 'shin', 'thigh', 'upperarm', 'waist']
......
......@@ -3,7 +3,8 @@
from placement_finder import *
from sensor_finder import *
def combined_sensor_finder(sensors, placement, position_key, acc_freq=0, gyr_freq=0):
def combined_sensor_finder(sensors, placement, acc_freq=0, gyr_freq=0):
"""
This function compares certain thresholds and compares sensors
pairwise to decide which sensor belongs to a given placement.
......@@ -21,7 +22,6 @@ def combined_sensor_finder(sensors, placement, position_key, acc_freq=0, gyr_fre
placement: one placement as string
position_key: the key as string which can identify related accelerometer and gyroscope streams
:return:
The accelerometer and gyroscope stream which is most likely to belong to the given placement
"""
......@@ -38,7 +38,7 @@ def combined_sensor_finder(sensors, placement, position_key, acc_freq=0, gyr_fre
print("Are you sure these are correct sensors? ")
freq = acc_freq
else:
print("Needs to be implemented if frequencies are different for accelerometer and gyroscope \n \
print("Not yet implemented if frequencies are different for accelerometer and gyroscope \n \
The Accelerometer freq will be used ")
freq = sensors[0][0].info.sample_rate
......@@ -430,3 +430,87 @@ def combined_sensor_finder(sensors, placement, position_key, acc_freq=0, gyr_fre
else:
return "This placement is not in a subset of the used data set"
def combination_linter(file, placement, bp_key=0):
"""
This function checks for one given configuration
which sensor pair is most likely related to the wanted placement
:args:
file: the file path
placement: the wanted placement
bp_key: the key for the metadata to get the on-body placement (in the metadata) of a sensor.
If this key is not available choose another key to identify related accelerometers and gyroscopes.
The result will still be the chosen sensor pair however the printed results will not be usefull anymore.
:return:
accelerometer stream, gyroscope stream
"""
a = read("a:", file=file)
s = read("s:", file=file)
# remove all sensors except accelerometer and gyroscope
a = get_acc_gyr(a)
# get the frequency
try:
freq1 = a[0].info.sample_rate
freq2 = a[1].info.sample_rate
if freq1 == freq2:
freq = freq1
else:
raise Exception("The frequency of sensor 0 and sensor 1 need to be the same")
except:
raise Exception("Either there are to few sensors available or sensor 0 and sensor 1 has no frequency or not the same frequency")
key = bp_key #"BODY_POSITION"
start, end = get_walking_sequences(s, freq)
sensors = get_acc_gyr(a)
# filter body parts which cannot be compared yet
bps = ["chest", "forearm", "wrist", "head", "thigh", "shin", "upperarm", "upper arm", "waist"]
s_help = []
for i in sensors:
if i.info.metadata[key].lower() in bps:
s_help.append(i)
sensors = s_help
minimum = min([len(stream) for stream in sensors])
sensors = [stream[start:end] for stream in sensors]
combi = list(paired_acc_gyr(sensors, key))
if not minimum > end:
if minimum < start:
i = 0
while i < len(combi):
if len(combi[i][0]) < start or len(combi[i][1]) < start:
combi.pop(i)
print("The matadata placement: ", combi[i][0].info.metadata[key], "needed to be discarded since ther was no walking sequence available")
discarded_placement = combi[i][0].info.metadata[key]
else:
i += 1
minimum = min([len(combi[i][0]) for i in range(len(combi))] + [len(combi[i][1]) for i in range(len(combi))])
if minimum < end:
end = minimum
print("So all sensors could be included in the decisiion process the end needed to be reset to: ", end)
elif minimum < end:
end = minimum
print("So all sensors could be included in the decisiion process the end needed to be reset to: ", end)
if start > end:
raise Exception("Somethings wrong with the walking data the start is after the end")
result = combined_sensor_finder(combi, placement, acc_freq=0, gyr_freq=0)
acc, gyr = result
print("For the wanted placement: ", placement, "the sensor with the metadata placement: ", acc.info.metadata[key], "was chosen.")
print("All available metadata placements were: ", [s[0].info.metadata[bp_key] for s in combi])
return result
if __name__ == "__main__":
# set properties
file = "../Proband3.mkv"
placement = "forearm"
bp_key = "BODY_POSITION"
combination_linter(file, placement, bp_key)
......@@ -5,6 +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
from numpy import mean, sqrt, square, var, corrcoef, std, quantile, percentile
from scipy.stats import skew, kurtosis
def placement_decider(walking_acc, walking_gyro, freq=100, walking_mag=0):
"""
......
......@@ -210,7 +210,7 @@ def n_placement_restriction(n, paired_sensors, restrictions):
break
return p_s
def sensor_finder(sensors, placement, position_key):
def sensor_finder(sensors, placement):
"""
This function compares certain thresholds and compares sensors
pairwise to decide which sensor belongs to a given placement.
......@@ -225,7 +225,6 @@ def sensor_finder(sensors, placement, position_key):
placement: one placement as string
position_key: the key as string which can identify related accelerometer and gyroscope streams
:return:
The accelerometer and gyroscope stream which is most likely to belong to the given placement
"""
......@@ -397,6 +396,19 @@ def sensor_finder(sensors, placement, position_key):
def combination_linter(file, placement, bp_key):
"""
This function checks for one given configuration
which sensor pair is most likely related to the wanted placement
:args:
file: the file path
placement: the wanted placement
bp_key: if available, the key for the metadata to get the on-body placement (in the metadata) of a sensor
:return:
accelerometer stream, gyroscope stream
"""
a = read("a:", file=file)
s = read("s:", file=file)
# remove all sensors except accelerometer and gyroscope
......@@ -449,7 +461,7 @@ def combination_linter(file, placement, bp_key):
if start > end:
raise Exception("Somethings wrong with the walking data the start is after the end")
result = sensor_finder(combi, placement, key)
result = sensor_finder(combi, placement)
acc, gyr = result
print("For the wanted placement: ", placement, "the sensor with the metadata placement: ", acc.info.metadata[key], "was chosen.")
......
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