Skip to content
Snippets Groups Projects
Commit c5b26ddb authored by Andi Gerken's avatar Andi Gerken
Browse files

Merge branch 'develop' into 'master'

Fixed internal issues with wrong conversions of speeds and turns.

See merge request !18
parents 58b37a81 79c40e50
Branches
Tags 0.2.1
1 merge request!18Fixed internal issues with wrong conversions of speeds and turns.
Pipeline #38494 passed
......@@ -63,14 +63,14 @@ As described in `robofish.io`, Files and Entities have useful properties.
<small>
| Entity function | Description |
| ------------------------------------------------ | ------------------------------------------------------------------------ |
| `robofish.io.entity.Entity.positions` | Positions as a `(timesteps, 2 (x, y))` array. |
| `robofish.io.entity.Entity.orientations` | Orientations as a `(timesteps, 2 (ori_x, ori_y))` array. |
| `robofish.io.entity.Entity.orientations_rad` | Orientations as a `(timesteps, 1 (ori_rad))` array. |
| `robofish.io.entity.Entity.poses` | Poses as a `(timesteps, 4 (x, y, x_ori, y_ori))` array. |
| `robofish.io.entity.Entity.poses_rad` | Poses as a `(timesteps, 3(x, y, ori_rad))` array. |
| `robofish.io.entity.Entity.actions_speeds_turns` | Speed and turn as a `(timesteps - 1, 2 (speed_cm/s, turn_rad/s))` array. |
| Entity function | Description |
| ------------------------------------------------ | -------------------------------------------------------------------------------------- |
| `robofish.io.entity.Entity.positions` | Positions as a `(timesteps, 2 (x, y))` array. |
| `robofish.io.entity.Entity.orientations` | Orientations as a `(timesteps, 2 (ori_x, ori_y))` array. |
| `robofish.io.entity.Entity.orientations_rad` | Orientations as a `(timesteps, 1 (ori_rad))` array. |
| `robofish.io.entity.Entity.poses` | Poses as a `(timesteps, 4 (x, y, x_ori, y_ori))` array. |
| `robofish.io.entity.Entity.poses_rad` | Poses as a `(timesteps, 3(x, y, ori_rad))` array. |
| `robofish.io.entity.Entity.actions_speeds_turns` | Speed and turn as a `(timesteps - 1, 2 (speed in cm/frame, turn in rad/frame))` array. |
</small>
......
......@@ -124,14 +124,14 @@ In the same scheme the following properties are available:
<small>
| File/ Entity function | Description |
| ----------------------------- | ------------------------------------------------------------------------------------ |
| *entity_*positions | Positions as a `(*entities*, timesteps, 2 (x, y))` arary. |
| *entity_*orientations | Orientations as a `(*entities*, timesteps, 2 (ori_x, ori_y))` arary. |
| *entity_*orientations_rad | Orientations as a `(*entities*, timesteps, 1 (ori_rad))` arary. |
| *entity_*poses | Poses as a `(*entities*, timesteps, 4 (x, y, x_ori, y_ori))` array. |
| *entity_*poses_rad | Poses as a `(*entities*, timesteps, 3(x, y, ori_rad))` array. |
| *entity_*actions_speeds_turns | Speed and turn as a `(*entities*, timesteps - 1, 2 (speed_cm/s, turn_rad/s))` array. |
| File/ Entity function | Description |
| ----------------------------- | -------------------------------------------------------------------------------------------------- |
| *entity_*positions | Positions as a `(*entities*, timesteps, 2 (x, y))` array. |
| *entity_*orientations | Orientations as a `(*entities*, timesteps, 2 (ori_x, ori_y))` array. |
| *entity_*orientations_rad | Orientations as a `(*entities*, timesteps, 1 (ori_rad))` array. |
| *entity_*poses | Poses as a `(*entities*, timesteps, 4 (x, y, x_ori, y_ori))` array. |
| *entity_*poses_rad | Poses as a `(*entities*, timesteps, 3(x, y, ori_rad))` array. |
| *entity_*actions_speeds_turns | Speed and turn as a `(*entities*, timesteps - 1, 2 (speed in cm/frame, turn in rad/frame))` array. |
</small>
......
......@@ -8,7 +8,7 @@ extend-ignore = "E203"
[tool.black]
line-length = 88
include =''
include ='\.py'
[tool.pytest.ini_options]
filterwarnings = ["error"]
\ No newline at end of file
......@@ -73,11 +73,18 @@ def evaluate_speed(
"""
files_per_path = [robofish.io.read_multiple_files(p) for p in paths]
speeds = []
frequency = None
for k, files in enumerate(files_per_path):
path_speeds = []
for p, file in files.items():
assert frequency is None or frequency == file.frequency
frequency = file.frequency
for e_speeds_turns in file.entity_actions_speeds_turns:
path_speeds = np.concatenate([path_speeds, e_speeds_turns[:, 0]])
path_speeds = np.concatenate(
[path_speeds, e_speeds_turns[:, 0] * frequency]
)
speeds.append(path_speeds)
if labels is None:
......@@ -91,7 +98,7 @@ def evaluate_speed(
plt.title("Agent speeds")
plt.xlabel("Speed [cm/s]")
plt.ylabel("Frequency")
plt.ticklabel_format(useOffset=False)
plt.ticklabel_format(useOffset=False, style="plain")
plt.legend()
plt.tight_layout()
......@@ -130,14 +137,14 @@ def evaluate_turn(
frequency = file.frequency
for e_speeds_turns in file.entity_actions_speeds_turns:
path_turns.extend(e_speeds_turns[:, 1])
path_turns.extend(np.rad2deg(e_speeds_turns[:, 1]))
turns.append(path_turns)
if labels is None:
labels = paths
left_quantile = np.min(np.quantile(np.array(turns), 0.001, axis=1))
right_quantile = np.max(np.quantile(np.array(turns), 0.999, axis=1))
left_quantile = np.min(np.quantile(np.array(turns), 0.005, axis=1))
right_quantile = np.max(np.quantile(np.array(turns), 0.995, axis=1))
plt.hist(
turns,
bins=41,
......@@ -148,7 +155,7 @@ def evaluate_turn(
plt.title("Agent turns")
plt.xlabel("Change in orientation [Degree / timestep at %dhz]" % frequency)
plt.ylabel("Frequency")
plt.ticklabel_format(useOffset=False)
plt.ticklabel_format(useOffset=False, style="plain")
plt.legend()
# plt.tight_layout()
......
......@@ -241,15 +241,12 @@ class Entity(h5py.Group):
def actions_speeds_turns(self):
"""Calculate the speed, turn and from the recorded positions and orientations.
The turn is calculated by the change of orientation.
The turn is calculated by the change of orientation between frames.
The speed is calculated by the distance between the points, projected on the new orientation vector.
The sideway change of position cannot be represented with this method.
Returns:
An array with shape (number_of_positions -1, 3).
The first column is the speed (distance projected on new orientation).
The second column is the turning angle.
An array with shape (number_of_positions -1, 2 (speed in cm/frame, turn in rad/frame).
"""
ori = self.orientations
......
......@@ -463,6 +463,15 @@ class File(h5py.File):
@property
def entity_actions_speeds_turns(self):
"""Calculate the speed, turn and from the recorded positions and orientations.
The turn is calculated by the change of orientation between frames.
The speed is calculated by the distance between the points, projected on the new orientation vector.
The sideway change of position cannot be represented with this method.
Returns:
An array with shape (number_of_entities, number_of_positions -1, 2 (speed in cm/frame, turn in rad/frame).
"""
return self.select_entity_property(
None, entity_property=Entity.actions_speeds_turns
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment