Best practices for concurrent measurements in python

I would like to use two Joulescopes on the input and output of a circuit respectively to take measurements with over different conditions. The sampling would be for a few seconds at each condition, and with many (hundreds of) conditions. I would like to have them measure at as nearly the same time as possible.

Using the StreamProcess imported from read_by_callback (using separate instances of the StreamProcess and separate stop/quit flags) seems like it could be a strategy with the starts being sequential statements, but the first iteration often has no non-0 results and the third usually causes a ValueError exception:

    rv |= bool(fn(*args, **kwargs))
               ~~^^^^^^^^^^^^^^^^^
  File "E:\git\circuit_test\read_by_callback.py", line 77, in stream_notify
    self._buffer[buf_start:buf_end, 0] = data['signals']['current']['value']
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not broadcast input array from shape (0,) into shape (10000,)
StreamProcess stream_notify() exception
Traceback (most recent call last):
  File "C:\Users\Jeremy\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\joulescope\v1\device.py", line 433, in _stream_process_cal

I’ve also tried adding a reset function to StreamProcess to set the self.idx and self.idx_offset to None with only one StreamProcess instance per device which also did not work.
Maybe there is a better method?

Hi @Jeremy - You have a few options. I have a few questions to better understand what will work best for you:

  1. How are you planning to demarcate the different conditions for measurement?
  2. Do you have a GPIO signal that demarcates the measurements that you can wire to each JS220? Note that the JS220 GPIO are USB ground referenced.

Hi @mliberty,

Thanks for the fast reply!

  1. The conditions are based on lists of discrete conditions which are issued to an SMU (using the same python script) and then some settling time is allowed to transpire before the sampling of interest would be done/collected.
  2. Right now, I don’t have a GPIO that signals the condition change. It would be some effort to add one from another device, but could be done and I suspect that would give good time synchronization between devices. Using a GPIO between the Joulescopes would add less system complexity vs. another device. USB ground reference is OK.

I am also considering recording with the UI and analyzing separately - seeing it real-time has some advantages when things are not operating as expected.

One option is to use a JS220’s GPO to drive a GPI on each JS220. This gives you definitive time alignment. The JS220’s do time align to UTC using an NTP-like method over USB, but this GPO/GPI approach will give you much better, bounded accuracy.

I am a fan of recording and post-processing whenever possible. This gives you a historical record while also allowing you to modify analysis without recapturing data.

Capturing can be as easy as starting a record.

For controlling this through the UI, you have a couple of options:

  1. Create a Joulescope UI plugin
  2. Connect to the Joulescope UI using a socket API which does not yet exist, but could.

What do you think?

It would be really nice to drive the GPO from a (standalone) python script while the UI is open in a normal window. Starting and stopping a recording from the python script would also be helpful to automation.

It sounds like with a plugin I could trigger a script from within the UI, and I suspect control the JS devices including the GPO. If so, that probably is the fast/easiest path.

A socket sounds appealing, but maybe that’s because there are a lot of details I’m not considering yet.

I just pushed commit 985f88a that adds a --tcp-server command line option to the UI, which also addresses issue 314. When provided, it writes credentials to server.json in Joulescope config dir. See examples/tcp_server/change_views.py for an example. I will try to create an example closer to what you want sometime this week.

While this will be included in the next official UI release, you have to run from source for now to try it out.