diff --git a/src/conversion_scripts/convert_marc.py b/src/conversion_scripts/convert_marc.py index e4e037460c3267963747f3b1d40dd07eef813cf2..5640ca6775ee46f46f4a18a37d69ec16a52b98f4 100644 --- a/src/conversion_scripts/convert_marc.py +++ b/src/conversion_scripts/convert_marc.py @@ -19,7 +19,7 @@ import robofish.io def convertTrajectory(path, save_path, categories): ar = pd.read_csv(path, sep=";").to_numpy() - new = robofish.io.File(world_size_cm=[100, 100], frequency_hz=20) + new = robofish.io.File(world_size_cm=[100, 100], frequency_hz=25) # convert x,y from m to cm ar[:, [0, 1, 3, 4]] = ar[:, [0, 1, 3, 4]] * 100 diff --git a/src/robofish/evaluate/evaluate.py b/src/robofish/evaluate/evaluate.py index 6670645a03ce8a6460a6e4febbbc63b3c8e32e74..a5719a5037c76b7ce76256d9481ea5ad1e342824 100644 --- a/src/robofish/evaluate/evaluate.py +++ b/src/robofish/evaluate/evaluate.py @@ -87,7 +87,7 @@ def evaluate_speed( if labels is None: labels = paths - plt.hist(speeds, bins=20, label=labels, density=True, range=[0, 50]) + plt.hist(speeds, bins=20, label=labels, density=True, range=[0, 25]) plt.title("Agent speeds") plt.xlabel("Speed [cm/s]") plt.ylabel("Frequency") @@ -147,7 +147,7 @@ def evaluate_turn( labels = paths # TODO: Quantil range - plt.hist(turns, bins=40, label=labels, density=True, range=[-30, 30]) + plt.hist(turns, bins=41, label=labels, density=True, range=[-30, 30]) plt.title("Agent turns") plt.xlabel("Change in orientation [Degree / timestep at %dhz]" % frequency) plt.ylabel("Frequency") @@ -193,8 +193,8 @@ def evaluate_orientation( world_size[0] / 2, world_size[1] / 2, ] - xbins = np.linspace(world_bounds[0], world_bounds[2], 10) - ybins = np.linspace(world_bounds[1], world_bounds[3], 10) + xbins = np.linspace(world_bounds[0], world_bounds[2], 11) + ybins = np.linspace(world_bounds[1], world_bounds[3], 11) ret_1 = stats.binned_statistic_2d( poses[:, 0], poses[:, 1], poses[:, 2], "mean", bins=[xbins, ybins] ) @@ -226,13 +226,13 @@ def evaluate_orientation( plot = ax[i].pcolormesh( xx, - yy * (-1), + yy, np.arctan2(s_2, s_1).T, vmin=-np.pi, vmax=np.pi, cmap="twilight", ) - # cbar = plt.colorbar(plot, ax=ax[i], pad=0.015, aspect=10) + cbar = plt.colorbar(plot, ax=ax[i], pad=0.015, aspect=10) show_values(plot) if save_path is None: @@ -419,7 +419,10 @@ def evaluate_tankpositions( ax[i].set_xlim(-world_bounds[i][0] / 2, world_bounds[i][0] / 2) ax[i].set_ylim(-world_bounds[i][1] / 2, world_bounds[i][1] / 2) - sns.kdeplot(x=x_pos[i], y=y_pos[i] * (-1), n_levels=25, shade=True, ax=ax[i]) + ax[i].set_xlabel("x [cm]") + ax[i].set_ylabel("y [cm]") + + sns.kdeplot(x=x_pos[i], y=y_pos[i], n_levels=25, shade=True, ax=ax[i]) if save_path is None: plt.show() @@ -450,21 +453,26 @@ def evaluate_trajectories( pos = [] world_bounds = [] for k, files in enumerate(files_per_path): + path_poses = [] for p, file in files.items(): poses = file.select_entity_poses( None if predicate is None else predicate[k] ) world_bounds.append(file.attrs["world_size_cm"]) - path_pos = { - fish: pd.DataFrame({"x": poses[fish, :, 0], "y": poses[fish, :, 1]}) - for fish in range(len(poses)) - } - combined = pd.concat( - [ - path_pos[fish].assign(Agent=f"Agent {fish}") - for fish in path_pos.keys() - ] - ) + path_poses.append(poses[:, :, :2]) + poses = np.concatenate(path_poses, axis = 1) + + path_pos = { + fish: pd.DataFrame({"x": poses[fish, :, 0], "y": poses[fish, :, 1]}) + for fish in range(len(poses)) + } + combined = pd.concat( + [ + path_pos[fish].assign(Agent=f"Agent {fish}") + for fish in path_pos.keys() + ] + ) + pos.append((path_pos, combined)) fig, ax = plt.subplots(1, len(pos), figsize=(len(pos) * 8, 8)) @@ -481,7 +489,7 @@ def evaluate_trajectories( ax[i].set_title("Trajectories (%s)" % labels[i]) ax[i].set_xlim(-world_bounds[i][0] / 2, world_bounds[i][0] / 2) ax[i].set_ylim(-world_bounds[i][1] / 2, world_bounds[i][1] / 2) - ax[i].invert_yaxis() + # ax[i].invert_yaxis() ax[i].xaxis.set_ticks_position("top") ax[i].xaxis.set_label_position("top") ax[i].yaxis.set_ticks_position("left") @@ -557,11 +565,10 @@ def evaluate_positionVec( worldBoundsX, worldBoundsY = max(worldBoundsX), max(worldBoundsY) for i in range(len(posVec)): - df = pd.DataFrame({"x": posVec[i][:, 0], "y": posVec[i][:, 1] * (-1)}) + df = pd.DataFrame({"x": posVec[i][:, 0], "y": posVec[i][:, 1]}) grid = sns.displot(df, x="x", y="y", binwidth=(10, 10), cbar=True) grid.axes[0, 0].set_xlabel("x [cm]") grid.axes[0, 0].set_ylabel("y [cm]") - # print(worldBoundsX, worldBoundsY) grid.set(xlim=(-worldBoundsX, worldBoundsX)) grid.set(ylim=(-worldBoundsY, worldBoundsY)) grids.append(grid) @@ -636,12 +643,12 @@ def evaluate_follow_iid( } ) + plt.rcParams["lines.markersize"] = 1 grid = sns.jointplot( x="IID [cm]", y="Follow", data=follow_iid_data, linewidth=0, - s=1, kind="scatter", xlim=(0, maxDist), ylim=(-5, 5), @@ -682,7 +689,7 @@ def evaluate_all( predicate: a lambda function, selecting entities (example: lambda e: e.category == "fish") """ - save_folder = Path(save_folder) + # save_folder = Path(save_folder) evaluate_speed(paths, labels, save_folder + "speed.png", predicate) evaluate_turn(paths, labels, save_folder + "turn.png", predicate) evaluate_orientation(paths, labels, save_folder + "orientation.png", predicate)