Skip to content

Futurize #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
9 changes: 6 additions & 3 deletions python/check_lock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from __future__ import division
from __future__ import print_function
from builtins import range
from past.utils import old_div
from numpy import *

from mce import mce
Expand All @@ -8,10 +12,9 @@
m = mce()
n_frames = 100
dm = m.read('rc1', 'data_mode')[0]
data = array(m.read_frames(n_frames, data_only=True)).transpose() \
/ scales[dm]
data = old_div(array(m.read_frames(n_frames, data_only=True)).transpose(), scales[dm])

for i in range(30):
print '%4i %10.2f %10.2f' % (i, data[i].mean(), data[i].std())
print('%4i %10.2f %10.2f' % (i, data[i].mean(), data[i].std()))


7 changes: 4 additions & 3 deletions python/mcelib/pymce/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import absolute_import
import mcelib
from basic import BasicMCE
import compat
import const
from .basic import BasicMCE
from . import compat
from . import const

class MCE(BasicMCE):
pass
Expand Down
28 changes: 18 additions & 10 deletions python/mcelib/pymce/basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from builtins import str
from builtins import zip
from builtins import range
from past.utils import old_div
from builtins import object
import mcelib
import const
from . import const

import numpy

Expand All @@ -8,7 +16,7 @@
except:
mce_data = None

class BasicMCE:
class BasicMCE(object):
"""
Minimal connection to the MCE library.

Expand Down Expand Up @@ -68,7 +76,7 @@ def card_list(self, cards):
if isinstance(cards, str):
_card = const.RC_CODES.get(cards.lower(), None)
if _card == None:
print "Could not parse card string '%s'"%_card
print("Could not parse card string '%s'"%_card)
return None
if _card == -1:
cards = [i+1 for i in range(len(const.RCS_BITS))]
Expand All @@ -82,16 +90,16 @@ def card_list(self, cards):
(sum([(c<=0) or (c>const.MAX_RC) for c in cards]) == 0) and \
(sum([cards[i]-cards[i-1]<=0 for i in range(1,len(cards))]) == 0)
if not ok:
print "Could not decode cards argument", cards_in
print "... got as far as ", cards
print("Could not decode cards argument", cards_in)
print("... got as far as ", cards)
return None
return cards

def read_raw(self, count, cards=None, n_rows=None):
# Decode cards list -- ends up as a list of card numbers [1,2]
cards = self.card_list(cards)
if cards == None:
raise ValueError, "Invalid card list %s" % str(cards)
raise ValueError("Invalid card list %s" % str(cards))
frame_size = self.frame_size(cards, n_rows)
card_code = sum([1<<(c-1) for c in cards])
# Create array, read.
Expand All @@ -114,8 +122,8 @@ def read_data(self, count=1, cards=None, fields=None, extract=False,
return None
# To go any further we need mce_data
if mce_data == None:
raise RuntimeError, "mce_data module is required to process data "\
"(pass raw_frames=True to suppress)."
raise RuntimeError("mce_data module is required to process data "\
"(pass raw_frames=True to suppress).")
d.fast_axis = 'dets'

# Before _GetPayloadInfo(), populate self.header using info
Expand All @@ -140,7 +148,7 @@ def read_data(self, count=1, cards=None, fields=None, extract=False,
d.data.shape = (d.n_rows, d.n_cols*d.n_rc, -1)
d.fast_axis = 'time'
if fields != None:
d.data = dict(zip(fields, d.extract(fields, unfilter=unfilter)))
d.data = dict(list(zip(fields, d.extract(fields, unfilter=unfilter))))
return d

def lock_query(self):
Expand Down Expand Up @@ -188,7 +196,7 @@ def extract(self, field, unfilter=False):
ftype = self.mce.read('rc1', 'fltr_type')[0]
fpara = self.mce.read('rc1', 'fltr_coeff')
filt = mce_data.MCEButterworth.from_params(ftype, fpara)
return data / filt.gain()
return old_div(data, filt.gain())
return data

# Replace _rfMCEParam, and load stuff right from the MCE
Expand Down
8 changes: 5 additions & 3 deletions python/mcelib/test/_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from __future__ import print_function
# Use this tree's build by default!
from builtins import object
import sys
sys.path.insert(1, '../build/lib.linux-i686-2.6')

# Did you build your edits? Ask make if target is up-to-date
import os
err = os.system('make -q -C ..')
if err != 0:
print '.. is out of date! make?'
print
print('.. is out of date! make?')
print()

# Utility:

import time
class timer:
class timer(object):
def __init__(self):
self.t0 = time.time()
def get(self):
Expand Down
15 changes: 8 additions & 7 deletions python/mcelib/test/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import sys
sys.path.append('../build/lib.linux-i686-2.6')

Expand All @@ -11,16 +12,16 @@
"RCS",
2]

print "These should work:"
print("These should work:")
for c in card_args:
print " Decoding %s to:" % repr(c)
print " ", mce.card_list(c)
print(" Decoding %s to:" % repr(c))
print(" ", mce.card_list(c))

print "These should not work:"
print("These should not work:")
for c in [[3,1], 'sdfa']:
print " Decoding %s to:" % repr(c)
print " ", mce.card_list(c)
print(" Decoding %s to:" % repr(c))
print(" ", mce.card_list(c))


data = mce.read_raw(10)
print data[:,5]
print(data[:,5])
29 changes: 15 additions & 14 deletions python/mcelib/test/test_data.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
from __future__ import print_function
import _test

from pymce import MCE

mce = MCE()
print 'Basic read'
print('Basic read')
data = mce.read_raw(10)
print ' ARZ: ', data[:,5]
print
print(' ARZ: ', data[:,5])
print()

print 'Frame data object'
print('Frame data object')
data = mce.read_data(10)
print data.data.shape
print
print(data.data.shape)
print()

print 'Rectangle extract'
print('Rectangle extract')
data = mce.read_data(10, extract=True)
print data.data.shape
print
print(data.data.shape)
print()

print 'Row-col form'
print('Row-col form')
data = mce.read_data(10, row_col=True)
print data.data.shape
print
print(data.data.shape)
print()

print 'Invalid read?'
print('Invalid read?')
data = mce.read_data(10, cards=[1,3])
print ' We got None: ', data==None
print(' We got None: ', data==None)
34 changes: 19 additions & 15 deletions python/mcelib/test/test_lib.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
"""
Low-level library connection demonstration.
"""
from __future__ import division
from __future__ import print_function

from builtins import range
from past.utils import old_div
import _test

from pymce import mcelib

print 'Connecting...'
print('Connecting...')
m = mcelib.connect()
print ' ', m
print
print 'write...'
print(' ', m)
print()
print('write...')
mcelib.write(m, "cc", "led", 0, [7])
print
print()

print 'read...'
print ' %x' % mcelib.read(m, "cc", "fw_rev", 0, -1)[0]
print
print('read...')
print(' %x' % mcelib.read(m, "cc", "fw_rev", 0, -1)[0])
print()

print 'write invalid command'
print ' should return False; returns: ', mcelib.write(m, 'cc', 'ledx', 0, [7])
print
print('write invalid command')
print(' should return False; returns: ', mcelib.write(m, 'cc', 'ledx', 0, [7]))
print()

print 'data...'
print('data...')
import numpy
z = numpy.zeros(10000, 'int32')
mcelib.read_data(m, 1, 1, z)
print ' %x' % z[0]
print(' %x' % z[0])

print 'command timing'
print('command timing')
N = 10000
t = _test.timer()
for i in range(N):
mcelib.write(m, 'cc', 'led', 0, [7])
print ' write rate: ', (N/t.get())
print(' write rate: ', (old_div(N,t.get())))

10 changes: 7 additions & 3 deletions python/noise_setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from __future__ import division
from __future__ import print_function
from builtins import range
from past.utils import old_div
import mce

from numpy import *
Expand Down Expand Up @@ -112,7 +116,7 @@ def freeze_servo(self, row=0, n_frames=10, degain=False):
# Mod out the flux quantum
q = self.flux_quanta[row]
if degain:
data += q/2
data += old_div(q,2)
data = (data % q + q) % q
# Prepare adc_offset
new_adc = zeros(self.adc_offsets.shape)
Expand All @@ -138,7 +142,7 @@ def one_row(self):
o.add_option('--no-status', action='store_true')
opts, args = o.parse_args()
m = xmce(load_status=not opts.no_status)
print 'm is your object.'
print('m is your object.')
if opts.no_status:
print 'run m._load_status() before using.'
print('run m._load_status() before using.')

20 changes: 13 additions & 7 deletions python/servo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from __future__ import division
from __future__ import print_function
from builtins import zip
from builtins import range
from past.utils import old_div
from builtins import object
from mce import *

class Ramp:
class Ramp(object):
def __init__(self, this_mce, card, param, param_offset=0, param_count=8,
start = 0, count = 1, step = 0. ):
self.card = card
Expand Down Expand Up @@ -29,7 +35,7 @@ def WriteNext(self):
self.i = self.i + 1
return True

class MCEStage:
class MCEStage(object):
SQ1_fb = 1
SQ2_fb = 2
SA_fb = 3
Expand All @@ -48,7 +54,7 @@ def __str__(self):



class ColumnServo:
class ColumnServo(object):
"""
Class for servoing MCE parameters on a per-column basis. Class
handles frame acquisition and manipulation of SA, SQ2, or SQ1
Expand Down Expand Up @@ -81,7 +87,7 @@ def __init__(self, this_mce, stage, gain=0.1, gain_set=None, columns=None,
raise ServoException('len(gain_list) != n_columns')

# Get rcs based on columns
rcs = [ i for i in range(4) if [ c/8 for c in self.columns ].count(i) > 0 ]
rcs = [ i for i in range(4) if [ old_div(c,8) for c in self.columns ].count(i) > 0 ]
if len(rcs) > 1:
self.channel_set = ChannelSet('rcs')
else:
Expand Down Expand Up @@ -116,7 +122,7 @@ def Servo(self):
return self.ServoStep()

while self.ServoStep(update_ramp=True):
print self.ramp.i
print(self.ramp.i)

def ServoStep(self, update_ramp=True, write_values=True, read_data=True):
done = True
Expand All @@ -132,7 +138,7 @@ def ServoStep(self, update_ramp=True, write_values=True, read_data=True):
for (c,d) in zip(self.columns, d):
self.values[c] += int(self.gain*d)

print self.values
print(self.values)
if write_values:
self.mce.write(self.card, self.param, self.values)

Expand All @@ -142,7 +148,7 @@ def ServoStep(self, update_ramp=True, write_values=True, read_data=True):
m = mce()
r = Ramp(m, 'sq2', 'fb', param_offset=8, param_count=8,
start = 0, count = 400, step = 160)
s = ColumnServo(m, MCEStage.SA_fb, columns = range(8,16),
s = ColumnServo(m, MCEStage.SA_fb, columns = list(range(8,16)),
ramp = r)

s.Start()
Expand Down
6 changes: 4 additions & 2 deletions swig/chan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# Some code based on embedding_in_ex.py by Jeremy O'Donoghue

from __future__ import print_function
from builtins import str
import wx
import mce
from mceViewport import *
Expand Down Expand Up @@ -73,7 +75,7 @@ def Go(self, even):
p = ca.acq(col, row, n_frames)

trim = int(self.trim.GetValue())
print "Trim is %i" % trim
print("Trim is %i" % trim)
if trim > 0:
p.x_limits = (0, trim)
else:
Expand All @@ -83,7 +85,7 @@ def Go(self, even):
self.viewport.Update(p)

def Destroy(self, force=False):
print 'Caught!'
print('Caught!')
self.fig.Close(force)
wx.Frame.Destroy(self, force)

Expand Down
Loading