From 74a313070e5ea437c6b5c0e78ee15fc0fc2db72c Mon Sep 17 00:00:00 2001 From: Frederike Duembgen Date: Tue, 28 Jun 2022 22:40:10 -0400 Subject: [PATCH] Final adjustments for revision plots --- crazyflie-audio | 2 +- python/DistanceFlying.ipynb | 79 +++++++++++++--------------- python/Makefile | 22 ++++---- python/StepperAnalysis.ipynb | 8 ++- python/generate_filtering_results.py | 9 ++++ python/generate_flying_results.py | 2 + 6 files changed, 66 insertions(+), 56 deletions(-) diff --git a/crazyflie-audio b/crazyflie-audio index 5471fc30..30d2daf6 160000 --- a/crazyflie-audio +++ b/crazyflie-audio @@ -1 +1 @@ -Subproject commit 5471fc306642426d39b6f1f2cdc281219920cc91 +Subproject commit 30d2daf61ea80438f33e1ca4437e5160b30c5925 diff --git a/python/DistanceFlying.ipynb b/python/DistanceFlying.ipynb index ff5d9d8d..c2a723c8 100644 --- a/python/DistanceFlying.ipynb +++ b/python/DistanceFlying.ipynb @@ -382,7 +382,7 @@ "PLOT_D_MAX = 30\n", "\n", "no_deco = True\n", - "fig_size = (8, 4)\n", + "fig_size = (6, 3)\n", "\n", "chosen_calibration_param = 0.3\n", "simplify_angles = False\n", @@ -409,7 +409,7 @@ "#for estimator in [\"moving\"]: #[\"particle\"]:#, \"moving\"]:\n", "for estimator in [\"particle\"]:\n", "#for estimator in [\"histogram\", \"moving\", \"particle\"]:#, \"moving\"]:\n", - " fig_cdf, axs_cdf = plt.subplots(1, 2)\n", + " fig_cdf, axs_cdf = plt.subplots(1, 2, sharey=True)\n", " fig_cdf.set_size_inches(*fig_size_cdf)\n", " for i_app, appendix in enumerate(appendices):\n", " \n", @@ -479,10 +479,15 @@ " ax.set_title(f\" exp{appendix} {estimator}\".replace(\"_\", \"\\\\_\"))\n", " fig.set_size_inches(*fig_size)\n", "\n", + " lines = []; leg_labels = []\n", + " line, = axs_cdf[1].plot([], [], color=\"C0\")\n", + " lines.append(line); leg_labels.append(\"dataset \\nglass wall\")\n", + " line, = axs_cdf[1].plot([], [], color=\"C1\")\n", + " lines.append(line); leg_labels.append(\"dataset \\nwhiteboard\")\n", + " \n", " # generate random\n", " d_random = np.random.choice(range(*D_RANGE), size=len(gt_distances))\n", " a_random = np.random.choice(range(360), size=len(gt_angles))\n", - " lines = []; leg_labels = []\n", " axs_cdf[0].plot(sorted(np.abs(d_random-gt_distances)), np.linspace(0, 1, len(gt_distances)), color=color[\"random\"])\n", " line, = axs_cdf[1].plot(sorted(np.abs(angle_error(a_random, gt_angles))), np.linspace(0, 1, len(gt_angles)), color=color[\"random\"])\n", " lines.append(line); leg_labels.append(\"random\")\n", @@ -494,11 +499,7 @@ " lines.append(line); leg_labels.append(\"fixed\")\n", "\n", " axs_cdf[1].plot(sorted(np.abs(angle_error(a_fixed, gt_angles))), np.linspace(0, 1, len(gt_angles)), ls=\":\", color=color[\"fixed\"])\n", - " line, = axs_cdf[1].plot([], [], color=\"C0\")\n", - " lines.append(line); leg_labels.append(\"dataset glass wall\")\n", - " line, = axs_cdf[1].plot([], [], color=\"C1\")\n", - " lines.append(line); leg_labels.append(\"dataset whiteboard\")\n", - " axs_cdf[1].legend(lines, leg_labels, title=\"used data\", loc=\"upper left\", bbox_to_anchor=[1.0, 0.5])\n", + " axs_cdf[1].legend(lines, leg_labels, title=\"used data\", loc=\"upper left\", bbox_to_anchor=[1.0, 0.8])\n", "\n", " axs_cdf[0].grid(True)\n", " axs_cdf[1].grid(True)\n", @@ -507,11 +508,11 @@ " axs_cdf[0].set_title(\"distance estimation\")\n", " axs_cdf[1].set_title(\"angle estimation\")\n", " axs_cdf[0].set_ylabel(\"cdf [-]\")\n", - " axs_cdf[1].set_ylabel(\"cdf [-]\")\n", + " #axs_cdf[1].set_ylabel(\"cdf [-]\")\n", " axs_cdf[0].set_xlim(0, PLOT_D_MAX)\n", " axs_cdf[1].set_xlim(0, 200)\n", " fig_cdf.set_size_inches(*fig_size)\n", - " fig_cdf.subplots_adjust(wspace=0.3)\n", + " fig_cdf.subplots_adjust(wspace=0.1)\n", " if beamform:\n", " save_fig(fig_cdf, f\"plots/experiments/{exp_name}_{discretization.replace(' ','_')}_{estimator}_beamform_cdfs.pdf\")\n", " else:\n", @@ -531,7 +532,7 @@ "cell_type": "code", "execution_count": null, "metadata": { - "scrolled": true + "scrolled": false }, "outputs": [], "source": [ @@ -555,6 +556,10 @@ " \"pyroom\": \" simulated\",\n", " \"\": \"\"\n", "}\n", + "rename = {\n", + " \"stepper\": \"drone\",\n", + " \"epuck\": \"e-puck\",\n", + "}\n", "\n", "fig_hor, (ax_dist, ax_ang) = plt.subplots(2, 1, sharex=True)\n", "\n", @@ -588,7 +593,8 @@ " d_errors = d_estimates - gt_distances_here\n", " cdf_distances = np.sort(np.abs(d_errors))\n", " y = np.linspace(0, 1, len(cdf_distances))\n", - " axs_cdf[0].plot(cdf_distances, y, ls=linestyles[simulate], label=name+names[simulate], color=color[name])\n", + " label=rename[name] if simulate == \"\" else None\n", + " axs_cdf[0].plot(cdf_distances, y, ls=linestyles[simulate], label=label, color=color[name])\n", " ax_dist.plot(gt_distances_here, d_errors, color=color[name], ls=linestyles[simulate])\n", "\n", " a_estimates = get_estimates_here(matrix_angles, a_here)\n", @@ -599,7 +605,8 @@ " \n", " cdf_angles = np.sort(np.abs(a_errors))\n", " y = np.linspace(0, 1, len(cdf_angles))\n", - " axs_cdf[1].plot(cdf_angles, y, ls=linestyles[simulate], label=name+names[simulate], color=color[name])\n", + " label=rename[name] if simulate == \"\" else None\n", + " axs_cdf[1].plot(cdf_angles, y, ls=linestyles[simulate], label=label, color=color[name])\n", "\n", " fig, ax = plot_matrix(d_here, matrix_distances, #xvalues=times, \n", " gt_values=gt_distances_here,\n", @@ -624,29 +631,35 @@ "a_fixed = gt_angles[0] + 180\n", "axs_cdf[0].plot(sorted(np.abs(d_fixed-gt_distances_here)), np.linspace(0, 1, len(gt_distances_here)), ls=\":\", color=color[\"fixed\"], label=\"fixed\")\n", "axs_cdf[1].plot(sorted(np.abs(angle_error(a_fixed, gt_angles_here))), np.linspace(0, 1, len(gt_angles_here)), ls=\":\", color=color[\"fixed\"], label=\"fixed\")\n", - "axs_cdf[1].legend(title=\"used data\", loc=\"upper left\", bbox_to_anchor=[1.0, 0.75])\n", + "\n", + "#axs_cdf[1].legend(title=\"used data\", loc=\"upper left\", bbox_to_anchor=[1.0, 0.75])\n", + "axs_cdf[1].legend(title=\"used data\", loc=\"lower right\", framealpha=1.0)\n", "\n", "axs_cdf[0].grid(True)\n", "axs_cdf[1].grid(True)\n", - "axs_cdf[0].set_xlabel(\"absolute distance error [cm]\")\n", - "axs_cdf[1].set_xlabel(\"absolute angle error [deg]\")\n", + "axs_cdf[0].set_xlabel(\"absolute error [cm]\")\n", + "axs_cdf[1].set_xlabel(\"absolute error [deg]\")\n", "axs_cdf[0].set_title(\"distance estimation\")\n", "axs_cdf[1].set_title(\"angle estimation\")\n", "axs_cdf[0].set_ylabel(\"cdf [-]\")\n", "#axs_cdf[1].set_ylabel(\"cdf [-]\")\n", "axs_cdf[0].set_xlim(0, PLOT_D_MAX)\n", "axs_cdf[1].set_xlim(0, 200)\n", - "fig_cdf.set_size_inches(8, 4)\n", + "fig_cdf.set_size_inches(5, 4)\n", "#fig_cdf.subplots_adjust(wspace=0.3)\n", "\n", - "fig_hor.set_size_inches(4, 4)\n", + "fig_hor.set_size_inches(3, 4)\n", + "\n", "ax_ang.set_xlabel(\"distance [cm]\")\n", "#ax_dist.set_xlabel(\"distance [cm]\")\n", "ax_dist.set_title(\"error evolution\")\n", - "ax_ang.set_ylabel(\"angle error [deg]\", x=1.5)\n", + "\n", + "ax_ang.set_ylabel(\"error [deg]\")\n", + "ax_dist.set_ylabel(\"error [cm]\")\n", + "ax_ang.yaxis.set_label_coords(-0.23,0.5)\n", + "ax_dist.yaxis.set_label_coords(-0.23,0.5)\n", "ax_ang.grid()\n", "ax_dist.grid()\n", - "ax_dist.set_ylabel(\"distance error [cm]\")\n", "if beamform:\n", " save_fig(fig_cdf, f\"plots/experiments/comparison_{estimator}_beamform_cdfs.pdf\")\n", " save_fig(fig_hor, f\"plots/experiments/comparison_{estimator}_beamform.pdf\")\n", @@ -888,7 +901,7 @@ " if i % 20 == 0:\n", " print(f\"{i+1}/{n_timesteps}\")\n", " res = wall_detection.listener_callback_offline(\n", - " signals_f[i].T, freqs, positions_cm[i], yaws_deg[i], timestamp=times[i]*1e3\n", + " signals_f[i], freqs, positions_cm[i], yaws_deg[i], timestamp=times[i]*1e3\n", " )\n", " #fig, ax = plt.subplots()\n", " #ax.pcolorfast(wall_detection.calibration_data[0, :, :])\n", @@ -913,7 +926,9 @@ " #angle_local = wall_detection.estimator.get_local_forward_angle()\n", " #angles_forward.append(angle_local)\n", " \n", - " __, __, prob_moving_dist, prob_moving_angle = res\n", + " prob_moving_dist = res[\"prob_dist_moving\"]\n", + " prob_moving_angle = res[\"prob_angle_moving\"]\n", + " #__, __, prob_moving_dist, prob_moving_angle = res\n", " \n", " results_matrix_moving[:, i] = prob_moving_dist\n", " \n", @@ -949,26 +964,6 @@ "print(\"done\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "plt.figure()\n", - "plt.title(\"factor graph runtime\")\n", - "plt.plot(np.array(runtimes_fg) * 1e3)\n", - "plt.axhline(np.mean(runtimes_fg) * 1e3)\n", - "plt.xlabel(\"time index [-]\")\n", - "plt.ylabel(\"time [ms]\")\n", - "plt.figure()\n", - "plt.title(\"inference runtime\")\n", - "plt.plot(np.array(runtimes_inference) * 1e3)\n", - "plt.axhline(np.mean(runtimes_inference) * 1e3)\n", - "plt.xlabel(\"time index [-]\")\n", - "plt.ylabel(\"time [ms]\")" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/python/Makefile b/python/Makefile index a4d67915..1977b8a6 100644 --- a/python/Makefile +++ b/python/Makefile @@ -4,28 +4,28 @@ EXPERIMENT_ROOT=../datasets .PHONY: stepper_results -all: crazyflie_demo crazyflie_flying crazyflie_stepper_paper epuck_results +all: crazyflie_demo crazyflie_flying crazyflie_stepper epuck_results crazyflie_demo: - #python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_11_23_demo --demo - #python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2022_01_27_demo --demo + python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_11_23_demo --demo + python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2022_01_27_demo --demo python generate_flying_results.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2022_01_27_demo crazyflie_flying: - #python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_10_12_flying + python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_10_12_flying python generate_flying_results.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_10_12_flying crazyflie_stepper: - #python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_08_stepper_fast - #python generate_stepper_results.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_08_stepper_fast + python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_08_stepper_fast + python generate_stepper_results.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_08_stepper_fast python generate_flying_results.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_08_stepper_fast - #python generate_filtering_results.py + python generate_filtering_results.py --platform crazyflie epuck_results: - #python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_27_epuck_wall --platform epuck - #python generate_stepper_results.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_27_epuck_wall --platform epuck - python generate_flying_results.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_27_epuck_wall - #python generate_filtering_results.py + python csv_or_wav_parser.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_27_epuck_wall --platform epuck + python generate_stepper_results.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_27_epuck_wall --platform epuck + python generate_flying_results.py --experiment_root $(EXPERIMENT_ROOT) --experiment_names 2021_07_27_epuck_wall --platform epuck + python generate_filtering_results.py --platform epuck clean: rm $(EXPERIMENT_ROOT)/2021_07_08_stepper_fast/all_data.pkl diff --git a/python/StepperAnalysis.ipynb b/python/StepperAnalysis.ipynb index 31b8cedf..cddd6808 100644 --- a/python/StepperAnalysis.ipynb +++ b/python/StepperAnalysis.ipynb @@ -578,7 +578,7 @@ "colors = plt.get_cmap(\"viridis\", lut=len(plot_df.chosen_mics.unique()))\n", "\n", "fig, axs = plt.subplots(1, 2, sharey=True)\n", - "fig.set_size_inches(8, 4)\n", + "fig.set_size_inches(6, 2)\n", "\n", "for i, (algorithm, df_dis) in enumerate(plot_df.groupby(\"algorithm\", sort=False)):\n", " boxplots = {}\n", @@ -600,7 +600,11 @@ "#ax_plot.boxplot(boxplots.values())\n", "#ax_plot.set_xticklabels(boxplots.keys(), rotation=45)\n", "\n", - "axs[i].legend(loc=\"upper left\", bbox_to_anchor=[1.0,1.0], title=\"used mics\", ncol=2)\n", + "\n", + "fig.subplots_adjust(wspace=0.1)\n", + "axs[1].legend(loc=\"upper left\", bbox_to_anchor=[1.0,1.0], title=\"used mics\", ncol=2)\n", + "handles, labels = axs[i].get_legend_handles_labels()\n", + "axs[1].legend(handles[::1], labels[::1],ncol=2,fontsize=10, title=\"used mics\", loc=\"lower left\", bbox_to_anchor=[1.0, -0.2])\n", "save_fig(fig, f\"plots/experiments/{exp_name}_{discretization.replace(' ', '_')}_mics_cdfs.pdf\")" ] }, diff --git a/python/generate_filtering_results.py b/python/generate_filtering_results.py index 35f739b0..aec5588f 100644 --- a/python/generate_filtering_results.py +++ b/python/generate_filtering_results.py @@ -290,6 +290,15 @@ def fill_random_and_fixed(err_df): if __name__ == "__main__": + from utils.custom_argparser import exp_parser, check_platform + + parser = exp_parser( + "Apply the moving or particle estimator to flying or stepper datasets." + ) + args = parser.parse_args() + + check_platform(args) + if PLATFORM == "crazyflie": exp_name = "2021_07_08_stepper_fast" motors = "all45000" diff --git a/python/generate_flying_results.py b/python/generate_flying_results.py index 42ac9538..0f665865 100644 --- a/python/generate_flying_results.py +++ b/python/generate_flying_results.py @@ -247,6 +247,8 @@ def generate_matrix_results(data_row, parameters, estimator, fname="", verbose=F ) args = parser.parse_args() + check_platform(args) + beamform = False for exp_name in args.experiment_names: