flywheel.gear_context
Provides gear helper functions
GearContext
Bases: object
This class is DEPRECATED. Please use the Flywheel Gear Toolkit <https://flywheel-io.gitlab.io/public/gear-toolkit/index.html>_ instead.
Provides helper functions for gear development
client property
Get the SDK client, if an api key input exists.
Raises a ValueError if there is no api-key input.
Returns:
| Type | Description |
|---|---|
Client | The SDK client |
config property
Get the config dictionary.
Returns:
| Type | Description |
|---|---|
dict | The configuration dictionary. |
destination property
Get the destination reference.
Returns:
| Type | Description |
|---|---|
dict | The destination dictionary. |
output_dir property
Get the absolute path to the output directory.
Returns:
| Type | Description |
|---|---|
str | The absolute path to outputs. |
work_dir property
Get the absolute path to a work directory
Returns:
| Type | Description |
|---|---|
str | The absolute path to work. |
download_project_bids(target_dir='work/bids', src_data=False, subjects=None, sessions=None, folders=None, **kwargs)
Download the project in bids format to target_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_dir | str | The destination directory (otherwise work/bids will be used) | 'work/bids' |
src_data | bool | Whether or not to include src data (e.g. dicoms) | False |
subjects | list | The list of subjects to include (via subject code) otherwise all subjects | None |
sessions | list | The list of sessions to include (via session label) otherwise all sessions | None |
folders | list | The list of folders to include (otherwise all folders) e.g. ['anat', 'func'] | None |
kwargs | Additional arguments to pass to | {} |
Returns:
| Type | Description |
|---|---|
str | The absolute path to the downloaded bids directory |
download_session_bids(target_dir='work/bids', src_data=False, folders=None, **kwargs)
Download the session in bids format to target_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_dir | str | The destination directory (otherwise work/bids will be used) | 'work/bids' |
src_data | bool | Whether or not to include src data (e.g. dicoms) | False |
folders | list | The list of folders to include (otherwise all folders) e.g. ['anat', 'func'] | None |
kwargs | Additional arguments to pass to | {} |
Returns:
| Type | Description |
|---|---|
str | The absolute path to the downloaded bids directory |
get_context_value(name)
Get the context input for name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | The name of the input | required |
Returns:
| Type | Description |
|---|---|
dict | The input context value, or None if not found. |
get_input(name)
Get the input for name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | The name of the input | required |
Returns:
| Type | Description |
|---|---|
dict | The input dictionary, or None if not found. |
get_input_path(name)
Get the full path to the given input file.
Raises an exception if the input exists, but is not a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | The name of the input | required |
Returns:
| Type | Description |
|---|---|
str | The path to the input file if it exists, otherwise None |
init_logging(level='INFO')
Initializes logging to the given level
log_config()
Print the configuration and input files to the logger
open_input(name, mode='r', **kwargs)
Open the named input file.
Raises an exception if the input does not exist or is not a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | The name of the input | required |
mode | str | The open mode (default is 'r') | 'r' |
kwargs | Additional args to pass to | {} |
Returns:
| Type | Description |
|---|---|
file | The file object |
open_output(name, mode='w', **kwargs)
Open the named output file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | The name of the output | required |
mode | str | The open mode (default is 'w') | 'w' |
kwargs | Additional args to pass to | {} |
Returns:
| Type | Description |
|---|---|
file | The file object |
update_container_metadata(container_type, *args, **kwargs)
Update metadata for the given container name in the hierarchy.
A dictionary and/or a set of key=value args can be passed to this function.
The metadata will be written when write_metadata() is called, or if using this as a context manager, when the context is exited.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container_type | str | The container type (e.g. session or acquisition) | required |
args | The optional update dictionary | () | |
kwargs | The optional update key-value pairs | {} |
update_destination_metadata(*args, **kwargs)
Update metadata for the destination container.
A dictionary and/or a set of key=value args can be passed to this function.
The metadata will be written when write_metadata() is called, or if using this as a context manager, when the context is exited.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args | The optional update dictionary | () | |
kwargs | The optional update key-value pairs | {} |
update_file_metadata(file_name, *args, **kwargs)
Update metadata for the given file on the destination.
A dictionary and/or a set of key=value args can be passed to this function.
The metadata will be written when write_metadata() is called, or if using this as a context manager, when the context is exited.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_name | str | The name of the file | required |
args | The optional update dictionary | () | |
kwargs | The optional update key-value pairs | {} |
write_metadata()
Write the metadata json file to the output folder