labstreaminglayer / app-vernier

Read from Vernier devices, stream as LSL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sampling frequency

mariaf3s opened this issue · comments

Hello,
In the vernier graphical analysis app there is a way to increase the sampling frequency, but is there a way to do this through python for use with LSL? Thank you!

Hey @mariaf3s, because the app wraps godirect-py, theoretically, yes: https://github.com/VernierST/godirect-py/blob/main/godirect/device.py#L141

I found that this would work not very reliably on the devices i tested a couple of years ago. I therefore did not implement a CLI option to configure the sampling rate of the device - but that should not be too difficult to implement.

I currently have no longer any access to a Vernier device, which i would need to test and develop. Therefore you might to try to implement this functionality yourself.

thanks for responding! OK, that may be a little outside of my experience level but I'm open to try, any idea of where to point me to get started?

Certainly.

According to godirect-py, one can give a period argument to device.start (see https://github.com/VernierST/godirect-py/blob/main/godirect/device.py#L141)

This method is called in verniersl during the starting of the Outlet: https://github.com/labstreaminglayer/app-vernier/blob/master/verniersl/__main__.py#L153

If you add a CLI argument like

        "--rate",
        type=int,
        default=-1,
        help="""Sets the sampling rate of the device, defaults to -1 (which takes the typical data rate for this device)""",
    )

and give this to the Outlet instantiation as an additional argument https://github.com/labstreaminglayer/app-vernier/blob/master/verniersl/__main__.py#L281
like

rate = device.get_default_period() if args.rate <0 else args.rate
o = Outlet(device=device, enable=enable, rate=rate)

In Outlets init, store the rate as self.rate and in https://github.com/labstreaminglayer/app-vernier/blob/master/verniersl/__main__.py#L152 it is then passed over to

stream = device_to_stream(device, self.rate)
device.start(self.rate)

(obviously, adapt device_to_stream to accomodate the new sampling rate (which is currently set to irregular, as - i mentioned earlier - i found it to be not as stable as i expected.

Good Luck!