question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Medial view non-"region" is being mapped onto

See original GitHub issue

In the picture below, I think the large area in the middle of the medial views is usually greyed out in images and in this use case (I think it should just be white)I’m not sure why values are being mapped onto it.

xb_brain

That result is gotten using:

import os
import sys
import numpy as np
from custom import utils
import nibabel as nb
from surfer import Brain

result_name = sys.argv[1]
header_name = sys.argv[2]
save_name = sys.argv[3]

brain = Brain("fsaverage", "split", "inflated",
               views=['lat', 'med'], background="white")


hp = "/storage/gablab001/data/genus/fs_cog/exp1/column_headers"
rp = "/storage/gablab001/data/genus/fs_cog/exp1/lg/results"
with open(os.path.join(hp, header_name), "r") as tmp:
    headers = np.array(tmp.read().strip("\n").split("\n"))

res = utils.read_pickle(os.path.join(rp,"{}".format(result_name)))
coefs = [val for key, val in res.items() if "coef" in key]
nz = lambda x: np.nonzero(x)[0]
features_selected_lh = []
features_selected_rh = []
features_all = []

from collections import Counter
import pandas as pd

for coef in coefs:
    idx = nz(coef)
    features_all.extend(headers[idx].tolist())
    for col in headers[idx].tolist():
        if 'lh' in col:
            features_selected_lh.append(col)
        elif 'rh' in col:
            features_selected_rh.append(col)

left_count = dict(Counter(features_selected_lh))
right_count = dict(Counter(features_selected_rh))

left_df = pd.DataFrame({
    'col': [key.replace('lh_','').replace('.','-').replace('_thickness_D','')
            for key, val in left_count.items()],
    'val': [val for key, val in left_count.items()]
})

right_df = pd.DataFrame({
    'col': [key.replace('rh_','').replace('.','-').replace('_thickness_D','')
            for key, val in right_count.items()],
    'val': [val for key, val in right_count.items()]
})

label_dir = '/cm/shared/openmind/freesurfer/5.3.0/subjects/fsaverage/label'
left_label_file = 'lh.aparc.a2009s.annot'
right_label_file = 'rh.aparc.a2009s.annot'
lh_aparc_file = os.path.join(label_dir, left_label_file)
rh_aparc_file = os.path.join(label_dir, right_label_file)
lh_labels, lh_ctab, lh_names = nb.freesurfer.read_annot(lh_aparc_file)
rh_labels, rh_ctab, rh_names = nb.freesurfer.read_annot(rh_aparc_file)
left_df = left_df.set_index('col').loc[lh_names].reset_index().fillna(0)
right_df = right_df.set_index('col').loc[rh_names].reset_index().fillna(0)
vtx_lh = left_df.val.values[lh_labels]
vtx_rh = right_df.val.values[rh_labels]

brain.add_data(vtx_lh,
               0,
               400,
               colormap="Reds",
               alpha=.8,
               hemi='lh')

brain.add_annotation(lh_aparc_file, hemi='lh')

brain.add_data(vtx_rh,
               0,
               400,
               colormap="Reds",
               alpha=.8,
               hemi='rh')

brain.add_annotation(rh_aparc_file, hemi='rh', remove_existing=False)

If I look at left_df for values equal to or less than 70 I get:

                       col   val
0                  Unknown   0.0
7   G_and_S_cingul-Mid-Ant  51.0
13     G_front_inf-Orbital  57.0
24               G_orbital  69.0
26   G_pariet_inf-Supramar  46.0
30             G_precuneus  60.0
34      G_temp_sup-Lateral  36.0
42             Medial_wall   0.0
43          Pole_occipital  57.0
46               S_central  51.0
47     S_cingul-Marginalis  52.0
49   S_circular_insula_inf  63.0
51     S_collat_transv_ant  61.0
53             S_front_inf  54.0

I thought maybe something was happening with “Unknown” and it doesn’t seem to be in the map from the names to the labels:

# these returns False
"Unknown" in np.array(lh_names)[lh_labels]
"Unknown" in left_df.col.values[lh_labels]

# this gives a 1. 
(np.array(lh_names)[lh_labels] == left_df.col.values[lh_labels]).mean()

Any ideas on what’s happening?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mwaskomcommented, Jul 12, 2017

I think all you need to do is account separately for the vertices that are undefined in the parcellation. I.e.

vtx_lh[lh_labels == -1] = 0

Then the medial wall will be white in your colormap. Or you can set it to some negative number and do thresh=0 and it will be gray.

In the parcellation example, the Yeo atlas uses a label for the medial vertices (rather than leaving them undefined) so this problem doesn’t arise.

0reactions
YSanchezAraujocommented, Jul 12, 2017

Oh ok that works. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create a map—ArcGIS Insights | Documentation
Create interactive maps by dragging a field, or switch to a map from an existing ... Click on the icon to display the...
Read more >
Create a Map chart in Excel - Microsoft Support
Create a Map chart in Excel to display geographic data by value or category. Map charts are compatible with Geography data types to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found