summaryrefslogtreecommitdiff
path: root/src/sardana/macroserver
diff options
context:
space:
mode:
authortiagocoutinho <tiagocoutinho@users.sourceforge.net>2012-07-10 15:58:39 +0000
committertiagocoutinho <tiagocoutinho@users.sourceforge.net>2012-07-10 15:58:39 +0000
commite30711b4835c56b5ed361828507610c76374c3c5 (patch)
treec663190e9ad47004a85825ce7a567a5d55f619a8 /src/sardana/macroserver
parent367bb413328f082eec2079b6c56b559ce068e4ae (diff)
fix plotting feature
git-svn-id: file:///home/cpascual/src/sdnongit/svnbck/sardana/share/Sardana/trunk@20879 c480fdf4-a248-4bb0-8e4a-34cd1ef68f4f
Diffstat (limited to 'src/sardana/macroserver')
-rw-r--r--src/sardana/macroserver/macro.py25
-rw-r--r--src/sardana/macroserver/macros/examples/plotting.py24
-rw-r--r--src/sardana/macroserver/msdoor.py37
3 files changed, 82 insertions, 4 deletions
diff --git a/src/sardana/macroserver/macro.py b/src/sardana/macroserver/macro.py
index c330fed2..75a8be7b 100644
--- a/src/sardana/macroserver/macro.py
+++ b/src/sardana/macroserver/macro.py
@@ -696,12 +696,31 @@ class Macro(Logger):
def plot(self, *args, **kwargs):
"""**Macro API**.
Sends the plot command to the client using the 'RecordData' DevEncoded
- attribute. The data is encoded using the JSON -> BZ2 codec.
+ attribute. The data is encoded using the pickle -> BZ2 codec.
:param args: the plotting args
:param kwargs: the plotting keyword args"""
- data = dict(args=args, kwargs=kwargs)
- self.sendRecordData(data, codec='bz2_json_plot')
+ self.pyplot.plot(*args, **kwargs)
+# data = dict(args=args, kwargs=kwargs)
+# self.sendRecordData(data, codec='bz2_pickle_plot')
+
+ @property
+ @mAPI
+ def pylab(self):
+ try:
+ pylab = self._pylab
+ except AttributeError:
+ self._pylab = pylab = self.door.pylab
+ return pylab
+
+ @property
+ @mAPI
+ def pyplot(self):
+ try:
+ pyplot = self._pyplot
+ except AttributeError:
+ self._pyplot = pyplot = self.door.pyplot
+ return pyplot
@property
def data(self):
diff --git a/src/sardana/macroserver/macros/examples/plotting.py b/src/sardana/macroserver/macros/examples/plotting.py
new file mode 100644
index 00000000..e32237bf
--- /dev/null
+++ b/src/sardana/macroserver/macros/examples/plotting.py
@@ -0,0 +1,24 @@
+import math
+from numpy import linspace
+from scipy.integrate import quad
+from scipy.special import j0
+
+from sardana.macroserver.macro import macro
+
+def j0i(x):
+ """Integral form of J_0(x)"""
+ def integrand(phi):
+ return math.cos(x * math.sin(phi))
+ return (1.0/math.pi) * quad(integrand, 0, math.pi)[0]
+
+@macro()
+def J0_plot(self):
+ x = linspace(0, 20, 200)
+ y = j0(x)
+ x1 = x[::10]
+ y1 = map(j0i, x1)
+ self.pyplot.plot(x, y, label=r'$J_0(x)$') #
+ self.pyplot.plot(x1, y1, 'ro', label=r'$J_0^{integ}(x)$')
+ self.pyplot.title(r'Verify $J_0(x)=\frac{1}{\{pi}\int_0^{\pi}\cos(x \sin\phi)\,d\phi$')
+ self.pyplot.xlabel('$x$')
+ self.pyplot.legend()
diff --git a/src/sardana/macroserver/msdoor.py b/src/sardana/macroserver/msdoor.py
index 694462ad..03333cd6 100644
--- a/src/sardana/macroserver/msdoor.py
+++ b/src/sardana/macroserver/msdoor.py
@@ -114,6 +114,7 @@ class MSDoor(MSObject):
self._record_data = None
self._macro_proxy_cache = None
self._input_handler = BaseInputHandler()
+ self._pylab_handler = None
MSObject.__init__(self, **kwargs)
def get_type(self):
@@ -129,6 +130,40 @@ class MSDoor(MSObject):
running_macro = property(get_running_macro)
+ def set_pylab_handler(self, ph):
+ self._pylab_handler = ph
+
+ def get_pylab_handler(self):
+ return self._pylab_handler
+
+ pylab_handler = property(get_pylab_handler, set_pylab_handler)
+
+ def get_pylab(self):
+ ph = self.pylab_handler
+ if ph is None:
+ import matplotlib.pylab
+ ph = matplotlib.pylab
+ return ph
+
+ pylab = property(get_pylab)
+
+ def set_pyplot_handler(self, ph):
+ self._pyplot_handler = ph
+
+ def get_pyplot_handler(self):
+ return self._pyplot_handler
+
+ pyplot_handler = property(get_pyplot_handler, set_pyplot_handler)
+
+ def get_pyplot(self):
+ ph = self.pyplot_handler
+ if ph is None:
+ import matplotlib.pyplot
+ ph = matplotlib.pyplot
+ return ph
+
+ pyplot = property(get_pyplot)
+
def set_input_handler(self, ih):
self._input_handler = ih
@@ -164,7 +199,7 @@ class MSDoor(MSObject):
if macro is None:
macro = self
- input_data = dict(prompt=msg)
+ input_data = dict(prompt=msg, type='input')
input_data.update(kwargs)
data_type = kwargs['data_type']
is_seq = not isinstance(data_type, (str, unicode)) and \