jetperch / pyjoulescope_examples

Python scripting and programming examples using the joulescope package
Apache License 2.0
12 stars 9 forks source link

Assigning `np.nan` to integer dtype crashes `read_by_pyjoulescope_driver.py` #15

Open MM-Lehmann opened 6 months ago

MM-Lehmann commented 6 months ago

The following line crashes whenever there is a problem reading integer samples, because np.nan cannot be assigned: https://github.com/jetperch/pyjoulescope_examples/blob/73a192f7f5a2d3394f7ea66b1536c2438eb56ba0/bin/read_by_pyjoulescope_driver.py#L160

my current workaround is to wrap the line in a try except block and assign -9999 when the line is failing. I am sure there is a more elegant solution.

mliberty1 commented 6 months ago

I believe that this is now fixed, but I also cannot easily test it.

Are you seeing dropped samples frequently? If so, can you post the output of the following command:

python -m pyjoulescope_driver info

Note that you may need to use python3 rather than python on some macOS and Linux machines.

MM-Lehmann commented 6 months ago

Thanks for the quick fixing. However, I have some concerns about the proposed solution: https://github.com/jetperch/pyjoulescope_examples/commit/44a01944d5a13c44c32eaa38f3624a48a956bb4c#r141300162

mliberty1 commented 6 months ago

GPI data comes in as packed bits, 8 samples per uint8. In Python, you can unpack them like this:

y = np.unpackbits(y, bitorder='little')

As a result, there is no value you can set here that is invalid. If you want, you can unpack GPI samples to float32 and use np.nan, too. The downside is a 32 times increase in RAM use for GPI signal buffers.

If you really want to track dropped samples, you could store dropped segment (start, stop) pairs in a list.

Depending upon the host computer, the JS110 often has a drop or two at the very beginning. After that, you should not normally see drops. The JS220 should also not normally have drops. Are you seeing frequent drops on your system?

MM-Lehmann commented 4 months ago

After running a few more tests, I do indeed see frequent drops which I need to take care of. Probably the issues lies with USB device handling in Windows/WSL. I have implemented a capturing of the dropped samples in the example code and am happy to create a PR if you're interested.

mliberty1 commented 4 months ago

We officially do not support running Joulescope software within a VM. While it seems to work reliably on some computers, it just doesn't with some VMs and some computers. I have no idea about WSL2.

I saw this earlier this week: https://blog.golioth.io/usb-support-in-wsl2-now-with-a-gui/

and I want to play around to see how good/bad WSL2 is these days. I have added it to my task list, but it is not currently a priority.

Can you run the Joulescope software natively (not under WSL2)? Is WSL2 for development of some automated test only, and you will deploy on real Linux PC?