### Getting Started with Kineticstoolkit
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/getting_started.md
This section guides users through the initial steps of installing and setting up the Kineticstoolkit. It is the recommended starting point for users with no prior programming experience.
```markdown
[](getting_started_installing.md)
```
--------------------------------
### Getting Started Paths
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/src/getting_started.md
This section outlines different entry points into the Kinetic Toolkit documentation based on the user's prior experience with programming (Python, NumPy, Matplotlib) and biomechanical analysis (Matlab). It suggests specific documents to read for each user profile.
```markdown
## Where to start
Depending on your background, you may want to start your journey at different points:
:::::{tab-set}
::::{tab-item} I never programmed using Python.
:::{card}
Simply start at the beginning: [](getting_started_installing.md).
:::
::::
::::{tab-item} I know Python, NumPy, and Matplotlib, but I'm new to biomechanical analysis.
:::{card}
- You may be interested in a refresher by attempting these different [programming exercises](python_exercises.md).
- Then, jump to [](ktk_importing.md).
:::
::::
::::{tab-item} I already do biomechanical analysis, but under Matlab instead of Python.
:::{card}
- You may want to start at the beginning to learn the Python syntax: [](getting_started_installing.md).
- You may skip [](matplotlib.md) as this is practically identical to Matlab.
- However, be sure to go through [](numpy.md) as there are some fundamental differences between Matlab and NumPy.
- Then, jump to [](ktk_importing.md).
:::
::::
::::{tab-item} I already do biomechanical analysis under Python.
:::{card}
You may want to understand what Kinetics Toolkit could add to your Python workflow. Start directly here: [](ktk_importing.md).
You may also consult the API Reference.
:::
::::
:::::
```
--------------------------------
### Setup Symlinks for Kinetics Toolkit
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/README.md
Instructions for creating symbolic links to the Kinetics Toolkit package. These links are necessary for building the website and should point to the inner 'kineticstoolkit' folder of the installed package.
```shell
ln -s [SOME_FOLDER]/kineticstoolkit/kineticstoolkit ktk
ln -s [SOME_FOLDER]/kineticstoolkit/kineticstoolkit kineticstoolkit
```
--------------------------------
### Navigation Structure
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started_intro.html
This snippet defines the navigation structure for the documentation, including main sections like 'Getting Started' and 'Learning Python for Biomechanics', with nested subsections and links to specific pages.
```html
[Skip to main content](#main-content)
Back to top
Ctrl+K
[ document.write(``);](index.html)
Part I. Getting Started
* [1. Introduction](#)
* [2. Where to start](getting_started.html)
* [2.1. Installing Python and Kinetics Toolkit](getting_started_installing.html)
* [2.2. Installing and configuring Spyder](getting_started_configuring_spyder.html)
* [2.3. Using Spyder](getting_started_using_spyder.html)
Part II. Learning Python for Biomechanics
* [3. The Python Language](python_intro.html)
* [3.1. Python basics](python_basics.html)
* [3.1.1. Arithmetic operations](python_arithmetics.html)
* [3.1.2. Printing to the console](python_print.html)
* [3.1.3. Comments](python_comments.html)
* [3.1.4. Variables](python_variables.html)
* [3.1.4.1. Exercise: Python basics 1](python_basics_exercise1.html)
* [3.1.4.2. Exercise: Python basics 2](python_basics_exercise2.html)
* [3.2. Numbers](python_numbers.html)
* [3.2.1. Difference between integers and floats](python_int_float.html)
* [3.2.1.1. Exercise: Integers and floats](python_int_float_exercise.html)
* [3.2.2. Arithmetic operations between integers and floats](python_int_float_arithmetics.html)
* [3.3. Strings](python_strings.html)
* [3.3.1. Creating strings using quotes](python_strings_quotes.html)
* [3.3.2. Backslash](python_strings_backslash.html)
* [3.3.3. Creating strings using triple-quotes](python_strings_triple_quotes.html)
* [3.3.4. Creating long strings](python_strings_long_strings.html)
* [3.3.5. Including variable contents in strings using f-strings](python_strings_fstrings.html)
* [3.3.5.1. Exercise: Strings](python_strings_exercise.html)
* [3.3.6. User input](python_strings_input.html)
* [3.4. Functions](python_functions.html)
* [3.4.1. Function syntax](python_functions_syntax.html)
* [3.4.2. Argument names](python_functions_arguments.html)
* [3.4.2.1. Exercise: Function arguments](python_functions_arguments_exercise.html)
* [3.4.3. Return values](python_functions_return.html)
* [3.4.3.1. Exercise: Function return values 1](python_functions_return_exercise1.html)
* [3.4.3.2. Exercise: Function return values 2](python_functions_return_exercise2.html)
* [3.4.4. Docstrings](python_functions_docstrings.html)
* [3.4.5. Type annotations](python_functions_type_annotations.html)
* [3.4.6. Positional and keyword arguments](python_functions_positional_keywords.html)
* [3.4.7. Default values](python_functions_default_values.html)
* [3.4.7.1. Exercise: Function argument’s default values](python_functions_default_values_exercise.html)
* [3.5. Conditions and booleans](python_conditions.html)
* [3.5.1. Boolean and comparisons](python_conditions_boolean.html)
* [3.5.2. Conditional code](python_conditions_if_elif_else.html)
```
--------------------------------
### Download Example Data
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_modules/ktk/doc.html
Downloads example data from GitHub, used for generating documentation website examples. It checks for local availability and optionally forces a download. Requires the 'requests' library.
```python
import kineticstoolkit.config as config
from kineticstoolkit.typing_ import check_param
import os
def __dir__():
return ["download"]
[[docs]](../../api/ktk.doc.download.html#ktk.doc.download)
def download(filename: str, **kwargs) -> str:
"""
Download example data and return its local file name.
This function downloads example data from GitHub. These data are the same
as those used to generate the documentation website:
https://kineticstoolkit.uqam.ca
Parameters
----------
filename
A string that indicates which file to download.
Returns
-------
str
The file name (with complete path) of the downloaded sample data.
Caution
-------
These example data are volatile; they are supplied only for the user to
reproduce the tutorials. Therefore, these data may change according to
changes in the tutorials.
Note
----
The `**kwargs` arguments are for debugging and internal use only.
"""
# Additional information for developers:
# kwargs may include force_download=True, to force download from github.
# In standard case, the local git version is used to save on download time.
check_param("filename", filename, str)
if "force_download" not in kwargs:
kwargs["force_download"] = False
try:
import requests
except ModuleNotFoundError:
raise ModuleNotFoundError(
"The requests module is an optional dependency of Kinetics "
"Toolkit. It must be installed to allow downloading data."
)
# Try to get the file locally from the local git repository
path = config.root_folder + "/data/" + filename
if os.path.exists(path) is True and kwargs["force_download"] is False:
return path
else:
# Otherwise download it.
file = requests.get(
"https://github.com/felixchenier/kineticstoolkit/raw/master/data/"
+ filename
)
if file.status_code == 404:
raise FileNotFoundError(
f"'{filename}' could not be found on the server."
)
path = config.temp_folder + "/" + filename
open(path, "wb").write(file.content)
return path
```
--------------------------------
### Install Kinetic Toolkit from GitHub
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/dev_installing_from_github.html
Instructions for cloning the Kinetic Toolkit repository and setting up the Python environment for development.
```bash
git clone https://github.com/felixchenier/kineticstoolkit.git kineticstoolkit
export PYTHONPATH=$PYTHONPATH:kineticstoolkit
```
--------------------------------
### For loop with range(begin, end, step) - custom start
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/python_for_range.md
Demonstrates `range(begin, end, step)` with a custom starting point. This example counts from 5 to 9 by steps of 2.
```python
# Count from 5 to 9 by steps of 2
for i in range(5, 10, 2):
print("The variable i is:", i)
```
--------------------------------
### Project Initialization and Theme Setup
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/timeseries_data_management.html
Initializes project settings by retrieving theme preferences from local storage and applying them to the document element. It also sets up Thebe for interactive code execution.
```javascript
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
let toggleHintShow = 'Click to show';
let toggleHintHide = 'Click to hide';
let toggleOpenOnPrint = 'true';
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
DOCUMENTATION_OPTIONS.pagename = 'timeseries_data_management';
```
--------------------------------
### Get TimeSeries After Index
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.TimeSeries.get_ts_after_index.html
Retrieves a subset of the TimeSeries data starting from a specified index. It can optionally include the element at the index itself.
```python
ts.get_ts_after_index(2)
# Output: array([0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
ts.get_ts_after_index(2, inclusive=True).time
# Output: array([0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
```
--------------------------------
### Kineticstoolkit API Reference
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/getting_started.md
Access to the comprehensive API reference for the Kineticstoolkit, providing detailed information on all available functions, classes, and methods for experienced Python biomechanics analysts.
```markdown
API Reference
```
--------------------------------
### Python List Slicing Syntax
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/python_lists_slicing.html
Demonstrates how to extract sub-lists from a list in Python using slicing. It explains the syntax `list[start:stop]` where `start` is inclusive and `stop` is exclusive, and provides examples.
```python
list_of_strings = [
"string 0",
"string 1",
"string 2",
"string 3",
"string 4",
"string 5",
"string 6",
"string 7",
"string 8",
"string 9",
]
# Extracting a single element (index 2)
print(list_of_strings[2])
# Extracting a sub-list from index 2 up to (but not including) index 7
print(list_of_strings[2:7])
```
--------------------------------
### Importing Data into Kineticstoolkit
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/getting_started.md
This section covers the process of importing data into the Kineticstoolkit, a crucial step for users who are ready to begin their biomechanical analysis workflow with the library.
```markdown
[](ktk_importing.md)
```
--------------------------------
### Get Time Series After Time
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.TimeSeries.get_ts_after_time.html
Retrieves a time series that starts after a specified time. This function is part of the Kinetics Toolkit for biomechanical analysis.
```python
ktk.TimeSeries.get_ts_after_time
```
--------------------------------
### Initialize Thebe
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started_installing.html
Configures and initializes Thebe for interactive code execution within the documentation. It sets up selectors for Thebe cells and input/output elements.
```javascript
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
```
--------------------------------
### For loop with range(begin, end)
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/python_for_range.md
Illustrates how to use `range(begin, end)` to create a sequence of numbers starting from `begin` (inclusive) up to `end` (exclusive). This example counts from 5 to 9.
```python
# Count from 5 to 9
for i in range(5, 10):
print("The variable i is:", i)
```
--------------------------------
### Installing Kinetic Toolkit from GitHub
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.Player.to_video.html
This section provides instructions on how to install the Kinetic Toolkit directly from its GitHub repository. It is useful for developers who want to use the latest version or contribute to the project.
```bash
git clone https://github.com/kineticstoolkit/kineticstoolkit.git
cd kineticstoolkit
pip install -e .
```
--------------------------------
### Get TimeSeries After Time
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/timeseries_segmenting.html
Extracts a TimeSeries segment starting from a specific timestamp. This method allows analysis of data that occurred after a known point in time.
```python
new_ts = ts.get_ts_after_time(4.37)
```
--------------------------------
### Contribute to Kinetic Toolkit
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/dev_installing_from_github.html
Steps for forking the repository, making code modifications, running tests, and submitting pull requests.
```bash
# Fork the repository
# Clone your fork
git clone
# Install development dependencies
pip install pytest mypy coverage
# Make changes, run tests, commit, push, and create a Pull Request
```
--------------------------------
### Initialize Theme and Mode
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started.html
This JavaScript code snippet initializes the application's mode and theme based on local storage settings. It also defines constants for Thebe.js integration and selectors for interactive elements.
```javascript
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
let toggleHintShow = 'Click to show';
let toggleHintHide = 'Click to hide';
let toggleOpenOnPrint = 'true';
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
DOCUMENTATION_OPTIONS.pagename = 'getting_started';
```
--------------------------------
### Python User Input Example - Python
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/dev_rules.html
Shows how to get input from the user in Python using the `input()` function. The input received is always a string.
```python
# Example of getting user input
user_name = input("Enter your name: ")
print(f"Hello, {user_name}!")
```
--------------------------------
### Get TimeSeries Between Events with Inclusive Options
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/timeseries_segmenting.md
Demonstrates the effect of the 'inclusive' parameter on the get_ts_between_events method, showing how it affects the data extraction based on whether the start and end events are included.
```python
plt.subplot(2, 2, 1)
ts1 = ts.get_ts_between_events("push", "push", 0, 4, inclusive=False)
ts1 = ts1.trim_events()
ts1.plot(legend=False)
plt.xlabel("Inclusive = False")
plt.subplot(2, 2, 2)
ts2 = ts.get_ts_between_events("push", "push", 0, 4, inclusive=True)
ts2 = ts2.trim_events()
ts2.plot(legend=False)
plt.xlabel("Inclusive = True")
plt.subplot(2, 2, 3)
ts3 = ts.get_ts_between_events("push", "push", 0, 4, inclusive=[False, True])
ts3 = ts3.trim_events()
ts3.plot(legend=False)
plt.xlabel("Inclusive = [False, True]")
plt.subplot(2, 2, 4)
ts4 = ts.get_ts_between_events("push", "push", 0, 4, inclusive=[True, False])
ts4 = ts4.trim_events()
ts4.plot(legend=False)
plt.xlabel("Inclusive = [True, False]")
plt.tight_layout()
```
--------------------------------
### Search Button Initialization
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started.html
This HTML and JavaScript code dynamically writes an image logo and a search button with a keyboard shortcut hint. It's designed to be part of a documentation website.
```html
document.write(``);
document.write(` `);
```
--------------------------------
### Get TimeSeries Between Events (Multiple)
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/timeseries_segmenting.md
Extracts a new TimeSeries between a start and end event, with options to specify the occurrence number and inclusivity. Also demonstrates trimming events from the resulting TimeSeries.
```python
# Extract the four pushes
first_four_pushes = ts.get_ts_between_events("push", "push", 0, 4, inclusive=True)
# Remove the events outside the resulting TimeSeries
first_four_pushes = first_four_pushes.trim_events()
# Plot the result
first_four_pushes.plot()
```
--------------------------------
### Set Document Mode and Theme
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started_installing.html
Sets the document's mode and theme based on local storage settings, allowing for persistent user preferences.
```javascript
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
```
--------------------------------
### Initialize Theme and Mode
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/python_basics.html
Sets the initial theme and mode for the document based on local storage settings. This JavaScript code ensures a consistent user experience across sessions.
```javascript
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
```
--------------------------------
### Get Time Series After Index
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/api/ktk.TimeSeries.get_ts_after_index.rst
Retrieves a subset of the time series data starting from the index immediately following the specified index. This is useful for segmenting or analyzing data that occurs after a particular event or point in time.
```python
ktk.TimeSeries.get_ts_after_index(index: int) -> TimeSeries
Retrieves a subset of the time series data starting from the index immediately following the specified index.
Args:
index (int): The index after which to retrieve data.
Returns:
TimeSeries: A new TimeSeries object containing data after the specified index.
```
--------------------------------
### For loop with range(begin, end)
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/src/python_for_range.md
Illustrates using `range(begin, end)` to create a sequence of numbers starting from a specified beginning value up to (but not including) an end value. This example counts from 5 to 9.
```python
# Count from 5 to 9
for i in range(5, 10):
print("The variable i is:", i)
```
--------------------------------
### Python Exercises for Biomechanics
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/getting_started.md
A collection of programming exercises designed to refresh or introduce Python concepts relevant to biomechanical analysis. Useful for users familiar with Python but new to the field.
```markdown
[](python_exercises.md)
```
--------------------------------
### Search Button Initialization
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started_installing.html
Dynamically writes an HTML image element for the logo and a search button with keyboard shortcut functionality.
```javascript
document.write(``);
document.write(` `);
```
--------------------------------
### Python Looping a List using 'for' and 'enumerate'
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started.html
This section explains how to use the 'enumerate()' function with 'for' loops to get both the index and the value of each item in a list during iteration.
```python
# Using enumerate with a list
my_list = ["apple", "banana", "cherry"]
for index, value in enumerate(my_list):
print(f"Index: {index}, Value: {value}")
# Output:
# Index: 0, Value: apple
# Index: 1, Value: banana
# Index: 2, Value: cherry
```
--------------------------------
### Get TimeSeries Between Times
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_modules/kineticstoolkit/timeseries.html
Retrieves a subset of the TimeSeries data within a specified time range. Supports inclusive or exclusive boundaries for the start and end times. Raises TimeSeriesRangeError if no data exists within the specified range.
```python
def get_ts_between_times(
self,
time1: float,
time2: float,
*,
inclusive: bool | tuple[bool, bool] = False,
) -> TimeSeries:
"""
Get a TimeSeries between two specified times.
Parameters
----------
time1, time2
Times to look for in the TimeSeries' time attribute.
inclusive
Optional. Either a bool or a tuple of two bools. Used to
specify which times are returned:
- False or (False, False) (default): time1 < time < time2
- True or (True, True): time1 <= time <= time2
- (True, False): time1 <= time < time2
- (False, True): time1 < time <= time2
Returns
-------
TimeSeries
A new TimeSeries that fulfils the specified conditions.
Raises
------
TimeSeriesRangeError
If there is no data between the specified times.
See Also
--------
ktk.TimeSeries.get_ts_between_indexes
ktk.TimeSeries.get_ts_between_events
ktk.TimeSeries.get_ts_before_time
ktk.TimeSeries.get_ts_after_time
Example
-------
>>> ts = ktk.TimeSeries(time=np.arange(10)/10)
>>> ts.time
array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
>>> ts.get_ts_between_times(0.2, 0.5).time
array([0.3, 0.4])
>>> ts.get_ts_between_times(0.2, 0.5, inclusive=True).time
array([0.2, 0.3, 0.4, 0.5])
>>> ts.get_ts_between_times(0.2, 0.5, inclusive=[True, False]).time
array([0.2, 0.3, 0.4])
"""
check_param("time1", time1, float)
check_param("teim2", time2, float)
if isinstance(inclusive, bool):
inclusive = (inclusive, inclusive)
try:
inclusive = cast(tuple[bool, bool], tuple(inclusive))
check_param(
"inclusive",
inclusive,
tuple,
length=2,
contents_type=bool,
)
except TypeError:
raise TypeError(
"inclusive must be either a bool or a tuple of two bools."
)
if time2 < time1:
raise ValueError(
"The parameters time2 must be higher or equal to time1. "
f"However, time2 is {time2} while time1 is {time1}."
)
index1 = self.get_index_after_time(time1, inclusive=inclusive[0])
index2 = self.get_index_before_time(time2, inclusive=inclusive[1])
return self.get_ts_between_indexes(index1, index2, inclusive=True)
```
--------------------------------
### Developer Installation from GitHub
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.Player.to_image.html
This section provides instructions on how to install the Kinetics Toolkit directly from its GitHub repository. This is typically for developers who want the latest code or wish to contribute to the project.
```bash
git clone https://github.com/user/kineticstoolkit.git
cd kineticstoolkit
pip install -e .
```
--------------------------------
### Reading a Subset of Elements (Slicing)
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/numpy_indexing_slicing_1d.md
Demonstrates how to extract a range of elements from a one-dimensional NumPy array using slicing. This includes specifying start, stop, and step values. The example plots both the original and the sliced data.
```python
# Keep only the values at indexes 2, 4, 6 and 8 of the original array
# Start at 2 (incl.), up to 9 (excl.) by steps of 2:
data_subset = data[2:9:2]
time_subset = time[2:9:2]
# Plot the result
plt.plot(time, data, "s-", label="original data")
plt.plot(time_subset, data_subset, "o-", label="subset")
plt.grid(True)
plt.legend();
```
--------------------------------
### Document Initialization and Thebe Setup
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/files.html
Initializes document properties for dark/light mode and theme, sets up Thebe for interactive code execution, and defines selectors for Thebe elements.
```javascript
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
let toggleHintShow = 'Click to show';
let toggleHintHide = 'Click to hide';
let toggleOpenOnPrint = 'true';
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
```
--------------------------------
### Get Time Series Between Indexes
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.TimeSeries.get_ts_between_indexes.html
Retrieves a segment of a time series data between specified start and end indexes. This method is useful for isolating specific portions of biomechanical data for analysis.
```python
ktk.TimeSeries.get_ts_between_indexes(start_index, end_index)
```
--------------------------------
### Initialize Thebe and Spyder Configuration
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started_configuring_spyder.html
This snippet initializes Thebe for interactive Python execution and sets up Spyder IDE configuration options. It includes settings for Thebe's JavaScript URL, selectors for interactive cells, and theme/mode persistence using local storage.
```javascript
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
let toggleHintShow = 'Click to show';
let toggleHintHide = 'Click to hide';
let toggleOpenOnPrint = 'true';
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
DOCUMENTATION_OPTIONS.pagename = 'getting_started_configuring_spyder';
```
--------------------------------
### Get Time Series Between Indexes
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/api/ktk.TimeSeries.get_ts_between_indexes.rst
Retrieves a segment of the time series data between two specified index values. This method is useful for isolating specific portions of time series for analysis or visualization. It requires the start and end indexes as input.
```python
ktk.TimeSeries.get_ts_between_indexes(start_index: int, end_index: int) -> TimeSeries
"""Get a segment of the time series between two indexes.
Args:
start_index (int): The starting index (inclusive).
end_index (int): The ending index (inclusive).
Returns:
TimeSeries: A new TimeSeries object containing the data between the specified indexes.
"""
pass
```
--------------------------------
### Developer Installation from GitHub
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.Player.html
This section provides instructions on how to install the Kinetics Toolkit directly from its GitHub repository. This is typically for developers who want the latest code or wish to contribute to the project.
```bash
git clone https://github.com/user/kineticstoolkit.git
cd kineticstoolkit
pip install -e .
```
--------------------------------
### Coordinate Transformation with get_global_coordinates
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/geometry_transform_changing_coordinate_system_example.md
This snippet shows a simplified way to get global coordinates using the `get_global_coordinates` function from Kinetics Toolkit. It takes local coordinates and reference frames as input to compute the transformed global coordinates.
```python
global_p_elbow = ktk.geometry.get_global_coordinates(
local_coordinates=local_p_elbow, reference_frames=T_upperarm
)
global_p_elbow
```
--------------------------------
### Get Time Series Between Times
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_sources/api/ktk.TimeSeries.get_ts_between_times.rst
Retrieves a subset of the time series data that falls within a specified start and end time. This method is useful for isolating specific periods of data for analysis. It requires the TimeSeries object to have valid time-indexed data.
```python
ktk.TimeSeries.get_ts_between_times(start_time, end_time)
Parameters:
start_time (float): The starting timestamp (inclusive).
end_time (float): The ending timestamp (inclusive).
Returns:
TimeSeries: A new TimeSeries object containing data within the specified time range.
```
--------------------------------
### Project Configuration and Initialization
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.kinematics.track_cluster.html
This snippet shows the initial setup for the project, including setting the document mode and theme, defining toggle hints, and configuring Thebe for interactive code execution. It also sets the page name for documentation purposes.
```javascript
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
let toggleHintShow = 'Click to show';
let toggleHintHide = 'Click to hide';
let toggleOpenOnPrint = 'true';
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
DOCUMENTATION_OPTIONS.pagename = 'api/ktk.kinematics.track_cluster';
```
--------------------------------
### Developer Installation from GitHub
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.TimeSeries.ui_sync.html
This section provides instructions on how to install the Kinetics Toolkit directly from its GitHub repository. This is typically for developers who want the latest code or wish to contribute to the project.
```bash
git clone https://github.com/user/kineticstoolkit.git
cd kineticstoolkit
pip install -e .
```
--------------------------------
### Python Looping: for Loop with range Exercise 2
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started_configuring_spyder.html
This is the second exercise on using `for` loops with `range()`, potentially involving different `range()` parameters (start, stop, step) for varied iteration patterns.
```python
# Exercise for for loops with range (Part 2)
# Practice with different range() arguments.
```
--------------------------------
### Python List Slicing Exercise 2
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/getting_started_configuring_spyder.html
This is the second exercise on Python list slicing, offering more complex scenarios or variations of slicing techniques. It aims to solidify understanding of start, stop, and step parameters.
```python
# Exercise for list slicing (Part 2)
# Advanced list slicing practice.
```
--------------------------------
### Project Initialization and Configuration
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.write_c3d.html
This snippet shows the initial JavaScript code executed for the project, likely for setting up the user interface theme, handling local storage for mode and theme preferences, and configuring Thebe for interactive code execution.
```javascript
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
let toggleHintShow = 'Click to show';
let toggleHintHide = 'Click to hide';
let toggleOpenOnPrint = 'true';
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
var togglebuttonSelector = '.toggle, .admonition.dropdown';
const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js";
const thebe_selector = ".thebe,.cell";
const thebe_selector_input = "pre";
const thebe_selector_output = ".output, .cell_output"
DOCUMENTATION_OPTIONS.pagename = 'api/ktk.write_c3d';
```
--------------------------------
### Kinetic Toolkit Initialization
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/_modules/kineticstoolkit/player.html
Demonstrates the initialization of the Kinetic Toolkit, including setting up default interconnections and vectors, and configuring playback and view parameters.
```python
def __init__(
self,
*ts: TimeSeries,
interconnections: dict[str, dict[str, Any]] = {
"ForcePlatforms": {
"Links": [
["*_Corner1", "*_Corner2"],
["*_Corner2", "*_Corner3"],
["*_Corner3", "*_Corner4"],
["*_Corner1", "*_Corner4"],
],
"Color": (0.5, 0.0, 1.0),
},
},
vectors: dict[str, dict[str, Any]] = {
"*Force": {
"Origin": "*COP",
"Scale": 0.001,
"Color": (1.0, 1.0, 0.0),
}
},
current_index: int = 0,
current_time: float | None = None,
playback_speed: float = 1.0,
up: str = "y",
anterior: str = "x",
zoom: float = 1.0,
azimuth: float = 0.0,
elevation: float = 0.2,
pan: tuple[float, float] = (0.0, 0.0),
target: tuple[float, float, float] = (0.0, 0.0, 0.0),
perspective: bool = True,
track: bool = False,
default_point_color: str | tuple[float, float, float] = (
0.8,
0.8,
0.8,
),
default_interconnection_color: str | tuple[float, float, float] = (
0.8,
0.8,
0.8,
),
default_vector_color: str | tuple[float, float, float] = (
1.0,
1.0,
0.0,
),
point_size: float = 4.0,
interconnection_width: float = 1.5,
):
```
--------------------------------
### Python Example: Moving a Trajectory
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/geometry_moving_coordinates_exercise3.html
This snippet demonstrates moving a trajectory using Python, likely within the Kineticstoolkit library. It shows the setup of an arm reference with specific angles and sequence, followed by an array representing transformed coordinates.
```python
p_elbow_ref_arm,
angles=[0, 5, 10, 15],
seq="z",
)
array([[ 0. , -0.5 , 0. , 1. ],
[-0.47946214, -0.14183109, 0. , 1. ],
[-0.27201056, 0.41953576, 0. , 1. ],
[ 0.32514392, 0.37984396, 0. , 1. ]])
```
--------------------------------
### Python Lists: Slicing Lists Exercise 1
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/python_numbers.html
This exercise introduces the concept of list slicing in Python, focusing on extracting sub-lists using start and end indices. It covers basic slicing to get a range of elements.
```python
my_list = ['apple', 'banana', 'cherry', 'date', 'elderberry']
# Get elements from index 1 up to (but not including) index 3
sub_list = my_list[1:3]
print(f"Slice [1:3]: {sub_list}")
# Get elements from the beginning up to index 2
sub_list_start = my_list[:2]
print(f"Slice [:2]: {sub_list_start}")
```
--------------------------------
### Developer Installation from GitHub
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.Player.get_contents.html
This section provides instructions on how to install the Kinetics Toolkit directly from its GitHub repository. This is typically for developers who want the latest code or wish to contribute to the project.
```bash
git clone https://github.com/user/kineticstoolkit.git
cd kineticstoolkit
pip install -e .
```
--------------------------------
### Python Lists: Slicing Lists Exercise 1
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/extensions.html
This exercise introduces the concept of list slicing in Python, focusing on extracting sub-lists using start and end indices. It covers basic slicing to get a range of elements.
```python
my_list = ['apple', 'banana', 'cherry', 'date', 'elderberry']
# Get elements from index 1 up to (but not including) index 3
sub_list = my_list[1:3]
print(f"Slice [1:3]: {sub_list}")
# Get elements from the beginning up to index 2
sub_list_start = my_list[:2]
print(f"Slice [:2]: {sub_list_start}")
```
--------------------------------
### Initialize Theme and Mode
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/python_for_writing_list.html
Sets the initial theme and mode for the document based on local storage settings. This script ensures a consistent user experience across sessions.
```javascript
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
```
--------------------------------
### Python Lists: Slicing Lists Exercise 1
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/python_strings_backslash.html
This exercise introduces the concept of list slicing in Python, focusing on extracting sub-lists using start and end indices. It covers basic slicing to get a range of elements.
```python
my_list = ['apple', 'banana', 'cherry', 'date', 'elderberry']
# Get elements from index 1 up to (but not including) index 3
sub_list = my_list[1:3]
print(f"Slice [1:3]: {sub_list}")
# Get elements from the beginning up to index 2
sub_list_start = my_list[:2]
print(f"Slice [:2]: {sub_list_start}")
```
--------------------------------
### Developer Installation from GitHub
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.Player.set_view.html
This section provides instructions on how to install the Kinetics Toolkit directly from its GitHub repository. This is typically for developers who want the latest code or wish to contribute to the project.
```bash
git clone https://github.com/user/kineticstoolkit.git
cd kineticstoolkit
pip install -e .
```
--------------------------------
### Python Lists: Slicing Lists Exercise 1
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/python_functions_docstrings.html
This exercise introduces the concept of list slicing in Python, focusing on extracting sub-lists using start and end indices. It covers basic slicing to get a range of elements.
```python
my_list = ['apple', 'banana', 'cherry', 'date', 'elderberry']
# Get elements from index 1 up to (but not including) index 3
sub_list = my_list[1:3]
print(f"Slice [1:3]: {sub_list}")
# Get elements from the beginning up to index 2
sub_list_start = my_list[:2]
print(f"Slice [:2]: {sub_list_start}")
```
--------------------------------
### Installing Kinetic Toolkit from GitHub
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/api/ktk.Player.play.html
This section provides instructions on how to install the Kinetic Toolkit directly from its GitHub repository. It is useful for developers who want to use the latest version or contribute to the project.
```bash
git clone https://github.com/kineticstoolkit/kineticstoolkit.git
cd kineticstoolkit
pip install -e .
```
--------------------------------
### Python Lists: Slicing Lists Exercise 1
Source: https://github.com/kineticstoolkit/kineticstoolkit_doc/blob/master/html/python_conditions_if_elif_else.html
This exercise introduces the concept of list slicing in Python, focusing on extracting sub-lists using start and end indices. It covers basic slicing to get a range of elements.
```python
my_list = ['apple', 'banana', 'cherry', 'date', 'elderberry']
# Get elements from index 1 up to (but not including) index 3
sub_list = my_list[1:3]
print(f"Slice [1:3]: {sub_list}")
# Get elements from the beginning up to index 2
sub_list_start = my_list[:2]
print(f"Slice [:2]: {sub_list_start}")
```