##// END OF EJS Templates
Update & fix jars_server.py
Update & fix jars_server.py

File last commit:

r265:33a1411c93df
r312:b2b8d81ad03b
Show More
utils.py
244 lines | 9.6 KiB | text/x-python | PythonLexer
Fiorella Quino
RC utils file has been updated...
r265 '''
'''
Juan C. Espinoza
Update RC models, views, templates & statics...
r45
Juan C. Espinoza
- Update rc app...
r79 import json
Juan C. Espinoza
Update RC models, views, templates & statics...
r45
Fiorella Quino
RC utils file has been updated...
r265 from apps.main.utils import Params
Juan C. Espinoza
Fix importing racp, fix sub-baudio windows reference ...
r237
def parse_range(s):
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Fix importing racp, fix sub-baudio windows reference ...
r237 vars = ('TXA,', 'A,', 'TXB,', 'B,', 'TXA', 'TXB', 'A', 'B')
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Fix importing racp, fix sub-baudio windows reference ...
r237 for var in vars:
if var in s:
s = s.replace(var, '')
if 'A' in var:
ref = 'TXA'
else:
ref = 'TXB'
return ref, s
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Fix importing racp, fix sub-baudio windows reference ...
r237 return '0', s
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Fix importing racp, fix sub-baudio windows reference ...
r237
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 class RCFile(object):
Juan C. Espinoza
- Update rc app...
r79 '''
Class to handle Radar controller configuration files
'''
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 def __init__(self, f=None):
Fiorella Quino
RC utils file has been updated...
r265 print dir(f)
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 self.data = {}
Fiorella Quino
RC utils file has been updated...
r265 self.lines = []
Juan C. Espinoza
Fix importing racp, fix sub-baudio windows reference ...
r237 self.line = ''
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if isinstance(f, str):
self.f = open(f)
self.name = f.split('/')[-1]
elif hasattr(f, 'read'):
self.f = f
self.name = f.name.split('/')[-1]
else:
self.f = f
self.name = None
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if self.f:
if 'racp' in self.name:
self.parse_racp()
elif 'dat' in self.name:
self.parse_dat()
Juan C. Espinoza
- Update rc app...
r79 elif 'json' in self.name:
self.data = json.load(self.f)
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
- Update rc app...
r79 self.f.close()
Juan C. Espinoza
Update RC models, views, templates & statics...
r45
def get_line_parameters(self, data, line):
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 line_params = {}
for label in data:
if 'L%d' % line in label or '(Line %d)' % line in label or 'Line%d' % line in label:
line_params[label] = data[label]
return line_params
def parse_racp(self):
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 data = {}
raw_data = [s.strip() for s in self.f.readlines()]
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 for line in raw_data:
if line and '=' in line:
label, value = line.strip().split('=')
data[label] = value
Fiorella Quino
RC utils file has been updated...
r265
self.data['id'] = '1'
self.data['device_type'] = 'rc'
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 self.data['experiment_type'] = data['EXPERIMENT TYPE']
self.data['header_version'] = data['HEADER VERSION']
self.data['name'] = data['EXPERIMENT NAME']
self.data['ipp'] = float(data['IPP'])
self.data['ntx'] = int(data['NTX'])
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if 'CLOCK DIVIDER' in data:
self.data['clock_divider'] = int(data['CLOCK DIVIDER'])
else:
self.data['clock_divider'] = 1
Juan C. Espinoza
- Update rc app...
r79 self.data['clock_in'] = float(data['RELOJ'])*self.data['clock_divider']
self.data['clock'] = float(data['RELOJ'])
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 self.data['time_before'] = int(data['TR_BEFORE'])
self.data['time_after'] = int(data['TR_AFTER'])
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if 'SYNCHRO DELAY' in data:
self.data['sync'] = int(data['SYNCHRO DELAY'])
else:
self.data['sync'] = 0
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 self.data['lines'] = []
Juan C. Espinoza
- Update rc app...
r79
if 'SAMPLING REFERENCE' in data:
if data['SAMPLING REFERENCE']=='MIDDLE OF FIRST BAUD':
self.data['sampling_reference'] = 'first_baud'
elif data['SAMPLING REFERENCE']=='MIDDLE OF FIRST SUB-BAUD':
self.data['sampling_reference'] = 'sub_baud'
else:
Fiorella Quino
RC utils file has been updated...
r265 self.data['sampling_reference'] = 'none'
self.data['lines'].append('10')
Juan C. Espinoza
- Update rc app...
r79
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 #Add TX's lines
if 'TXA' in data:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'tx', 'id':'11', 'name':'TXA',
'params':{'pulse_width':data['TXA'], 'delays':'0', 'range':'0'}}
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if 'Pulse selection_TXA' in data:
Fiorella Quino
RC utils file has been updated...
r265 line['params']['range'] = data['Pulse selection_TXA']
self.data['lines'].append('11')
self.lines.append(line)
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if 'TXB' in data:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'tx', 'id':'12', 'name':'TXB',
'params':{'pulse_width':data['TXB'], 'delays':'0', 'range':'0'}}
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if 'Pulse selection_TXB' in data:
Fiorella Quino
RC utils file has been updated...
r265 line['params']['range'] = data['Pulse selection_TXB']
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if 'Number of Taus' in data:
delays = [data['TAU({0})'.format(i)] for i in range(int(data['Number of Taus']))]
Fiorella Quino
RC utils file has been updated...
r265 line['params']['delays'] = ','.join(delays)
self.data['lines'].append('12')
self.lines.append(line)
#Add TR line
line = {'line_type':'tr', 'id':'10', 'name':'TR',
'params':{'TX_ref':'0', 'range':'0'}}
if 'Pulse selection_TR' in data:
ref, rng = parse_range(data['Pulse selection_TR'])
line['params']['range'] = rng if rng else '0'
if ref=='TXA':
line['params']['TX_ref'] = '11'
elif ref=='TXB':
line['params']['TX_ref'] = '12'
self.lines.append(line)
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 #Add Other lines (4-6)
for n in range(4, 7):
Fiorella Quino
RC utils file has been updated...
r265 id = '{:2d}'.format(10*n)
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 params = self.get_line_parameters(data, n)
labels = params.keys()
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if 'L%d_FLIP' % n in labels:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'flip', 'id':id,
'params':{'number_of_flips':data['L%d_FLIP' % n]}}
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 elif 'Code Type' in data and n==4:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'codes', 'id':id, 'params':{'code':data['Code Type']}}
if data['L%d_REFERENCE' % n]=='TXA':
line['params']['TX_ref'] = '11'
else:
line['params']['TX_ref'] = '12'
Juan C. Espinoza
- Update rc app...
r79 if 'Number of Codes' in data:
Fiorella Quino
RC utils file has been updated...
r265 line['params']['codes'] = [data['COD({})'.format(x)] for x in range(int(data['Number of Codes']))]
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 elif 'Code Type (Line %d)' % n in labels:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'codes', 'id':id, 'params':{'code':data['Code Type (Line %d)' % n]}}
if data['L%d_REFERENCE' % n]=='TXA':
line['params']['TX_ref'] = '11'
else:
line['params']['TX_ref'] = '12'
Juan C. Espinoza
- Update rc app...
r79 if 'Number of Codes (Line %d)' % n in data:
Fiorella Quino
RC utils file has been updated...
r265 line['params']['codes'] = [data['L{}_COD({})'.format(n, x)] for x in range(int(data['Number of Codes (Line %d)' % n]))]
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 elif 'Sampling Windows (Line %d)' % n in data:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'windows', 'id':id, 'params':{}}
if data['L%d_REFERENCE' % n]=='TXA':
line['params']['TX_ref'] = '11'
else:
line['params']['TX_ref'] = '12'
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 windows = []
for w in range(int(data['Sampling Windows (Line %d)' % n])):
windows.append({'first_height':float(data['L%d_H0(%d)' % (n, w)]),
Juan C. Espinoza
sync repo...
r157 'resolution':float(data['L%d_DH(%d)' % (n, w)]),
Fiorella Quino
RC utils file has been updated...
r265 'number_of_samples':int(float(data['L%d_NSA(%d)' % (n, w)])),
'last_height':float(data['L%d_DH(%d)' % (n, w)])*(int(float(data['L%d_NSA(%d)' % (n, w)]))-1)+float(data['L%d_H0(%d)' % (n, w)])
Juan C. Espinoza
sync repo...
r157 }
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 )
Fiorella Quino
RC utils file has been updated...
r265 line['params']['params'] = windows
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 elif 'Line%d' % n in labels and data['Line%d' % n]=='Synchro':
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'sync', 'id':id, 'params':{'invert':0}}
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 elif 'L%d Number Of Portions' % n in labels:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'prog_pulses', 'id':id, 'params':{}}
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 if 'L%s Portions IPP Periodic' % n in data:
Fiorella Quino
RC utils file has been updated...
r265 line['params']['periodic'] = '1' if data['L%s Portions IPP Periodic' % n]=='YES' else '0'
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 portions = []
x = raw_data.index('L%d Number Of Portions=%s' % (n, data['L%d Number Of Portions' % n]))
for w in range(int(data['L%d Number Of Portions' % n])):
Fiorella Quino
RC utils file has been updated...
r265 begin = float(raw_data[x+1+2*w].split('=')[-1])
end = float(raw_data[x+2+2*w].split('=')[-1])
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 portions.append({'begin':int(begin),
'end':int(end)}
)
Fiorella Quino
RC utils file has been updated...
r265 line['params']['params'] = portions
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 elif 'FLIP1' in data and n==5:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'flip', 'id':id, 'params':{'number_of_flips':data['FLIP1']}}
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 elif 'FLIP2' in data and n==6:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'flip', 'id':id, 'params':{'number_of_flips':data['FLIP2']}}
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 else:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'none', 'id':id, 'params':{}}
self.data['lines'].append(id)
self.lines.append(line)
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 #Add line 7 (windows)
if 'Sampling Windows' in data:
Fiorella Quino
RC utils file has been updated...
r265 line = {'line_type':'windows', 'id':'17', 'params':{}}
if data['L7_REFERENCE']=='TXA':
line['params']['TX_ref'] = '11'
else:
line['params']['TX_ref'] = '12'
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 windows = []
x = raw_data.index('Sampling Windows=%s' % data['Sampling Windows'])
for w in range(int(data['Sampling Windows'])):
h0 = raw_data[x+1+3*w].split('=')[-1]
nsa = raw_data[x+2+3*w].split('=')[-1]
dh = raw_data[x+3+3*w].split('=')[-1]
windows.append({'first_height':float(h0),
'number_of_samples':int(nsa),
Juan C. Espinoza
sync repo...
r157 'resolution':float(dh),
'last_height':float(h0)+float(dh)*(int(nsa)-1)}
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 )
Fiorella Quino
RC utils file has been updated...
r265 line['params']['params'] = windows
self.data['lines'].append('17')
self.lines.append(line)
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 #Add line 8 (synchro inverted)
Fiorella Quino
RC utils file has been updated...
r265 self.data['lines'].append('18')
self.lines.append({'line_type':'sync', 'id':'18', 'params':{'invert':1}})
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 return
Fiorella Quino
RC utils file has been updated...
r265
Juan C. Espinoza
Update RC models, views, templates & statics...
r45 def parse_dat(self):
pass
Fiorella Quino
RC utils file has been updated...
r265 def to_dict(self):
Juan C. Espinoza
Update RC models, views, templates & statics...
r45
Fiorella Quino
RC utils file has been updated...
r265 out = Params()
out.add(self.data, 'configurations')
for line_data in self.lines:
out.add(line_data, 'lines')
Juan C. Espinoza
Update RC models, views, templates & statics...
r45
Fiorella Quino
RC utils file has been updated...
r265 return out.data