{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Exporting pyAFQ Results\n\nThis example shows how to use the ``export`` methods to obtain results from\nthe ParticipantAFQ object. The ``export`` methods are used to calculate\nderived quantities from the data, such as DKI parameters, tract profiles,\nand bundle segmentations. \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import os\nimport os.path as op\nimport plotly\n\nfrom AFQ.api.participant import ParticipantAFQ\nimport AFQ.data.fetch as afd\nimport AFQ.definitions.image as afm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Preparing the ParticipantAFQ object\nIn this example, we will create a ParticipantAFQ object based on the\n:doc:`plot_002_participant_afq_api` example. Please refer to that\nexample for a detailed description of the parameters.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "afd.fetch_hbn_preproc([\"NDARAA948VFH\"])\n\nsub_dir = op.join(afd.afq_home, \"HBN\", \"derivatives\", \"qsiprep\",\n \"sub-NDARAA948VFH\")\ndwi_data_file = op.join(sub_dir, \"ses-HBNsiteRU\", \"dwi\", (\n \"sub-NDARAA948VFH_\"\n \"ses-HBNsiteRU_\"\n \"acq-64dir_space-T1w_desc-preproc_dwi.nii.gz\"))\nbval_file = op.join(sub_dir, \"ses-HBNsiteRU\", \"dwi\", (\n \"sub-NDARAA948VFH_\"\n \"ses-HBNsiteRU_\"\n \"acq-64dir_space-T1w_desc-preproc_dwi.bval\"))\nbvec_file = op.join(sub_dir, \"ses-HBNsiteRU\", \"dwi\", (\n \"sub-NDARAA948VFH_\"\n \"ses-HBNsiteRU_\"\n \"acq-64dir_space-T1w_desc-preproc_dwi.bvec\"))\nt1_file = op.join(sub_dir, \"anat\",\n \"sub-NDARAA948VFH_desc-preproc_T1w.nii.gz\")\n\noutput_dir = op.join(afd.afq_home, \"HBN\",\n \"derivatives\", \"afq\", \"sub-NDARAA948VFH\",\n \"ses-HBNsiteRU\", \"dwi\")\nos.makedirs(output_dir, exist_ok=True)\n\npve = afm.PVEImages(\n afm.ImageFile(\n path=op.join(sub_dir, \"anat\", \n \"sub-NDARAA948VFH_label-CSF_probseg.nii.gz\")),\n afm.ImageFile(\n path=op.join(sub_dir, \"anat\", \n \"sub-NDARAA948VFH_label-GM_probseg.nii.gz\")),\n afm.ImageFile(\n path=op.join(sub_dir, \"anat\", \n \"sub-NDARAA948VFH_label-WM_probseg.nii.gz\")))\n\n# Initialize the ParticipantAFQ object\nmyafq = ParticipantAFQ(\n dwi_data_file=dwi_data_file,\n bval_file=bval_file,\n bvec_file=bvec_file,\n t1_file=t1_file,\n output_dir=output_dir,\n pve=pve,\n tracking_params={\n \"n_seeds\": 10000,\n \"random_seeds\": True,\n \"rng_seed\": 2022,\n \"trx\": True\n },\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The Export Method\nThe ParticipantAFQ object has a method called ``export``, which allows the user\nto calculate various derived quantities from the data.\n\nThe ``export`` method can be called with a string argument that specifies the\ntype of quantity to be calculated. For example, ``myafq.export(\"OPTIONS\")``.\n\nTo list the available options, you can call the ``export`` method with the\nargument \"help\". This will return a list of all the available options for\nthe ``export`` method.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "myafq.export(\"help\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
No all options are possible even if they are valid. This will depend on\n you dataset and pyAFQ API parameters. For example, you cannot calculate\n DKI model from single shell data. Please refer to\n :doc:`/howto/tractography_params` for more documentation.
The AFQ API computes quantities lazily. This means that DKI parameters\n are not computed until they are required. This means that the first\n line below is the one that requires time.
Running the code below triggers the full pipeline of operations\n leading to the computation of the tract profiles. Therefore, it\n takes a little while to run (about 40 minutes, typically).
By default we resample a 100 points within a bundle, however to reduce\n processing time we will only resample 50 points.
You can hide or show a bundle by clicking the legend, or select a\n single bundle by double clicking the legend. The interactive\n visualization will also all you to pan, zoom, and rotate.