[Tutor] Connecting with running module and capturing the data

Alan Gauld alan.gauld at btinternet.com
Mon Jul 20 11:23:13 CEST 2015


On 20/07/15 08:26, Patrycja Niewosz wrote:

> I am a beginner in python and have just started using it a couple weeks ago.
> I am using python 3.4.3 on windows 7 machine together with IDLE 3.4.3 for compiling a code.
> The following steps are:
>
> I have a program, called PyAquire, such as:

Can you tell us where you got it?
I did a search and the only one I could find was called pyacquire
(with a c) and seems to be an astronomy tool that is allegedly
hosted on google code but the site has no code! And no wiki
entries or issues or logged changes - in short its dead!

Is this the same package or something else? (Or did you
write it yourself?)

The reason I did the search is that this list is for questions about the 
Python language and its standard library so normally I'd suggest you ask 
on the pyaquire list or forum. But since I can't find one
that's not much help! The only other place you might get help is the 
main Python mailing list.

> import PyAquireUi
> import sys
> from PySide import QtGui

For PySide questions you can try any of several Qt mailing lists/fora


> import PyAquireMain
>
> def main():
>      master = PyAquireMain.PyAquireMain()
>      app = QtGui.QApplication(sys.argv)
>      ex = PyAquireUi.PyAquireMainWindow(master)
>      sys.exit(app.exec_())
>
>
>
> if __name__ == '__main__':
>      main()
>
> which opens a new window, where by clicking  RUN/STOP button,
 > program acquires data. The data is running in the window.
> Program runs in the background, acquiring data all the time

That last line is probably not true, but without knowing more about the 
module I can't be sure. However I strongly suspect that it is probably 
running within an event loop which gives your code the opportunity to 
register an event whereby you can intercept the results. But without any 
sign of code or documentation we can't really help.


> a)      to connect with this program without interrupting the process
 > b)      capture the current available data

See comment above but we need to see the API.

> c)       and save data to excel file.

There are a couple of modules for saving to Excel native format,
but I'd suggest you use a csv file instead since that is compatible with 
most spreadsheets etc - not everyone uses Excel and you might
have to share the results someday! The csv module will do that for
you.

> The code I have written is:
>
> import PyAquireMain
>
> def main():
>      obj = PyAquireMain.PyAquireMain()# Create instance obj
>         obj.saveSweepData()# call the method from PyAquireMain to save the file

Its not clear how this relates to the other program above?
Do you run the previous code in one interpreter and this
code in another? That's almost certainly the wrong way to
go about things.

> saveSweepData function from PyAquireMain is:
>     def saveSweepData(self):
>          fileSuffix = QtCore.QDateTime.currentDateTime().toString('yyyy-MM-dd_hh.mm.ss')
>          fileType = '.csv' # was .txt
>          if self.ch1.yData is not None:
>              saveFileName = 'data' + fileSuffix + fileType
>              with open(os.path.join(self.settings.saveDir,saveFileName),'wb') as f:
>                  #    f.writelines(header)
>                      np.savetxt(f,self.ch1.yData,fmt='%d',delimiter='\n')

This doesn't help us very much except that the reference to np
suggests this might be part of numpy so the numpy or scipy fora
might be able to help.

> Therefore the question is how can I access the PyAquireMain, capture data and save file
> simultaneously when other program is running in the background.

It all depends on how pyaquire does its job.
One possibility might be to use the new asyncio module in Python 3.4
but until we know more about this module we can't be sure.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list