Skip to content

Commit

Permalink
Final adjustments for revision plots
Browse files Browse the repository at this point in the history
  • Loading branch information
duembgen committed Jun 29, 2022
1 parent 9d9dfcc commit 74a3130
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 56 deletions.
2 changes: 1 addition & 1 deletion crazyflie-audio
79 changes: 37 additions & 42 deletions python/DistanceFlying.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -531,7 +532,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
"scrolled": false
},
"outputs": [],
"source": [
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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": {},
Expand Down
22 changes: 11 additions & 11 deletions python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions python/StepperAnalysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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\")"
]
},
Expand Down
9 changes: 9 additions & 0 deletions python/generate_filtering_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions python/generate_flying_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 74a3130

Please sign in to comment.