DAMARIS can now run scripts immediatly upon startup.

This is the first step towards a simple queing implementation.
This commit is contained in:
Markus Rosenstihl 2018-03-16 17:03:44 +01:00
parent 328d50fc43
commit 8991e61600
5 changed files with 55 additions and 38 deletions

View File

@ -3,23 +3,33 @@
# setup script will insert local DAMARIS installation path behind import sys statement # setup script will insert local DAMARIS installation path behind import sys statement
# this must happen before any damaris stuff is called! # this must happen before any damaris stuff is called!
import sys import sys
import os, argparse
import os
# for numpy-1.1 and later: check the environment for LANG and LC_NUMERIC # for numpy-1.1 and later: check the environment for LANG and LC_NUMERIC
# see: http://projects.scipy.org/scipy/numpy/ticket/902 # see: http://projects.scipy.org/scipy/numpy/ticket/902
if os.environ.get("LANG", "").startswith("de") or os.environ.get("LC_NUMERIC", "").startswith("de"): if os.environ.get("LANG", "").startswith("de") or os.environ.get("LC_NUMERIC", "").startswith("de"):
os.environ["LC_NUMERIC"] = "C" os.environ["LC_NUMERIC"] = "C"
import damaris.gui.DamarisGUI parser = argparse.ArgumentParser(description='DArmstadt MAgnetic Resonance Instrumentation Software')
parser.add_argument("--run", action="store_true", help="run DAMARIS immediately with given scripts")
parser.add_argument("--debug", action="store_true", help="run DAMARIS with DEBUG flag set")
parser.add_argument("--mpl", help="run DAMARIS with matplotlib backend",
choices=["GTKAgg","GTKCairo","GTK"], default="GTKAgg")
parser.add_argument("exp_script", help="experiment script", nargs="?", metavar="EXP.py")
parser.add_argument("res_script", help="result script", nargs="?", metavar="RES.py")
args = parser.parse_args()
import matplotlib import matplotlib
import os.path if args.mpl:
# argv is already parsed by gtk initialisation matplotlib.use(args.mpl)
myargs=sys.argv[1:]
myname=os.path.basename(sys.argv[0])
# find debug flag: import damaris.gui.DamarisGUI
if "--debug" in myargs:
if args.debug:
damaris.gui.DamarisGUI.debug = True damaris.gui.DamarisGUI.debug = True
print "debug flag set" print "debug flag set"
try: try:
@ -28,24 +38,9 @@ if "--debug" in myargs:
except ImportError: except ImportError:
pass pass
matplotlib.rcParams["verbose.level"] = "debug" matplotlib.rcParams["verbose.level"] = "debug"
myargs.remove("--debug")
# remove matplotlib flags d = damaris.gui.DamarisGUI.DamarisGUI(args.exp_script, args.res_script, start_immediatly=args.run)
if "-d"+matplotlib.rcParams["backend"] in myargs:
myargs.remove("-d"+matplotlib.rcParams["backend"])
# find scripts to load in parameter list
exp_script = None
res_script = None
if len(myargs)<=2:
if len(myargs)>=1:
exp_script=myargs[0]
if len(myargs)==2:
res_script=myargs[1]
else:
print """too many arguments.\n%s [--debug] [-dGTK(Agg|Cairo|)] (Experiment File|"") (Result File|"")"""%(myname)
d=damaris.gui.DamarisGUI.DamarisGUI(exp_script, res_script)
d.run() d.run()
sys.stdout = sys.__stdout__ sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__ sys.stderr = sys.__stderr__

View File

@ -174,7 +174,7 @@ class Experiment:
:param float time: seconds to wait :param float time: seconds to wait
:param int ttls: lines to set (integer) :param int ttls: lines to set (integer)
:param bool gating: reduce time by gating, i.e. wat in front of rf_pulse :param bool gating: reduce time by gating, i.e. wait in front of rf_pulse
:return: :return:
""" """
if gating: if gating:

View File

@ -52,11 +52,9 @@ matplotlib.rcParams[ "axes.formatter.limits" ] = "-3,3"
if matplotlib.rcParams[ "backend" ] == "GTK": if matplotlib.rcParams[ "backend" ] == "GTK":
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
max_points_to_display = 0 # no limit max_points_to_display = 0 # no limit
elif matplotlib.rcParams[ "backend" ] == "GTKCairo": elif matplotlib.rcParams[ "backend" ] == "GTKCairo":
from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas
max_points_to_display = 1 << 14 # cairo cannot render longer paths than 18??? max_points_to_display = 1 << 14 # cairo cannot render longer paths than 18???
else: else:
# default # default
@ -130,7 +128,7 @@ class DamarisGUI:
Stop_State = 3 Stop_State = 3
Quit_State = 4 Quit_State = 4
def __init__( self, exp_script_filename=None, res_script_filename=None ): def __init__( self, exp_script_filename=None, res_script_filename=None, start_immediatly=False ):
# state: edit, run, stop, quit # state: edit, run, stop, quit
# state transitions: # state transitions:
# edit -> run|quit # edit -> run|quit
@ -172,6 +170,15 @@ class DamarisGUI:
res_script = self.sw.load_file_as_unicode( res_script_filename ) res_script = self.sw.load_file_as_unicode( res_script_filename )
self.sw.set_scripts( exp_script, res_script ) self.sw.set_scripts( exp_script, res_script )
if start_immediatly:
if exp_script and res_script:
self.start_immediatly = start_immediatly
else:
raise ("RuntimeError", "experiment and result scripts not given,\
aborting immediate start of experiment")
else:
self.start_immediatly = False
self.statusbar_init( ) self.statusbar_init( )
self.main_window.show_all( ) self.main_window.show_all( )
@ -226,16 +233,16 @@ class DamarisGUI:
# prolong lifetime of clipboard till the very end (avoid error message) # prolong lifetime of clipboard till the very end (avoid error message)
self.main_clipboard = self.sw.main_clipboard self.main_clipboard = self.sw.main_clipboard
gtk.gdk.threads_enter( ) gtk.gdk.threads_enter( )
if self.start_immediatly:
self.toolbar_run_button.emit("clicked")
gtk.main( ) gtk.main( )
gtk.gdk.threads_leave( ) gtk.gdk.threads_leave( )
self.si = None self.si = None
self.sw = None self.sw = None
self.config = None self.config = None
self.xml_gui = None self.xml_gui = None
# event handling: the real acitons in gui programming
# first global events # first global events
def quit_event( self, widget, data=None ): def quit_event( self, widget, data=None ):

11
tests/exp_test.py Normal file
View File

@ -0,0 +1,11 @@
def test():
e=Experiment()
e.ttl_pulse(length=1e-6, value=1)
e.wait(1e-3)
e.ttl_pulse(length=1e-6,value=1)
e.record(samples=1024,frequency=1e6,sensitivity=1)
return e
def experiment():
for i in range(1):
yield test()

4
tests/res_test.py Normal file
View File

@ -0,0 +1,4 @@
def result():
for num,ts in enumerate(results):
data["ts %i"%num] = ts
print ts