112 lines
3.8 KiB
Python
112 lines
3.8 KiB
Python
import pandas as pd
|
|
import glob
|
|
import os
|
|
import image_marker as im
|
|
import numpy as np
|
|
import tracking_result as tr
|
|
from IPython import embed
|
|
import matplotlib.pyplot as plt
|
|
|
|
# wir estellen eine Tabelle, die fuer jeden Tag die Setup Configuration enthält.
|
|
# Folgende Spalten:
|
|
# Versuchstag, Datum, light_on_area, feeder_positions, feeder_risks, temperature, salinity
|
|
x_limits = np.array([0, 1.24])
|
|
y_limits = np.array([0, 0.81])
|
|
|
|
def get_risk(position, light_area_y, x_limits, y_limits, light_risk=1):
|
|
"""Calculates the risk associated with a certain position in the arena
|
|
|
|
Args:
|
|
position (iterable): two-element vector of position i.e. (x,y)
|
|
light_area_y (iterable): two element vactor with the start and stop y-coordinates of light area
|
|
light_risk (float, optional): if position is on the bright side, a malus is added. Defaults to 1.
|
|
x_limits : extent of the tank on x axis in cm
|
|
y_limits : extent of the tank on y axis in cm
|
|
|
|
Returns:
|
|
float: the risk for this position
|
|
"""
|
|
min_wall_dist_x = min(np.abs(position[0] - x_limits))
|
|
min_wall_dist_y = min(np.abs(position[1] - y_limits))
|
|
|
|
risk_x = 1/(max(x_limits)/2) * min_wall_dist_x
|
|
risk_y = 1/(max(y_limits)/2) * min_wall_dist_y
|
|
total_risk = min(risk_x, risk_y)
|
|
|
|
is_position_on_the_bright_side = position[1] >= light_area_y[0] and position[1] < light_area_y[1]
|
|
if is_position_on_the_bright_side:
|
|
total_risk = total_risk + light_risk
|
|
return total_risk
|
|
|
|
|
|
def get_feeder_risks(feeder_positions, light_on_area):
|
|
feeder_risks = {}
|
|
if light_on_area['light_center'][1] < light_on_area['left'][1]:
|
|
light_area = [0, light_on_area['left'][1]]
|
|
else:
|
|
light_area = [light_on_area['left'][1], y_limits[1]]
|
|
for k in feeder_positions.keys():
|
|
feeder_risks[k] = get_risk(feeder_positions[k], light_area, x_limits, y_limits)
|
|
embed()
|
|
|
|
|
|
def get_feeder_positions(vid):
|
|
feeder_task = im.MarkerTask("Feeder positions", list(map(str, range(1, 9))), "Mark feeder positions")
|
|
tasks = [feeder_task]
|
|
image_marker = im.ImageMarker(tasks)
|
|
feeder_positions = image_marker.mark_movie(vid, 100)
|
|
for k in feeder_positions[0].keys():
|
|
pos = feeder_positions[0][k]
|
|
new_pos = tr.coordinate_transformation(pos)
|
|
feeder_positions[0][k] = new_pos
|
|
return feeder_positions[0]
|
|
|
|
|
|
def get_light_on_area(vid):
|
|
light_on_task = im.MarkerTask("Light ON", ["left", "right", "light_center"], "Mark light on area")
|
|
tasks = [light_on_task]
|
|
image_marker = im.ImageMarker(tasks)
|
|
marker_positions = image_marker.mark_movie(vid, 100)
|
|
for k in marker_positions[0].keys():
|
|
pos = marker_positions[0][k]
|
|
new_pos = tr.coordinate_transformation(pos)
|
|
marker_positions[0][k] = new_pos
|
|
print(marker_positions)
|
|
return marker_positions[0]
|
|
|
|
|
|
def check_day(path):
|
|
vids = sorted(glob.glob(os.path.join(path, '*.mp4')))
|
|
if len(vids) < 1:
|
|
return
|
|
vid = vids[0]
|
|
la = get_light_on_area(vid)
|
|
fp = get_feeder_positions(vid)
|
|
fr = get_feeder_risks(fp, la)
|
|
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
folder = '/mnt/movies/merle_verena/boldness/labeled_videos'
|
|
days = sorted(glob.glob(os.path.join(folder, 'day*')))
|
|
x_range = np.arange(0.0, 1.24, .01)
|
|
y_range = np.arange(0.0, .82, .01)
|
|
risk_matrix = np.zeros((len(x_range), len(y_range)))
|
|
|
|
"""
|
|
light_on = [0.5687952439426905, 0.82]
|
|
#light_on = [0, 0.5687952439426905]
|
|
# light_on = [45.5, 81]
|
|
|
|
for i, x in enumerate(x_range):
|
|
for j, y in enumerate(y_range):
|
|
risk_matrix[i, j] = get_risk([x, y], light_on, x_limits=x_limits, y_limits=y_limits )
|
|
plt.imshow(risk_matrix.T, origin='lower')
|
|
plt.show()
|
|
exit()
|
|
"""
|
|
for d in days:
|
|
check_day(d)
|
|
print(d)
|
|
exit() |