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

Congruence np1e Offset #195

Closed
RobertoDF opened this issue Jan 29, 2025 · 10 comments
Closed

Congruence np1e Offset #195

RobertoDF opened this issue Jan 29, 2025 · 10 comments

Comments

@RobertoDF
Copy link

Hi,

I have a doubt abt the offset to apply to the recordings with np1e.
in https://open-ephys.github.io/bonsai-onix1-docs/articles/getting-started/reference.html#fn:1 offset is fixed at 512, however in the load data script it is set dynamically depending on the value of the scaling (itself dependent on the Gain applied):

ap_scalar = 1.2e6 / (2 ** bit_depth) / ap_gain
ap_offset = (2 ** (bit_depth - 1)) * ap_scalar

Which one is right?

Thanks!
R

@RobertoDF
Copy link
Author

I also notice now that for np2 here scaling is 2.44141 and on the table 3.0517578125

@cjsha
Copy link
Member

cjsha commented Jan 29, 2025

Hey @RobertoDF, good question.

The spikeinterface docs scales data in the following manner:

gain = 0.1
offset = -(2 ** (10 - 1)) * gain
recording.set_channel_gains(gain)
recording.set_channel_offsets(offset)

In the example script we provide, we scale data using read_binary which seems to require pre-scaling the offset as it internally executes the same functions set_channel_gains(gain_to_uV) and set_channel_offsets(offset_to_uV) in the same sequence.

        if gain_to_uV is not None:
            self.set_channel_gains(gain_to_uV)


        if offset_to_uV is not None:
            self.set_channel_offsets(offset_to_uV)

Also, if I'm interpreting spikeinterface's code correctly, this line suggests that offset subtraction seems to be applied after gain multiplication (Python follows PEMDAS order of operations).

Have you plotted the traces? I ran this on some test data and the traces seem centered around zero. I want to make sure it does on your end as well in case I'm overlooking something. Also, you can change num_channels = 384 to num_channels = 1 to inspect the one trace's plot more easily imo, this might be helpful.

@cjsha
Copy link
Member

cjsha commented Jan 29, 2025

It should be 3.05176. Thanks for the heads up.

@RobertoDF
Copy link
Author

And np1e ? 1.2e6 / (2 ** bit_depth) / ap_gain or 512?

@cjsha
Copy link
Member

cjsha commented Jan 29, 2025

The first one. I laid out my reasoning here.

In any case, please plot your data, confirm it's centered around zero, and let me know how it goes.

@RobertoDF
Copy link
Author

RobertoDF commented Jan 29, 2025

Image
Here is a problem! It isnt centered even after the proposed scaling and offset.
ap_gain=1000, bit_depth=10

@RobertoDF
Copy link
Author

Image
mean seems to be at 553 somehow not 600

@RobertoDF
Copy link
Author

I am still a bit puzzled that after the offset the mean is not at 0 but my original question regarding which was the correct answer was answered.

@cjsha
Copy link
Member

cjsha commented Jan 31, 2025

The offset could be the result of a real voltage difference between the ref and the electrode in question. What are you using for your GND? And are your reference and your GND tied together on your probe like in the attached photo?

Image

First try reducing the offset by altering these kinds of parameters

@RobertoDF
Copy link
Author

Ground is connected to Ref like in the pic 👍. I was in external REF

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