Free Motion Capture for Everyone πβ¨
TypeScript
Patches (#504)
philipqueen6a4a3f2c972a
diff --git a/.github/workflows/linting-flake8.yml b/.github/workflows/linting-flake8.ymlindex c4434c07..04287725 100755--- a/.github/workflows/linting-flake8.yml+++ b/.github/workflows/linting-flake8.yml@@ -2,7 +2,7 @@ name: Linting Flake8on:pull_request:- branches: [ main ]+ branches: [ main, development ]paths:- 'freemocap/**'diff --git a/.github/workflows/python-testing.yml b/.github/workflows/python-testing.ymlindex 3f22d6aa..6c055e3c 100755--- a/.github/workflows/python-testing.yml+++ b/.github/workflows/python-testing.yml@@ -2,7 +2,7 @@ name: Freemocap Testson:pull_request:- branches: [ main ]+ branches: [ main, development ]paths:- 'freemocap/**'@@ -11,11 +11,17 @@ jobs:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v3+ - name: System Info+ run: |+ uname -a || true+ lsb_release -a || true+ gcc --version || true+ env- name: Set up Python 3.xuses: actions/setup-python@v4with:# Semantic version range syntax or exact version of a Python version- python-version: '3.9'+ python-version: '3.11'# Optional - x64 or x86 architecture, defaults to x64architecture: 'x64'cache: 'pip'@@ -26,7 +32,7 @@ jobs:- name: Install libegl1run: |sudo apt-get update- sudo apt-get install libegl1-mesa+ sudo apt-get install -y libegl1-mesa- name: Run Tests with Pytestrun: |pip install pytestdiff --git a/freemocap/data_layer/recording_models/recording_info_model.py b/freemocap/data_layer/recording_models/recording_info_model.pyindex 75829fd6..2511b110 100644--- a/freemocap/data_layer/recording_models/recording_info_model.py+++ b/freemocap/data_layer/recording_models/recording_info_model.py@@ -21,6 +21,7 @@ from freemocap.tests.test_image_tracking_data_shape import test_image_tracking_dfrom freemocap.tests.test_mediapipe_skeleton_data_shape import test_mediapipe_skeleton_data_shapefrom freemocap.tests.test_synchronized_video_frame_counts import test_synchronized_video_frame_countsfrom freemocap.tests.test_total_body_center_of_mass_data_shape import test_total_body_center_of_mass_data_shape+from freemocap.utilities.get_video_paths import get_video_pathslogger = logging.getLogger(__name__)@@ -130,6 +131,10 @@ class RecordingInfoModel:def synchronized_videos_status_check(self) -> bool:return self._recording_folder_status_checker.check_synchronized_videos_status()+ @property+ def single_video_check(self) -> bool:+ return self._recording_folder_status_checker.check_single_video()+@propertydef data2d_status_check(self) -> bool:return self._recording_folder_status_checker.check_data2d_status()@@ -169,6 +174,12 @@ class RecordingFolderStatusChecker:except AssertionError:return False+ def check_single_video(self) -> bool:+ if len(get_video_paths(path_to_video_folder=self.recording_info_model.synchronized_videos_folder_path)) == 1:+ return True+ else:+ return False+def check_data2d_status(self) -> bool:try:test_image_tracking_data_shape(diff --git a/freemocap/gui/qt/widgets/control_panel/process_mocap_data_panel/process_motion_capture_data_panel.py b/freemocap/gui/qt/widgets/control_panel/process_mocap_data_panel/process_motion_capture_data_panel.pyindex 635b60d1..58970c16 100644--- a/freemocap/gui/qt/widgets/control_panel/process_mocap_data_panel/process_motion_capture_data_panel.py+++ b/freemocap/gui/qt/widgets/control_panel/process_mocap_data_panel/process_motion_capture_data_panel.py@@ -226,17 +226,22 @@ class ProcessMotionCaptureDataPanel(QWidget):logger.error(f"Recording path does not exist: {session_parameter_model.recording_info_model.path}.")return- selected_camera_calibration_toml_path = self._calibration_control_panel.calibration_toml_path- session_parameter_model.recording_info_model.calibration_toml_path = selected_camera_calibration_toml_path-- #check if there is already a calibration toml in the recording folder, if not save this one there- if len(list(Path(session_parameter_model.recording_info_model.path).glob("*.toml")))==0:- # copy the calibration toml to the recording folder (keeping the original filename- logger.info(f"Copying calibration toml from {selected_camera_calibration_toml_path} to {session_parameter_model.recording_info_model.path}")- Path(session_parameter_model.recording_info_model.path).mkdir(parents=True, exist_ok=True)- copied_toml_path = Path(session_parameter_model.recording_info_model.path)/Path(selected_camera_calibration_toml_path).name- shutil.copyfile(selected_camera_calibration_toml_path, copied_toml_path)-+ if session_parameter_model.recording_info_model.single_video_check is False:+ selected_camera_calibration_toml_path = self._calibration_control_panel.calibration_toml_path+ session_parameter_model.recording_info_model.calibration_toml_path = selected_camera_calibration_toml_path++ # check if there is already a calibration toml in the recording folder, if not save this one there+ if len(list(Path(session_parameter_model.recording_info_model.path).glob("*.toml"))) == 0:+ # copy the calibration toml to the recording folder (keeping the original filename+ logger.info(+ f"Copying calibration toml from {selected_camera_calibration_toml_path} to {session_parameter_model.recording_info_model.path}"+ )+ Path(session_parameter_model.recording_info_model.path).mkdir(parents=True, exist_ok=True)+ copied_toml_path = (+ Path(session_parameter_model.recording_info_model.path)+ / Path(selected_camera_calibration_toml_path).name+ )+ shutil.copyfile(selected_camera_calibration_toml_path, copied_toml_path)self._process_motion_capture_data_thread_worker = ProcessMotionCaptureDataThreadWorker(session_parameter_model, kill_event=self._kill_thread_eventdiff --git a/ipython_jupyter_notebooks/COM_Jumping_Analysis.ipynb b/ipython_jupyter_notebooks/COM_Jumping_Analysis.ipynbnew file mode 100644index 00000000..77d7e424--- /dev/null+++ b/ipython_jupyter_notebooks/COM_Jumping_Analysis.ipynb@@ -0,0 +1,752 @@+{+ "cells": [+ {+ "cell_type": "markdown",+ "source": [+ "# Jumping Notebook!"+ ],+ "metadata": {+ "collapsed": false,+ "id": "1cdfdca98234e968"+ },+ "id": "1cdfdca98234e968"+ },+ {+ "cell_type": "markdown",+ "source": [],+ "metadata": {+ "collapsed": false,+ "id": "41378eca2319bd7a"+ },+ "id": "41378eca2319bd7a"+ },+ {+ "cell_type": "code",+ "execution_count": 1,+ "outputs": [+ {+ "name": "stdout",+ "output_type": "stream",+ "text": [+ "No module named 'numpy'\n",+ "Collecting numpy\r\n",+ " Downloading numpy-1.26.1-cp311-cp311-macosx_11_0_arm64.whl.metadata (115 kB)\r\n",+ "\u001B[2K \u001B[90mβββββββββββββββββββββββββββββββββββββββ\u001B[0m \u001B[32m115.1/115.1 kB\u001B[0m \u001B[31m1.6 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0ma \u001B[36m0:00:01\u001B[0m\r\n",+ "\u001B[?25hDownloading numpy-1.26.1-cp311-cp311-macosx_11_0_arm64.whl (14.0 MB)\r\n",+ "\u001B[2K \u001B[90mββββββββββββββββββββββββββββββββββββββββ\u001B[0m \u001B[32m14.0/14.0 MB\u001B[0m \u001B[31m5.1 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m00:01\u001B[0m\r\n",+ "\u001B[?25hInstalling collected packages: numpy\r\n",+ "Successfully installed numpy-1.26.1\r\n",+ "Note: you may need to restart the kernel to use updated packages.\n",+ "No module named 'scipy'\n",+ "Collecting scipy\r\n",+ " Downloading scipy-1.11.3-cp311-cp311-macosx_12_0_arm64.whl.metadata (165 kB)\r\n",+ "\u001B[2K \u001B[90mβββββββββββββββββββββββββββββββββββββββ\u001B[0m \u001B[32m165.4/165.4 kB\u001B[0m \u001B[31m2.6 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0ma \u001B[36m0:00:01\u001B[0m\r\n",+ "\u001B[?25hRequirement already satisfied: numpy<1.28.0,>=1.21.6 in /opt/homebrew/Caskroom/miniconda/base/envs/freemocap_analysis/lib/python3.11/site-packages (from scipy) (1.26.1)\r\n",+ "Downloading scipy-1.11.3-cp311-cp311-macosx_12_0_arm64.whl (29.7 MB)\r\n",+ "\u001B[2K \u001B[90mββββββββββββββββββββββββββββββββββββββββ\u001B[0m \u001B[32m29.7/29.7 MB\u001B[0m \u001B[31m6.6 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m00:01\u001B[0m\r\n",+ "\u001B[?25hInstalling collected packages: scipy\r\n",+ "Successfully installed scipy-1.11.3\r\n",+ "Note: you may need to restart the kernel to use updated packages.\n",+ "No module named 'plotly'\n",+ "Collecting plotly\r\n",+ " Downloading plotly-5.18.0-py3-none-any.whl.metadata (7.0 kB)\r\n",+ "Collecting tenacity>=6.2.0 (from plotly)\r\n",+ " Downloading tenacity-8.2.3-py3-none-any.whl.metadata (1.0 kB)\r\n",+ "Requirement already satisfied: packaging in /opt/homebrew/Caskroom/miniconda/base/envs/freemocap_analysis/lib/python3.11/site-packages (from plotly) (23.1)\r\n",+ "Downloading plotly-5.18.0-py3-none-any.whl (15.6 MB)\r\n",+ "\u001B[2K \u001B[90mββββββββββββββββββββββββββββββββββββββββ\u001B[0m \u001B[32m15.6/15.6 MB\u001B[0m \u001B[31m6.9 MB/s\u001B[0m eta \u001B[36m0:00:00\u001B[0m00:01\u001B[0m00:01\u001B[0m\r\n",+ "\u001B[?25hDownloading tenacity-8.2.3-py3-none-any.whl (24 kB)\r\n",+ "Installing collected packages: tenacity, plotly\r\n",+ "Successfully installed plotly-5.18.0 tenacity-8.2.3\r\n",+ "Note: you may need to restart the kernel to use updated packages.\n"+ ]+ }+ ],+ "source": [+ "#Importing libraries\n",+ "\n",+ "\n",+ "from pathlib import Path\n",+ "\n",+ "try:\n",+ " import numpy as np\n",+ "except Exception as e:\n",+ " print(e)\n",+ " %pip install numpy\n",+ " import numpy as np\n",+ "\n",+ "try:\n",+ " from scipy.signal import find_peaks\n",+ "except Exception as e:\n",+ " print(e)\n",+ " %pip install scipy\n",+ " from scipy.signal import find_peaks\n",+ "\n",+ "try:\n",+ " from plotly.subplots import make_subplots\n",+ " import plotly.graph_objects as go\n",+ "except Exception as e:\n",+ " print(e)\n",+ " %pip install plotly\n",+ " from plotly.subplots import make_subplots\n",+ " import plotly.graph_objects as go"+ ],+ "metadata": {+ "id": "21dd4017a36af8f4",+ "ExecuteTime": {+ "end_time": "2023-11-12T12:34:15.709645Z",+ "start_time": "2023-11-12T12:33:48.548369Z"+ }+ },+ "id": "21dd4017a36af8f4"+ },+ {+ "cell_type": "code",+ "execution_count": 2,+ "outputs": [],+ "source": [+ "path_to_recording = r\"/Users/mdn/Documents/PROJECTS/FreeMoCap_data/2023-10-05_max_jump_recording_sessions_KK_ML/session_2023-10-05_15_59_45/recording_16_04_29_gmt-4__ML_max_jump\""+ ],+ "metadata": {+ "id": "f6e8800a49f64c7e",+ "ExecuteTime": {+ "end_time": "2023-11-12T12:34:15.710397Z",+ "start_time": "2023-11-12T12:34:15.707866Z"+ }+ },+ "id": "f6e8800a49f64c7e"+ },+ {+ "cell_type": "markdown",+ "source": [+ "### What does the \"shape\" of the data mean?\n",+ "The shape of the data is the number of frames by the number of dimensions. In this case, the data is 3D, so the shape is (number of frames, 3)."+ ],+ "metadata": {+ "collapsed": false,+ "id": "a8200e75a3457e6"+ },+ "id": "a8200e75a3457e6"+ },+ {+ "cell_type": "code",+ "execution_count": 6,+ "outputs": [],+ "source": [+ "\n",+ "mediapipe_indices = ['nose',\n",+ " 'left_eye_inner',\n",+ " 'left_eye',\n",+ " 'left_eye_outer',\n",+ " 'right_eye_inner',\n",+ " 'right_eye',\n",+ " 'right_eye_outer',\n",+ " 'left_ear',\n",+ " 'right_ear',\n",+ " 'mouth_left',\n",+ " 'mouth_right',\n",+ " 'left_shoulder',\n",+ " 'right_shoulder',\n",+ " 'left_elbow',\n",+ " 'right_elbow',\n",+ " 'left_wrist',\n",+ " 'right_wrist',\n",+ " 'left_pinky',\n",+ " 'right_pinky',\n",+ " 'left_index',\n",+ " 'right_index',\n",+ " 'left_thumb',\n",+ " 'right_thumb',\n",+ " 'left_hip',\n",+ " 'right_hip',\n",+ " 'left_knee',\n",+ " 'right_knee',\n",+ " 'left_ankle',\n",+ " 'right_ankle',\n",+ " 'left_heel',\n",+ " 'right_heel',\n",+ " 'left_foot_index',\n",+ " 'right_foot_index']\n",+ "\n",+ "joint_to_plot_index = mediapipe_indices.index('nose') #You can choose what point you'd like to look at here by changing the string in the mediapipe_indices list."+ ],+ "metadata": {+ "id": "55b9e432c98ab003",+ "ExecuteTime": {+ "end_time": "2023-11-12T12:37:14.600201Z",+ "start_time": "2023-11-12T12:37:14.594506Z"+ }+ },+ "id": "55b9e432c98ab003"+ },+ {+ "cell_type": "code",+ "execution_count": 7,+ "outputs": [+ {+ "ename": "IndexError",+ "evalue": "too many indices for array: array is 2-dimensional, but 3 were indexed",+ "output_type": "error",+ "traceback": [+ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",+ "\u001B[0;31mIndexError\u001B[0m Traceback (most recent call last)",+ "Cell \u001B[0;32mIn[7], line 9\u001B[0m\n\u001B[1;32m 6\u001B[0m freemocap_3d_body_data \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mload(path_to_center_of_mass_npy)\n\u001B[1;32m 7\u001B[0m total_body_com_data \u001B[38;5;241m=\u001B[39m np\u001B[38;5;241m.\u001B[39mload(path_to_freemocap_3d_body_data_npy)\n\u001B[0;32m----> 9\u001B[0m freemocap_3d_body_data_to_plot \u001B[38;5;241m=\u001B[39m freemocap_3d_body_data[:,joint_to_plot_index,:]\n",+ "\u001B[0;31mIndexError\u001B[0m: too many indices for array: array is 2-dimensional, but 3 were indexed"+ ]+ }+ ],+ "source": [+ "path_to_recording = Path(path_to_recording)\n",+ "path_to_center_of_mass_npy = path_to_recording/'output_data'/'center_of_mass'/'total_body_center_of_mass_xyz.npy'\n",+ "path_to_freemocap_3d_body_data_npy = path_to_recording/'output_data'/'mediapipe_body_3d_xyz.npy'\n",+ "\n",+ "\n",+ "freemocap_3d_body_data = np.load(path_to_center_of_mass_npy)\n",+ "total_body_com_data = np.load(path_to_freemocap_3d_body_data_npy)\n",+ "\n",+ "freemocap_3d_body_data_to_plot = freemocap_3d_body_data[:,joint_to_plot_index,:]"+ ],+ "metadata": {+ "id": "deb5427474d3d920",+ "ExecuteTime": {+ "end_time": "2023-11-12T12:37:22.510130Z",+ "start_time": "2023-11-12T12:37:22.473846Z"+ }+ },+ "id": "deb5427474d3d920"+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [],+ "metadata": {+ "id": "dcd3caa0780c1472",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.487149Z"+ }+ },+ "id": "dcd3caa0780c1472"+ },+ {+ "cell_type": "markdown",+ "source": [+ "## 3D Plotting\n",+ "\n",+ "We are creating a 3D plot of the skeleton movement, tracking all the joints in the `mediapipe_indices` list over time. \n",+ "\n",+ "The 'Play' button at the bottom allows you to watch the motion as if it were a video. Before pressing play, you can manually click and drag the plot around to orient the view of the plot."+ ],+ "metadata": {+ "collapsed": false,+ "id": "748172036eafe524"+ },+ "id": "748172036eafe524"+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [+ "def calculate_axes_means(skeleton_3d_data):\n",+ " mx_skel = np.nanmean(skeleton_3d_data[:,0:33,0])\n",+ " my_skel = np.nanmean(skeleton_3d_data[:,0:33,1])\n",+ " mz_skel = np.nanmean(skeleton_3d_data[:,0:33,2])\n",+ "\n",+ " return mx_skel, my_skel, mz_skel\n",+ "\n",+ "ax_range = 1500\n",+ "\n",+ "mx_skel, my_skel, mz_skel = calculate_axes_means(freemocap_3d_body_data)\n",+ "\n",+ "# Create a list of frames\n",+ "frames = [go.Frame(data=[go.Scatter3d(\n",+ " x=freemocap_3d_body_data[i, :, 0],\n",+ " y=freemocap_3d_body_data[i, :, 1],\n",+ " z=freemocap_3d_body_data[i, :, 2],\n",+ " mode='markers',\n",+ " marker=dict(\n",+ " size=2, # Adjust marker size as needed\n",+ " )\n",+ ")], name=str(i)) for i in range(freemocap_3d_body_data.shape[0])]\n",+ "\n",+ "# Define axis properties\n",+ "axis = dict(\n",+ " showbackground=True,\n",+ " backgroundcolor=\"rgb(230, 230,230)\",\n",+ " gridcolor=\"rgb(255, 255, 255)\",\n",+ " zerolinecolor=\"rgb(255, 255, 255)\",\n",+ ")\n",+ "\n",+ "# Create a figure\n",+ "fig = go.Figure(\n",+ " data=[go.Scatter3d(\n",+ " x=freemocap_3d_body_data[0, :, 0],\n",+ " y=freemocap_3d_body_data[0, :, 1],\n",+ " z=freemocap_3d_body_data[0, :, 2],\n",+ " mode='markers',\n",+ " marker=dict(\n",+ " size=2, # Adjust marker size as needed\n",+ " )\n",+ " )],\n",+ " layout=go.Layout(\n",+ " scene=dict(\n",+ " xaxis=dict(axis, range=[mx_skel-ax_range, mx_skel+ax_range]), # Adjust range as needed\n",+ " yaxis=dict(axis, range=[my_skel-ax_range, my_skel+ax_range]), # Adjust range as needed\n",+ " zaxis=dict(axis, range=[mz_skel-ax_range, mz_skel+ax_range]), # Adjust range as needed\n",+ " aspectmode='cube'\n",+ " ),\n",+ " updatemenus=[dict(\n",+ " type='buttons',\n",+ " showactive=False,\n",+ " buttons=[dict(\n",+ " label='Play',\n",+ " method='animate',\n",+ " args=[None, {\"frame\": {\"duration\": 30}}]\n",+ " )]\n",+ " )]\n",+ " ),\n",+ " frames=frames\n",+ ")\n",+ "\n",+ "fig.show()"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/",+ "height": 542+ },+ "id": "363ed68144eaffc8",+ "outputId": "aec20410-5fd4-4c8f-ada2-525e5c5b78d3",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.489473Z"+ }+ },+ "id": "363ed68144eaffc8"+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Now lets start analysing the data!"+ ],+ "metadata": {+ "collapsed": false,+ "id": "6953e7463574d038"+ },+ "id": "6953e7463574d038"+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [+ "\n",+ "fig = make_subplots(rows=3, cols=1, subplot_titles=('Center of Mass X', 'Center of Mass Y', 'Center of Mass Z'))\n",+ "\n",+ "fig.add_trace(\n",+ " go.Scatter(y=total_body_com_data[:, 0]),\n",+ " row=1, col=1\n",+ ")\n",+ "\n",+ "fig.add_trace(\n",+ " go.Scatter(y=total_body_com_data[:, 1]),\n",+ " row=2, col=1\n",+ ")\n",+ "\n",+ "fig.add_trace(\n",+ " go.Scatter(y=total_body_com_data[:, 2]),\n",+ " row=3, col=1\n",+ ")\n",+ "\n",+ "# COM plot axes labels\n",+ "fig.update_yaxes(title_text=\"X Axis (mm)\", row=1, col=1)\n",+ "fig.update_yaxes(title_text=\"Y Axis (mm)\", row=2, col=1)\n",+ "fig.update_yaxes(title_text=\"Z Axis (mm)\", row=3, col=1)\n",+ "fig.update_xaxes(title_text=\"Frame #\", row=3, col=1) # Assuming you only want x-axis title for the bottommost subplot\n",+ "\n",+ "fig.update_layout(height=600, width=800, showlegend=False)\n",+ "fig.show()\n"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/",+ "height": 617+ },+ "id": "a9b876fa14fbc378",+ "outputId": "400b1c32-f8d3-44d0-a6c9-16e17e726391",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.490925Z"+ }+ },+ "id": "a9b876fa14fbc378"+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Lets calculate the kinetics of the COM in the Z direction (vertical)"+ ],+ "metadata": {+ "collapsed": false,+ "id": "e416eb5e7bf88e27"+ },+ "id": "e416eb5e7bf88e27"+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [+ "from scipy.signal import butter, filtfilt\n",+ "\n",+ "# First lets filter the position data to get it nice a clean\n",+ "# We will use a low pass filter to smooth the data\n",+ "position_com_z_data = total_body_com_data[:, 2]\n",+ "\n",+ "# Filter Function\n",+ "def butterworth_filter(data, cutoff, frame_rate, order=4, filter_type='low'):\n",+ " nyq = 0.5 * frame_rate\n",+ " normal_cutoff = cutoff / nyq\n",+ " b, a = butter(order, normal_cutoff, btype=filter_type, analog=False)\n",+ "\n",+ " # Adjust the padlen based on the length of the data\n",+ " padlen = min(order * 3, len(data) - 1)\n",+ "\n",+ " y = filtfilt(b, a, data, padlen=padlen)\n",+ " return y\n",+ "\n",+ "# Filter the data\n",+ "position_com_z_data = butterworth_filter(position_com_z_data, 5, 30, order=4, filter_type='low')\n"+ ],+ "metadata": {+ "id": "ef6bedc02a5d19c9",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.492066Z"+ }+ },+ "id": "ef6bedc02a5d19c9"+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [+ "\n",+ "velocity_com_z_data = np.diff(position_com_z_data, axis=0)\n",+ "acceleration_com_z_data = np.diff(velocity_com_z_data, axis=0)\n",+ "\n",+ "time = 1/30\n"+ ],+ "metadata": {+ "id": "9042f15e6e3c0051",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.493306Z"+ }+ },+ "id": "9042f15e6e3c0051"+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [+ "# Function to normalize and scale data to fit between -1 and 1\n",+ "def normalize_and_scale(data):\n",+ " normalized_data = 2 * ((data - min(data)) / (max(data) - min(data))) - 1\n",+ " return normalized_data\n",+ "\n",+ "# Apply the function to your data\n",+ "scaled_position = normalize_and_scale(position_com_z_data)\n",+ "scaled_velocity = normalize_and_scale(velocity_com_z_data)\n",+ "scaled_acceleration = normalize_and_scale(acceleration_com_z_data)\n",+ "\n",+ "# Plot the data\n",+ "fig = make_subplots(rows=4, cols=1, subplot_titles=('Z Position', 'Z Velocity', 'Z Acceleration', 'Superimposed'))\n",+ "\n",+ "fig.add_trace(\n",+ " go.Scatter(y=position_com_z_data, name='Z Position', line=dict(color='red')),\n",+ " row=1, col=1\n",+ ")\n",+ "\n",+ "fig.add_trace(\n",+ " go.Scatter(y=velocity_com_z_data, name='Z Velocity', line=dict(color='green')),\n",+ " row=2, col=1\n",+ ")\n",+ "\n",+ "fig.add_trace(\n",+ " go.Scatter(y=acceleration_com_z_data, name='Z Acceleration', line=dict(color='blue')),\n",+ " row=3, col=1\n",+ ")\n",+ "\n",+ "# Add the scaled traces to the fourth subplot\n",+ "fig.add_trace(\n",+ " go.Scatter(y=scaled_position, name='Scaled Z Position', line=dict(color='red')),\n",+ " row=4, col=1\n",+ ")\n",+ "fig.add_trace(\n",+ " go.Scatter(y=scaled_velocity, name='Scaled Z Velocity', line=dict(color='green')),\n",+ " row=4, col=1\n",+ ")\n",+ "fig.add_trace(\n",+ " go.Scatter(y=scaled_acceleration, name='Scaled Z Acceleration', line=dict(color='blue')),\n",+ " row=4, col=1\n",+ ")\n",+ "\n",+ "# COM plot axes labels\n",+ "fig.update_yaxes(title_text=\"Z Position\", row=1, col=1)\n",+ "fig.update_yaxes(title_text=\"Z Velocity\", row=2, col=1)\n",+ "fig.update_yaxes(title_text=\"Z Acceleration\", row=3, col=1)\n",+ "fig.update_xaxes(title_text=\"Frame #\", row=4, col=1)\n",+ "\n",+ "fig.update_layout(height=800, width=800, showlegend=True)\n",+ "fig.show()\n"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/",+ "height": 817+ },+ "id": "d867e48cfa98abce",+ "outputId": "fe8649af-652c-4622-d5b9-dcc4eab6f4d7",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.494799Z"+ }+ },+ "id": "d867e48cfa98abce"+ },+ {+ "cell_type": "markdown",+ "source": [+ "## Lets look a little closer at the acceleration data."+ ],+ "metadata": {+ "collapsed": false,+ "id": "af56c1f276cf367a"+ },+ "id": "af56c1f276cf367a"+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [+ "liftoff_time_stamps = []\n",+ "bottom_time_stamps = []\n",+ "apex_time_stamps = []\n",+ "\n",+ "for t in range(velocity_com_z_data.size-2):\n",+ " if (velocity_com_z_data[t+2]<velocity_com_z_data[t+1]\n",+ " and velocity_com_z_data[t] < velocity_com_z_data[t+1]):\n",+ " liftoff_time_stamps.append(t+1)\n",+ "\n",+ "for t in range(velocity_com_z_data.size-1):\n",+ " if velocity_com_z_data[t+1] > 0 and velocity_com_z_data[t] <= 0:\n",+ " bottom_time_stamps.append(t)\n",+ " if velocity_com_z_data[t+1] < 0 and velocity_com_z_data[t] >= 0:\n",+ " apex_time_stamps.append(t)\n",+ "\n",+ "print(f\"number of iterations at bottom: \", len(bottom_time_stamps))\n",+ "print(f\"number of iterations at apex: \", len(apex_time_stamps))"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/"+ },+ "id": "e960df75d5a7c9b7",+ "outputId": "0c262dd9-7010-4f98-c63e-1c698fc0ec45",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.496192Z"+ }+ },+ "id": "e960df75d5a7c9b7"+ },+ {+ "cell_type": "code",+ "source": [+ "fig = go.Figure()\n",+ "\n",+ "# Add the velocity data\n",+ "fig.add_trace(\n",+ " go.Scatter(y=velocity_com_z_data, mode='lines', name='Velocity COM Z')\n",+ ")\n",+ "\n",+ "fig.add_trace(\n",+ " go.Scatter(x=liftoff_time_stamps, y=velocity_com_z_data[liftoff_time_stamps],\n",+ " mode='markers', marker_symbol='star', marker_size=10,\n",+ " marker_color='yellow', name='Lift Off')\n",+ ")\n",+ "\n",+ "# Show the plot\n",+ "fig.show()"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/",+ "height": 542+ },+ "id": "MKT7Ebrk6mo-",+ "outputId": "182871e2-b1be-4591-8f7e-1e1e40ac7c82",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.496952Z"+ }+ },+ "id": "MKT7Ebrk6mo-",+ "execution_count": null,+ "outputs": []+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [+ "fig = go.Figure()\n",+ "\n",+ "# Add the acceleration data\n",+ "fig.add_trace(\n",+ " go.Scatter(y=acceleration_com_z_data, mode='lines', name='Acceleration COM Z')\n",+ ")\n",+ "\n",+ "fig.add_trace(\n",+ " go.Scatter(x=liftoff_time_stamps, y=acceleration_com_z_data[liftoff_time_stamps],\n",+ " mode='markers', marker_symbol='star', marker_size=10,\n",+ " marker_color='yellow', name='Lift Off')\n",+ ")\n",+ "\n",+ "# Show the plot\n",+ "fig.show()"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/",+ "height": 542+ },+ "id": "65d1afedca8851f0",+ "outputId": "1cad5eb7-f3aa-4cc3-c6c6-3c56ff0091f4",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.497837Z"+ }+ },+ "id": "65d1afedca8851f0"+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [+ "# Create the state space plot\n",+ "fig = go.Figure()\n",+ "\n",+ "# Plot height_position vs height_velocity\n",+ "fig.add_trace(\n",+ " go.Scatter(x= velocity_com_z_data, y=position_com_z_data, mode='lines+markers', marker=dict(symbol='circle', size=6, opacity=0.5), name='Data')\n",+ ")\n",+ "\n",+ "# Mark the start\n",+ "fig.add_trace(\n",+ " go.Scatter(x=[velocity_com_z_data[0]], y=[position_com_z_data[0]], mode='markers', marker=dict(symbol='triangle-down', color='red', size=10), name='Start')\n",+ ")\n",+ "\n",+ "# Mark the bottom timestamps\n",+ "fig.add_trace(\n",+ " go.Scatter(x=velocity_com_z_data[bottom_time_stamps], y=position_com_z_data[bottom_time_stamps], mode='markers', marker=dict(symbol='circle', color='brown', size=10), name='Bottom')\n",+ ")\n",+ "\n",+ "# Mark the apex timestamps\n",+ "fig.add_trace(\n",+ " go.Scatter(x=velocity_com_z_data[apex_time_stamps], y=position_com_z_data[apex_time_stamps], mode='markers', marker=dict(symbol='circle', color='magenta', size=10), name='Apex')\n",+ ")\n",+ "\n",+ "# Mark the liftoff timestamps\n",+ "fig.add_trace(\n",+ " go.Scatter(x=velocity_com_z_data[liftoff_time_stamps], y=position_com_z_data[liftoff_time_stamps], mode='markers', marker=dict(symbol='circle', color='green', size=10), name='Lift Off')\n",+ ")\n",+ "\n",+ "# Set axis labels\n",+ "fig.update_layout(xaxis_title='velocity', yaxis_title='position')\n",+ "fig.update_layout(height=1200, width=600, showlegend=True)\n",+ "\n",+ "# Show the plot\n",+ "fig.show()\n"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/",+ "height": 1000+ },+ "id": "335879ffef8f8362",+ "outputId": "ae5b13c1-fc75-4b60-f4bb-993bf7f0a82a",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.498587Z"+ }+ },+ "id": "335879ffef8f8362"+ },+ {+ "cell_type": "code",+ "execution_count": null,+ "outputs": [],+ "source": [+ "fig = go.Figure()\n",+ "\n",+ "# Plot position_com_z_data vs velocity_com_z_data vs acceleration_com_z_data\n",+ "fig.add_trace(\n",+ " go.Scatter3d(\n",+ " x=position_com_z_data,\n",+ " y=velocity_com_z_data,\n",+ " z=acceleration_com_z_data,\n",+ " mode='lines+markers',\n",+ " marker=dict(size=2, opacity=0.8),\n",+ " name='State Space Data'\n",+ " )\n",+ ")\n",+ "\n",+ "# Set axis labels\n",+ "fig.update_layout(\n",+ " scene=dict(\n",+ " xaxis_title='Position COM Z [??]',\n",+ " yaxis_title='Velocity COM Z [??]',\n",+ " zaxis_title='Acceleration COM Z [??]'\n",+ " )\n",+ ")\n",+ "\n",+ "# Show the plot\n",+ "fig.show()"+ ],+ "metadata": {+ "colab": {+ "base_uri": "https://localhost:8080/",+ "height": 542+ },+ "id": "9f9a49d6c214e75b",+ "outputId": "3cac9972-2a93-4a84-db30-71b23bcacfcb",+ "ExecuteTime": {+ "start_time": "2023-11-12T12:37:22.499330Z"+ }+ },+ "id": "9f9a49d6c214e75b"+ }+ ],+ "metadata": {+ "kernelspec": {+ "display_name": "Python 3",+ "language": "python",+ "name": "python3"+ },+ "language_info": {+ "codemirror_mode": {+ "name": "ipython",+ "version": 2+ },+ "file_extension": ".py",+ "mimetype": "text/x-python",+ "name": "python",+ "nbconvert_exporter": "python",+ "pygments_lexer": "ipython2",+ "version": "2.7.6"+ },+ "colab": {+ "provenance": []+ }+ },+ "nbformat": 4,+ "nbformat_minor": 5+}diff --git a/poetry_pyproject.toml b/poetry_pyproject.tomlindex 65adb0d3..e87a3c5c 100644--- a/poetry_pyproject.toml+++ b/poetry_pyproject.toml@@ -1,6 +1,6 @@[tool.poetry]name = "freemocap"-version = "1.0.26"+version = "1.0.28"description = "A free and open source markerless motion capture system for everyone πβ¨"authors = ["Skelly FreeMoCap <[email protected]>"]license = "AGPLv3"@@ -14,7 +14,7 @@ Issues = "https://github.com/freemocap/freemocap/issues"Community_Discord = "https://discord.gg/uTvkkJnSff"[tool.poetry.dependencies]-python = ">=3.9,<3.13"+python = ">=3.9,<3.12"skellycam = "2023.9.1086"skelly_viewer = "2023.5.1019 "skellyforge = "2023.9.1004 "@@ -28,7 +28,7 @@ ipykernel="6.23.1"plotly="^5.17.1"pydantic="1.*"packaging = "^23.2"-ajc27-freemocap-blender-addon = "*"+ajc27-freemocap-blender-addon = "^0.2.14"numpy = "^1.23.5"diff --git a/pyproject.toml b/pyproject.tomlindex 5fc88e27..f8116785 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -68,7 +68,7 @@ keywords = [#dynamic = ["dependencies"]dependencies = [- "skellycam",+ "skellycam@https://github.com/freemocap/skellycam/archive/philip/pyside6-change.zip","skelly_viewer","skellyforge","skelly_synchronize>=2023.9.1026",@@ -80,10 +80,12 @@ dependencies = ["ipykernel==6.23.1","plotly==5.14.1","pydantic==1.*",+ "pyqt6==6.6.*","packaging","ajc27_freemocap_blender_addon"]-requires-python = ">=3.8"++requires-python = ">=3.9,<3.12"dynamic = ["version", "description"]