{"action":"created","issue":{"url":"https://api.github.com/repos/mne-tools/mne-python/issues/3089","repository_url":"https://api.github.com/repos/mne-tools/mne-python","labels_url":"https://api.github.com/repos/mne-tools/mne-python/issues/3089/labels{/name}","comments_url":"https://api.github.com/repos/mne-tools/mne-python/issues/3089/comments","events_url":"https://api.github.com/repos/mne-tools/mne-python/issues/3089/events","html_url":"https://github.com/mne-tools/mne-python/issues/3089","id":145013635,"number":3089,"title":"extract_label_time_course mode='pca_flip' has NaNs depending on label thresh","user":{"login":"kdoelling1919","id":13767931,"avatar_url":"https://avatars.githubusercontent.com/u/13767931?v=3","gravatar_id":"","url":"https://api.github.com/users/kdoelling1919","html_url":"https://github.com/kdoelling1919","followers_url":"https://api.github.com/users/kdoelling1919/followers","following_url":"https://api.github.com/users/kdoelling1919/following{/other_user}","gists_url":"https://api.github.com/users/kdoelling1919/gists{/gist_id}","starred_url":"https://api.github.com/users/kdoelling1919/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kdoelling1919/subscriptions","organizations_url":"https://api.github.com/users/kdoelling1919/orgs","repos_url":"https://api.github.com/users/kdoelling1919/repos","events_url":"https://api.github.com/users/kdoelling1919/events{/privacy}","received_events_url":"https://api.github.com/users/kdoelling1919/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-03-31T20:48:13Z","updated_at":"2016-07-18T22:06:57Z","closed_at":"2016-07-18T22:06:57Z","body":"I am trying to extract the time course from label created using mne.stc_to_label. The behavior seems to change depending on the threshold I used in the stc. The relevant piece of code I have written below. The code allows me to view a plot of the source estimate and choose a threshold as a percentage from maximum (i.e val = 70 -> threshold is .7*np.max(stc.data)). The trouble is that depending on my choice of val I can get NaNs: 70 works, 60 works but 62 creates NaNs in a few of the samples. 90 has NaNs and 75 gets an 'SVD did not converge' error. Also, both 53 and 6 work fine, in case you think its about the singles digit....\r\n\r\nI just pulled the most recent mne version from github. My source estimate has no NaNs in it. I guess there is a problem with the labels? or in the extract_label_time_course function itself. Has anyone come across anything like this issue before?\r\n\r\nThanks in advance!\r\nKeith\r\n\r\n```\r\n    #------- Set things up\r\n    # read in stc and src files\r\n    stc = mne.read_source_estimate(stcfile,subject=subject)\r\n    inv = read_inverse_operator(invfile)\r\n    src = inv['src']\r\n    \r\n    # master copy before editing\r\n    master_stc=stc.copy()\r\n    \r\n    # pick peak around some time window and get average response\r\n    pk=stc.get_peak(tmin=tlim[0],tmax=tlim[1])\r\n    tmin=pk[1]-winsize/2.\r\n    tmax=pk[1]+winsize/2.\r\n    win_stc = stc.crop(tmin,tmax).mean()\r\n\r\n    # find best clims and plot\r\n    clim = np.max(win_stc.data)\r\n    clims = (0*clim,.5*clim,.9*clim)\r\n    brain = win_stc.plot(hemi='split',surface='white',subject=subject,subjects_dir=freesurfer_dir,\r\n                        clim=dict(kind='value',lims=clims),transparent=False,alpha=.7)\r\n    \r\n    #------ create labels and inspect\r\n    # enter a percentage for a threshold = val% * max response\r\n    val=raw_input('Enter a percentage from 0-100: ')\r\n    if not val:\r\n        val = '70'\r\n        print('Fine! Be that way... I''ll try 70...')\r\n    while val:\r\n        brain.remove_labels(hemi='lh')\r\n        brain.remove_labels(hemi='rh')\r\n        # check user input\r\n        try:\r\n            val=int(val)*.01\r\n        except Exception:\r\n            val = raw_input('Must enter a valid integer from 0-100!!!: ')\r\n            continue\r\n        # create label given this threshold\r\n        print('Trying %f' % val)\r\n        win_stc_label = win_stc.copy()\r\n        # turn everything below threshold to 0\r\n        win_stc_label.data[win_stc.data<val*np.max(win_stc.data)]=0\r\n        # create the labels for both left and right hemispheres\r\n        func_labels=mne.stc_to_label(win_stc_label,src,smooth=True,connected=False,\r\n                                                        subjects_dir=freesurfer_dir)\r\n\r\n        # add label to plot\r\n        for i in xrange(len(func_labels)):\r\n            brain.add_label(func_labels[i],color='b',borders=False,hemi=func_labels[i].hemi,alpha=.4)\r\n        # if satisfied, move on. If not, try another percentage\r\n        val=raw_input('If all good, press enter, else, more numbers please!')\r\n\r\n    #--- extract time course from label using pca_flip and check for NaN\r\n    pca_func=master_stc.extract_label_time_course(func_labels,src,mode='pca_flip')\r\n    print(np.isnan(pca_func).any())\r\n```"},"comment":{"url":"https://api.github.com/repos/mne-tools/mne-python/issues/comments/233473770","html_url":"https://github.com/mne-tools/mne-python/issues/3089#issuecomment-233473770","issue_url":"https://api.github.com/repos/mne-tools/mne-python/issues/3089","id":233473770,"user":{"login":"Eric89GXL","id":2365790,"avatar_url":"https://avatars.githubusercontent.com/u/2365790?v=3","gravatar_id":"","url":"https://api.github.com/users/Eric89GXL","html_url":"https://github.com/Eric89GXL","followers_url":"https://api.github.com/users/Eric89GXL/followers","following_url":"https://api.github.com/users/Eric89GXL/following{/other_user}","gists_url":"https://api.github.com/users/Eric89GXL/gists{/gist_id}","starred_url":"https://api.github.com/users/Eric89GXL/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Eric89GXL/subscriptions","organizations_url":"https://api.github.com/users/Eric89GXL/orgs","repos_url":"https://api.github.com/users/Eric89GXL/repos","events_url":"https://api.github.com/users/Eric89GXL/events{/privacy}","received_events_url":"https://api.github.com/users/Eric89GXL/received_events","type":"User","site_admin":false},"created_at":"2016-07-18T22:06:57Z","updated_at":"2016-07-18T22:06:57Z","body":"Closing due to non-response, but @kdoelling1919 please reopen if you can provide a gist to replicate"}}
{"actor":{"display_login":"Eric89GXL"}}