NeuralAnalysis / PyalData

Repository for the Python implementation of the TrialData analysis library.
GNU General Public License v3.0
7 stars 9 forks source link

combine_time_bins cannot handle 1-D fields #80

Closed JulioEI closed 3 years ago

JulioEI commented 3 years ago

mat2dataframe reads (x,1) fields in the MatLab structures as one-dimensional (x, ).

Inside _combine_timebins, the function _rebinarray (used to rebinarize spike_fields, kin_fields, and rate fields) calls T, N = arr.shape to get the dimensions of the array. However, when the array is one-dimensional (i.e. (x,)) the line prompts an error since it cannot unpack enough values.

I believe a solution would be to first check the dimension of arr and then proceed accordingingly. That is:

if arr.ndim==1:
        arr.shape = (arr.size,1)
elif arr.ndim>=2:
        ValueError(??)
T, N = arr.shape
....

Or maybe it is less messy to just re-do my matlab structure so that one-column fields are embedded inside another column to avoid one-dimensional fields when reading them into python

bagibence commented 3 years ago

Thank you, nice catch! We definitely need to handle this without having to re-do your struct.

bagibence commented 3 years ago

How about #82? It seems to work for me.

The only issue I see is if someone stored their array as T x 1 on purpose, this squeezes it to (T, ). But I'm not sure why they would do that in the first place, so I think it's safe to ignore that for now.

JulioEI commented 3 years ago

82 works for me too. Thank you!

Squeezing it back to (T,) should be fine, that way dimensionality is always consistent. The only advantage I can see of not squeezing it back is that it would avoid potential following problems with other functions that may have the same 1-D predicament (I haven't found any so far).