Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpose bug with analog channels #7

Closed
AKuederle opened this issue Jul 11, 2017 · 2 comments
Closed

Transpose bug with analog channels #7

AKuederle opened this issue Jul 11, 2017 · 2 comments

Comments

@AKuederle
Copy link
Collaborator

I think there is a little bug when reading the analog channels.
Here you use:

raw = np.fromstring(self._handle.read(n * analog_bytes),  dtype=analog_dtype, count=n).reshape((self.analog_used, -1))

This will result in the analog channels being in the wrong order, because you reshape the wrong way around.

Let me show you what I mean with a little example:

Let's say we have 20 analog channels, which are sampled at 5 times the frequency of the other points.
Than the information for 1 frame would look like that:

np.array(list(range(20))*5)

>>> array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
       17, 18, 19,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13,
       14, 15, 16, 17, 18, 19,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10,
       11, 12, 13, 14, 15, 16, 17, 18, 19,  0,  1,  2,  3,  4,  5,  6,  7,
        8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,  0,  1,  2,  3,  4,
        5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19])

Now we want to extract the 5 values belonging to each channel:

With the current implementation, that happens:

np.array(list(range(20))*5).reshape((20,-1))

>>> array([[ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19],
       [ 0,  1,  2,  3,  4],
       [ 5,  6,  7,  8,  9],
       [10, 11, 12, 13, 14],
       [15, 16, 17, 18, 19]])

But what we actually want is:

np.array(list(range(20))*5).reshape((-1,20)).T

>>>array([[ 0,  0,  0,  0,  0],
       [ 1,  1,  1,  1,  1],
       [ 2,  2,  2,  2,  2],
       [ 3,  3,  3,  3,  3],
       [ 4,  4,  4,  4,  4],
       [ 5,  5,  5,  5,  5],
       [ 6,  6,  6,  6,  6],
       [ 7,  7,  7,  7,  7],
       [ 8,  8,  8,  8,  8],
       [ 9,  9,  9,  9,  9],
       [10, 10, 10, 10, 10],
       [11, 11, 11, 11, 11],
       [12, 12, 12, 12, 12],
       [13, 13, 13, 13, 13],
       [14, 14, 14, 14, 14],
       [15, 15, 15, 15, 15],
       [16, 16, 16, 16, 16],
       [17, 17, 17, 17, 17],
       [18, 18, 18, 18, 18],
       [19, 19, 19, 19, 19]])

Correct me, if I am mistaken, but i think that a little bug in the module. If you agree I will prepare a tiny pull request to fix it :)

Best regards

@lmjohns3
Copy link
Member

Awesome, yes, please send a PR -- I think someone else recently filed a bug on this issue. Thanks for the detective work!

AKuederle added a commit to AKuederle/py-c3d that referenced this issue Jul 13, 2017
This should resolve EmbodiedCognition#6 and EmbodiedCognition#7.
However, it is not tested yet
@lmjohns3
Copy link
Member

I'll go ahead and close this, please reopen if the PR doesn't fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants