Top List Farm Search Help RSS Login


  • 追加された行はこのように表示されます。
  • 削除された行はこのように表示されます。
[[Softwares]] > HARK-Python

!!! HARK-Python

!! What is HARK-Python?
HARK-Python is a glue that combines HARK and [Python|] using [Boost.Python|].

HARK-python provides two functions: 
+ data visualization nodes using [matplotlib|], a powerful visualization module for python
+ a wrapper to develop a HARK node using python.

{{img harkpython-overview.png,"border='0'"}}

!! Benefits of HARK-Python
! Rich visualization
The visualization of HARK basic packages is not enough. Only DisplayLocalization for visualizing localization results is provided. 
HARK-Python package provides visualization modules for 
* waveform(plotWaveform), 
* spectrogram (plotSpec), and 
* localization(plotSource).

! Quick development of a new node.

When you use PyCodeExecutor node, you can just write your code.
+ write your code like this:

1. write your code like this:
 import harkpython.harkbasenode as harkbasenode
 class HarkNode (harkbasenode.HarkBaseNode):
     def __init__(self):
         # define the output names and types of your node as tuples here.
     def calculate(self):
         # write your code here.
+ then, build a network that uses your code.
2. then, build a network that uses your code.

!! Installation
+ add HARK repository and install Basic HARK Packages. see [HARK installation instructions|] for details.
+ Install HARK-Python
 sudo apt-get install hark-python

!! Tutorial
! Tutorial 1:  Run examples
1. run 

Then, you will see the instruction like this:
 set the path first:
2. Then, you will see the instruction like this: 
 /usr/share/doc/hark-python/examples/plotSourceNetwork.n /usr/share/doc/hark-python/examples/plotSourceExample.xml
 Plot localization result
 /usr/share/doc/hark-python/examples/plotSourceNetwork.n /usr/share/doc/hark-python/examples/plotSourceExample.dat
 Plot spectrogram
 /usr/share/doc/hark-python/examples/plotSpecNetwork.n /usr/share/doc/hark-python/examples/longsample.wav
 Plot waveform
 /usr/share/doc/hark-python/examples/plotWaveformNetwork.n /usr/share/doc/hark-python/examples/shortsample.wav

Following this instruction, set the environmental variable PYTHONPATH first, 
then, cut and paste the lines.
3. To run these instructions, cut and paste the command line.

! Tutorial 2: Implement your node with python
Goal: calculate  input1^3 + input2^5

+ Put two Constants and one PyCodeExecutor, and connect them, save as samplecode.n  {{img harkpython-simple.png,"border='0'"}}
+ Set parameters
++ Constant: int 3
++ Constant: int 5
++ PyCodeExecutor: default.
+ write a code. save it as at the same path as the network file.
1. Put two Constants and one PyCodeExecutor
{{img harkpython-simple.20160405.png,"border='0'"}}

2. Set parameters
++ node_Constant_1:VALUE: int 3
++ node_Constant_2:VALUE: int 5
++ node_PyCodeExecutor_1:DIRECTORY_NAME: /usr/share/hark-designer/userdata/networks
(It's set in DIRECTORY_NAME that a path of the network file you save.)

3. Set terminals to node_PyCodeExecutor_1
++ Add Input: input1
++ Add Input: input2
++ Add Output: output (and Set as Output)
4. Connect terminals
++ node_Constant_1:VALUE to node_PyCodeExecutor:input1
++ node_Constant_2:VALUE to node_PyCodeExecutor:input2
5. Save as samplecode.n

6. write a code. save it as at the same path as the network file.
 import harkpython.harkbasenode as harkbasenode
 class HarkNode(harkbasenode.HarkBaseNode):
     def __init__(self):
         self.outputNames=("output",)  # one output terminal named "output"
         self.outputTypes=("prim_float",)  # the type is primitive float.
     def calculate(self):
         self.outputValues["output"] = self.input1 ** 3 + self.input2 ** 5
        # set output value
        # from two inputs: input1 and input2.
+ run 
7. When click Execute button, you'll see "Status: Normally finished. __see more__"
Click __see more__ link and see the complete log will be shown the following.
 <Float 3152 >

!! Advanced tips
! Detailed description of harkbasenode.
see /usr/share/doc/hark-python/harkbasenode.html or for details. 
in python interpreter.
 import harkpython.harkbasenode
 help harkpython.harkbasenode

! Other examples
see /usr/lib/python2.7/dist-packages/harkpython

! Support types
* Primitives:  
** int, float, complex<float>, and ObjectRef (= Source)
* Containers:  
**Vector<T> [T = int, float, complex<float>, and Source]
**Matrix<T> [T = int, float, complex<float>]
**Map<int, T> [T = Vector<int>, Vector<float>, Vector<complex<float> >, Float, Matrix<int>, Matrix<float>, Matrix<complex<float> >]

! Instance variables 
+ self.nodeName:  the name of the node. e.g., node_PyCodeExecutor_1. 
+ self.nodeID: the ID of the node. if the node name is node_PyCodeExecutor_1, the ID is 1.
+ self.count: the number of iteration.

If you want to plot the data for every 100 frames, 
 if self.count % 100 == 0

! Parameters of PyCodeExecuter and how they are used.
! Parameters of PyCodeExecutor and how they are used.
+ DIRECTORY_NAME --> This path is added to python path. 
+ FILENAME (no extensions)

Equivalent code
 import sys
 import FILENAME
 # For each iteration, calculate() is called