DrSAR / SARlabpy

git clone git@pfeifer.phas.ubc.ca:SARlabpy (do not push to github, please)
http://code.SARlab.ca
Other
1 stars 0 forks source link

resample_onto (née visu_pars_2_matrix_size) returns a strange ValueError exception in some cases #115

Closed firasm closed 11 years ago

firasm commented 11 years ago

debugging and updating live

The returned error is:

Traceback (most recent call last):

  File "<ipython-input-3-077b22bf106d>", line 1, in <module>
    runfile(r'/Volumes/Data/Dropboxes/PhD./Dropbox/studies/analysis/NecS3/NecS3_LL_roi_flattened.py', wdir=r'/Volumes/Data/Dropboxes/PhD./Dropbox/studies/analysis/NecS3')

  File "/Applications/Spyder.app/Contents/Resources/lib/python2.7/spyderlib/widgets/externalshell/sitecustomize.py", line 529, in runfile
    execfile(filename, namespace)

  File "/Volumes/Data/Dropboxes/PhD./Dropbox/studies/analysis/NecS3/NecS3_LL_roi_flattened.py", line 46, in <module>
    LLresample1 = sarpy.ImageProcessing.resample_onto.resample_onto_pdata(LL_1, roi1)

  File "/Volumes/Data/Dropboxes/PhD./Dropbox/code/python/sarpy/ImageProcessing/resample_onto.py", line 130, in resample_onto_pdata
    header = visu_pars_2_Nifti1Header(source_pdata.visu_pars)

  File "/Volumes/Data/Dropboxes/PhD./Dropbox/code/python/sarpy/io/visu_pars_2_Nifti1Header.py", line 163, in visu_pars_2_Nifti1Header
    matrix_size, dimdesc, dimcomment = visu_pars_2_matrix_size(visu_pars)

  File "/Volumes/Data/Dropboxes/PhD./Dropbox/code/python/sarpy/io/visu_pars_2_Nifti1Header.py", line 78, in visu_pars_2_matrix_size
    numpy.array(dimcomment)[swp_axis])

ValueError: cannot set an array element with a sequence

Error can be produced by executing this code:

import sarpy
import sarpy.fmoosvi.getters
import sarpy.fmoosvi.wrappers
import sarpy.ImageProcessing.resample_onto

import pylab
import numpy
import json

with open('/Volumes/Data/Dropboxes/PhD./Dropbox/studies/analysis/NecS3/NecS3.json','r') as infile:
    master_sheet = json.load(infile)

data_list = []
for k,v in master_sheet.iteritems():

    try:
        data_list = []
        key_list = []
        key_list.append(k) # 0
        key_list.append('T1map-') #1
        key_list.append('0h-LL') #2
        key_list.append('24h-LL') #3
        key_list.append('0h-IR_A') #4
        key_list.append('24h-IR_A') #5
        key_list.append('T1map_LL') #6
        key_list.append('IR_tumour_rois') #7

#        LL_1 = sarpy.Scan(master_sheet[k][key_list[2]][0]).adata[key_list[6]]
#        LL_2 = sarpy.Scan(master_sheet[k][key_list[3]][0]).adata[key_list[6]]

        LL_1 = sarpy.Scan(master_sheet[k][key_list[2]][0]).pdata[0]
        LL_2 = sarpy.Scan(master_sheet[k][key_list[3]][0]).pdata[0]        

        roi1 = sarpy.Scan(master_sheet[k][key_list[4]][0]).adata[key_list[7]]
        roi2 = sarpy.Scan(master_sheet[k][key_list[5]][0]).adata[key_list[7]]

        LLresample1 = sarpy.ImageProcessing.resample_onto.resample_onto_pdata(LL_1, roi1)      
        LLresample2 = sarpy.ImageProcessing.resample_onto.resample_onto_pdata(LL_2, roi2)

    except:
        pylab.close('all')
        print('Unknown error {0}'.format(k))
        raise
firasm commented 11 years ago

AHA! found the bug....

something to do with the way LL scans store things in VisuFGElemComment

visu_pars1.VisuFGElemComment ## This is the LL visu_pars
Out[30]: 
frame 1> <frame 2> <frame 3> <frame 4> <frame 5> <frame 6> <frame 7> <frame 8 
> <frame 9> <frame 10> <frame 11> <frame 12> <frame 13> <frame 14> <frame 15> 
 <frame 16> <frame 17> <frame 18> <frame 19> <frame 20> <frame 21> <frame 22> 
< frame 23> <frame 24> <frame 25

visu_pars.VisuFGElemComment ## This is a regular DCE scan 
Traceback (most recent call last):

  File "<ipython-input-31-6948b0b331e7>", line 1, in <module>
    visu_pars.VisuFGElemComment

AttributeError: 'JCAMP_file' object has no attribute 'VisuFGElemComment'
firasm commented 11 years ago

further debugging:

Using the debugger in situation 1(Where resample_onto does not work):

ipdb> dimcomment ['', '', '', ['frame 1', 'frame 2', 'frame 3', 'frame 4', 'frame 5', 'frame 6', 'frame 7', 'frame 8 ', 'frame 9', 'frame 10', 'frame 11', 'frame 12', 'frame 13', 'frame 14', 'frame 15> <frame 16', 'frame 17', 'frame 18', 'frame 19', 'frame 20', 'frame 21', 'frame 22', ' frame 23', 'frame 24', 'frame 25']]

ipdb> numpy.array(dimcomment)[swp_axis] *\ ValueError: cannot set an array element with a sequence


Using the debugger in situation 2 (where resample_onto works)

ipdb> dimcomment ['', '', '']

ipdb> numpy.array(dimcomment)[swp_axis] array(['', '', ''], dtype='|S1')

So, the swapping is innocuous when the list is empty but fatal when the list is populated with frames.

firasm commented 11 years ago

P.S. I think this bug exists because i am passing in an adata file (T1 parameter map) that doesn't match with its corresponding pdata's visa_pars file due to visu_pars.VisuFGElemComment

Let me know how I should override this header for the adata