This page is part of the documentation for the training session to take place in Barcelona on the 22nd of May of 2013.
In this part we show how to write simple macros.
Duration: 1h'
#
# 1
#
from sardana.macroserver.macro import macro
@macro()
def hello_world(self):
"""This prints hello world on the screen"""
self.output("Hello, world!")
#
# 2
#
import numpy
from sardana.macroserver.macro import macro
@macro()
def fft_freq(self):
signal = numpy.array([-2, 8, 6, 4, 1, 0, 3, 5],
dtype=numpy.double)
fourier = numpy.fft.fft(signal)
n = signal.size
timestep = 0.1
freq = numpy.fft.fftfreq(n, d=timestep)
self.output(freq)
#
# 3
#
from sardana.macroserver.macro import macro, Type
@macro([["message", Type.String, None, "message to print"]])
def hello_world_2(self, message):
"""This prints hello world on the screen + a message"""
self.output("Hello, world!")
self.output("Your message is %s", message)
#
# 4
#
from sardana.macroserver.macro import macro, Type
@macro([["moveable", Type.Moveable, None, "moveable to get position"]])
def where_moveable(self, moveable):
"""This prints hello world on the screen + a message"""
self.output("%s is now at %s", moveable.getName(), moveable.getPosition())
#
# 5
#
from sardana.macroserver.macro import macro, Type
@macro([["energy", Type.Float, None, "energy (eV) to go to"]])
def move_energy(self, energy):
"""Change the monochromator energy"""
E = self.getMoveable("energy")
E.move(energy)
self.output("Energy is now at %s". E.getPosition())
@macro([["energy", Type.Float, None, "energy (eV) to go to"]])
def move_energy(self, energy):
"""Change the monochromator energy"""
E = self.getMoveable("energy")
E.move(energy)
self.output("Energy is now at %s". E.getPosition())