Skip to content

Commit

Permalink
Changes to style of .csv files.
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Nicholls committed May 7, 2019
1 parent 37c0fbe commit c458bb8
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 48 deletions.
31 changes: 14 additions & 17 deletions ioc/atip_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def __init__(self, ring_mode, limits_csv=None, feedback_csv=None,
if mirror_csv is not None:
self._create_mirror_records(mirror_csv)
print("Finished creating all {0} records."
.format(len(self._all_record_names) +
.format(len(self.all_record_names) +
len(self._mirrored_records)))

@property
def _all_record_names(self):
def all_record_names(self):
return {record.name: record for record in self._in_records.keys() +
self._out_records.keys() + self._feedback_records.values()}

Expand Down Expand Up @@ -208,7 +208,7 @@ def _on_update(self, name, value):
name (str): The name of record object that has just been set to.
value (number): The value that has just been set to the record.
"""
in_record = self._out_records[self._all_record_names[name]]
in_record = self._out_records[self.all_record_names[name]]
in_record.set(value)
index, field = self._in_records[in_record]

Expand All @@ -219,7 +219,7 @@ def _on_update(self, name, value):
pass
else:
offset = caget(offset_pv)
value = value + offset
value += offset
self.lattice[index - 1].set_value(field, value, units=pytac.ENG,
data_source=pytac.SIM)

Expand Down Expand Up @@ -268,36 +268,33 @@ def _create_mirror_records(self, mirror_csv):
'summate']):
raise IndexError("collation and summation mirror types take at"
" least two input PVs.")
if line['monitor'] == '':
monitor = input_pvs
else:
monitor = line['monitor'].split(', ')
monitor = input_pvs # need to update to support camonitor multiple
# Convert input pvs to record objects
input_records = []
for pv in input_pvs:
try:
input_records.append(self._all_record_names[pv])
input_records.append(self.all_record_names[pv])
except KeyError:
input_records.append(caget_mask(pv))
# Create output record.
prefix, suffix = line['out'].split(':', 1)
builder.SetDeviceName(prefix)
if line['record type'] == 'caput':
if line['output type'] == 'caput':
output_record = caput_mask(line['out'])
elif line['record type'] == 'aIn':
elif line['output type'] == 'aIn':
value = float(line['value'])
output_record = builder.aIn(suffix, initial_value=value)
elif line['record type'] == 'longIn':
elif line['output type'] == 'longIn':
value = int(line['value'])
output_record = builder.longIn(suffix, initial_value=value)
elif line['record type'] == 'Waveform':
elif line['output type'] == 'Waveform':
value = numpy.asarray(line['value'][1:-1].split(', '),
dtype=float)
output_record = builder.Waveform(suffix, initial_value=value)
else:
raise TypeError("{0} isn't a supported mirroring output type;"
"please enter 'caput', 'aIn', 'longIn', or "
"'Waveform'.".format(line['record type']))
"'Waveform'.".format(line['output type']))
# Update the mirror dictionary.
for pv in monitor:
if pv not in self._mirrored_records:
Expand Down Expand Up @@ -332,7 +329,7 @@ def monitor_mirrored_pvs(self):

def refresh_record(self, pv_name):
try:
record = self._all_record_names[pv_name]
record = self.all_record_names[pv_name]
except KeyError:
raise ValueError("{0} is not the name of a record created by this "
"server.".format(pv_name))
Expand All @@ -351,8 +348,8 @@ def start_tune_feedback(self, tune_csv=None):
self.monitor_mirrored_pvs()
self.tune_feedback_status = True
for line in csv_reader:
quad_pv = line['quad_set_pv']
offset_pv = line['offset_pv']
quad_pv = line['quad set pv']
offset_pv = line['offset pv']
self._offset_pvs[quad_pv] = offset_pv
mask = callback_refresh(self, quad_pv)
try:
Expand Down
40 changes: 20 additions & 20 deletions ioc/create_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,43 +107,43 @@ def generate_mirrored_pvs():
the only transformation type currently supported is 'inverse'.
"""
lattice = atip.utils.loader()
data = [("monitor", "in", "out", "value", "record type", "mirror type")]
data = [("output type", "mirror type", "in", "out", "value")]
# Tune PV aliases.
tune = [lattice.get_value('tune_x', pytac.RB, data_source=pytac.SIM),
lattice.get_value('tune_y', pytac.RB, data_source=pytac.SIM)]
data.append(('', 'SR23C-DI-TMBF-01:X:TUNE:TUNE',
'SR23C-DI-TMBF-01:TUNE:TUNE', tune[0], 'aIn', 'basic'))
data.append(('', 'SR23C-DI-TMBF-01:Y:TUNE:TUNE',
'SR23C-DI-TMBF-02:TUNE:TUNE', tune[1], 'aIn', 'basic'))
data.append(('aIn', 'basic', 'SR23C-DI-TMBF-01:X:TUNE:TUNE',
'SR23C-DI-TMBF-01:TUNE:TUNE', tune[0]))
data.append(('aIn', 'basic', 'SR23C-DI-TMBF-01:Y:TUNE:TUNE',
'SR23C-DI-TMBF-02:TUNE:TUNE', tune[1]))
# Combined emittance and average emittance PVs.
emit = [lattice.get_value('emittance_x', pytac.RB, data_source=pytac.SIM),
lattice.get_value('emittance_y', pytac.RB, data_source=pytac.SIM)]
data.append(('', 'SR-DI-EMIT-01:HEMIT', 'SR-DI-EMIT-01:HEMIT_MEAN',
emit[0], 'aIn', 'basic'))
data.append(('', 'SR-DI-EMIT-01:VEMIT', 'SR-DI-EMIT-01:VEMIT_MEAN',
emit[1], 'aIn', 'basic'))
data.append(('', 'SR-DI-EMIT-01:HEMIT, SR-DI-EMIT-01:VEMIT',
'SR-DI-EMIT-01:EMITTANCE', sum(emit), 'aIn', 'summate'))
data.append(('aIn', 'basic', 'SR-DI-EMIT-01:HEMIT',
'SR-DI-EMIT-01:HEMIT_MEAN', emit[0]))
data.append(('aIn', 'basic', 'SR-DI-EMIT-01:VEMIT',
'SR-DI-EMIT-01:VEMIT_MEAN', emit[1]))
data.append(('aIn', 'summate','SR-DI-EMIT-01:HEMIT, SR-DI-EMIT-01:VEMIT',
'SR-DI-EMIT-01:EMITTANCE', sum(emit)))
# Electron BPMs enabled.
bpm_enabled_pvs = lattice.get_element_pv_names('BPM', 'enabled', pytac.RB)
data.append(('', ', '.join(bpm_enabled_pvs), 'EBPM-ENABLED:INTERIM',
[0] * len(bpm_enabled_pvs), 'Waveform', 'collate'))
data.append(('', 'EBPM-ENABLED:INTERIM', 'SR-DI-EBPM-01:ENABLED',
[0] * len(bpm_enabled_pvs), 'Waveform', 'inverse'))
data.append(('Waveform', 'collate', ', '.join(bpm_enabled_pvs),
'EBPM-ENABLED:INTERIM', [0] * len(bpm_enabled_pvs)))
data.append(('Waveform', 'inverse', 'EBPM-ENABLED:INTERIM',
'SR-DI-EBPM-01:ENABLED', [0] * len(bpm_enabled_pvs)))
# BPM x positions for display on diagnostics screen.
bpm_x_pvs = lattice.get_element_pv_names('BPM', 'x', pytac.RB)
data.append(('', ', '.join(bpm_x_pvs), 'SR-DI-EBPM-01:SA:X',
[0] * len(bpm_x_pvs), 'Waveform', 'collate'))
data.append(('Waveform', 'collate', ', '.join(bpm_x_pvs),
'SR-DI-EBPM-01:SA:X', [0] * len(bpm_x_pvs)))
# BPM y positions for display on diagnostics screen.
bpm_y_pvs = lattice.get_element_pv_names('BPM', 'y', pytac.RB)
data.append(('', ', '.join(bpm_y_pvs), 'SR-DI-EBPM-01:SA:Y',
[0] * len(bpm_y_pvs), 'Waveform', 'collate'))
data.append(('Waveform', 'collate', ', '.join(bpm_y_pvs),
'SR-DI-EBPM-01:SA:Y', [0] * len(bpm_y_pvs)))
return data


def generate_tune_pvs():
lattice = atip.utils.loader()
data = [('quad_set_pv', 'offset_pv')]
data = [('quad set pv', 'offset pv')]
# Offset PV for quadrupoles in tune feedback.
tune_pvs = []
offset_pvs = []
Expand Down

0 comments on commit c458bb8

Please sign in to comment.