Browse Source

examples: sort output of cells to ensure reproducibility on python3.5

Fabian Peter Hammerle 3 months ago
parent
commit
aafafa0b59

+ 1 - 1
.github/workflows/python.yml

@@ -135,7 +135,7 @@ jobs:
     strategy:
       matrix:
         python-version:
-        #- 3.5 TODO
+        - 3.5
         - 3.6
         - 3.7
         #- 3.8 TODO

+ 29 - 28
examples/ashs.ipynb

@@ -117,54 +117,54 @@
        "    <tr>\n",
        "      <th>0</th>\n",
        "      <td>CA1</td>\n",
-       "      <td>678.903</td>\n",
+       "      <td>678.901</td>\n",
        "      <td>bert</td>\n",
-       "      <td>right</td>\n",
+       "      <td>left</td>\n",
        "      <td>nogray</td>\n",
        "    </tr>\n",
        "    <tr>\n",
-       "      <th>1</th>\n",
-       "      <td>CA2+3</td>\n",
-       "      <td>123.458</td>\n",
+       "      <th>3</th>\n",
+       "      <td>CA1</td>\n",
+       "      <td>678.903</td>\n",
        "      <td>bert</td>\n",
        "      <td>right</td>\n",
        "      <td>nogray</td>\n",
        "    </tr>\n",
        "    <tr>\n",
-       "      <th>2</th>\n",
-       "      <td>DG</td>\n",
-       "      <td>901.236</td>\n",
+       "      <th>5</th>\n",
+       "      <td>CA2+3</td>\n",
+       "      <td>123.457</td>\n",
        "      <td>bert</td>\n",
-       "      <td>right</td>\n",
-       "      <td>nogray</td>\n",
+       "      <td>left</td>\n",
+       "      <td>usegray</td>\n",
        "    </tr>\n",
        "    <tr>\n",
-       "      <th>3</th>\n",
+       "      <th>14</th>\n",
        "      <td>ERC</td>\n",
-       "      <td>789.013</td>\n",
+       "      <td>789.014</td>\n",
        "      <td>bert</td>\n",
-       "      <td>right</td>\n",
-       "      <td>nogray</td>\n",
+       "      <td>left</td>\n",
+       "      <td>None</td>\n",
        "    </tr>\n",
        "    <tr>\n",
-       "      <th>4</th>\n",
-       "      <td>PHC</td>\n",
-       "      <td>2345.878</td>\n",
+       "      <th>21</th>\n",
+       "      <td>PRC</td>\n",
+       "      <td>2345.679</td>\n",
        "      <td>bert</td>\n",
-       "      <td>right</td>\n",
-       "      <td>nogray</td>\n",
+       "      <td>left</td>\n",
+       "      <td>usegray</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
        "</div>"
       ],
       "text/plain": [
-       "  subfield  volume_mm^3 subject hemisphere correction\n",
-       "0      CA1      678.903    bert      right     nogray\n",
-       "1    CA2+3      123.458    bert      right     nogray\n",
-       "2       DG      901.236    bert      right     nogray\n",
-       "3      ERC      789.013    bert      right     nogray\n",
-       "4      PHC     2345.878    bert      right     nogray"
+       "   subfield  volume_mm^3 subject hemisphere correction\n",
+       "0       CA1      678.901    bert       left     nogray\n",
+       "3       CA1      678.903    bert      right     nogray\n",
+       "5     CA2+3      123.457    bert       left    usegray\n",
+       "14      ERC      789.014    bert       left       None\n",
+       "21      PRC     2345.679    bert       left    usegray"
       ]
      },
      "execution_count": 4,
@@ -174,8 +174,9 @@
    ],
    "source": [
     "import pandas\n",
-    "volume_frame = pandas.concat([f.read_volumes_dataframe() for f in volume_files])\n",
-    "volume_frame.head()"
+    "volume_frame = pandas.concat(f.read_volumes_dataframe() for f in volume_files)\n",
+    "volume_frame.sort_values(by=['subfield', 'hemisphere', 'correction']) \\\n",
+    "    .reset_index(drop=True).iloc[[0, 3, 5, 14, 21]]"
    ]
   },
   {
@@ -1158,7 +1159,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.7.10"
+   "version": "3.5.10"
   }
  },
  "nbformat": 4,

+ 29 - 28
examples/compare_ashs_freesurfer_hipposf.ipynb

@@ -211,67 +211,67 @@
        "    <tr>\n",
        "      <th>7</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>Hippocampal_tail</td>\n",
+       "      <td>CA1</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>8</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>subiculum</td>\n",
+       "      <td>CA3</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>9</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>CA1</td>\n",
+       "      <td>CA4</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>10</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>hippocampal-fissure</td>\n",
+       "      <td>GC-ML-DG</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>11</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>presubiculum</td>\n",
+       "      <td>HATA</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>12</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>parasubiculum</td>\n",
+       "      <td>Hippocampal_tail</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>13</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>molecular_layer_HP</td>\n",
+       "      <td>Whole_hippocampus</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>14</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>GC-ML-DG</td>\n",
+       "      <td>fimbria</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>15</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>CA3</td>\n",
+       "      <td>hippocampal-fissure</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>16</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>CA4</td>\n",
+       "      <td>molecular_layer_HP</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>17</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>fimbria</td>\n",
+       "      <td>parasubiculum</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>18</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>HATA</td>\n",
+       "      <td>presubiculum</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>19</th>\n",
        "      <td>Freesurfer</td>\n",
-       "      <td>Whole_hippocampus</td>\n",
+       "      <td>subiculum</td>\n",
        "    </tr>\n",
        "  </tbody>\n",
        "</table>\n",
@@ -286,19 +286,19 @@
        "4         ASHS                  PHC\n",
        "5         ASHS                  PRC\n",
        "6         ASHS                  SUB\n",
-       "7   Freesurfer     Hippocampal_tail\n",
-       "8   Freesurfer            subiculum\n",
-       "9   Freesurfer                  CA1\n",
-       "10  Freesurfer  hippocampal-fissure\n",
-       "11  Freesurfer         presubiculum\n",
-       "12  Freesurfer        parasubiculum\n",
-       "13  Freesurfer   molecular_layer_HP\n",
-       "14  Freesurfer             GC-ML-DG\n",
-       "15  Freesurfer                  CA3\n",
-       "16  Freesurfer                  CA4\n",
-       "17  Freesurfer              fimbria\n",
-       "18  Freesurfer                 HATA\n",
-       "19  Freesurfer    Whole_hippocampus"
+       "7   Freesurfer                  CA1\n",
+       "8   Freesurfer                  CA3\n",
+       "9   Freesurfer                  CA4\n",
+       "10  Freesurfer             GC-ML-DG\n",
+       "11  Freesurfer                 HATA\n",
+       "12  Freesurfer     Hippocampal_tail\n",
+       "13  Freesurfer    Whole_hippocampus\n",
+       "14  Freesurfer              fimbria\n",
+       "15  Freesurfer  hippocampal-fissure\n",
+       "16  Freesurfer   molecular_layer_HP\n",
+       "17  Freesurfer        parasubiculum\n",
+       "18  Freesurfer         presubiculum\n",
+       "19  Freesurfer            subiculum"
       ]
      },
      "execution_count": 3,
@@ -307,7 +307,8 @@
     }
    ],
    "source": [
-    "volume_frame[['source_type', 'subfield']].drop_duplicates().reset_index(drop=True)"
+    "volume_frame[['source_type', 'subfield']].drop_duplicates() \\\n",
+    "    .sort_values(by=['source_type', 'subfield']).reset_index(drop=True)"
    ]
   },
   {
@@ -1299,7 +1300,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.7.10"
+   "version": "3.5.10"
   }
  },
  "nbformat": 4,

+ 37 - 26
examples/freesurfer_hipposf.ipynb

@@ -25,7 +25,7 @@
     {
      "data": {
       "text/plain": [
-       "['lh.hippoSfVolumes-T1.v10.txt', 'lh.hippoSfVolumes-T1-T2.v10.txt']"
+       "['lh.hippoSfVolumes-T1-T2.v10.txt', 'lh.hippoSfVolumes-T1.v10.txt']"
       ]
      },
      "execution_count": 2,
@@ -39,7 +39,7 @@
     "\n",
     "volume_files = list(filter(lambda f: f.subject == SUBJECT, \n",
     "                           HippocampalSubfieldsVolumeFile.find(SUBJECTS_DIR)))\n",
-    "[os.path.basename(f.absolute_path) for f in volume_files]"
+    "sorted(os.path.basename(f.absolute_path) for f in volume_files)"
    ]
   },
   {
@@ -79,44 +79,53 @@
        "  <tbody>\n",
        "    <tr>\n",
        "      <th>0</th>\n",
-       "      <td>Hippocampal_tail</td>\n",
-       "      <td>123.456789</td>\n",
+       "      <td>CA1</td>\n",
+       "      <td>44.567891</td>\n",
        "      <td>bert</td>\n",
        "      <td>left</td>\n",
        "      <td>True</td>\n",
-       "      <td>None</td>\n",
+       "      <td>T2</td>\n",
        "    </tr>\n",
        "    <tr>\n",
        "      <th>1</th>\n",
-       "      <td>subiculum</td>\n",
-       "      <td>234.567891</td>\n",
+       "      <td>CA1</td>\n",
+       "      <td>34.567891</td>\n",
        "      <td>bert</td>\n",
        "      <td>left</td>\n",
        "      <td>True</td>\n",
        "      <td>None</td>\n",
        "    </tr>\n",
        "    <tr>\n",
-       "      <th>2</th>\n",
-       "      <td>CA1</td>\n",
-       "      <td>34.567891</td>\n",
+       "      <th>3</th>\n",
+       "      <td>CA3</td>\n",
+       "      <td>678.912345</td>\n",
        "      <td>bert</td>\n",
        "      <td>left</td>\n",
        "      <td>True</td>\n",
        "      <td>None</td>\n",
        "    </tr>\n",
        "    <tr>\n",
-       "      <th>3</th>\n",
-       "      <td>hippocampal-fissure</td>\n",
-       "      <td>345.678912</td>\n",
+       "      <th>5</th>\n",
+       "      <td>CA4</td>\n",
+       "      <td>789.123456</td>\n",
        "      <td>bert</td>\n",
        "      <td>left</td>\n",
        "      <td>True</td>\n",
        "      <td>None</td>\n",
        "    </tr>\n",
        "    <tr>\n",
-       "      <th>4</th>\n",
-       "      <td>presubiculum</td>\n",
-       "      <td>456.789123</td>\n",
+       "      <th>8</th>\n",
+       "      <td>HATA</td>\n",
+       "      <td>91.244567</td>\n",
+       "      <td>bert</td>\n",
+       "      <td>left</td>\n",
+       "      <td>True</td>\n",
+       "      <td>T2</td>\n",
+       "    </tr>\n",
+       "    <tr>\n",
+       "      <th>13</th>\n",
+       "      <td>Whole_hippocampus</td>\n",
+       "      <td>1234.567899</td>\n",
        "      <td>bert</td>\n",
        "      <td>left</td>\n",
        "      <td>True</td>\n",
@@ -127,12 +136,13 @@
        "</div>"
       ],
       "text/plain": [
-       "              subfield  volume_mm^3 subject hemisphere  T1_input analysis_id\n",
-       "0     Hippocampal_tail   123.456789    bert       left      True        None\n",
-       "1            subiculum   234.567891    bert       left      True        None\n",
-       "2                  CA1    34.567891    bert       left      True        None\n",
-       "3  hippocampal-fissure   345.678912    bert       left      True        None\n",
-       "4         presubiculum   456.789123    bert       left      True        None"
+       "             subfield  volume_mm^3 subject hemisphere  T1_input analysis_id\n",
+       "0                 CA1    44.567891    bert       left      True          T2\n",
+       "1                 CA1    34.567891    bert       left      True        None\n",
+       "3                 CA3   678.912345    bert       left      True        None\n",
+       "5                 CA4   789.123456    bert       left      True        None\n",
+       "8                HATA    91.244567    bert       left      True          T2\n",
+       "13  Whole_hippocampus  1234.567899    bert       left      True        None"
       ]
      },
      "execution_count": 3,
@@ -143,7 +153,8 @@
    "source": [
     "import pandas\n",
     "volume_frame = pandas.concat([f.read_volumes_dataframe() for f in volume_files])\n",
-    "volume_frame.head()"
+    "volume_frame.sort_values(by=['subfield', 'analysis_id']) \\\n",
+    "    .reset_index(drop=True).iloc[[0, 1, 3, 5, 8, 13]]"
    ]
   },
   {
@@ -223,8 +234,8 @@
     "    return ' & '.join(filter(None, mri_sequences))\n",
     "\n",
     "volume_frame['segmentation_mode'] = volume_frame.apply(generate_mode_label, axis=1)\n",
-    "volume_frame.to_csv('freesurfer_hipposf_volumes_{}.csv'.format(SUBJECT),\n",
-    "                    index=False)\n",
+    "volume_frame.sort_values(by=['subfield', 'segmentation_mode']) \\\n",
+    "    .to_csv('freesurfer_hipposf_volumes_{}.csv'.format(SUBJECT), index=False)\n",
     "volume_frame['segmentation_mode'].value_counts().sort_index()"
    ]
   },
@@ -2016,7 +2027,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.7.10"
+   "version": "3.5.10"
   }
  },
  "nbformat": 4,

+ 19 - 19
examples/freesurfer_hipposf_volumes_bert.csv

@@ -1,27 +1,27 @@
 subfield,volume_mm^3,subject,hemisphere,T1_input,analysis_id,segmentation_mode
-Hippocampal_tail,123.456789,bert,left,True,,T1
-subiculum,234.567891,bert,left,True,,T1
 CA1,34.567891,bert,left,True,,T1
-hippocampal-fissure,345.678912,bert,left,True,,T1
-presubiculum,456.789123,bert,left,True,,T1
-parasubiculum,45.678912,bert,left,True,,T1
-molecular_layer_HP,56.789123,bert,left,True,,T1
-GC-ML-DG,567.891234,bert,left,True,,T1
+CA1,44.567891,bert,left,True,T2,T1 & T2
 CA3,678.912345,bert,left,True,,T1
+CA3,678.912445,bert,left,True,T2,T1 & T2
 CA4,789.123456,bert,left,True,,T1
-fimbria,89.123456,bert,left,True,,T1
+CA4,789.124456,bert,left,True,T2,T1 & T2
+GC-ML-DG,567.891234,bert,left,True,,T1
+GC-ML-DG,567.891244,bert,left,True,T2,T1 & T2
 HATA,91.234567,bert,left,True,,T1
-Whole_hippocampus,1234.567899,bert,left,True,,T1
+HATA,91.244567,bert,left,True,T2,T1 & T2
+Hippocampal_tail,123.456789,bert,left,True,,T1
 Hippocampal_tail,124.456789,bert,left,True,T2,T1 & T2
-subiculum,244.567891,bert,left,True,T2,T1 & T2
-CA1,44.567891,bert,left,True,T2,T1 & T2
+Whole_hippocampus,1234.567899,bert,left,True,,T1
+Whole_hippocampus,1244.567899,bert,left,True,T2,T1 & T2
+fimbria,89.123456,bert,left,True,,T1
+fimbria,89.124456,bert,left,True,T2,T1 & T2
+hippocampal-fissure,345.678912,bert,left,True,,T1
 hippocampal-fissure,445.678912,bert,left,True,T2,T1 & T2
-presubiculum,456.789124,bert,left,True,T2,T1 & T2
-parasubiculum,45.678912,bert,left,True,T2,T1 & T2
+molecular_layer_HP,56.789123,bert,left,True,,T1
 molecular_layer_HP,56.789124,bert,left,True,T2,T1 & T2
-GC-ML-DG,567.891244,bert,left,True,T2,T1 & T2
-CA3,678.912445,bert,left,True,T2,T1 & T2
-CA4,789.124456,bert,left,True,T2,T1 & T2
-fimbria,89.124456,bert,left,True,T2,T1 & T2
-HATA,91.244567,bert,left,True,T2,T1 & T2
-Whole_hippocampus,1244.567899,bert,left,True,T2,T1 & T2
+parasubiculum,45.678912,bert,left,True,,T1
+parasubiculum,45.678912,bert,left,True,T2,T1 & T2
+presubiculum,456.789123,bert,left,True,,T1
+presubiculum,456.789124,bert,left,True,T2,T1 & T2
+subiculum,234.567891,bert,left,True,,T1
+subiculum,244.567891,bert,left,True,T2,T1 & T2