from data_folders import data_folder_list

import pickle
import numpy as np

csv_folder = 'fill_heatload_data_csvs'
if not os.path.isdir(csv_folder):
    os.mkdir(csv_folder)

if len(sys.argv) > 1:
    filln = int(sys.argv[1])

dict_fill_bmodes = {}
for df in data_folder_list:
    with open(df + '/fills_and_bmodes.pkl', 'rb') as fid:
        this_dict_fill_bmodes = pickle.load(fid)
        for kk in this_dict_fill_bmodes:
            this_dict_fill_bmodes[kk]['data_folder'] = df
        dict_fill_bmodes.update(this_dict_fill_bmodes)

t_start_fill = dict_fill_bmodes[filln]['t_startfill']
t_end_fill = dict_fill_bmodes[filln]['t_endfill']

sector_list = HL.sector_list()
variable_list = HL.sector_all_variables(sector_list)
#variable_list=['CMS:LUMI_TOT_INST','S12_QBS_AVG_ARC.POSST']

fill_file = csv_folder + '/hl_all_cells_fill_%d.csv' % filln

lldb.dbquery(variable_list, t_start_fill, t_end_fill, fill_file)
Example #2
0
    snapshots[i_snapshot]['n_bunches_b2'] = n_bunches_b2
    snapshots[i_snapshot]['energy_GeV'] = energy_GeV
    snapshots[i_snapshot]['dict_hl_cell_by_cell'] = dict_hl_cell_by_cell
    snapshots[i_snapshot]['hl_imped_sample'] = hl_imped_sample
    snapshots[i_snapshot]['hl_sr_sample'] = hl_sr_sample
    snapshots[i_snapshot]['tref_string_short'] = tref_string_short

    if t_offset_h is None:
        snapshots[i_snapshot]['t_offs_h_str'] = '-'
    else:
        snapshots[i_snapshot][
            't_offs_h_str'] = '%.2f' % snapshots[i_snapshot]['t_offs_h']

# check consistency in cell naming
for i_snapshot in range(N_snapshots):
    for s in hl.sector_list():
        if len(snapshots[i_snapshot]['dict_hl_cell_by_cell'][s]['cell_names']
               ) != len(snapshots[0]['dict_hl_cell_by_cell'][s]['cell_names']):
            raise ValueError('Found inconsistency type 1 in dict!')
        for c1, c2 in zip(
                snapshots[i_snapshot]['dict_hl_cell_by_cell'][s]['cell_names'],
                snapshots[0]['dict_hl_cell_by_cell'][s]['cell_names']):
            if c1 != c2:
                raise ValueError('Found inconsistency type 2 in dict!')

# Plots!
plt.close('all')
myfontsz = 13
ms.mystyle_arial(fontsz=13, dist_tick_lab=3)
if N_snapshots == 1:
    width = 0.6
Example #3
0
    (5386, '25 ns, 48b/tr'),
    (5393, '25 ns, 48b/tr'),
    (5219, '25 ns, 72b/tr'),
    # (4565, '25 ns - 36b/train')
]

list_n_bunches = []
list_bunch_intensity_avg = []
list_bunch_length_avg = []
list_filln = []
list_tags = []
list_imped = []
list_sr = []

dict_hl = {}
for sector in HL.sector_list():
    dict_hl[sector] = []

for filln, tag in fills_to_analyze:
    i_fill = np.argmin(np.abs(filln - main_dict['filln']))

    n_bunches = main_dict[moment]['n_bunches']['b1'][i_fill]
    total_intensity_2beams = main_dict[moment]['intensity']['b1'][
        i_fill] + main_dict[moment]['intensity']['b2'][i_fill]
    bunch_intensity_avg = total_intensity_2beams / 2 / n_bunches
    bunch_length_avg = 0.5 * (
        main_dict[moment]['blength']['b1']['avg'][i_fill] +
        main_dict[moment]['blength']['b2']['avg'][i_fill])

    list_n_bunches.append(n_bunches)
    list_bunch_intensity_avg.append(bunch_intensity_avg)
        dict_fill_bmodes.update(this_dict_fill_bmodes)

# get location of current data
data_folder_fill = dict_fill_bmodes[filln]['data_folder']

t_fill_st = dict_fill_bmodes[filln]['t_startfill']
t_fill_end = dict_fill_bmodes[filln]['t_endfill']
t_ref = t_fill_st
tref_string = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(t_ref))

plt.close('all')
ms.mystyle_arial(fontsz=12, dist_tick_lab=3)
width = 0.6
show_labels = True

sectors = hl.sector_list()


def swap_even_odd(vect):
    temp_list = []
    for ii in range(len(vect) // 2):
        temp_list.append(vect[2 * ii + 1])
        temp_list.append(vect[2 * ii])
    return np.array(temp_list)


for i, s in enumerate(sectors):

    sect_str = str(s)
    R_part = 'R' + sect_str[0]
    L_part = 'L' + sect_str[1]
    snapshots[i_snapshot]['n_bunches_b1'] = n_bunches_b1
    snapshots[i_snapshot]['n_bunches_b2'] = n_bunches_b2
    snapshots[i_snapshot]['energy_GeV'] = energy_GeV
    snapshots[i_snapshot]['dict_hl_cell_by_cell'] = dict_hl_cell_by_cell
    snapshots[i_snapshot]['hl_imped_sample'] = hl_imped_sample
    snapshots[i_snapshot]['hl_sr_sample'] = hl_sr_sample
    snapshots[i_snapshot]['tref_string_short'] = tref_string_short

    if t_offset_h is None:
        snapshots[i_snapshot]['t_offs_h_str'] = '-'
    else:
        snapshots[i_snapshot]['t_offs_h_str'] = '%.2f'%snapshots[i_snapshot]['t_offs_h']

# check consistency in cell naming
for i_snapshot in xrange(N_snapshots):
    for s in hl.sector_list():
        if len(snapshots[i_snapshot]['dict_hl_cell_by_cell'][s]['cell_names'])!=len(snapshots[0]['dict_hl_cell_by_cell'][s]['cell_names']):
            raise ValueError('Found inconsistency type 1 in dict!')
        for c1, c2 in zip(snapshots[i_snapshot]['dict_hl_cell_by_cell'][s]['cell_names'], snapshots[0]['dict_hl_cell_by_cell'][s]['cell_names']):
            if c1!=c2:raise ValueError('Found inconsistency type 2 in dict!')


# Plots!
plt.close('all')
myfontsz = 13
ms.mystyle_arial(fontsz=13,dist_tick_lab=3)
if N_snapshots==1:
    width = 0.6
else:
    width = 0.8
spshare = None
Example #6
0
def save_cell_by_cell(infolder='./'):
    str_file = 'fill%dat%.2fh_' % (filln, t_sample_h)
    for fig, s in zip(figsect_list, hl.sector_list()):
        fig.savefig(infolder + '/correctors_cellbycell_%s_sector%d.png' %
                    (str_file, s),
                    dpi=200)
Example #7
0
    loc = kk.split('.')[2][-2:] + kk.split('.')[1][-2:]
    plane = kk.split('RCB')[-1][0]

    simplified_name = loc + '_' + beam_name
    if '16L2' in kk:
        print(kk, simplified_name, plane)

    dict_avg[simplified_name] = np.mean(dict_correctors[kk][1])
    dict_plane[simplified_name] = plane

# get cell quad association
dict_cell_to_quad = cn.cell_to_quad_dict()

# cell corrector association
dict_correctors_sector = {}
for i_s, s in enumerate(hl.sector_list()):
    cells = dict_hl_cell_by_cell[s]['cell_names']
    list_corr_B1_B2 = []
    list_current_B1 = []
    list_current_B2 = []
    for cell in cells:
        extname = cell.replace('_', '_CV94')
        name_quad = dict_cell_to_quad[extname]
        place = name_quad.replace('Q', '')

        if place.startswith('10') or place.startswith('34'):
            print('Skipped %s!' % place)
            list_corr_B1_B2.append('')
            list_current_B1.append(np.nan)
            list_current_B2.append(np.nan)
        else:
def sample_and_sort_cell_by_cell(cell_by_cell_db_dictionary,
                                 t_ref,
                                 t_sample_h,
                                 t_offset_h,
                                 first_cell=11):

    hid = cell_by_cell_db_dictionary

    sectors = hl.sector_list()
    dict_hl_cellbycell = {}
    for i, s in enumerate(sectors[:]):

        sect_str = str(s)
        R_part = 'R' + sect_str[0]
        L_part = 'L' + sect_str[1]

        # Find values at t_sample_h and t2 for each cell.
        val1 = []
        cells = []
        for cell in list(hid.keys()):
            if '_D2' in cell or '_D3' in cell or '_D4' in cell or '_Q1' in cell:
                continue
            if R_part not in cell and L_part not in cell:
                continue
            try:
                ind1 = np.argmin(
                    np.abs((np.array(hid[cell].t_stamps) - t_ref) / 3600 -
                           t_sample_h))
            except ValueError as e:
                print(('Got Error %s, skipping cell %s' % (e, cell)))
                continue
            cellname = cell.split('_')[1] + '_' + cell.split('.POSST')[0][-1]
            if int(cellname[:2]) <= first_cell: continue  # skip LSS and DS

            #~ if cellname=='11L1_3': print cell, cellname
            cells.append(cellname)

            # remove offset
            if t_offset_h is not None:
                ind_offset = np.argmin(
                    np.abs((np.array(hid[cell].t_stamps) - t_ref) / 3600 -
                           t_offset_h))
                val_offset = float(hid[cell].values[ind_offset])
                offset_info = ', no beam at %.2fh' % t_offset_h
            else:
                val_offset = 0.
                offset_info = ''

            val1.append(float(hid[cell].float_values()[ind1]) - val_offset)

        val1 = np.array(val1)
        cells = np.array(cells)

        # Sort everything
        # it's R(IP) 09, 10, 11, ... L(IP+1) 33, 32, ...
        msk_l = (np.char.find(cells, 'L') > -1)
        cells_lip = cells[msk_l]
        cells_rip = cells[~msk_l]

        #~ print val1.shape
        #~ print msk_l.shape
        val1_lip = val1[msk_l]
        val1_rip = val1[~msk_l]

        ind_sort = (np.argsort(cells_lip))[::-1]
        cells_lip = cells_lip[ind_sort]
        val1_lip = val1_lip[ind_sort]
        ind_sort = swap_even_odd(np.argsort(cells_rip))
        cells_rip = cells_rip[ind_sort]
        val1_rip = val1_rip[ind_sort]

        cells = np.append(cells_rip, cells_lip)
        val1 = np.append(val1_rip, val1_lip)

        dict_hl_cellbycell[s] = {'cell_names': cells, 'heat_loads': val1}

    return dict_hl_cellbycell