diff --git a/docs/notebooks/path_and_velocity_copy.ipynb b/docs/notebooks/path_and_velocity_copy.ipynb deleted file mode 100644 index 2baf4e9..0000000 --- a/docs/notebooks/path_and_velocity_copy.ipynb +++ /dev/null @@ -1,299 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Show some statistics of the enclosed geometric object with psydat file" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "from psychopy.misc import fromFile\n", - "from vstt.stats import get_velocity" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Import\n", - "A psydat file can be imported using the psychopy `fromFile` function: \n", - "If you want to know the detailed content of the data in psydat file, please check the notebook 'raw_data.ipynb'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "psydata = fromFile(\"example.psydat\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Plot of results for each trial\n", - "For example, a scatter plot of the mouse positions for each trial, labelled by the condition, trial number and repetition number:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "colors = [\"blue\", \"green\", \"red\", \"cyan\", \"magenta\", \"yellow\", \"black\", \"orange\"]\n", - "\n", - "nTrials, nReps = psydata.sequenceIndices.shape\n", - "fig, axs = plt.subplots(nTrials, nReps, figsize=(6, 6 * nTrials * nReps))\n", - "axs = np.reshape(\n", - " axs, (nTrials, nReps)\n", - ") # ensure axs is a 2d-array even if nTrials or nReps is 1\n", - "for trial in range(nTrials):\n", - " for rep in range(nReps):\n", - " loc = (trial, rep)\n", - " condition = psydata.sequenceIndices[loc]\n", - " target_radius = psydata.trialList[condition][\"target_size\"]\n", - " central_target_radius = psydata.trialList[condition][\"central_target_size\"]\n", - " ax = axs[loc]\n", - " ax.set_title(f\"Trial {trial}, Rep {rep} [Condition {condition}]\")\n", - " for positions, target_pos, color in zip(\n", - " psydata.data[\"to_target_mouse_positions\"][loc],\n", - " psydata.data[\"target_pos\"][loc],\n", - " colors,\n", - " ):\n", - " ax.plot(positions[:, 0], positions[:, 1], color=color)\n", - " ax.add_patch(\n", - " plt.Circle(\n", - " target_pos,\n", - " target_radius,\n", - " edgecolor=\"none\",\n", - " facecolor=color,\n", - " alpha=0.1,\n", - " )\n", - " )\n", - " if not psydata.trialList[condition][\"automove_cursor_to_center\"]:\n", - " for positions, color in zip(\n", - " psydata.data[\"to_center_mouse_positions\"][loc],\n", - " colors,\n", - " ):\n", - " ax.plot(positions[:, 0], positions[:, 1], color=color)\n", - " ax.add_patch(\n", - " plt.Circle(\n", - " [0, 0],\n", - " central_target_radius,\n", - " edgecolor=\"none\",\n", - " facecolor=\"black\",\n", - " alpha=0.1,\n", - " )\n", - " )\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Plot of results for each target\n", - "For example, a scatter plot of the mouse positions for each target, labelled by trial number, repetition number, target number and condition:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fig, axs = plt.subplots(nTrials, nReps * 8, figsize=(6 * 8, 6 * nTrials * nReps))\n", - "axs = np.reshape(\n", - " axs, (nTrials, nReps * 8)\n", - ") # ensure axs is a 2d-array even if nTrials or nReps is 1\n", - "for trial in range(nTrials):\n", - " for rep in range(nReps):\n", - " loc = (trial, rep)\n", - " condition = psydata.sequenceIndices[loc]\n", - " for positions, color, i in zip(\n", - " psydata.data[\"to_target_mouse_positions\"][loc],\n", - " colors,\n", - " range(8),\n", - " ):\n", - " ax = axs[(trial, rep + i)]\n", - " ax.set_title(\n", - " f\"Trial {trial}, Rep {rep}, Target {i} [Condition {condition}]\"\n", - " )\n", - " ax.set_xlim(-0.5, 0.5)\n", - " ax.set_ylim(-0.5, 0.5)\n", - " if not psydata.trialList[condition][\"automove_cursor_to_center\"]:\n", - " positions = np.concatenate(\n", - " (positions, psydata.data[\"to_center_mouse_positions\"][loc][i]),\n", - " axis=0,\n", - " )\n", - " ax.plot(positions[:, 0], positions[:, 1], color=color)\n", - "\n", - "fig.delaxes(axs[2][6])\n", - "fig.delaxes(axs[2][7])\n", - "fig.delaxes(axs[3][6])\n", - "fig.delaxes(axs[3][7])\n", - "plt.show()" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Plot velocity for each trial\n", - "For example, a scatter plot of the velocity for each target, labelled by trial number, repetition number and condition:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fig, axs = plt.subplots(nTrials, nReps, figsize=(6, 6 * nTrials * nReps))\n", - "axs = np.reshape(\n", - " axs, (nTrials, nReps)\n", - ") # ensure axs is a 2d-array even if nTrials or nReps is 1\n", - "for trial in range(nTrials):\n", - " for rep in range(nReps):\n", - " loc = (trial, rep)\n", - " condition = psydata.sequenceIndices[loc]\n", - " ax = axs[loc]\n", - " ax.set_title(f\"Trial {trial}, Rep {rep} [Condition {condition}]\")\n", - "\n", - " final_position = []\n", - " final_timesteps = []\n", - " for positions, timestamps, i in zip(\n", - " psydata.data[\"to_target_mouse_positions\"][loc],\n", - " psydata.data[\"to_target_timestamps\"][loc],\n", - " range(8),\n", - " ):\n", - " final_position.append(positions)\n", - " # print(f'only to target positions : {final_position}')\n", - " final_timesteps.append(timestamps)\n", - " if not psydata.trialList[condition][\"automove_cursor_to_center\"]:\n", - " final_position.append(psydata.data[\"to_center_mouse_positions\"][loc][i])\n", - " # print(f'add to center positions : {final_position}')\n", - " final_timesteps.append(psydata.data[\"to_center_timestamps\"][loc][i])\n", - " ax.plot(\n", - " np.concatenate(final_timesteps)[:-1],\n", - " get_velocity(\n", - " np.concatenate(final_timesteps), np.concatenate(final_position)\n", - " ),\n", - " )\n", - "\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fig, axs = plt.subplots(nTrials, nReps * 8, figsize=(6 * 8, 6 * nTrials * nReps))\n", - "axs = np.reshape(\n", - " axs, (nTrials, nReps * 8)\n", - ") # ensure axs is a 2d-array even if nTrials or nReps is 1\n", - "for trial in range(nTrials):\n", - " for rep in range(nReps):\n", - " loc = (trial, rep)\n", - " condition = psydata.sequenceIndices[loc]\n", - " for positions, timestamps, color, i in zip(\n", - " psydata.data[\"to_target_mouse_positions\"][loc],\n", - " psydata.data[\"to_target_timestamps\"][loc],\n", - " colors,\n", - " range(8),\n", - " ):\n", - " ax = axs[(trial, rep + i)]\n", - " ax.set_title(\n", - " f\"Trial {trial}, Rep {rep}, Target {i} [Condition {condition}]\"\n", - " )\n", - " if not psydata.trialList[condition][\"automove_cursor_to_center\"]:\n", - " positions = np.concatenate(\n", - " (positions, psydata.data[\"to_center_mouse_positions\"][loc][i]),\n", - " axis=0,\n", - " )\n", - " timestamps = np.concatenate(\n", - " (timestamps, psydata.data[\"to_center_timestamps\"][loc][i])\n", - " )\n", - " ax.plot(timestamps[:-1], get_velocity(timestamps, positions), color=color)\n", - "fig.delaxes(axs[2][6])\n", - "fig.delaxes(axs[2][7])\n", - "fig.delaxes(axs[3][6])\n", - "fig.delaxes(axs[3][7])\n", - "plt.show()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "fig, axs = plt.subplots(nTrials, nReps, figsize=(6, 6 * nTrials * nReps))\n", - "axs = np.reshape(\n", - " axs, (nTrials, nReps)\n", - ") # ensure axs is a 2d-array even if nTrials or nReps is 1\n", - "for trial in range(nTrials):\n", - " for rep in range(nReps):\n", - " loc = (trial, rep)\n", - " condition = psydata.sequenceIndices[loc]\n", - " ax = axs[loc]\n", - " ax.set_title(f\"Trial {trial}, Rep {rep} [Condition {condition}]\")\n", - " for positions, timestamps, color, i in zip(\n", - " psydata.data[\"to_target_mouse_positions\"][loc],\n", - " psydata.data[\"to_target_timestamps\"][loc],\n", - " colors,\n", - " range(8),\n", - " ):\n", - " if not psydata.trialList[condition][\"automove_cursor_to_center\"]:\n", - " positions = np.concatenate(\n", - " (positions, psydata.data[\"to_center_mouse_positions\"][loc][i]),\n", - " axis=0,\n", - " )\n", - " timestamps = np.concatenate(\n", - " (timestamps, psydata.data[\"to_center_timestamps\"][loc][i])\n", - " )\n", - " ax.plot(\n", - " timestamps[:-1] - timestamps[0],\n", - " get_velocity(timestamps, positions),\n", - " color=color,\n", - " )\n", - "plt.show()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.12" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -}