fbct = FBCT.FBCT(fill_dict, beam=beam) bct = BCT.BCT(fill_dict, beam=beam) fig1 = plt.figure(i_fig, figsize=(14, 8), tight_layout=False) fig1.patch.set_facecolor('w') ax0 = plt.subplot(211) ax1 = plt.subplot(212) ms.mystyle() ax0.plot((bct.t_stamps-t_ref)/3600., bct.values, color=beam_col[beam-1], lw=2) for i in xrange(0, n_traces): t_cut_h = traces_times[i] t_curr = t_ref+t_cut_h*3600. fbct_curr, t_fbct_curr = fbct.nearest_older_sample(t_curr, flag_return_time=True) ax1.plot(fbct_curr, color=ms.colorprog(i, n_traces), label='%.2f h'%((t_fbct_curr-t_ref)/3600.)) ax0.axvline((t_fbct_curr-t_ref)/3600., lw=1.5, color=ms.colorprog(i, n_traces)) ax1.set_xlabel('25 ns slot') ax1.set_xlim(0, 3500) ax1.set_ylabel('Bunch intensity [p$^+$]') ax1.grid('on') ax0.set_xlabel('Time [h]') ax0.grid('on') ax0.set_ylim(bottom=0) plt.subplots_adjust(top=0.9, bottom=0.1, right=0.95, left=0.1, hspace=0.3, wspace=0.4) fig1.suptitle('Fill %d: B%d, started on %s'%(filln, beam, tref_string), fontsize=20) filename_out = 'outputs/Fill_%d_FBCTraw_B%d.png'%(filln, beam) i_fig += 1
fig = plt.figure() fig.canvas.set_window_title(title_str) plt.suptitle(title_str,fontsize=25) for dev_ctr, device in enumerate(devices): sp = plt.subplot(2,2,dev_ctr+1) sp.set_xlabel('Chamber bin position [cm]') sp.set_ylabel('Number of $e^-$ per bin') sp.set_title(device_labels_dict[device]) for coast_ctr, coast_str in enumerate(coast_strs): for sey_ctr, sey_str in enumerate(this_sey_list): if dev_ctr == 1 and sey_ctr == 0: label = coast_str + ' e9 coasting' elif dev_ctr == 2 and coast_ctr == 0: label = 'SEY %s' % sey_str else: label = None ls = coast_linestyle_dict[coast_str] color = colorprog(sey_ctr, len(this_sey_list)) try: nel_hist = nel_hist_dict[main_key][device][coast_str][sey_str][beam] except KeyError: #print(main_key,device,coast_str,sey_str,beam) nel_hist = yy_zero sp.plot(xg_hist*100,nel_hist,label=label,ls=ls,color=color) sp.legend(bbox_to_anchor=(1.1, 1)) plt.show()
# remove offset if zero_at is not None: for device in hl_varlist: heatloads.timber_variables[device].values = heatloads.timber_variables[device].values - dict_offsets[device] # normalize to the length if normalization_to_length_of is not None: for device in hl_varlist: heatloads.timber_variables[device].values = heatloads.timber_variables[device].values/norm_length_dict[device] if plot_all: for ii, kk in enumerate(heatloads.variable_list): #if '13L5' in kk and ('D2' in kk or 'D3' in kk): # continue colorcurr = ms.colorprog(i_prog=ii, Nplots=len(heatloads.variable_list)) kwplt = {} # # Enhance S12 # if 'S12' in kk: # kwplt = {'zorder':10} # colorcurr = tk' # Labels if first_fill: label = '' for st in kk.split('.POSST')[0].split('_'): if 'QRL' in st or 'QBS' in st or 'AVG' in st or 'ARC' in st: pass else:
heatloads = SetOfHomogeneousNumericVariables(variable_list=hl_var_names, timber_variables=dict_hl_data) hl_model = SetOfHomogeneousNumericVariables(variable_list=HL.variable_lists_heatloads['MODEL'], timber_variables=fill_dict) # CORRECT ARC AVERAGES if group_name == 'Arcs' and filln < first_correct_filln: hl_corr_factors = [] for ii, varname in enumerate(dict_hl_groups[group_name]): if varname not in blacklist: hl_corr_factors.append(arc_correction_factor_list[ii]) heatloads.correct_values(hl_corr_factors) if flag_average: hl_ts_curr, hl_aver_curr = heatloads.mean() for ii, kk in enumerate(heatloads.variable_list): colorcurr = ms.colorprog(i_prog=ii, Nplots=len(heatloads.variable_list)) if t_zero is not None: offset = np.interp(t_ref+t_zero*3600, heatloads.timber_variables[kk].t_stamps, heatloads.timber_variables[kk].values) else: offset=0. sphlcell.plot((heatloads.timber_variables[kk].t_stamps-t_ref)/3600, heatloads.timber_variables[kk].values-offset, '-', color=colorcurr, lw=2., label=kk.split('.POSST')[0])#.split('_QBS')[0]) if plot_model and group_name == 'Arcs': kk = 'LHC.QBS_CALCULATED_ARC.TOTAL' label='Imp.+SR' sphlcell.plot((hl_model.timber_variables[kk].t_stamps-t_ref)/3600., hl_model.timber_variables[kk].values, '--', color='grey', lw=2., label=label) if flag_average: if t_zero is not None:
sp2.set_ylim(0, 7) sp2.set_ylabel('Energy [TeV]') sp2.plot(energy.t_stamps, energy.energy / 1e3, c='black', lw=2., label='Energy') summed_log, summed_re = 0., 0. for ctr, affix in enumerate(affix_list): var = cell_vars[affix] row_ctr = heatloads.variables.index(var) values = heatloads.data[:, row_ctr] summed_log += values summed_re += special_hl[cell][affix]['Sum'] color = ms.colorprog(ctr, cell_vars) if logged: sp.plot(timestamps, values, label=affix + ' logged', ls='--', lw=2., color=color) sp.plot(special_tt, special_hl[cell][affix]['Sum'], ls='-', lw=2., color=color, label=affix) #sp.axvline(avg_time_hrs, color='black') # summed
sp2.set_ylim(10, 105) sp2.set_xlim(2, 4) for sp_ in (sp, sphlcell): sp_.set_title('Average arc half cells') sp_.grid(True) sp_.set_ylabel('Heat load [W]') def plot_both(*args, **kwargs): sp.plot(*args, **kwargs) sphlcell.plot(*args, **kwargs) tt = (qbs_ob.timestamps - t_ref) / 3600. for arc_ctr, key in enumerate(arc_keys_list): color = ms.colorprog(arc_ctr, len(arc_keys_list) + 1) label = key[:3] if args.selected and label not in ('S12', 'S56'): continue # Logged # Recalculated if arc_ctr == 0: label1 = label + ' with dP' label2 = label + ' without dP' else: label1 = label label2 = None if args.subtract_offset: subtract = find_offset(tt, qbs_arc_avg[:, arc_ctr]) else: subtract = 0
# CORRECT ARC AVERAGES if not use_recalculated and group_name == 'Arcs' and filln < first_correct_filln: hl_corr_factors = [] for ii, varname in enumerate(dict_hl_groups[group_name]): if varname not in blacklist: hl_corr_factors.append(arc_correction_factor_list[ii]) heatloads.correct_values(hl_corr_factors) if flag_average: hl_ts_curr, hl_aver_curr = heatloads.mean() # Loop for arcs fill_arc_hl_dict[filln] = {} for ii, kk in enumerate(heatloads.variable_list): colorcurr = ms.colorprog(ii, heatloads.variable_list) # offset if t_zero is not None: offset = np.interp(t_ref + t_zero * 3600, heatloads.timber_variables[kk].t_stamps, heatloads.timber_variables[kk].values) else: offset = 0. label = '' for st in kk.split('.POSST')[0].split('_'): if 'QRL' in st or 'QBS' in st or 'AVG' in st or 'ARC' in st: pass else: label += st + ' '
if args.vs_bunch_inten: fig_bint = pl.figure(100+ii, figsize=(8*1.4, 6*1.4)) fig_bint.set_facecolor('w') spbint = pl.subplot(1,1,1) if args.beam_events: keys_labels = [('t_start_INJPHYS', 'Injection'), ('t_start_RAMP', 'Ramp'), ('t_start_FLATTOP', 'Flat top'), ('t_start_SQUEEZE', 'Squeeze'), ('t_start_ADJUST', 'Adjust'), ('t_start_STABLE', 'Stable beams') ] for ctr, (key, label) in enumerate(keys_labels): color = ms.colorprog(ctr, len(keys_labels)+1) tt = (dict_fill_bmodes[filln][key] - t_ref)/3600. spenergy.axvline(tt, ls='-', color=color, label=label) n_bunches_bx = {} for beam_n in beams_list: if flag_fbct: sptotint.plot((fbct_bx[beam_n].t_stamps-t_ref)/3600., fbct_bx[beam_n].totint, '.--', color=colstr[beam_n]) sptotint.plot((bct_bx[beam_n].t_stamps-t_ref)/3600., bct_bx[beam_n].values/1e14, '-', color=colstr[beam_n], lw=2., label='Intensity B%i' % beam_n) sptotint.set_ylabel('Total intensity\n[10$^{14}$ p$^+$]',fontsize = 24) sptotint.grid('on') sptotint.set_ylim(0, None) if flag_bunch_length and not normtointen: spavbl.plot((blength_bx[beam_n].t_stamps-t_ref)/3600., blength_bx[beam_n].avblen/1e-9, '.-', color=colstr[beam_n]) spavbl.set_ylabel('Bunch length\n[ns]',fontsize = 24) spavbl.set_ylim(0.8,1.8)
ax0 = plt.subplot(211) ax1 = plt.subplot(212) ms.mystyle() ax0.plot((bct.t_stamps - t_ref) / 3600., bct.values, color=beam_col[beam - 1], lw=2) for i in xrange(0, n_traces): t_cut_h = traces_times[i] t_curr = t_ref + t_cut_h * 3600. fbct_curr, t_fbct_curr = fbct.nearest_older_sample( t_curr, flag_return_time=True) ax1.plot(fbct_curr, color=ms.colorprog(i, n_traces), label='%.2f h' % ((t_fbct_curr - t_ref) / 3600.)) ax0.axvline((t_fbct_curr - t_ref) / 3600., lw=1.5, color=ms.colorprog(i, n_traces)) ax1.set_xlabel('25 ns slot') ax1.set_xlim(0, 3500) ax1.set_ylabel('Bunch intensity [p$^+$]') ax1.grid('on') ax0.set_xlabel('Time [h]') ax0.grid('on') ax0.set_ylim(bottom=0) plt.subplots_adjust(top=0.9, bottom=0.1, right=0.95,
axhist.plot(x_hist, tempy, linewidth=3, color='blue', alpha=0.8) axhist.grid('on') axhist.set_xlim(minhist, maxhist) y_list.append(tempy) figlist.append(fig_sect) plt.figure(2000) bad_sectors = [12, 23, 81, 78] good_sectors = [34, 45, 56, 67] bad_distr = 0 * x_hist good_distr = 0 * x_hist for ii, s in enumerate(sectors[:]): colorcurr = ms.colorprog(ii, 8) plt.plot(x_hist, y_list[ii], color=colorcurr, linewidth=3) if s in bad_sectors: bad_distr += y_list[ii] else: good_distr += y_list[ii] plt.figure(3000) plt.plot(x_hist, bad_distr / np.sum(bad_distr)) plt.plot(x_hist, good_distr / np.sum(good_distr)) if args.o: for fig, s in zip(figlist, sectors[:]): fig.savefig( 'cell_by_cell_plots/cellbycell_fill%d_t%.2fh_%s_sector%d.png' % (filln, t1, tagfname, s),
ax2_sect.bar(ind, np.abs(dict_correctors_sector[s]['list_current_B2']), width / 2., color='r', alpha=.5) ax2_sect.set_xticks(ind) ax2_sect.set_xticklabels(dict_correctors_sector[s]['list_corr_B1_B2'], rotation=90) ax2_sect.yaxis.grid(True) ax2_sect.set_ylabel('Corrector current (abs.) [A]') for ax in [ax1_sect, ax2_sect]: for igrey in ind[1::2]: ax.axvspan(igrey - 0.5, igrey + 0.5, color='k', alpha=.1) colorcurr = ms.colorprog(i_s, 8, v1=0.9, v2=1.0, cm='hsv') axcorr.plot(np.abs(dict_correctors_sector[s]['list_current_B1']), dict_hl_cell_by_cell[s]['heat_loads'], '.', markersize=10, color=colorcurr) axcorrlog.semilogx(np.abs(dict_correctors_sector[s]['list_current_B1']), dict_hl_cell_by_cell[s]['heat_loads'], '.', markersize=10, color=colorcurr) fig_sect.subplots_adjust(left=.06, right=.96, top=0.9, hspace=0.12,
hl_keys = main_dict[moment]['heat_load'].keys() # Heat load fig2 = plt.figure(2, figsize=(8 * 1.5, 6 * 1.5)) fig2.set_facecolor('w') sphl1 = plt.subplot(2, 1, 1, sharex=sp3) sphl2 = plt.subplot(2, 1, 2, sharex=sp3) hl_keys.sort() arc_ctr = 0 for key in hl_keys: if key[0] != 'S': continue color = colorprog(arc_ctr, 8) sphl1.plot(main_dict['filln'], main_dict[moment]['heat_load']['arc_averages'][key], '.', label=key, color=color, markersize=12) sphl1.grid('on') sphl2.plot(main_dict['filln'], main_dict[moment]['heat_load']['arc_averages'][key] / main_dict[moment]['intensity']['total'], '.', label=key, color=color, markersize=12)