DAMARIS can now run scripts immediatly upon startup.
This is the first step towards a simple queing implementation.
This commit is contained in:
parent
328d50fc43
commit
8991e61600
@ -3,49 +3,44 @@
|
||||
# setup script will insert local DAMARIS installation path behind import sys statement
|
||||
# this must happen before any damaris stuff is called!
|
||||
import sys
|
||||
import os, argparse
|
||||
|
||||
import os
|
||||
# for numpy-1.1 and later: check the environment for LANG and LC_NUMERIC
|
||||
# see: http://projects.scipy.org/scipy/numpy/ticket/902
|
||||
if os.environ.get("LANG","").startswith("de") or os.environ.get("LC_NUMERIC", "").startswith("de"):
|
||||
os.environ["LC_NUMERIC"]="C"
|
||||
if os.environ.get("LANG", "").startswith("de") or os.environ.get("LC_NUMERIC", "").startswith("de"):
|
||||
os.environ["LC_NUMERIC"] = "C"
|
||||
|
||||
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 damaris.gui.DamarisGUI
|
||||
import matplotlib
|
||||
|
||||
import os.path
|
||||
# argv is already parsed by gtk initialisation
|
||||
myargs=sys.argv[1:]
|
||||
myname=os.path.basename(sys.argv[0])
|
||||
if args.mpl:
|
||||
matplotlib.use(args.mpl)
|
||||
|
||||
# find debug flag:
|
||||
if "--debug" in myargs:
|
||||
import damaris.gui.DamarisGUI
|
||||
|
||||
if args.debug:
|
||||
damaris.gui.DamarisGUI.debug = True
|
||||
print "debug flag set"
|
||||
try:
|
||||
import resource
|
||||
resource.setrlimit(resource.RLIMIT_CORE, (-1,-1))
|
||||
resource.setrlimit(resource.RLIMIT_CORE, (-1, -1))
|
||||
except ImportError:
|
||||
pass
|
||||
matplotlib.rcParams["verbose.level"]="debug"
|
||||
myargs.remove("--debug")
|
||||
matplotlib.rcParams["verbose.level"] = "debug"
|
||||
|
||||
# remove matplotlib flags
|
||||
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 = damaris.gui.DamarisGUI.DamarisGUI(args.exp_script, args.res_script, start_immediatly=args.run)
|
||||
d.run()
|
||||
sys.stdout=sys.__stdout__
|
||||
sys.stderr=sys.__stderr__
|
||||
|
||||
sys.stdout = sys.__stdout__
|
||||
sys.stderr = sys.__stderr__
|
||||
|
@ -174,7 +174,7 @@ class Experiment:
|
||||
|
||||
:param float time: seconds to wait
|
||||
: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:
|
||||
"""
|
||||
if gating:
|
||||
|
@ -52,11 +52,9 @@ matplotlib.rcParams[ "axes.formatter.limits" ] = "-3,3"
|
||||
|
||||
if matplotlib.rcParams[ "backend" ] == "GTK":
|
||||
from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas
|
||||
|
||||
max_points_to_display = 0 # no limit
|
||||
elif matplotlib.rcParams[ "backend" ] == "GTKCairo":
|
||||
from matplotlib.backends.backend_gtkcairo import FigureCanvasGTKCairo as FigureCanvas
|
||||
|
||||
max_points_to_display = 1 << 14 # cairo cannot render longer paths than 18???
|
||||
else:
|
||||
# default
|
||||
@ -130,7 +128,7 @@ class DamarisGUI:
|
||||
Stop_State = 3
|
||||
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 transitions:
|
||||
# edit -> run|quit
|
||||
@ -172,6 +170,15 @@ class DamarisGUI:
|
||||
res_script = self.sw.load_file_as_unicode( res_script_filename )
|
||||
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.main_window.show_all( )
|
||||
@ -226,16 +233,16 @@ class DamarisGUI:
|
||||
# prolong lifetime of clipboard till the very end (avoid error message)
|
||||
self.main_clipboard = self.sw.main_clipboard
|
||||
gtk.gdk.threads_enter( )
|
||||
if self.start_immediatly:
|
||||
self.toolbar_run_button.emit("clicked")
|
||||
|
||||
gtk.main( )
|
||||
gtk.gdk.threads_leave( )
|
||||
|
||||
self.si = None
|
||||
self.sw = None
|
||||
self.config = None
|
||||
self.xml_gui = None
|
||||
|
||||
# event handling: the real acitons in gui programming
|
||||
|
||||
# first global events
|
||||
|
||||
def quit_event( self, widget, data=None ):
|
||||
|
11
tests/exp_test.py
Normal file
11
tests/exp_test.py
Normal 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
4
tests/res_test.py
Normal file
@ -0,0 +1,4 @@
|
||||
def result():
|
||||
for num,ts in enumerate(results):
|
||||
data["ts %i"%num] = ts
|
||||
print ts
|
Loading…
Reference in New Issue
Block a user