diff --git a/notebooks/2020-09-03-visualize-qsiprep-qc.ipynb b/notebooks/2020-09-03-visualize-qsiprep-qc.ipynb new file mode 100644 index 0000000..0a5fc6a --- /dev/null +++ b/notebooks/2020-09-03-visualize-qsiprep-qc.ipynb @@ -0,0 +1,298 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "import dask.dataframe as dd\n", + "import altair as alt\n", + "\n", + "%matplotlib inline" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "def scatter_brush(df, title):\n", + " # Brush for selection\n", + " brush = alt.selection(type='interval')\n", + "\n", + " # Scatter Plot\n", + " points = alt.Chart(df).mark_point().encode(\n", + " x=alt.X(\"raw_neighbor_corr:Q\", scale=alt.Scale(zero=False)),\n", + " y=alt.Y(\"t1_neighbor_corr:Q\", scale=alt.Scale(zero=False)),\n", + " color=\"mean_fd:Q\",\n", + " size=\"max_fd:Q\",\n", + " tooltip=\"subject_id:N\",\n", + " ).add_selection(brush).properties(title=title)\n", + "\n", + " # Base chart for data tables\n", + " ranked_text = alt.Chart(df).mark_text().encode(\n", + " y=alt.Y(\"row_number:O\",axis=None)\n", + " ).transform_window(\n", + " row_number=\"row_number()\"\n", + " ).transform_filter(\n", + " brush\n", + " ).transform_window(\n", + " rank=\"rank(row_number)\"\n", + " ).transform_filter(\n", + " alt.datum.rank<20\n", + " )\n", + "\n", + " # Data Tables\n", + " subjects = ranked_text.encode(text=\"subject_id:N\").properties(\n", + " title=\"Subjects\", width=125\n", + " )\n", + "\n", + " # Build chart\n", + " chart = alt.hconcat(\n", + " points,\n", + " subjects\n", + " ).resolve_legend(\n", + " color=\"independent\"\n", + " )\n", + " \n", + " return chart" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['raw_dimension_x', 'raw_dimension_y', 'raw_dimension_z',\n", + " 'raw_voxel_size_x', 'raw_voxel_size_y', 'raw_voxel_size_z', 'raw_max_b',\n", + " 'raw_neighbor_corr', 'raw_num_bad_slices', 'raw_num_directions',\n", + " 't1_dimension_x', 't1_dimension_y', 't1_dimension_z', 't1_voxel_size_x',\n", + " 't1_voxel_size_y', 't1_voxel_size_z', 't1_max_b', 't1_neighbor_corr',\n", + " 't1_num_bad_slices', 't1_num_directions', 'mean_fd', 'max_fd',\n", + " 'max_rotation', 'max_translation', 'max_rel_rotation',\n", + " 'max_rel_translation', 't1_dice_distance', 'file_name', 'subject_id',\n", + " 'session_id', 'task_id', 'acq_id', 'space_id', 'rec_id', 'run_id'],\n", + " dtype='object')" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_camcan = dd.read_csv('s3://cam-can-mri/derivatives/qsiprep/sub-*/dwi/sub-*_desc-ImageQC_dwi.csv')\n", + "df_camcan = df_camcan.compute()\n", + "df_camcan.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "
\n", + "" + ], + "text/plain": [ + "alt.HConcatChart(...)" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scatter_brush(df=df_camcan, title=\"Cam-CAN\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Index(['raw_dimension_x', 'raw_dimension_y', 'raw_dimension_z',\n", + " 'raw_voxel_size_x', 'raw_voxel_size_y', 'raw_voxel_size_z', 'raw_max_b',\n", + " 'raw_neighbor_corr', 'raw_num_bad_slices', 'raw_num_directions',\n", + " 't1_dimension_x', 't1_dimension_y', 't1_dimension_z', 't1_voxel_size_x',\n", + " 't1_voxel_size_y', 't1_voxel_size_z', 't1_max_b', 't1_neighbor_corr',\n", + " 't1_num_bad_slices', 't1_num_directions', 'mean_fd', 'max_fd',\n", + " 'max_rotation', 'max_translation', 'max_rel_rotation',\n", + " 'max_rel_translation', 't1_dice_distance', 'file_name', 'subject_id',\n", + " 'session_id', 'task_id', 'acq_id', 'space_id', 'rec_id', 'run_id'],\n", + " dtype='object')" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_hbn = dd.read_csv('s3://hbn-derivatives/derivatives/qsiprep/sub-*/dwi/sub-*_desc-ImageQC_dwi.csv')\n", + "df_hbn = df_hbn.compute()\n", + "df_hbn.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "" + ], + "text/plain": [ + "alt.HConcatChart(...)" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "scatter_brush(df=df_hbn, title=\"HBN\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.6.10" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/viz-environment.yml b/viz-environment.yml new file mode 100644 index 0000000..077748c --- /dev/null +++ b/viz-environment.yml @@ -0,0 +1,6 @@ +name: viz-qsiprep-qc +channels: + - conda-forge +dependencies: + - altair==4.1.0 + - dask==2.6.0