Thursday, July 27, 2017

Live data features alive in LabPlot

Hey guys. It's been a while since my last post here, but we did a good job meanwhile. Beside implementing the features I have described in my previous post I have implemented some other useful features/additional options. Let's see what we have here.

First of all I'll just list the options that are implemented already and in the end I'll talk a bit about the next steps.
  • Source type
    • File or named pipe
    • Network TCP socket
    • Network UDP socket
    • Local socket
    • Serial port
  • Reading type
    • Continuously fixed
    • From end
    • Till the end
  •  Update type
    • Periodically
    • On new data
  • Keep last N values
  • Update now
  • Pause/Continue
  • Update interval
  • Sample rate
As I told you, for "Periodically" update type the user has to provide a value in milliseconds (planning to extend this to other interval types such as minutes, formatted time values..). For "Continuously fixed" and "From end" reading types the user has to provide a value which is the sample rate. On every update we'll read sample rate number of samples if they're available.

The option that I had no words about in my previous post is the "Reading type" one. Let's think a bit, if we have a device that sends lots of data then we may want to check only a piece from the end of the data. For this we have the "From end" reading type. It's possible that we want to observe continuously this new data, but read just some samples at a time. For this we have the "Continuously fixed" reading type. Also it's possible that we need all of the new data every time we update. In this case we have a third reading type, this is the "Till the end" one. For the "Continuously fixed" and "From end" the user must provide a value (sample rate) to tell LabPlot how many lines he/she wants to read on every update. No worries if the user enters a larger number than the actual new lines, we'll read just as much as we have in that case.  

Using our new LiveDataDock we allow users to change almost every option while doing the actual reading. Only the "Keep last N values" cannot be changed, because if we use that we want to have a fixed size that's not changing.

The new reading type option in "action":

Reading types
After creating the FileDataSource we get the newly implemented LiveDataDock. For "Till the end" as I said we don't need sample rate, so in that case LiveDataDock looks like this:

Till the end reading type selected
But if the "From end" reading type is selected then the Sample rate line edit shows up: 

From end reading type
In the other hand if the user wants to read the new data only if there is actually new data then this can be done as explained in my previous post, using the "On new data" update type:

From end with On new data
For almost every of the newly implemented features I have an example video which was made right after I got it working. 

In this video I'm presenting the use of the "Update interval" option.


This video is about changing the sample rate and pausing/continuing the reading.

The "Update now" button is presented in the video above.

This one demonstrates the "Keep last N values" option in action.

As you can see I have spent lots of time in these demo videos with the plot setup. We knew we need to speed up this procedure, so one of my mentors (Alexander Semke) implemented the PlotDataDialog for FileDataSources and so in just 1-2 clicks we can get our data plotted nicely. 

Then I came up with an idea which I thought we need for live data, but as we talked with Alexander I realized that this feature is useful for static data too. This feature is the data ranging, which consists of setting the plot's X min and max values to a calculated one. We get this value after providing the number of samples we want to see plotted from the end or the beginning of our FileDataSource. This feature is currently in development, but it will be soon working. This new feature is added to the CartesianPlotDock:

CartesianPlot data range
The "Free ranges" data range will be the same as it was available in LabPlot before. For live data sources the "Show last" option makes more sense, but in case of fixed sized FileDataSources even the "Show first" option can be useful. These options take a value which means the number of samples to be plotted. Using "Show last" we can watch the latest N new samples plotted. As I was thinking about this feature I "hacked" a fast prototype to demonstrate my idea about the "Show last" option to Alexander, you can check it here:

Here I'm using the PlotDataDialog for FileDataSources, you can see the difference I guess :).

About the source types: we need to learn a bit about the data extraction from sockets and every source type should be working just fine.

About the next steps, there can be lots always. The first steps are to fix the data extraction from sockets. After this we will be working on optimizing the data plotting which wasn't really designed for growing/frequently changing data, but we'll try our best to make LabPlot better and faster :)

This was for now folks, thanks for your attention, check out LabPlot! See you! :)

Wednesday, June 28, 2017

LabPlot getting "live support"

As I told you guys in my previous post, I'm here now to show you some new, cool stuff about LabPlot. First let me introduce you the synopsis of my project's proposal: 

"Currently, the visualization and analysis of data is only possible on static data that was imported into or generated in one of LabPlot's data containers. The goal of the project is to add support for streaming data. At the moment LabPlot has no support for this kind of data processing even though it is very important for this feature to be available in a scientific data plotting software."

As you can see one of the main tasks here is to be able to handle changing, streaming data. Somebody may plug in their physical device and then watch as their datas are being plotted. For this to work nicely and user friendly, we collected a handful of options to control this kind of data source. The first thing you want to do is to create a new FileDataSource, you can do that this way:

FileDataSource creation

After this you get this nice looking dialog with the new options, controls. We decided to support more types of live data sources, as you can see in the picture below.

FileDataSources options
For "File or named pipe" source type we have the following options:

File or named pipe options

This kind of source consists of reading from a local ascii or binary file or a named pipe. A named pipe is a bit more than a traditional pipe because it has a name and unlike the traditional one it can last till the system is up. In Unix systems one has to explicitly create a named pipe using mkfifo or mknod. After creation one process can write to it and one can read from it by name. Also for "Local socket" live data source type we have the same options, but this consist of reading from a local socket using QLocalSocket. To work with QLocalSocket we just need the name of the server the socket is connected to.

The next type of live data source is the Network socket one. The following options we have right now to configure this kind of live data source:
Network socket options

A network socket is an endpoint for sending/receiving data in a computer network. In our situation we want to read from it. To access a socket we must have the socket host's address and port number. 

The last type of live data source for now is the Serial port one. In the following picture you can see the options for this kind of data source:

Serial port options
This kind of live data source consist of reading from a port to which a physical device is connected. We just have to select the port our device is connected to, set the baud rate and voilá, it should work nicely soon. We use QSerialPort to access, work with serial ports. Using QSerialPortInfo class we can have informations easily about the available ports on our system. Also the supported baud rates can be acquired using QSerialPortInfo.

These options are necessary to set up the wanted kind of live data source. Beside this we must have some control above this kind of data source, right now we have the following options to control the update a FileDataSource:

Update options
Here you can see that we have two types of updates. The "Time interval" one will update the curves on a specified time interval (every second, every five seconds or so) which is a value in milliseconds. The "New data" update type will update the curves only when there's new data available. In the "Update frequency" we set the interval between the updates when using "Time interval" update type. The "Keep last N values" will control how much of the data we want to update. For this kind of data source one usually want to observe how the data is changing, to take a snapshot of their data. 

Another thing we might want is to have control over this kind of data source even after creation. For this we'll have a dock widget, it's not yet used, but currently it looks like this in Creator:

FileDataSource dock widget

With these options we will be able to modify the number of values we want to keep on every update, the time between updates. If the user uses a long interval between the updates then a functionality like the "Update now" button will provide it's very useful because there might be moments we didn't think we'd need to check the actual state of our data. Also the pausing and stopping the updates/data reading helps in the control of this kind of data source.

I have created a demo video which shows the creation of a FileDataSource, setting the X and Y axis data of some xy curves. Then a python script writes Brownians motion data to a file on which the FileDataSource was created. We can see there the curves being updated on new data:

An issue you can see here is that I have to set for every curve separately the X and Y value columns. We will use the PlotDataDialog which is used for plotting spreadsheet columns to solve this issue. PlotDataDialog is a very user friendly dialog which can be accessed from the spreadsheet's context menu. In this dialog we can select the X data and Y data for any curves we might want to plot from spreadsheet column data. This is the PlotDataDialog:


This is for now, hope you guys enjoyed it! The next step is to implement all the logic behind these options and make them do their job. A greater step after implementing the options will be to optimize our code on larger amount of data. Thanks to my mentors, Alexander and Stefan for their great help. Every time I am unsure on something they take their time to talk about it so together we can make LabPlot even cooler than it is right now :).

See you guys soon again! Have fun on your GSoC project!

Saturday, June 17, 2017

A harder beginning brings cool changes

Hi folks, it's been a while since my last post here. I had a hard time to start on GSoC but now that I have successfully graduated from the university (Computer Science BSc) I have all my time for my project. While learning for the exams and preparing for my final exam I've been talking to my mentors often to share our ideas about the project. Thanks to the fact that I have already worked previously (and continously after GSoC) on LabPlot I can implement the needed features much easier and quicker now than last year :) Now that I have my own branch and a few new classes added I can continue the adventure with LabPlot! See you soon! :)