Jump to content
Sign in to follow this  
G.Treisbach

"VarPythDemo" with time series data from a measurement device

Recommended Posts

Hi, with your VarPyth Demo I'm able to create a numpy array, fill it with data, "transfer" it to python, modify the data, "transfer" it back to delphi and use it in delphi without any problems.

So far this works perfect.

 

My problem is, that I have to use  time series data from a measurement device (I would like to calculate a fft with (numpy / scipy)  and do not know on how to transfer my time series data to python.
Here is my "Pseudo-Code":

procedure TForm1.FormCreate(Sender: TObject);
begin
   var np                := Import('numpy');
   var np_array: Variant := np.zeros(10);  // 'normally this will be at least 96000 elements

   np_array[0] := 0.00123;
   np_array[1] := 0.43312;
   np_array[2] := 0.20033;
   np_array[3] := 0.00111;
   ...
   and so on

   PythonModule.SetVar('np_array', ExtractPythonObjectFrom(np_array));
end;

Of cause this doesn’t work, because np_array contains only one element, and this is my numpy-array that is containing 10 elements each set to 0.

I'm looking for a possibility to create a numpy array in Delphi, fill all elements to the appropriate values and then assign the array to a variant, so that I can use the given mechanism to transfer the data into the python world.

 

Maybe there is another (better, mor simple) solution available?

 

Thanks for your help

  Gerhard

Share this post


Link to post
np_array.SetItem(0) 

 

should work.

 

From VarPyth source code:

 

          // here we handle a special case: COM (or Delphi?) doesn't allow you to have index properties
          // on a variant except from a true array variant! So if myVar is a Python variant that holds
          // a Python list, I can't write something like: myVar[0]! But if the list is a member of a
          // Python instance, it will work fine! Like: myInst.myList[0]
          // So, to handle this problem we detect some special names: GetItem, SetItem and Length
          // that will do the same as:
          // myList[0] <-> myList.GetItem(0)
          // myDict['Hello'] := 1 <-> myDict.SetItem('Hello', 1)
          // len(myList) <-> myList.Length()
          // we get some bonus with the slices and in operators also:
          // myList = [0, 1, 2, 3]; myList.GetSlice(1, 2) --> [1, 2]
          // myList.Contains(2) <-> 2 in myList

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×