Python script access to current data

I’m trying to do this to get some data from a current sweepme session and then (hopefully) return some new variables to sweepme for plotting.
The first problem I run into is that while the plot in sweepme for my replicated experiment has ~200 points, when I use parameter manager to get times it returns only a scalar, as is reflected in the Parameters widget. How do I get what sweepme is plotting?

import ParameterManager
ParM = ParameterManager.ParameterManager()

#used to extract data from live sweepme session
times = ParM.get_parameter(“Time_elapsed_s”)

#this doesn’t work because times is a scalar, not a vector
time_diffs = np.diff(times)

#Do histogram
counts, edges = np.histogram(time_diffs)

#untested and more of a fantasy than real code
ParM.set_parameter(“time diff bin edges”, edges)

1 Like

Hi,

the only way to get the history of data is to use CustomFunction.
You can handover a variable and you get all data in a numpy array since the last call of the script of the CustomFunction data.

The CustomFunction script could then return a new variable with exactly the data extracted and modified as needed for data. This could also mean that you need to return two variables, one for x axis and one for y axis.

Afterwards, you can select in the Plot widget these new variables and plot them. In this case both variables would be 1D data e.g. a list or an array and if they have both have the same length, they can also be plotted.

So, in your case. I would handover the the variable “Time elapsed [s]” to a CustomFunction script and maybe an additional variable that you like to process. This could be done in an additional branch after your measurement so that your histogram evaluation is performed after the acqusition of the data is finished.

If the CustomFunction script is called at every iteration of the sequencer, the value being handed over would be only a single value in the array. Then, you could still collect the data in your CustomFunction script over all iterations of the sequencer and return at each step an array that gets stepswise longer.

Hope this gives you an idea how to proceed. Otherwise, please let us know and I guess we can explain in more detail.

Best, Axel

1 Like

There is a scenario that came to my mind where is does not work and it is related to Time elapsed.

image

The above screenshot shows a sequencer that measures ten times the mouse cursor position (based on the Mouse Logger example).

A CustomFunction module in a second branch is then used to handover data and process it.

If you select “Time elapsed [s]” as variable it does not work, because it would return data from the last branch where the Time module is in. As the Time module is in every branch (as the invisible root item), you can only receive the Time value that was measured in the second branch, when the single iteration of the CustomFunction module was performed. This is a special case that is related to all modules that are at the top of sequencer and belong to both branches.

To explain this a bit more, I created another example:

image

This would also lead to the repetitive measurement of the Mouse cursor in the first branch, but because the Logger module “Mouse” is now at the top, it also part of the second branch. If you would handover the variable “Mouse x [px]” to the CustomFunction, you would not get the data of the first branch, but the single measurement point where the Mouse module was activated in the second branch.

To resolve or work around the problem in the first case with the Time module, you can add a Calc module to first branch that simply returns the Time elapsed variable. This way the value of Time elapsed is stored in a new variable created by the Calc module which then can be handedover with the full history of the first branch to the CustomFunction module.

I hope this helps a bit further to understand how handing over to CustomFunction with multiple branches works.

The basic use case would be that people for example measure a solar cell IV curve and in a second branch they can access entire IV curve and do a calculation like open-circuit voltage, short-circuit current, maximum power point or fill factor.

image

If you put everything into a Loop module, you can evaluate the IV curve at each repetition of the Loop module, because CustomFunction always can receive all the data since the last call of the CustomFunction module. This way it receives the last IV curve.

Best, Axel

1 Like