Showing with 83 additions and 55 deletions.
  1. +7 −27 pyKst/README
  2. +43 −0 pyKst/demo/numpy_io.py
  3. +4 −5 pyKst/demo/numpy_matrix.py
  4. +3 −3 pyKst/demo/numpy_vector.py
  5. +4 −4 pyKst/demo/pykstplotdemo.py
  6. +11 −8 pyKst/html/index.rst
  7. +5 −2 pyKst/pykstplot.py
  8. +6 −6 src/datasources/matlab/matlab.cpp
34 changes: 7 additions & 27 deletions pyKst/README
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
NOTE: This Readme is no longer accurate and needs to be updated.
Almost nothing in it is fully relevant any more.
PyKst is tested on Python 2.7 and does not work with Python 3.x.
It has not been tested on mac or windows, though it c/should work.

PyKst is, at the time of writing, not stable enough for serious use.
For the time being, do not write scripts with it except to test and to send feedback.

PyKst is tested on Python 2.6 and does not work with Python 3.x.

PyKst needs NumPy 1.6 and does not work with NumPy 1.5. If it is very important
that it should work with NumPy 1.5, modify pykstpp.py to work with the old
API (and submit these changes to kst!!) or send an email to the devel list.

PyKst currently is not portable as pykstpp.py contains C++ code which is
compiled upon first use. It should, instead, create a dynamic library at
Kst compile time. Also, it does not detect the location of the Qt library or
include files, so to get it to compile you might have to modify pykstpp.py.

Please email the Kst list with feature requests and bug reports. I am not able to work on
scripting as much as I have had the chance to do in the past two weeks because of
high school, but can certainly try to help with relatively minor fixes.

The fastest way to get started is to take a look at the examples inside the svn tree
at pyKst/

Documentation is available for now at hen.astro.utoronto.ca/pyKst or inside the
svn tree at pyKst/doc.

Josh
PyKst needs NumPy and scipy
The newest version of PyKst needs the newest version of kst.

Under Linux, install with:
sudo python2.7 setup.py install

Documentation and the latest version of pykst can be found on the kst web page kst.kde.org

----------------

43 changes: 43 additions & 0 deletions pyKst/demo/numpy_io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python2.7
import pykst as kst
import numpy as np
import time

client=kst.Client("VectorIO")

t0 = time.clock()

# create a pair of numpy arrays
x = np.linspace( 0, 50, 500000)
y = np.sin(x)

t1 = time.clock()

# copy the numpy arrays into kst and plot them
V1 = client.new_editable_vector(x)
V2 = client.new_editable_vector(y)
c1 = client.new_curve(V1, V2)
p1 = client.new_plot()
p1.add(c1)

t2 = time.clock()

# copy numpy array back into python.
A = V2.get_numpy_array()

t3 = time.clock()

# manipulate the array in python, and plot it in kst
A = A*A
V3 = client.new_editable_vector(A)
c2 = client.new_curve(V1, V3)
p1.add(c2)

# manipulate it again, and replace it in kst
A = A/2
V2.load(A)

print "creation of numpy arrays took", t1 - t0, "s"
print "copying onto kst and plotting took", t2-t1, "s"
print "copying from kst into python took:", t3-t2, "s"

9 changes: 4 additions & 5 deletions pyKst/demo/numpy_matrix.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#!/usr/bin/python
import pykst as kst
from numpy import *
#from PyQt4 import QtCore, QtNetwork, QtGui
import numpy as np

def mandelbrot( h,w, maxit=10 ):
'''Returns an image of the Mandelbrot fractal of size (h,w).
'''
y,x = ogrid[ -1.4:1.4:h*1j, -2:0.8:w*1j ]
y,x = np.ogrid[ -1.4:1.4:h*1j, -2:0.8:w*1j ]
c = x+y*1j
z = c
divtime = maxit + zeros(z.shape, dtype=float64)
divtime = maxit + np.zeros(z.shape, dtype=np.float64)

for i in xrange(maxit):
z = z**2 + c
diverge = z*conj(z) > 2**2 # who is diverging
diverge = z*np.conj(z) > 2**2 # who is diverging
div_now = diverge & (divtime==maxit) # who is diverging now
divtime[div_now] = i # note when
z[diverge] = 2.0 # avoid diverging too much
Expand Down
6 changes: 3 additions & 3 deletions pyKst/demo/numpy_vector.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/python2.7
import pykst as kst
from numpy import *
import numpy as np

client=kst.Client("NumpyVector")

# create a pair of numpy arrays
x = linspace( -10, 10, 1000)
y = sin(x)
x = np.linspace( -10, 10, 1000)
y = np.sin(x)

# copy the numpy arrays into kst and plot them
V1 = client.new_editable_vector(x, name="X")
Expand Down
8 changes: 4 additions & 4 deletions pyKst/demo/pykstplotdemo.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/python2.7
import pykstplot as plt
#import matplotlib.pyplot as plt
from numpy import *
import numpy as np

x = linspace( -10, 10, 100)
y = sin(x)
z = cos(x)
x = np.linspace( -10, 10, 100)
y = np.sin(x)
z = np.cos(x)

plt.subplot(221)
plt.plot(x,y*y, linewidth=2, color = "green", linestyle="-.", label="greenline")
Expand Down
19 changes: 11 additions & 8 deletions pyKst/html/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ kst can be also be used to plot numpy arrays, as in this example::

#!/usr/bin/python2.7
import pykst as kst
from numpy import *
import numpy as np

# create a pair of numpy arrays
x = linspace( -10, 10, 1000)
y = sin(x)
x = np.linspace( -10, 10, 1000)
y = np.sin(x)

# start a kst session with the arbitrary name "NumpyVector"
client=kst.Client("NumpyVector")
Expand All @@ -67,11 +67,11 @@ at the end of this document. As an example::
#!/usr/bin/python2.7
import pykstplot as plt
#import matplotlib.pyplot as plt
from numpy import *
import numpy as np

x = linspace( -10, 10, 100)
y = sin(x)
z = cos(x)
x = np.linspace( -10, 10, 100)
y = np.sin(x)
z = np.cos(x)

plt.subplot(221)
plt.plot(x,y*y, linewidth=2, color = "green", linestyle="-.", label="greenline")
Expand Down Expand Up @@ -261,6 +261,9 @@ Interactive items are controls which are part of a kst view and use QtNetwork.QL
:inherited-members:

Pykstplot
*******************
*********
pykstplot re-implements a tiny subset of matplotlib.pyplot. It is included by importing pykstplot,
and is conceptually incompatible with pykst.

.. automodule:: pykstplot
:members:
7 changes: 5 additions & 2 deletions pyKst/pykstplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def figure():
global _current_plot
global _subplots

if _client is None:
_client=kst.Client()

_client.new_tab()
_current_plot = None
_subplots = {}
Expand Down Expand Up @@ -282,7 +285,7 @@ def plot(*args, **kwargs):
C.f = arg
if (C.y is None) & (isinstance(C.x, _np.ndarray)):
C.y = C.x
C.x = linspace(0, C.y.size-1, C.y.size)
C.x = _np.linspace(0, C.y.size-1, C.y.size)
if (isinstance(C.x, _np.ndarray)):
_add_curve_to_plot(_current_plot, C)
C.reset()
Expand All @@ -297,7 +300,7 @@ def plot(*args, **kwargs):

if (C.y is None) & (isinstance(C.x, _np.ndarray)):
C.y = C.x
C.x = _np.asanyarray([0,1,2], dtype=_np.float64)
C.x = _np.asanyarray([0.0, C.y.size-1.0], dtype=_np.float64)
if (isinstance(C.x, _np.ndarray)):
_add_curve_to_plot(_current_plot, C)

Expand Down
12 changes: 6 additions & 6 deletions src/datasources/matlab/matlab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class DataInterfaceMatlabScalar : public DataSource::DataInterface<DataScalar>
bool isValid(const QString&) const;

// T specific
const DataScalar::DataInfo dataInfo(const QString&) const { return DataScalar::DataInfo(); }
const DataScalar::DataInfo dataInfo(const QString&, int frame=0) const { Q_UNUSED(frame) return DataScalar::DataInfo(); }
void setDataInfo(const QString&, const DataScalar::DataInfo&) {}

// meta data
Expand Down Expand Up @@ -125,7 +125,7 @@ class DataInterfaceMatlabString : public DataSource::DataInterface<DataString>
bool isValid(const QString&) const;

// T specific
const DataString::DataInfo dataInfo(const QString&) const { return DataString::DataInfo(); }
const DataString::DataInfo dataInfo(const QString&, int frame=0) const { Q_UNUSED(frame) return DataString::DataInfo(); }
void setDataInfo(const QString&, const DataString::DataInfo&) {}

// meta data
Expand Down Expand Up @@ -174,7 +174,7 @@ class DataInterfaceMatlabVector : public DataSource::DataInterface<DataVector>
bool isValid(const QString&) const;

// T specific
const DataVector::DataInfo dataInfo(const QString&) const;
const DataVector::DataInfo dataInfo(const QString&, int frame = 0) const;
void setDataInfo(const QString&, const DataVector::DataInfo&) {}

// meta data
Expand All @@ -187,7 +187,7 @@ class DataInterfaceMatlabVector : public DataSource::DataInterface<DataVector>
};


const DataVector::DataInfo DataInterfaceMatlabVector::dataInfo(const QString &field) const
const DataVector::DataInfo DataInterfaceMatlabVector::dataInfo(const QString &field, int) const
{
if (!matlab._fieldList.contains(field))
return DataVector::DataInfo();
Expand Down Expand Up @@ -242,7 +242,7 @@ class DataInterfaceMatlabMatrix : public DataSource::DataInterface<DataMatrix>
bool isValid(const QString&) const;

// T specific
const DataMatrix::DataInfo dataInfo (const QString&) const;
const DataMatrix::DataInfo dataInfo (const QString&, int frame = 0) const;
void setDataInfo(const QString&, const DataMatrix::DataInfo&) {}

// meta data
Expand All @@ -255,7 +255,7 @@ class DataInterfaceMatlabMatrix : public DataSource::DataInterface<DataMatrix>
};


const DataMatrix::DataInfo DataInterfaceMatlabMatrix::dataInfo(const QString& matrix) const
const DataMatrix::DataInfo DataInterfaceMatlabMatrix::dataInfo(const QString& matrix, int) const
{
if (!matlab._matrixList.contains( matrix ) ) {
return DataMatrix::DataInfo();
Expand Down