
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/02-multisite-data/05-run_explore_onharmony_features.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_02-multisite-data_05-run_explore_onharmony_features.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_02-multisite-data_05-run_explore_onharmony_features.py:


Explore ON-Harmony features
===========================

.. GENERATED FROM PYTHON SOURCE LINES 6-8

Imports
-------

.. GENERATED FROM PYTHON SOURCE LINES 8-15

.. code-block:: Python

    import seaborn as sns
    import matplotlib.pyplot as plt
    import pandas as pd
    import numpy as np

    from uniharmony.datasets import load_onharmony_structural_features








.. GENERATED FROM PYTHON SOURCE LINES 16-23

.. code-block:: Python

    df = load_onharmony_structural_features()
    # Plot some of the columns
    print("="*80)
    print(f"Data have shape: {df.shape}")
    print("="*80)
    print(df.head())





.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    Downloading data from 'https://raw.githubusercontent.com/Jake-Turnbull/HarmonisationDiagnostics/main/tests/onharmony.csv' to file '/home/runner/.cache/pooch/onharmony.csv'.
    ================================================================================
    Data have shape: (120, 2517)
    ================================================================================
       idx  ... freesurfer_rh.aparc.a2009s_MeanCurv_S_oc_sup&transversal
    0    0  ...                                                NaN      
    1    1  ...                                                NaN      
    2    2  ...                                                NaN      
    3    3  ...                                                NaN      
    4    4  ...                                                NaN      

    [5 rows x 2517 columns]




.. GENERATED FROM PYTHON SOURCE LINES 24-73

.. code-block:: Python

    subject_col = "subject"
    scanner_col = "scanner_code"

    # You can explore other features changing this name
    feature_name = "T1_GM_parcellation_L_Front_Pole_vol"

    # Filter for the needed features
    feature_df = df[[subject_col, scanner_col, feature_name]].copy()

    # Pivot to get subjects as rows, scanners as columns
    # The values come from the column that actually contains the numerical data
    pivot_df = feature_df.pivot_table(
        index=subject_col,
        columns=scanner_col,
        values=feature_name
    )

    # Compute differences between all scanner pairs
    scanners = pivot_df.columns.tolist()
    n_scanners = len(scanners)

    # Initialize difference matrix (scanner x scanner)
    diff_matrix = pd.DataFrame(
        np.zeros((n_scanners, n_scanners)),
        index=scanners,
        columns=scanners
    )

    # Fill with average absolute differences for each pair
    for i, s1 in enumerate(scanners):
        for j, s2 in enumerate(scanners):
            if i != j:
                diff = pivot_df[s1] - pivot_df[s2]
                diff_matrix.iloc[i, j] = diff.mean()

    # Plot heatmap
    plt.figure(figsize=(8, 6))
    sns.heatmap(
        diff_matrix,
        annot=True,
        cmap="vlag",
        fmt=".3f",
        square=True,
        cbar_kws={"label": "Mean Difference"}
    )
    plt.title(f"Scanner Differences for Feature: {feature_name}")
    plt.tight_layout()
    plt.show()




.. image-sg:: /auto_examples/02-multisite-data/images/sphx_glr_05-run_explore_onharmony_features_001.png
   :alt: Scanner Differences for Feature: T1_GM_parcellation_L_Front_Pole_vol
   :srcset: /auto_examples/02-multisite-data/images/sphx_glr_05-run_explore_onharmony_features_001.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 1.789 seconds)


.. _sphx_glr_download_auto_examples_02-multisite-data_05-run_explore_onharmony_features.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: 05-run_explore_onharmony_features.ipynb <05-run_explore_onharmony_features.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: 05-run_explore_onharmony_features.py <05-run_explore_onharmony_features.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: 05-run_explore_onharmony_features.zip <05-run_explore_onharmony_features.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
