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

Fix BAT calculation code to account for single slide DCE Data (Currently requires 4D) #293

Closed firasm closed 9 years ago

firasm commented 9 years ago

Options:

1) Artificially expand the data array from [x,y,t] to [x,y,0,t] - this is the cleanest option. Upon saving, flatten it to get rid of z dimension

2) separate function to deal with 3D data (quite a few things things have to change)

3) if/else statements checking the size and picking the right code-segment shudder

I'm inclined to try for option 1

firasm commented 9 years ago

Aha!! I knew you wrote something like this in the past (from sarpy.ImageProcessing.resample_onto):

def atleast_4d(arr):
    Return at least a 4d array and fill the missing axis with 1

    :param numpy.ndarray arr:
        numpy array

    Example:
        >>> atleast_4d(numpy.arange(720).reshape(2,3,4,5,6)).shape
        (2, 3, 4, 5, 6)
        >>> atleast_4d(numpy.arange(120).reshape(2,3,4,5)).shape
        (2, 3, 4, 5)
        >>> atleast_4d(numpy.arange(120).reshape(2,3,20)).shape
        (2, 3, 20, 1)
        >>> atleast_4d(numpy.arange(120).reshape(2,60)).shape
        (2, 60, 1, 1)
        >>> atleast_4d(numpy.arange(120).reshape(120)).shape
        (120, 1, 1, 1)

    arr.shape += (1,) * (4 - arr.ndim)
    return arr
firasm commented 9 years ago

Just had to add this little bit to have the added axis in the z position:

if length(rawdata.shape) == 3:

    # add an empty dimension to make it 4D, this code appends the exta axis
    data = sarpy.ImageProcessing.resample_onto.atleast_4d(rawdata) 

    # Move the appended dimension to position 2 to keep data formats the same
    data.reshape([data.shape[0], data.shape[1],
                 data.shape[3], data.shape[2]])
else:
    data = rawdata