7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.svn
CMakeLists.txt.user

*.dm
dm
dm.lnk
*.swp
_build
*.pyc
16 changes: 16 additions & 0 deletions pyKst/demo/testdataobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,19 @@
v2 = e1.Y()
v3 = e1.X()
print v2.name(), v2.value(3), v3.value(3)


c1 = client.new_curve(e1.X(), e1.Y())
c1.set_color("blue")

p1 = client.new_plot((0.5,0.25), (1,0.5))
p1.add(c1)

psd1 = client.new_spectrum(e1.X())
c2 = client.new_curve(psd1.X(), psd1.Y())
c2.set_color("green")

p2 = client.new_plot((0.5,0.75), (1,0.5))
p2.add(c2)

print "average?", psd1.interleaved_average()
34 changes: 34 additions & 0 deletions pyKst/html/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ Strings
:members:
:inherited-members:

Data Objects
************
Data Objects are objects which transform primitives into other
primitives.

Equations
---------
.. autoclass:: Equation
:members:
:inherited-members:

Spectra
-------
.. autoclass:: Spectrum
:members:
:inherited-members:

Linear Fit
----------
.. autoclass:: LinearFit
:members:
:inherited-members:

Polynomial Fit
--------------
.. autoclass:: PolynomailFit
:members:
:inherited-members:

Relations
*********
Relations are objects which can be added to a plot.
Expand All @@ -74,6 +103,11 @@ Curves
:members:
:inherited-members:

Images
------
.. autoclass:: Image
:members:
:inherited-members:

Annotations
***********
Expand Down
190 changes: 189 additions & 1 deletion pyKst/pykst.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,54 @@ def new_equation(self, x_vector, equation, name=""):
"""
return Equation(self, x_vector, equation, name)


def equation(self, name):
""" Returns an Equation from kst given its name.
See :class:`Equation`
"""
return Equation(self, "", "", name, new=False)

def new_spectrum(self,
vector,
sample_rate = 1.0,
interleaved_average = False,
fft_length = 10,
apodize = True,
remove_mean = True,
vector_units = "",
rate_units = "Hz",
apodize_function = 0,
sigma = 1.0,
output_type = 0,
interpolate_over_holes = True,
name=""):
""" Create a new Spectrum in kst.
See :class:`Spectrum`
"""
return Spectrum(self,
vector,
sample_rate,
interleaved_average,
fft_length,
apodize,
remove_mean,
vector_units,
rate_units,
apodize_function,
sigma,
output_type,
interpolate_over_holes,
name)

def spectrum(self, name):
""" Returns a spectrum from kst given its name.
See :class:`Spectrum`
"""
return Spectrum(self, "", name=name, new=False)

def new_linear_fit(self, xVector, yVector, weightvector = 0, name = ""):
""" Create a New Linear Fit in kst.
Expand Down Expand Up @@ -1340,7 +1381,7 @@ def min_z(self):
class Equation(NamedObject) :
""" An equation inside kst.
:param x_vector: the x vector of the equation
:param xvector: the x vector of the equation
:param equation: the equation
Vectors inside kst are refered to as [vectorname] or [scalarname].
Expand Down Expand Up @@ -1374,6 +1415,153 @@ def X(self) :
def set_x(self, xvector):
self.client.send_si(self.handle, "setInputVector(X,"+xvector.handle+")")

# Spectrum ############################################################
class Spectrum(NamedObject) :
""" An spectrum inside kst.
:param vector: the vector to take the spectrum of
:param sample_rate: the sample rate of the vector
:param interleaved_average: average spectra of length fft_length
:param fft_length: the fft is 2^fft_length long if interleaved_average is true.
:param apodize: if true, apodize the vector first
:param remove_mean: if true, remove mean first
:param vector_unints: units of the input vector - for labels.
:param rate_units: the units of the sample rate - for labels.
:param apodize_function: index of the apodization function - see apodize_function()
:param sigma: only used if gausian apodization is selected.
:param output_type: index for the output type - see output_type()
:param interpolate_over_holes: interpolate over NaNs, if true.
"""
def __init__(self, client,
vector,
sample_rate = 1.0,
interleaved_average = False,
fft_length = 10,
apodize = True,
remove_mean = True,
vector_units = "",
rate_units = "Hz",
apodize_function = 0,
sigma = 1.0,
output_type = 0,
interpolate_over_holes = True,
name="", new=True) :

NamedObject.__init__(self,client)

if (new == True):
self.client.send("newSpectrum()")

self.client.send("change(" + vector.handle + "," +
b2str(sample_rate) + "," +
b2str(interleaved_average) + "," +
b2str(fft_length) + "," +
b2str(apodize) + "," +
b2str(remove_mean) + "," +
vector_units + "," +
rate_units + "," +
b2str(apodize_function) + "," +
b2str(sigma) + "," +
b2str(output_type) + "," +
b2str(interpolate_over_holes) + ")")

self.handle=self.client.send("endEdit()")
self.handle.remove(0,self.handle.indexOf("ing ")+4)
self.set_name(name)
else:
self.handle = name

def Y(self) :
""" a vector containing the spectrum """
vec = VectorBase(self.client)
vec.handle = self.client.send_si(self.handle, "outputVector(S)")
return vec

def X(self) :
""" a vector containing the frequency bins """
vec = VectorBase(self.client)
vec.handle = self.client.send_si(self.handle, "outputVector(F)")
return vec

def set_vector(self, xvector):
""" set the input vector """
self.client.send_si(self.handle, "setInputVector(I,"+xvector.handle+")")

def interleaved_average(self):
""" average spectra of length fft_length() """
retval = self.client.send_si(self.handle, "interleavedAverage()")
return retval

def sample_rate(self):
""" the sample rate assumed for the spectra. """
retval = self.client.send_si(self.handle, "sampleRate()")
return retval

def fft_length(self):
""" ffts are 2^fft_length() long if interleaved_average is set """
retval = self.client.send_si(self.handle, "fftLength()")
return retval

def apodize(self):
""" apodize before taking spectra, if set """
retval = self.client.send_si(self.handle, "apodize()")
return retval

def remove_mean(self):
""" remove mean before taking spectra, if set """
retval = self.client.send_si(self.handle, "removeMean()")
return retval

def vector_units(self):
""" the units of the input vector. For labels """
retval = self.client.send_si(self.handle, "vectorUnits()")
return retval

def rate_units(self):
""" the units of the sample rate. For labels """
retval = self.client.send_si(self.handle, "rateUnits()")
return retval

def apodize_function(self):
""" the index of the apodize function.
The apodize funcition is::
0: default 1: Bartlett
2: Window 3: Connes
4: Cosine 5: Gaussian
6: Hamming 7: Hann
8: Welch 9: Uniform
"""
retval = self.client.send_si(self.handle, "apodizeFunctionIndex()")
return retval

def gaussian_sigma(self):
""" the width, if apodize_funcion_index() is 5 (gaussian). """
retval = self.client.send_si(self.handle, "gaussianSigma()")
return retval

def output_type(self):
""" the index of the spectrum output type.
The output type is::
0: Amplitude Spectral Density 1: Power Spectral Density = 1,
2: AmplitudeSpectrum 3: Power Spectrum
"""

retval = self.client.send_si(self.handle, "outputTypeIndex()")
return retval

def interpolate_over_holes(self):
""" replace NaNs with an interpolation, if true. """
retval = self.client.send_si(self.handle, "interpolateOverHoles()")
return retval


# FIT ###################################################################
class Fit(NamedObject) :
""" This is a class which provides some methods common to all fits """
Expand Down
8 changes: 4 additions & 4 deletions src/libkstapp/scriptserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ ScriptServer::ScriptServer(ObjectStore *obj) : _server(new QLocalServer(this)),
_fnMap.insert("getHistogramList()",&ScriptServer::getHistogramList);
// _fnMap.insert("newHistogram()",&ScriptServer::newHistogram);

_fnMap.insert("getPSDList()",&ScriptServer::getPSDList);
_fnMap.insert("newPSD()",&ScriptServer::newPSD);
_fnMap.insert("getSpectrumList()",&ScriptServer::getSpectrumList);
_fnMap.insert("newSpectrum()",&ScriptServer::newSpectrum);

_fnMap.insert("getPluginList()", &ScriptServer::getPluginList);
_fnMap.insert("newPlugin()",&ScriptServer::newPlugin);
Expand Down Expand Up @@ -611,13 +611,13 @@ QByteArray ScriptServer::newHistogram(QByteArray&, QLocalSocket* s,ObjectStore*,
*/


QByteArray ScriptServer::getPSDList(QByteArray&, QLocalSocket* s,ObjectStore*_store) {
QByteArray ScriptServer::getSpectrumList(QByteArray&, QLocalSocket* s,ObjectStore*_store) {

return outputObjectList<PSD>(s,_store);
}


QByteArray ScriptServer::newPSD(QByteArray&, QLocalSocket* s,ObjectStore*) {
QByteArray ScriptServer::newSpectrum(QByteArray&, QLocalSocket* s,ObjectStore*) {

if(_interface) {
return handleResponse("To access this function, first call endEdit()",s);
Expand Down
4 changes: 2 additions & 2 deletions src/libkstapp/scriptserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public slots:
QByteArray getHistogramList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
//QByteArray newHistogram(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray getPSDList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray newPSD(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray getSpectrumList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray newSpectrum(QByteArray& command, QLocalSocket* s,ObjectStore*_store);

QByteArray getPluginList(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
QByteArray newPlugin(QByteArray& command, QLocalSocket* s,ObjectStore*_store);
Expand Down
3 changes: 3 additions & 0 deletions src/libkstmath/curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,11 @@ void Curve::save(QXmlStreamWriter &s) {
s.writeAttribute("erroryminusvector", _inputVectors[EYMINUSVECTOR]->Name());
}
s.writeAttribute("color", Color.name());
s.writeAttribute("alpha", QString::number(Color.alpha()));
s.writeAttribute("headcolor", HeadColor.name());
s.writeAttribute("headalpha", QString::number(HeadColor.alpha()));
s.writeAttribute("barfillcolor", BarFillColor.name());
s.writeAttribute("barfillalpha", QString::number(BarFillColor.alpha()));

s.writeAttribute("haslines", QVariant(HasLines).toString());
s.writeAttribute("linewidth", QString::number(LineWidth));
Expand Down
Loading