PK V0Ww9 9 lemon_example.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# LEMON dataset example\n\nThis example illustrates the use of ``sovabids`` on the [LEMON dataset](http://fcon_1000.projects.nitrc.org/indi/retro/MPI_LEMON.html)\nusing both the python API and the CLI tool.\n\nThe main elements of this example are:\n * A source path with the original dataset.\n * A bids path that will be the output path of the conversion.\n * A rules file that configures how the conversion is done.\n * A mapping file that encodes how the conversion is performed to each individual file of the dataset.\n\n.. mermaid::\n\n graph LR\n S>\"Source path\"]\n B>\"Bids path\"]\n R>\"Rules file\"]\n AR((\"Apply Rules\"))\n M>\"Mappings file\"]\n CT((\"Convert Them\"))\n O[(\"Converted dataset\")]\n S --> AR\n B --> AR\n R --> AR\n AR --> M\n M --> CT\n CT --> O\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using the python API\nFirst we will illustrate how to run the software within python.\n\n### Imports\nFirst we import some functions we will need:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os # For path manipulation\nimport shutil # File manipulation\nfrom mne_bids import print_dir_tree # To show the input/output directories structures inside this example\nfrom sovabids.rules import apply_rules # Apply rules for conversion\nfrom sovabids.convert import convert_them # Do the conversion\nfrom sovabids.datasets import lemon_prepare # Download the dataset\nfrom sovabids.settings import REPO_PATH"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Getting and preparing the dataset\nWe have to download and decompress the dataset. We also need to fix a filename inconsistency\n(without this correction the file won't be able to be opened in mne). Luckily all of that is \nencapsulated in the lemon_prepare function since these issues are not properly of sovabids. \n\nBy default the files are saved in the '_data' directory of the sovabids project.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"lemon_prepare()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Setting up the paths\nNow we will set up four paths. Because this example is intended to run relative \nto the repository directory we use relative path but for real use-cases it is \neasier to just input the absolute-path. We will print these paths for more clarity.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"source_path = os.path.abspath(os.path.join(REPO_PATH,'_data','lemon')) # For the input data we will convert\nbids_path= os.path.abspath(os.path.join(REPO_PATH,'_data','lemon_bids')) # The output directory that will have the converted data\nrules_path = os.path.abspath(os.path.join(REPO_PATH,'examples','lemon_example_rules.yml')) # The rules file that setups the rule for conversion\nmapping_path = os.path.abspath(os.path.join(bids_path,'code','sovabids','mappings.yml')) # The mapping file that will hold the results of applying the rules to each file\n\nprint('source_path:',source_path.replace(REPO_PATH,''))\nprint('bids_path:', bids_path.replace(REPO_PATH,''))\nprint('rules_path:',rules_path.replace(REPO_PATH,''))\nprint('mapping_path:',mapping_path.replace(REPO_PATH,''))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Cleaning the output directory\nWe will clean the output path as a safety measure from previous conversions.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"try:\n shutil.rmtree(bids_path)\nexcept:\n pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The input directory\nFor clarity purposes we will print here the directory we are trying to convert to BIDS.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print_dir_tree(source_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Making the rules\nThe most important and complicated part of this is making the rules file, \neither by hand or by the \"DISCOVER_RULES\" module (which is not yet implemented).\n\nThis part is already done for you, but for clarification here are the rules \nwe are applying. Please read the following output as the yaml has some basic \ndocumentation comments.\n\nSee the Rules File Schema documentation for help regarding making this rules file.\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"with open(rules_path,encoding=\"utf-8\") as f:\n rules = f.read()\n print(rules)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Applying the rules\nWe apply the rules to the input dataset by giving the input,ouput,rules, and mapping paths to the apply_rules function.\n\nThis will produce by default a 'mappings.yml' file at the specified directory of 'bids_path/code/sovabids'.\n\nThis file holds the result of applying the rules to each of the dataset files.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"apply_rules(source_path,bids_path,rules_path,mapping_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Doing the conversion\nWe now do the conversion of the dataset by reading the mapping file ('mappings.yml') with the convert them module.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"convert_them(mapping_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Checking the conversion\nFor clarity purposes we will check the output directory we got from sovabids.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print_dir_tree(bids_path)\n\nprint('LEMON CONVERSION FINISHED!')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using the CLI tool\n\nsovabids can also be used through the command line. Here we provide an example of how to do so.\n\n\nThe overview of what we are doing is now:\n\n.. mermaid::\n\n graph LR\n S>\"Source path\"]\n B>\"Bids path\"]\n R>\"Rules file\"]\n AR((\"sovapply\"))\n M>\"Mappings file\"]\n CT((\"sovaconvert\"))\n O[(\"Converted dataset\")]\n S --> AR\n B --> AR\n R --> AR\n AR --> M\n M --> CT\n CT --> O\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Same old blues\nNotice that we will run this inside of python so that the example can be run without needing configuration.\n\nTo run this locally you will need to run lemon_prepare() function from the command line. You can do so by running:\n```bash\npython -c \"from sovabids.datasets import lemon_prepare; lemon_prepare()\"\n```\nSince we already have run lemon_prepare() inside this example, we will start from this step.\n\nWe set up the paths again, but now we will change the output to a new path (with \"_cli\" at the end). We will also clean this path as we did before.\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"source_path = os.path.abspath(os.path.join(REPO_PATH,'_data','lemon')) # For the input data we will convert\nbids_path= os.path.abspath(os.path.join(REPO_PATH,'_data','lemon_bids_cli')) # The output directory that will have the converted data\nrules_path = os.path.abspath(os.path.join(REPO_PATH,'examples','lemon_example_rules.yml')) # The rules file that setups the rule for conversion\nmapping_path = os.path.abspath(os.path.join(bids_path,'code','sovabids','mappings.yml')) # The mapping file that will hold the results of applying the rules to each file\n\nprint('source_path:',source_path.replace(REPO_PATH,''))\nprint('bids_path:', bids_path.replace(REPO_PATH,''))\nprint('rules_path:',rules_path.replace(REPO_PATH,''))\nprint('mapping_path:',mapping_path.replace(REPO_PATH,''))\n\ntry:\n shutil.rmtree(bids_path)\nexcept:\n pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Some necessary code\nTo be able to run commands from this notebook and capture their outputs we need to define the following, nevertheless this is not relevant to actually running this from the command line.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from subprocess import PIPE, run\n\ndef out(command):\n result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)\n return result.stdout\n\nmy_output = out(\"echo hello world\")\nprint(my_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### sovapply\nIn this example we have already made the rules. So we will apply them using the sovapply tool.\n\nUse the following command to print the help of the tool:\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"command = \"sovapply --help\"\nprint(command)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will give the following output\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"my_output= out(command)\nprint(my_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we will use the following command to get the mappings file.\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"command = 'sovapply '+source_path + ' '+ bids_path + ' ' + rules_path + ' -m ' + mapping_path\nprint(command)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will produce the following output:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"my_output= out(command)\nprint(my_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### sovaconvert\nNow we are ready to perform the conversion given the mapping file just made.\n\nUse the following command to print the help of the tool:\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"command = \"sovaconvert --help\"\nprint(command)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will give the following output\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"my_output= out(command)\nprint(my_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we will use the following command to perform the conversion.\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"command = 'sovaconvert ' + mapping_path\nprint(command)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will produce the following output:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"my_output= out(command)\nprint(my_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Checking the conversion\nFor clarity purposes we will check the output directory we got from sovabids.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print_dir_tree(bids_path)\n\nprint('LEMON CLI CONVERSION FINISHED!')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK
0W%N= = * example_heuristic_source_target_pair.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Usage example of source,target pair\n\nThis example illustrates how does the inference of the path_pattern from a (source,target) pair example works.\n\nThe main elements of this example are:\n * A source example path of one of your files\n * A target path that will be the expected mapping of your file.\n * The from_io_example heuristic that internally does the inference work.\n * A path pattern inferred from the above.\n\n\nBe sure to read [the Rules File Schema documentation section relating to the Paired Example](https://sovabids.readthedocs.io/en/latest/rules_schema.html#paired-example) before doing this example for more context.\n\n\n.. mermaid::\n\n graph LR\n S>\"source path example\"]\n B>\"target path example\"]\n AR((\"from_io_example\"))\n M>\"path pattern\"]\n S --> AR\n B --> AR\n AR --> M\n\n## The Rules File\nThe Rules File we are dealing here has the following path_analysis rule\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import json # utility\nfrom sovabids.files import _write_yaml # To print the yaml file\n\n# The rule we are dealing with\nrule = {\n 'non-bids':{\n 'path_analysis':\n {\n 'source' : 'data/lemon/V001/resting/010002.vhdr',\n 'target' : 'data_bids/sub-010002/ses-001/eeg/sub-010002_ses-001_task-resting_eeg.vhdr'\n }\n }\n }\n\nyaml_file = _write_yaml(rule)\n\nprint('Rules File:\\n\\n',yaml_file)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The from_io_example function\n\nAlthough this is hidden from the user, internally sovabids uses this function to infer the pattern.\n\nThe name of the function means \"from input-output example\", as one provides an input and output pair of (source,target) paths.\n\nHere we will illustrate how this function behaves. Lets see the documentation of the function:\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from sovabids.heuristics import from_io_example # The function itself\n\nprint('from_io_example:\\n\\n',from_io_example.__doc__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The result of the function\n\nThe function will return the placeholder pattern as explained in [the Rules File Schema documentation section relating to the Placeholder Pattern](https://sovabids.readthedocs.io/en/latest/rules_schema.html#placeholder-pattern) .\n\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"sourcepath = rule['non-bids']['path_analysis']['source']\ntargetpath = rule['non-bids']['path_analysis']['target']\nresult = from_io_example(sourcepath,targetpath)\n\nprint('Result:\\n\\n',result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ambiguity\n\nThis is explained in more detail in [the warning section of the the Paired Example documentation](https://sovabids.readthedocs.io/en/latest/rules_schema.html#paired-example) .\nBe sure to read it before for fully understading what ambiguity means here.\n\nAn ambiguous rule would be:\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"rule = {\n 'non-bids':{\n 'path_analysis':\n {\n 'source':'data/lemon/session001/taskT001/010002.vhdr',\n 'target':'data_bids/sub-010002/ses-001/eeg/sub-010002_ses-001_task-T001_eeg.vhdr'\n }\n }\n }\n\nyaml_file = _write_yaml(rule)\n\nprint('Ambiguous Example:\\n\\n',yaml_file)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If your example is ambiguous, the function will raise an error.\n\nNotice the last bit of the message, it will hint you about what part of the example is suspected to have ambiguity.\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from traceback import format_exc\n\ntry:\n sourcepath = rule['non-bids']['path_analysis']['source']\n targetpath = rule['non-bids']['path_analysis']['target']\n result = from_io_example(sourcepath,targetpath)\nexcept:\n print('Error:\\n\\n',format_exc())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK l0Wŀr8E E rpc_example.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# RPC API example with the LEMON dataset\n\nThis example illustrates the use of ``sovabids`` on the [LEMON dataset](http://fcon_1000.projects.nitrc.org/indi/retro/MPI_LEMON.html)\nusing the RPC API.\n\n
Warning
To run this example, you need to install sovabids in 'advanced-usage' mode ( [see here](https://sovabids.readthedocs.io/en/latest/README.html#installation-for-advanced-usage) ).
\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Sovabids uses an action-oriented API. Here we will illustrate each of the available functionalities.\n\n## Imports\nFirst we import some functions we will need:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os # For path manipulation\nimport shutil # File manipulation\nfrom mne_bids import print_dir_tree # To show the input/output directories structures inside this example\nfrom sovabids.datasets import lemon_prepare # Download the dataset\nfrom sovabids.settings import REPO_PATH\nfrom sovabids.sovarpc import app as sovapp # The RPC API application\nimport sovabids.sovarpc as sovarpc\nfrom fastapi.testclient import TestClient # This will be for simulating ourselves as a client of the RPC API\nimport json # for making json-based requests\nimport copy # just to make deep copies of variables"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Getting and preparing the dataset\nWe have to download and decompress the dataset. We also need to fix a filename inconsistency\n(without this correction the file won't be able to be opened in mne). Luckily all of that is \nencapsulated in the lemon_prepare function since these issues are not properly of sovabids. \n\nBy default the files are saved in the '_data' directory of the sovabids project.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"lemon_prepare()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setting up the paths\nNow we will set up four paths. Because this example is intended to run relative \nto the repository directory we use relative path but for real use-cases it is \neasier to just input the absolute-path. We will print these paths for more clarity.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"source_path = os.path.abspath(os.path.join(REPO_PATH,'_data','lemon')) # For the input data we will convert\nbids_path= os.path.abspath(os.path.join(REPO_PATH,'_data','lemon_bids_rpc')) # The output directory that will have the converted data\nrules_path = os.path.abspath(os.path.join(REPO_PATH,'examples','lemon_example_rules.yml')) # The rules file that setups the rule for conversion\nmapping_path = os.path.abspath(os.path.join(bids_path,'code','sovabids','mappings.yml')) # The mapping file that will hold the results of applying the rules to each file\n\nprint('source_path:',source_path.replace(REPO_PATH,''))\nprint('bids_path:', bids_path.replace(REPO_PATH,''))\nprint('rules_path:',rules_path.replace(REPO_PATH,''))\nprint('mapping_path:',mapping_path.replace(REPO_PATH,''))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cleaning the output directory\nWe will clean the output path as a safety measure from previous conversions.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"try:\n shutil.rmtree(bids_path)\nexcept:\n pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The input directory\nFor clarity purposes we will print here the directory we are trying to convert to BIDS.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print_dir_tree(source_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## RPC API\nSimulating ourselves as clients\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nWe will use the TestClient class to send requests to the API (the sovapp variable)\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"client = TestClient(sovapp)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The general request\nWe will define a function to make a request to the API\ngiven the name of the method and its parameters as a dictionary\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def make_request(method,params):\n print('Method:',method)\n print('');print('');\n print('Parameters:')\n print(json.dumps(params, indent=4))\n print('');print('');\n # We create the complete request\n request= { \n \"jsonrpc\": \"2.0\",\n \"id\": 0,\n \"method\": method,\n \"params\": params}\n print('Request:')\n print(json.dumps(request, indent=4))\n print('');print('');\n # json dumps is important to avoid parsing errors in the API request\n request = json.dumps(request)\n\n # Send the request\n request_url = \"/api/sovabids/\" +method\n print('Request URL:')\n print(request_url)\n print('');print('');\n response = client.post(request_url,data=request ) # POST request as common in RPC-based APIs\n\n # Get the answer\n result = json.loads(response.content.decode())['result']\n print('Answer:')\n print(json.dumps(result, indent=4))\n print('');print('');\n return result"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### load_rules\nFor loading a yaml rules file.\nLets see the docstring of this method\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(sovarpc.load_rules.__doc__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets define the request\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"method = 'load_rules' # Just a variable for the method name \n\nparams = { # Parameters of the method\n\"rules_path\": rules_path\n }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And proceed with it\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"result = make_request(method,params)\n\nrules = copy.deepcopy(result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### save_rules\nWe can for example use it as a way to save a backup of the already-existing rules file.\nLets see the docstring of this method\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(sovarpc.save_rules.__doc__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets define the request\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"method = \"save_rules\" # Just a variable for the method name \n\nparams = { # Parameters of the method\n \"rules\": rules,\n \"path\": mapping_path.replace('mappings','rules')+'.bkp' # We will do it as if we were saving a backup of the rules\n # Since the rules file already exists\n }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And proceed with it\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"result = make_request(method,params)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### get_files\nUseful for getting the files on a directory.\nLets see the docstring of this method\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(sovarpc.get_files.__doc__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note
get_files uses the rules because of the non-bids.eeg_extension configuration.
\n\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets define the request\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"method = \"get_files\" # Just a variable for the method name \n\nparams = { # Parameters of the method\n \"rules\": rules,\n \"path\": source_path\n }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And proceed with it\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"result = make_request(method,params)\n\nfilelist = copy.deepcopy(result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### apply_rules_to_single_file\nWe can use this to get a mapping for a single mapping \nand for previewing the bids files that would be written.\nLets see the docstring of this method\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(sovarpc.apply_rules_to_single_file.__doc__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets define the request\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"method = \"apply_rules_to_single_file\" # Just a variable for the method name \n\nparams = { # Parameters of the method\n \"file\": filelist[0],\n \"bids_path\": bids_path+'.preview',\n \"rules\": rules,\n \"write\":False,\n \"preview\":True\n }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And proceed with it\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"result = make_request(method,params)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### apply_rules\nWe can use this to get the mappings for all the files in a list of them.\nLets see the docstring of this method\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(sovarpc.apply_rules.__doc__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets define the request\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"method = \"apply_rules\" # Just a variable for the method name \n\nparams = { # Parameters of the method\n \"file_list\": filelist,\n \"bids_path\": bids_path,\n \"rules\": rules,\n \"mapping_path\":mapping_path\n }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And proceed with it\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"result = make_request(method,params)\n\nfile_mappings=copy.deepcopy(result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### save_mappings\nWe can use this to save a backup of the mappings.\nLets see the docstring of this method\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(sovarpc.save_mappings.__doc__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets define the request\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"method = \"save_mappings\" # Just a variable for the method name \n\nparams = { # Parameters of the method\n \"general\": file_mappings['General'],\n \"individual\":file_mappings['Individual'],\n \"path\": mapping_path+'.bkp'\n }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And proceed with it\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"result = make_request(method,params)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### convert_them\nWe can use this to perform the conversion given the mappings.\nLets see the docstring of this method\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(sovarpc.convert_them.__doc__)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets define the request\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"method = \"convert_them\" # Just a variable for the method name \n\nparams = { # Parameters of the method\n \"general\": file_mappings['General'],\n \"individual\":file_mappings['Individual']\n }"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And proceed with it\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"result = make_request(method,params)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Checking the conversion\nFor clarity purposes we will check the output directory we got from sovabids.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print_dir_tree(bids_path)\n\nprint('LEMON CONVERSION FINISHED!')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The ideal GUI for the designed API\nHere is the GUI schematic we had in mind when we designed the API\n\n\n\nWarning
The only difference is that apply_rules will receive a list of the paths of the files we want to convert rather than a single input directory path
\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK
0Wƽ"y y gui_example.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# GUI example with LEMON dataset \n\nThis example illustrates the use of ``sovabids`` on the [LEMON dataset](http://fcon_1000.projects.nitrc.org/indi/retro/MPI_LEMON.html)\nusing the preliminary GUI tool.\n\n## Install Sovabids in gui-usage mode\n([see here](https://sovabids.readthedocs.io/en/latest/README.html))\n\n## Download the Lemon dataset \n(if you have not already done so)\nIf you need to download the files, you can use:\n\n```bash\npython -c 'from sovabids.datasets import lemon_prepare; lemon_prepare()'\n```\nThis will download the lemon dataset inside the '_data' subfolder of the cloned sovabids repository.\n\n## Run front/app/app.py in a terminal \n(the front folder is the one in the root of the cloned sovabids repository.)\n\nAssuming you are at the root of the sovabids cloned repository, you can use:\n\n```bash\npython front/app/app.py\n```\n## Go to your browser at http://127.0.0.1:5000/ \n\nYou will see:\n\n\n\nThis is an introductory page of the GUI.\n\n## Click Upload Files\n\n\n\n## Choose Files\n\nClick 'Choose Files', select the lemon folder (inside the _data subdirectory) and click submit.\n\n\n\nYou will need to wait while the files are copied to the server. Since these are heavy eegs, it will take a bit.\n\n## Deselect any files you want to skip\n\n\n\nHere we won't skip any files. Notice though that there are non-eeg files (.csv and tar.gz ) mixed in there. Sovabids will skip them automatically.\n\nClick Send.\n\n## Confirm detected eegs\n\nSovabids will show the individual eegs found. Notice that since this is a brainvision dataset, sovabids lists the main files of this format (the .vhdr files) since the other ones (.eeg and .vmrk) are sidecars.\n\n\n\n\n## The rules files\n\nA suitable rules file is already at examples/lemon_example_rules.yml, you can upload that one.\n\nClick Choose File, then in the popup window select the rules file, click open and then submit.\n\n\n\nAfter that you will notice the text pane is updated:\n\n\n\nYou can edit the rules directly, as shown here where we modify the dataset name to \"Modified Name'.\n\n\n\nOnce ready, scroll down to find another submit and click it to continue.\n\n\n\n\n## Edit individual mappings\n\nYou will now see a list of the eeg files, for each you can edit its mapping. At first you will see an empty text pane since no eeg file is chosen.\n\n\n\nClick any of the files for editing it:\n\n\n\nOnce clicked, you will see the corresponding mapping:\n\n\n\nYou can edit the INDIVIDUAL mapping of this file, in example here we will change the power line frequency of this eeg to 60 Hz.\n\n\n\nTo save the edited individual mapping, press Send at the right:\n\n\n\nYou will be redirected to the empty mapping, but if you click the same eeg file again you will notice the changes are saved:\n\n\n\nOnce the mappings are ready, click next:\n\n\n\n\n## Proceed to the conversion\n\nClick on the button:\n\n\n\nOnce clicked it will take a while before the program finishes (a feedback information of the progress is not yet implemented on this preliminary GUI).\n\n## Save your conversion\n\nWhen the files are ready you will see:\n\n\n\nOnce you click there, sovabids will begin compressing your files so it will take a bit until the download windows is shown. Select where you want to download the file and press save.\n\n\n\nWhen the download is ready, navigate to the chosen folder and decompress the files. Go into the correspondent folder to see the converted files:\n\n\n\n## Inspect the sovabids logs and mappings\n\nInside the code/sovabids subdirectory you will see the mappings and log files.\n\n\n\nThe mappings.yml file will hold the mappings:\n\n\n\nThe logs will hold run-time information of the procedure:\n\n\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK 10WV֤.> .> bidscoin_example.ipynb{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# LEMON dataset example with BIDSCOIN\n\nThis example illustrates the use of ``sovabids`` on the [LEMON dataset](http://fcon_1000.projects.nitrc.org/indi/retro/MPI_LEMON.html)\nusing bidscoin.\n\nThe main elements of this example are:\n * A source path with the original dataset.\n * A bids path that will be the output path of the conversion.\n * A rules file that configures how the conversion is done.\n * A bidsmap template required by bidscoin. (Equivalent to our rules file)\n * A study bidsmap. (Equivalent to our mappings file)\n\nRefer to the [bidscoin documentation](https://bidscoin.readthedocs.io/en/stable/workflow.html) to understand the components and workflow of bidscoin.\n\nIn summary, bidscoin uses a bidsmap to encode how a conversion is done.\n\nIntuitively, the bidsmapper grabs a template to produce a study bidsmap, which may or may not be customized for each file through the bidseditor. Either way the final study bidsmap is passed to bidscoiner to perform the conversion.\n\nThe connection of sovabids and bidscoin is through a plugin called **sova2coin** which helps the bidscoin modules by dealing with the EEG data.\n\n.. mermaid::\n\n graph LR\n S>\"Source path\"]\n B>\"Bids path\"]\n R>\"Rules file\"]\n O[(\"Converted dataset\")]\n BM((bidsmapper))\n BC((bidscoiner))\n BE((bidseditor))\n BF>bidsmap template]\n SOVA((sova2coin)) --> BM\n B-->BM\n BM-->|bidsmap|BE\n BE-->|user-edited bidsmap|BC\n BC-->O\n R --> SOVA\n BF -->BM\n S --> BM\n SOVA-->BC\n\n\nWarning
If you didn't install sovabids in 'gui-usage' mode ( [see here](https://sovabids.readthedocs.io/en/latest/README.html) ), you will probably need to install bidscoin:\n\n Install our [bidscoin branch](https://github.com/yjmantilla/bidscoin/tree/sovabids)\n \n That is, you need to run:\n\n```bash\npip install git+https://github.com/yjmantilla/bidscoin.git@sovabids\n```\n If that doesn't work try:\n\n```bash\ngit clone https://github.com/yjmantilla/bidscoin/tree/sovabids\ncd bidscoin\npip install .
\n```\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Imports\nFirst we import some functions we will need:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\nimport shutil # File manipulation\nimport yaml # To do yaml operations\nfrom mne_bids import print_dir_tree # To show the input/output directories structures inside this example\nfrom sovabids.datasets import lemon_bidscoin_prepare # Dataset\nfrom sovabids.schemas import get_sova2coin_bidsmap # bidsmap template schema\nfrom sovabids.settings import REPO_PATH"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setting up the paths\nFirst, we will set up four paths. Because this example is intended to run relative \nto the repository directory we use relative path but for real use-cases it is \neasier to just input the absolute-path. We will print these paths for more clarity.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"dataset = 'lemon_bidscoin' # Just folder name where to save or dataset\ndata_dir = os.path.join(REPO_PATH,'_data')\ndata_dir = os.path.abspath(data_dir)\n\nsource_path = os.path.abspath(os.path.join(data_dir,dataset+'_input'))\nbids_path= os.path.abspath(os.path.join(data_dir,dataset+'_output'))\ncode_path = os.path.join(bids_path,'code','bidscoin')\nrules_path = os.path.join(code_path,'rules.yml')\ntemplate_path = os.path.join(code_path,'template.yml')\nbidsmap_path = os.path.join( code_path,'bidsmap.yaml')\nprint('source_path:',source_path.replace(data_dir,''))\nprint('bids_path:', bids_path.replace(data_dir,''))\nprint('rules_path:',rules_path.replace(data_dir,''))\nprint('template_path:',template_path.replace(data_dir,''))\nprint('bidsmap_path:',bidsmap_path.replace(data_dir,''))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Cleaning the output directory\nWe will clean the output path as a safety measure from previous conversions.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"try:\n shutil.rmtree(bids_path)\nexcept:\n pass"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Make the folders if they don't exist to avoid errors\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"for p in [source_path,bids_path,code_path]:\n os.makedirs(p,exist_ok=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Getting and preparing the dataset\nWe have to download and decompress the dataset. We also need to fix a filename inconsistency\n(without this correction the file won't be able to be opened in mne). Luckily all of that is \nencapsulated in the lemon_prepare function since these issues are not properly of sovabids. \n\nWe also need to prepare the data to the [bidscoin required source data structure](https://bidscoin.readthedocs.io/en/stable/preparation.html) .\n\nWe will save this input data to source_path .\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"lemon_bidscoin_prepare(source_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The input directory\nFor clarity purposes we will print here the directory we are trying to convert to BIDS.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print_dir_tree(source_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Making the rules\nSee the Rules File Schema documentation for help regarding making this rules file.\n\nHere we will make the rules from a python dictionary.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"rules ={\n'entities':{'task':'resting'},\n'dataset_description':{'Name':dataset},\n'sidecar':{'PowerLineFrequency':50,'EEGReference':'FCz'},\n'channels':{'type':{'VEOG':'VEOG'}},\n'non-bids':{'path_analysis':{'pattern':'sub-%entities.subject%/ses-%entities.session%/%ignore%/%ignore%.vhdr'}}\n}\nwith open(rules_path, 'w') as outfile:\n yaml.dump(rules, outfile, default_flow_style=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now print the rules to see how the yaml file we made from the python dictionary looks like\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"with open(rules_path,encoding=\"utf-8\") as f:\n rules = f.read()\n print(rules)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Making the bidsmap template\nThe template is equivalent to the \"rules\" file of sovabids. It encodes the general way of doing the conversion.\n\nExplaining this file is out of scope of this example (this is bidscoin territory).\n\nWe will notice however that:\n\n * We input our rules file as an option to the sova2coin plugin.\n * We are interested in a \"EEG\" dataformat with an \"eeg\" datatype.\n * We match every file with a .* in the properties.filename section\n * The attributes are basically the metadata information extracted from the files which may be used to derive bids-related information.\n * In the attributes section we have the objects as they are named in our rules file schema (that is, here we deal with sovabids terminology using a dot notation for nesting)\n * We populate bids-related info with the extracted attributes (see subject, session and bids sections of the file)\n * We set the suffix to eeg.\n * The ``<`` and ``<<`` is best explained [here](https://bidscoin.readthedocs.io/en/stable/bidsmap.html#special-bidsmap-features)\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"template = get_sova2coin_bidsmap().format(rules_path)\n\nprint(template)\n\nwith open(template_path,mode='w') as f:\n f.write(template)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
".. tip::\n\n You can also input the rules directly (ie writing the rules instead of the path to the rules file)\n\n What is important is that inside the \"rules\" field of the sova2coin \"options\"\n\nNote
The EEG:eeg hierarchy just says that there is an 'EEG' dataformat which a general 'eeg' datatype. \n\n This is a bit redundant but it happens because bidscoin was originally thought for DICOM (dataformat)\n which holds many datatypes (anat,perf,etc). In eeg this doesnt happens.
\n\n## Some necessary code\nTo be able to run commands from this notebook and capture their outputs we need to define the following, nevertheless this is not relevant to actually running this from the command line.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from subprocess import PIPE, run\n\ndef out(command):\n result = run(command, stdout=PIPE, stderr=PIPE, universal_newlines=True, shell=True)\n return result.stdout\n\nmy_output = out(\"echo hello world\")\nprint(my_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## bidsmapper\nFirst we execute the bidsmapper to get a study bidsmap from our bidsmap template.\n\nThe bidsmap file is equivalent to our \"mappings\" file; it encodes how the conversion is done on a per-file basis.\n\nLets see the help:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"command = \"bidsmapper --help\"\nprint(command)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will give the following output\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"my_output= out(command)\nprint(my_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we will use the following command to get the bidsmap study file.\n\nNote we use -t to set the template and -a to run this without the bidseditor\n\nYou can skip the -a option if you are able to open the bidseditor (ie you are able to give user-input in its interface)\n\nJust remember to save the bidsmap yaml at the end.\n\nSee the [bidseditor documentation](https://bidscoin.readthedocs.io/en/stable/workflow.html#main-window) for more info.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"command = 'bidsmapper '+source_path + ' '+ bids_path + ' -t ' + template_path + ' -a'\nprint(command)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will produce the following study bidsmap:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"my_output= out(command)\nprint(my_output)\n\nwith open(bidsmap_path,encoding=\"utf8\", errors='ignore') as f:\n bidsmap= f.read()\n print(bidsmap)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"at the following path:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print(bidsmap_path)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## bidscoiner\nNow we are ready to perform the conversion given the study bidsmap file just made.\n\nUse the following command to print the help of the tool:\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"command = \"bidscoiner --help\"\nprint(command)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will give the following output\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"my_output= out(command)\nprint(my_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we will use the following command to perform the conversion.\n\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"command = 'bidscoiner '+source_path + ' '+ bids_path + ' -b '+ bidsmap_path\n\nprint(command)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This will produce the following output:\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"my_output= out(command)\nprint(my_output)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Checking the conversion\nFor clarity purposes we will check the output directory we got from sovabids.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print_dir_tree(bids_path)\n\nprint('BIDSCOIN CONVERSION FINISHED!')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.18"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK V0Ww9 9 lemon_example.ipynbPK
0W%N= = * O9 example_heuristic_source_target_pair.ipynbPK l0Wŀr8E E N rpc_example.ipynbPK
0Wƽ"y y gui_example.ipynbPK 10WV֤.> .> ? bidscoin_example.ipynbPK [