### Installing Pre-commit Hooks (Shell) Source: https://github.com/me-ica/tedana/blob/main/CONTRIBUTING.md This command installs the pre-commit hooks for the tedana repository. These hooks automatically check and fix code style issues before a commit is pushed, ensuring compliance with the project's style guides. ```shell pre-commit install ``` -------------------------------- ### Install Tedana with All Dependencies using pip Source: https://github.com/me-ica/tedana/blob/main/CONTRIBUTING.md Installs tedana and all its optional dependencies into a pre-existing Python environment. This command is useful for setting up a development environment when uv is not used or when installing into an existing virtual environment. The '-e' flag installs the package in editable mode. ```shell pip install -e '.[all]' ``` -------------------------------- ### Verify Tedana Installation via CLI Source: https://github.com/me-ica/tedana/blob/main/README.md This command-line interface (CLI) command checks if tedana is installed and accessible. Running 'tedana --help' should display the help information for the tedana tool, indicating a successful installation. ```bash tedana --help ``` -------------------------------- ### Install Tedana with Development Dependencies (Pip) Source: https://github.com/me-ica/tedana/blob/main/CONTRIBUTING.md Installs the tedana package in editable mode, including all extra requirements needed for testing and documentation. This command ensures that the package is correctly linked to the user's profile and all necessary dependencies are met. ```bash pip install -e .[all] ``` -------------------------------- ### Launch Rica Interactive Report Source: https://github.com/me-ica/tedana/blob/main/docs/outputs.md This script launches the Rica interactive visualization tool for exploring ICA components. It checks for Rica files, downloads them if necessary, copies them to the output directory, starts a local HTTP server, and opens Rica in the default web browser. The script is executed from the output directory of a tedana run. ```bash cd output python open_rica_report.py ``` -------------------------------- ### Specify Rica Port (Python) Source: https://github.com/me-ica/tedana/blob/main/docs/outputs.md Shows how to specify a different starting port for the Rica web server when running the `open_rica_report.py` script. This is useful if the default port (8000) and subsequent ports are already in use. ```python python open_rica_report.py --port 9000 ``` -------------------------------- ### Import Tedana Workflows in Python Source: https://github.com/me-ica/tedana/blob/main/docs/installation.md Demonstrates how to import the main workflow functions from the tedana package into your Python scripts. This allows for programmatic control and integration of tedana analyses. ```python from tedana.workflows import ica_reclassify_workflow, t2smap_workflow, tedana_workflow ``` -------------------------------- ### Install tedana Python Package Source: https://github.com/me-ica/tedana/blob/main/README.md Installs the tedana Python library using pip. This command assumes you have Python >=3.8 and pip installed. It will download and install tedana along with its dependencies. ```bash pip install tedana ``` -------------------------------- ### Synchronize Development Environment with uv Source: https://github.com/me-ica/tedana/blob/main/CONTRIBUTING.md Installs tedana and all its dependencies into a local .venv directory using the uv package manager. This command ensures a clean and isolated development environment, preventing conflicts with other Python installations. It's recommended to run this from the root of your local tedana repository. ```shell uv sync --extra=all ``` -------------------------------- ### Set TEDANA_RICA_PATH Environment Variable (Bash) Source: https://github.com/me-ica/tedana/blob/main/docs/outputs.md Demonstrates how to set the TEDANA_RICA_PATH environment variable for the current session to point to a local Rica build. This is useful for developers or users who need to use a custom Rica installation. ```bash # Set for current session export TEDANA_RICA_PATH=/path/to/rica/build # Then run the launcher script python open_rica_report.py ``` -------------------------------- ### Verify Tedana Installation in Python Source: https://github.com/me-ica/tedana/blob/main/README.md This Python code snippet imports the tedana library. If the import is successful without raising an error, it confirms that tedana has been correctly installed and is accessible within the Python environment. ```python import tedana ``` -------------------------------- ### Install Tedana using Conda Source: https://github.com/me-ica/tedana/blob/main/docs/installation.md Creates a dedicated Conda environment named 'tedenv' with Python 3.12 and pip, then installs tedana within that environment. This method ensures dependency isolation and optimization for tedana. ```bash conda create -n tedenv python=3.12 pip conda activate tedenv pip install tedana ``` -------------------------------- ### Build Documentation Locally (Make) Source: https://github.com/me-ica/tedana/blob/main/CONTRIBUTING.md Renders the HTML documentation files locally. After running this command, you can view the rendered documentation in the 'docs/_build' directory in your web browser. ```bash make html ``` -------------------------------- ### Manually Download and Use Local Rica Bundle (Bash) Source: https://github.com/me-ica/tedana/blob/main/docs/outputs.md Provides instructions for manually downloading Rica release files and setting the TEDANA_RICA_PATH environment variable to use a local bundle. This is a workaround for Rica download failures. ```bash # Download Rica release manually wget https://github.com/ME-ICA/rica/releases/latest/download/index.html wget https://github.com/ME-ICA/rica/releases/latest/download/rica_server.py # Place files in a directory and set the environment variable mkdir ~/rica-bundle mv index.html rica_server.py ~/rica-bundle/ export TEDANA_RICA_PATH=~/rica-bundle # Run the launcher python open_rica_report.py ``` -------------------------------- ### Run Style Checks (Make) Source: https://github.com/me-ica/tedana/blob/main/CONTRIBUTING.md Executes style checks using flake8, black, and isort. This command requires these tools to be in your system's PATH. If you used 'uv sync --extra all', activate the environment first with 'source .venv/bin/activate'. ```bash make lint ``` -------------------------------- ### Create tar.gz Archive for Integration Tests Source: https://github.com/me-ica/tedana/blob/main/docs/contributing.md This bash command creates a compressed tar archive (.tar.gz) containing specified files, typically used to prepare data for integration tests in the tedana project. It takes the desired archive name and the source files/directories as input. ```bash tar czf my_data.tar.gz my_data/*.nii.gz ``` -------------------------------- ### Run Style Checks (Tox) Source: https://github.com/me-ica/tedana/blob/main/CONTRIBUTING.md Executes style checks using tox, which can manage virtual environments and dependencies for testing. This is an alternative to the 'make lint' command. ```bash tox -e lint ``` -------------------------------- ### Create and Activate Miniconda Environment for Tedana Source: https://github.com/me-ica/tedana/blob/main/README.md This snippet demonstrates how to create a new conda environment named 'ENVIRONMENT_NAME' with specified Python packages and then activate it. It also includes commands to install tedana and its dependencies using pip. This ensures tedana is installed in an isolated environment. ```bash conda create -n ENVIRONMENT_NAME python=3 pip mdp numpy scikit-learn scipy conda activate ENVIRONMENT_NAME pip install nilearn nibabel pip install tedana ``` -------------------------------- ### Get Elbow Index or Value Source: https://github.com/me-ica/tedana/blob/main/docs/generated/tedana.selection.selection_utils.getelbow.md Retrieves the elbow index or the corresponding metric value from a given array of metric values using a linear projection method. ```APIDOC ## GET /me-ica/tedana/selection/getelbow ### Description Retrieves the elbow index or the corresponding metric value from a given array of metric values using a linear projection method. This is useful for determining the optimal number of components in data analysis. ### Method GET ### Endpoint /me-ica/tedana/selection/getelbow ### Parameters #### Query Parameters - **arr** (array_like) - Required - Metric (e.g., Kappa or Rho) values. - **return_val** (bool) - Optional - If True, returns the value of the elbow instead of the index. Defaults to False. ### Request Example ``` GET /me-ica/tedana/selection/getelbow?arr=[1, 2, 3, 4, 5, 4, 3, 2, 1]&return_val=False ``` ### Response #### Success Response (200) - **result** (int or float) - Either the elbow index (if return_val is False) or the values at the elbow index (if return_val is True). #### Response Example ```json { "result": 4 } ``` ``` -------------------------------- ### Load Configuration Source: https://github.com/me-ica/tedana/blob/main/docs/generated/tedana.selection.component_selector.load_config.md Loads and validates a JSON configuration file for the component selection process. It takes a tree identifier or path and an output directory, returning a validated decision tree. ```APIDOC ## load_config ### Description Loads and validates a JSON configuration file for the component selection process. It takes a tree identifier or path and an output directory, returning a validated decision tree. ### Method POST ### Endpoint /me-ica/tedana/selection/component_selector/load_config ### Parameters #### Query Parameters - **tree** (str) - Required - The named tree or path to a JSON file that defines one. - **out_dir** (str) - Optional - The output directory. Default is current working directory. ### Request Example ```json { "tree": "path/to/your/decision_tree.json", "out_dir": "./output" } ``` ### Response #### Success Response (200) - **tree** (dict) - A validated decision tree for the component selection process. #### Response Example ```json { "tree": { "component1": { "condition": "some_condition", "action": "keep" } } } ``` #### Error Response (400) - **error** (str) - ValueError if the tree can't be loaded. ``` -------------------------------- ### tedana.selection.selection_nodes.calc_varex_kappa_ratio Source: https://github.com/me-ica/tedana/blob/main/docs/generated/tedana.selection.selection_nodes.calc_varex_kappa_ratio.md Calculates the cross-component metric 'kappa_rate' and the 'variance explained / kappa' ratio for components. This metric helps in identifying components that are likely to be rejected due to high variance and low kappa. ```APIDOC ## POST /me-ica/tedana/selection/calc_varex_kappa_ratio ### Description Calculates the cross-component metric 'kappa_rate' and the 'variance explained / kappa' ratio for components. This metric helps in identifying components that are likely to be rejected due to high variance and low kappa. ### Method POST ### Endpoint /me-ica/tedana/selection/calc_varex_kappa_ratio ### Parameters #### Request Body - **selector** (ComponentSelector) - Required - The component selector object. - **decide_comps** (str or list[str]) - Required - Specifies which classifications to operate on (e.g., 'unclassified', 'all'). - **log_extra_info** (str) - Optional - Additional information to log. Defaults to "". - **custom_node_label** (str) - Optional - A label for the step. If empty, a label is generated automatically. Defaults to "". - **only_used_metrics** (bool) - Optional - If True, only returns metrics that would be used. Defaults to False. ### Request Example ```json { "selector": {"type": "ComponentSelector", "data": "..."}, "decide_comps": "unclassified", "only_used_metrics": false } ``` ### Response #### Success Response (200) - **selector** (ComponentSelector) - The updated selector object if only_used_metrics is False. - **used_metrics** (set[str]) - A set of metric names used if only_used_metrics is True. #### Response Example ```json { "selector": {"type": "ComponentSelector", "data": "..."} } ``` #### NOTE These measures are used in the original kundu decision tree. kappa_rate = (max-min kappa values of selected components)/(max-min variance explained) varex_k. varex kappa ratio = kappa_rate * “variance explained”/”kappa” for each component. Components with larger variance and smaller kappa are more likely to be rejected. This metric sometimes causes issues with high magnitude BOLD responses such as the V1 response to a block-design flashing checkerboard. ``` -------------------------------- ### Tedana IO Module Overview Source: https://github.com/me-ica/tedana/blob/main/docs/api.md This section provides an overview of the tedana.io module and its primary functionalities for data handling in the tedana workflow. ```APIDOC ## Module: tedana.io ### Description Handle most file input and output in the tedana workflow. Other functions in the module help write outputs which require multiple data sources, assist in writing per-echo verbose outputs, or act as helper functions for any of the above. ### Key Classes and Functions * **`tedana.io.OutputGenerator`**: A class for managing tedana outputs. * **`tedana.io.InputHarvester`**: Class for turning a registry file into a lookup table to get previous data. * **`tedana.io.CustomEncoder`**: Class for converting some types because of JSON serialization and numpy incompatibilities. * **`tedana.io.load_data`**: Coerce input data files to required 3D array output. * **`tedana.io.load_json`**: Load a json file from path. * **`tedana.io.get_fields`**: Identify all fields in an unformatted string. * **`tedana.io.new_nii_like`**: Coerce data into NiftiImage format like ref_img. * **`tedana.io.prep_data_for_json`**: Attempt to create a JSON serializable dictionary from a data dictionary. * **`tedana.io.add_decomp_prefix`**: Create component name with leading zeros matching number of components. * **`tedana.io.denoise_ts`**: Apply component classifications to data for denoising. * **`tedana.io.split_ts`**: Split data time series into accepted component time series and remainder. * **`tedana.io.write_split_ts`**: Split data into denoised / noise / ignored time series and save to disk. * **`tedana.io.writeresults`**: Denoise ts and save all resulting files to disk. * **`tedana.io.writeresults_echoes`**: Save individually denoised echos to disk. ``` -------------------------------- ### Force Rica Re-download (Python) Source: https://github.com/me-ica/tedana/blob/main/docs/outputs.md Illustrates how to force the `open_rica_report.py` script to re-download Rica, useful for obtaining newer versions or resolving issues with cached files. ```python python open_rica_report.py --force-download ``` -------------------------------- ### Set TEDANA_RICA_PATH for Rica Development (Bash) Source: https://github.com/me-ica/tedana/blob/main/docs/outputs.md Shows how to set the TEDANA_RICA_PATH environment variable to use a local Rica build when developing Rica. This involves building Rica locally and then exporting the path to the build output directory. ```bash # Build Rica locally cd ~/GitHub/rica npm run build # Set the environment variable to use the local build export TEDANA_RICA_PATH=~/GitHub/rica/build # Run the launcher script python open_rica_report.py ``` -------------------------------- ### Unit test for say_hello function (Python) Source: https://github.com/me-ica/tedana/blob/main/docs/contributing.md This Python unit test verifies the functionality of the `say_hello` function. It checks if the expected file is created and then cleans up the created file. It assumes the `say_hello` function and necessary modules like `op` and `os` are available. ```python def test_say_hello(): # run the function say_hello() # test the function assert op.exists('hello_world.txt') # clean up os.remove('hello_world.txt') ``` -------------------------------- ### OutputGenerator.get_name Source: https://github.com/me-ica/tedana/blob/main/docs/generated/tedana.io.OutputGenerator.get_name.md Generates a file path for output based on a description and additional formatting arguments. ```APIDOC ## OutputGenerator.get_name ### Description Generates a file path for output based on a description and additional formatting arguments. ### Method Not applicable (this is a class method). ### Endpoint Not applicable (this is a class method). ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python # Assuming an instance of OutputGenerator is available as 'generator' file_path = generator.get_name(description='my_data_echo_1', echo=1) ``` ### Response #### Success Response (200) - **name** (str) - The full path for the filename. #### Response Example ```json { "name": "/path/to/output/my_data_echo_1.nii.gz" } ``` ``` -------------------------------- ### Tedana IO Load JSON Source: https://github.com/me-ica/tedana/blob/main/docs/generated/tedana.io.load_json.md Loads a JSON file from a specified path and returns its content as a dictionary. Handles potential file not found or directory path errors. ```APIDOC ## POST /me-ica/tedana/load_json ### Description Loads a JSON file from a specified path and returns its content as a dictionary. Handles potential file not found or directory path errors. ### Method POST ### Endpoint /me-ica/tedana/load_json ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **path** (str) - Required - The path to the JSON file to load. ### Request Example ```json { "path": "/path/to/your/file.json" } ``` ### Response #### Success Response (200) - **data** (dict) - A dictionary representation of the JSON data. #### Response Example ```json { "example": "{\"key\": \"value\"}" } ``` #### Error Responses - **FileNotFoundError**: If the file does not exist. - **IsADirectoryError**: If the path is a directory instead of a file. ``` -------------------------------- ### tedana.selection API Source: https://github.com/me-ica/tedana/blob/main/docs/api.md This section covers the TEDANA component selection methods, including loading and classifying components, error handling, configuration loading, and tree validation. ```APIDOC ## tedana.selection API ### Description Provides methods for component selection in TEDANA, including classification, configuration loading, and tree validation. ### Methods - **ComponentSelector**: Load and classify components based on a specified tree. - **TreeError**: Passes errors that are raised when validate_tree fails. - **load_config**: Load the JSON file with the decision tree and validate the fields. - **validate_tree**: Confirm that the provided tree is a valid decision tree. ### Related Modules - **tedana.selection.selection_nodes**: Functions used as steps in a decision tree. - **tedana.selection.selection_utils**: Utility functions for tedana.selection. - **tedana.selection.tedica**: Functions to identify TE-dependent and TE-independent components. - **tedana.selection.tedpca**: Functions to identify TE-dependent and TE-independent components. ``` -------------------------------- ### Updated unit test for parameterized say_hello (Python) Source: https://github.com/me-ica/tedana/blob/main/docs/contributing.md This Python unit test is an enhanced version for a parameterized `say_hello` function. It iterates through various inputs to test the function's robustness, ensuring it correctly generates filenames based on the provided arguments and cleans up after each test case. ```python def test_say_hello(): # prefix of all files to be checked prefix = 'hello_' # suffix of all files to be checked suffix = '.txt' # run the function with several cases for x in ['world', 'solar system', 'galaxy', 'universe']: # current test name outname = prefix + x + suffix # call the function say_hello(x) # test the function assert op.exists(outname) # clean up from this call os.remove(outname) ``` -------------------------------- ### add_decomp_prefix Source: https://github.com/me-ica/tedana/blob/main/docs/generated/tedana.io.add_decomp_prefix.md Creates a component name with leading zeros based on the total number of components. ```APIDOC ## add_decomp_prefix ### Description Creates a component name with leading zeros matching the number of components. ### Method N/A (This is a Python function, not a REST API endpoint) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "comp_num": 5, "prefix": "component", "max_value": 10 } ``` ### Response #### Success Response (200) - **comp_name** (str) - Component name in the form _ #### Response Example ```json { "comp_name": "component_05" } ``` ``` -------------------------------- ### Run t2smap_workflow for T2smap Estimation and Combination Source: https://github.com/me-ica/tedana/blob/main/docs/generated/tedana.workflows.t2smap_workflow.md This Python code snippet demonstrates how to use the t2smap_workflow function to estimate T2* and S0, and to optimally combine multi-echo fMRI data. It requires the input data (as a file path or list of paths) and a list of echo times. Optional parameters allow customization of the analysis, such as specifying an output directory, a mask file, the number of dummy scans to exclude, and the fitting and combination modes. ```python from tedana.workflows import t2smap_workflow # Example usage: t2smap_workflow( data='path/to/your/data.nii.gz', tes=[0.07, 0.09, 0.11], out_dir='./output', mask='path/to/your/mask.nii.gz', dummy_scans=5, fittype='loglin', combmode='t2s', verbose=True, overwrite=True ) ```