Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
*.py[cod]

# Text editor caches and backups
*.swp
*~

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject
21 changes: 11 additions & 10 deletions python/auto_setup/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import absolute_import
# -- Handy ruler ------------------------------------------------------|

import idl_compat
import util
import config
from . import idl_compat
from . import util
from . import config

from main import auto_setup
import series_array, sq2_servo, sq1_servo, frame_test
from .main import auto_setup
from . import series_array, sq2_servo, sq1_servo, frame_test

from series_array import SARamp
from sq2_servo import SQ2Servo
from sq1_servo import SQ1Servo, SQ1ServoSA
from sq1_ramp import SQ1Ramp, SQ1RampTes
from rs_servo import RSServo
from .series_array import SARamp
from .sq2_servo import SQ2Servo
from .sq1_servo import SQ1Servo, SQ1ServoSA
from .sq1_ramp import SQ1Ramp, SQ1RampTes
from .rs_servo import RSServo
15 changes: 8 additions & 7 deletions python/auto_setup/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import absolute_import
__all__ = ["get_exp_config", "get_exp_param", "set_exp_param",
"set_exp_param_range"]

from get_exp_config import get_exp_config
from get_exp_config import get_exp_param
from get_exp_config import set_exp_param
from get_exp_config import set_exp_param_range
from get_exp_config import mas_param
from get_exp_config import configFile
from get_exp_config import get_fake_expt #transitional
from .get_exp_config import get_exp_config
from .get_exp_config import get_exp_param
from .get_exp_config import set_exp_param
from .get_exp_config import set_exp_param_range
from .get_exp_config import mas_param
from .get_exp_config import configFile
from .get_exp_config import get_fake_expt #transitional
37 changes: 20 additions & 17 deletions python/auto_setup/config/get_exp_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import print_function
from builtins import str
from builtins import map
import numpy
import subprocess

Expand Down Expand Up @@ -57,9 +60,9 @@ def mas_param(file, key, type=None, no_singles=False):
stdout=subprocess.PIPE);
value = p.communicate()[0];
status = p.wait();
except OSError, (errno, strerror):
print "Failed to load parameter " + key + \
"\n[Errno {0}] {1}".format(errno, strerror)
except OSError as e:
print("Failed to load parameter " + key + \
"\n[Errno {0}] {1}".format(e.errno, e.strerror))
return None

if (status):
Expand Down Expand Up @@ -162,18 +165,18 @@ def get_param_descriptions(file):
value, err_text = p.communicate()
if p.wait() != 0:
raise OSError(1, err_text)
except OSError, (errno, strerror):
print "Failed to get parameter info table from mas_param\n" \
"[Errno {0}] {1}".format(errno, strerror)
except OSError as e:
print("Failed to get parameter info table from mas_param\n" \
"[Errno {0}] {1}".format(e.errno, e.strerror))
return None
params = []
info = {}
for line in value.split('\n'):
w = map(str.strip, line.split(':'))
w = list(map(str.strip, line.split(':')))
if len(w) == 0 or len(w[0]) == 0 or w[0][0] == '#':
continue
if len(w) != 4:
raise RuntimeError, "Failed to parse mas_param info line %s" % line
raise RuntimeError("Failed to parse mas_param info line %s" % line)
name, dtype, arrayness, size = w[0], w[1], w[2]=='array', int(w[3])
params.append(name)
info[name] = {'type': dtype,
Expand Down Expand Up @@ -215,7 +218,7 @@ def read_param(self, name):
# Numerical data are space-delimited
val = val.split()
if desc['is_array']:
val = numpy.array(map(cast, val))
val = numpy.array(list(map(cast, val)))
else:
val = cast(val[0])
# Update internal data and return
Expand All @@ -236,7 +239,7 @@ def get_param(self, name, missing_ok=False, default=None):
if not name in self:
if missing_ok or default is not None:
return default
raise ValueError, "key '%s' not found in config file." % name
raise ValueError("key '%s' not found in config file." % name)
if hasattr(self[name], '__copy__'):
# Don't expose references to mutable objects (arrays)
return self[name].copy()
Expand All @@ -260,7 +263,7 @@ def write(self):

def merge_from(self, filename, clobber=False, verbose=False):
src = configFile(filename)
for k in src.keys():
for k in list(src.keys()):
if (not k in self) or clobber:
self[k] = src[k]
self.info[k] = src.info[k]
Expand All @@ -270,7 +273,7 @@ def merge_from(self, filename, clobber=False, verbose=False):
@staticmethod
def compare(c1, c2):
results = []
c2k = [x for x in c2.keys()]
c2k = [x for x in list(c2.keys())]
for k in sorted(c1.keys()):
if not k in c2k:
results.append((k, 'left only'))
Expand All @@ -286,11 +289,11 @@ def compare(c1, c2):


def get_fake_expt(filename):
print """
print("""
Creating configFile based on hard-coded experiment.cfg parameters...

Please upgrade mas_param to support "info" dumping. Thanks.
"""
""")
e = configFile(filename, read=False)
names, info = [], {}
for dtype in ['string', 'float', 'integer']:
Expand All @@ -314,9 +317,9 @@ def get_fake_expt(filename):
# Unit test...
fn1 = mas_path().data_dir() + '/experiment.cfg'
fn2 = './experiment.cfg'
print 'load'
print('load')
c1 = configFile(fn1)
c2 = configFile(fn2)
print 'scan'
print('scan')
for x in c1.compare(c1, c2):
print x
print(x)
8 changes: 6 additions & 2 deletions python/auto_setup/frame_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from __future__ import print_function
from builtins import str
from builtins import range
import os, time
from mce_data import MCEFile, MCERunfile
from numpy import *
import auto_setup.idl_compat as idl_compat
import auto_setup.util as util
import auto_setup.servo as servo
from functools import reduce

def go(tuning, rc, filename=None):
ok, frametest = acquire(tuning, rc, filename=filename)
if not ok:
raise RuntimeError, frametest['error']
raise RuntimeError(frametest['error'])

lockflags = reduce(tuning, frametest)
plot(tuning, frametest, lockflags)
Expand Down Expand Up @@ -63,7 +67,7 @@ def reduce(tuning, frametest):

# Read data preserving rows/cols dimensioning
mcefile = MCEFile(datafile)
print mcefile.data_mode
print(mcefile.data_mode)
data = mcefile.Read(field='error',row_col=True)
data = data.data
n_cols = data.shape[1]
Expand Down
5 changes: 3 additions & 2 deletions python/auto_setup/idl_compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
These routines recreate IDL library routines where native Python or
NumPy/SciPy routines are inadequate.
"""
from __future__ import absolute_import

__all__ = ["deriv", "smooth"]

from deriv import deriv
from smooth import smooth
from .deriv import deriv
from .smooth import smooth
10 changes: 6 additions & 4 deletions python/auto_setup/idl_compat/deriv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import division
from past.utils import old_div
import numpy

def deriv(x, y=None):
Expand All @@ -8,7 +10,7 @@ def deriv(x, y=None):
returns an array of the same length as its input.
"""
if (x is None and y is None):
raise TypeError, "No data."
raise TypeError("No data.")
if (y is None):
y = x
x = numpy.arange(y.size)
Expand All @@ -17,7 +19,7 @@ def deriv(x, y=None):

n = x.size
if (n != y.size):
raise TypeError, "x and y must be the same size"
raise TypeError("x and y must be the same size")

#floatify
xx = x.astype("float")
Expand All @@ -29,8 +31,8 @@ def deriv(x, y=None):

d = numpy.empty([n], dtype="float")
# middle points
d = numpy.roll(y,1) * (x12 / (x01 * x02)) + y * (1. / x12 - 1. / x01) \
- numpy.roll(y,-1) * (x01 / (x02 * x12))
d = numpy.roll(y,1) * (old_div(x12, (x01 * x02))) + y * (old_div(1., x12) - old_div(1., x01)) \
- numpy.roll(y,-1) * (old_div(x01, (x02 * x12)))

# formulae for the first and last points:
d[0] = y[0] * (x01[1] + x02[1]) / (x01[1] * x02[1]) - y[1] * x02[1] \
Expand Down
8 changes: 5 additions & 3 deletions python/auto_setup/idl_compat/smooth.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import division
from past.utils import old_div
import numpy

def smooth(a, w):
Expand All @@ -7,10 +9,10 @@ def smooth(a, w):
something slightly less lame with the end points.
"""
if (a.ndim != 1):
raise ValueError, "Input must be single dimensional"
raise ValueError("Input must be single dimensional")

if (a.size < w):
raise ValueError, "Input must be longer than the smoothing kernel"
raise ValueError("Input must be longer than the smoothing kernel")

# the trivial case
if (w < 3):
Expand All @@ -24,6 +26,6 @@ def smooth(a, w):
s = numpy.r_[2 * a[0] - a[w:1:-1], a, 2 * a[-1]-a[-1:-w:-1]]

# perform the convolution
y = numpy.convolve(numpy.ones(w,'d')/w, s, mode='same')
y = numpy.convolve(old_div(numpy.ones(w,'d'),w), s, mode='same')

return y[w-1:-w+1]
Loading