def extract(infile, col_1, col_2, col_3=0): get = GetData(infile) data = get.data_column() turn = data[col_1] value = data[col_2] if col_3 == 0: return turn, value else: value_2 = data[col_3] return turn, value, value_2
def get_turns(infile): get = GetData(infile) data = get.data_column() x = np.asarray(data[0], dtype='float64') y = np.asarray(data[2], dtype='float64') if 'b1' in infile: name = txt.replace('b1.txt', '').upper() elif 'b2' in infile: name = txt.replace('b2.txt', '').upper() elif infile == 'data_turn.txt': name = 'Collimation system' return x, y, name
def get_data(infile): get = GetData(infile) data = get.data_column() x = np.asarray(data[0]) xp = data[1] y = data[2] yp = data[3] sigma_x = np.std(x) sigma_y = np.std(y) mu, std = norm.fit(x) return sigma_x, sigma_y, mu, std, x, y
def get_ap(infile): if os.stat(infile).st_size == 0: print '>> ' + infile + ' file is empty' return 0 else: get = GetData(infile) data = get.data_column(dtype='string') name = data[0] s = np.asarray(data[1], dtype='float64') l = np.asarray(data[2], dtype='float64') aper1 = np.asarray(data[3], dtype='float64') aper2 = np.asarray(data[4], dtype='float64') aper3 = np.asarray(data[5], dtype='float64') aper4 = np.asarray(data[6], dtype='float64') apertype = np.asarray(data[7]) return name, s, l, aper1, aper2, aper3, aper4, apertype
def get_twiss(infile): if os.stat(infile).st_size == 0: print '>> ' + infile + ' file is empty' return 0 else: get = GetData(infile) data = get.data_column(dtype='string') name = data[1] s = np.asarray(data[2]) l = np.asarray(data[3]) x = np.asarray(data[4]) y = np.asarray(data[5]) betx = np.asarray(data[6]) bety = np.asarray(data[7]) alfx = np.asarray(data[8]) alfy = np.asarray(data[9]) dx = np.asarray(data[12]) dy = np.asarray(data[13]) px = np.asarray(data[16]) py = np.asarray(data[17]) return name, s, l, x, y, betx, bety, alfx, alfy, dx, dy, px, py
from util import GetData get = GetData('data.txt') # Turn 6, 8, 15 def get_tau(tau): data = get.data_column(column=0, regex=tau) return data[0], data[1], data[2], data[8] tau_1, phase_1, turn_1, sigy_1 = get_tau(r'1') tau_2, phase_2, turn_2, sigy_2 = get_tau(r'2') tau_3, phase_3, turn_3, sigy_3 = get_tau(r'3') tau_4, phase_4, turn_4, sigy_4 = get_tau(r'4') max_1 = '217' max_2 = '359' max_3 = '359' max_4 = '359' for tau, phase, turn, sigy in zip(tau_1, phase_1, turn_1, sigy_1): if int(turn) == 1: offset = sigy if phase == max_1 and turn == '6': print float(sigy) - float(offset), tau, phase if phase == max_1 and turn == '8': print float(sigy) - float(offset), tau, phase if phase == max_1 and turn == '10': print float(sigy) - float(offset), tau, phase
import numpy as np import matplotlib from matplotlib import pyplot as plt from matplotlib import rc from matplotlib import rcParams from util import GetData # ------------------------------------------------------------------------------ # Constant voltage data loading # ------------------------------------------------------------------------------ infile = sys.argv[1] # title = sys.argv[2] get = GetData(infile) data = get.data_column() turns = np.asarray(data[0], dtype='float64') dx = np.asarray(data[1], dtype='float64') dy = np.asarray(data[2], dtype='float64') cx = np.asarray(data[3], dtype='float64') cy = np.asarray(data[4], dtype='float64') # ------------------------------------------------------------------------------ # PLOTTING # ------------------------------------------------------------------------------ DPI = 500 textwidth = 3.25 font_spec = { "font.family": "serif", # use as default font
#!/usr/bin/env python import sys from util import GetData infile = sys.argv[1] data = GetData(infile).data_column(dtype='string') name = data['NAME'] mux = data['MUX'] muy = data['MUY'] betx = data['BETX'] bety = data['BETY'] alfx = data['ALFX'] alfy = data['ALFY'] s = data['S'] outfile = 'crab_installation.txt' with open(outfile, 'w') as f: for n, ss, mx, my, bx, by, ax, ay in zip(name, s, mux, muy, betx, bety, alfx, alfy): if n.startswith('ACF'): print >> f, n, ss, mx, my, bx, by, ax, ay
#!/usr/bin/env python import sys import numpy as np from matplotlib import pyplot as plt from matplotlib import rc from matplotlib import rcParams from util import GetData infile_before = 'before.txt' get_before = GetData(infile_before) my_data_before = get_before.data_column(column=1, regex=r'2\b') yp_before = my_data_before[6] z_before = my_data_before[7] delta_before = my_data_before[8] infile_after = 'after.txt' get_after = GetData(infile_after) my_data_after = get_after.data_column(column=1, regex=r'2\b') yp_after = my_data_after[6] z_after = my_data_after[7] delta_after = my_data_after[8] y = [] x = [] for a, b, c, d, e, f in zip(yp_before, delta_before, z_before, yp_after, delta_after, z_after): term_1 = d / (1 + e) term_2 = a / (1 + b) y.append((term_1 - term_2) * 7 * 1e12)
def get_dist(data_file, dir_core, dir_tail, core_weight, tail_weight): if data_file == 'loss_maps.txt': col_1 = 1 col_2 = 3 elif data_file == 'aperture.txt': col_1 = 0 col_2 = 2 x = [] y = [] if os.path.isfile(dir_core + '/' + data_file) and os.path.isfile(dir_tail + '/' + data_file): print ' ' print '>> File ' + data_file + ' present for core and tail' get_core = GetData(dir_core + '/' + data_file) data_core = get_core.data_column(dtype='string') xc_coll = data_core[col_1] yc_coll = data_core[col_2] get_tail = GetData(dir_tail + '/' + data_file) data_tail = get_tail.data_column(dtype='string') xt_coll = data_tail[col_1] yt_coll = data_tail[col_2] for i, k in zip(xc_coll, yc_coll): for j, l in zip(xt_coll, yt_coll): if i == j: x.append(float(i)) y.append(core_weight * float(k) + tail_weight * float(l)) xc_coll.remove(i) yc_coll.remove(k) xt_coll.remove(j) yt_coll.remove(l) for i, k in zip(xc_coll, yc_coll): x.append(float(i)) y.append(core_weight * float(k)) for j, l in zip(xt_coll, yt_coll): x.append(float(j)) y.append(tail_weight * float(l)) elif os.path.isfile(dir_core + '/' + data_file) == False: print ' ' print '>> File ' + data_file + ' present only for tail' get_tail = GetData(dir_tail + '/' + data_file) data_tail = get_tail.data_column(dtype='string') xt_coll = data_tail[col_1] yt_coll = data_tail[col_2] for j, l in zip(xt_coll, yt_coll): x.append(float(j)) y.append(tail_weight * float(l)) elif os.path.isfile(dir_tail + '/' + data_file) == False: print ' ' print '>> File ' + data_file + ' present only for core' get_core = GetData(dir_core + '/' + data_file) data_core = get_core.data_column(dtype='string') xc_coll = data_core[col_1] yc_coll = data_core[col_2] for j, l in zip(xc_coll, yc_coll): x.append(float(j)) y.append(core_weight * float(l)) return x, y
plot_ip_labels(b2, height, text_size) else: print '>> Please input B1 or B2 as first argument' plt.subplots_adjust(left=0.16, bottom=0.19, right=0.94, top=0.88) plt.savefig('loss_map.png', dpi=1000) plt.savefig('loss_map.eps', format='eps', dpi=1000) plt.clf() elif len(sys.argv) == 2: files = glob.glob('*.txt') for txt in files: if txt == 'loss_maps.txt': print ' ' print '>> File ' + txt + ' present' get = GetData(txt) data = get.data_column(dtype='string') x_coll = np.asarray(data[1], dtype='float64') y_coll = np.asarray(data[3], dtype='float64') elif txt == 'aperture.txt': print ' ' print '>> File ' + txt + ' present' get = GetData(txt) data = get.data_column(dtype='string') x_ap = np.asarray(data[0], dtype='float64') y_ap = np.asarray(data[2], dtype='float64') # ------------------------------------------------------------------------------ # Plotting lossmaps # ------------------------------------------------------------------------------ if os.path.exists('loss_maps.txt') == False and os.path.exists( 'aperture.txt') == False: