-
Notifications
You must be signed in to change notification settings - Fork 0
/
002_export_to_HTML.py
111 lines (77 loc) · 3.07 KB
/
002_export_to_HTML.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import numpy as np
import pandas as pd
from pathlib import Path
import gc
import sys
# BOKEH
import bokeh.plotting as bk
import bokeh.models as bkmod
import bokeh.layouts as bklay
import bokeh.palettes as bkpalettes
# xsuite
import xtrack as xt
import xmask as xm
import xfields as xf
import xpart as xp
# Custom imports
sys.path.append('MiniHC/XMask/Jobs/004_export_dashboard')
import bokeh_tools as bktools
import Presets as bkpresets
# BBStudies
sys.path.append('/Users/pbelanger/ABPLocal/BBStudies')
import BBStudies.Tracking.XsuitePlus as xPlus
import BBStudies.Tracking.InteractionPoint as inp
import BBStudies.Physics.Detuning as tune
import BBStudies.Plotting.BBPlots as bbplt
import BBStudies.Physics.Base as phys
import BBStudies.Physics.Constants as cst
# Setting default values
#------------------------------------------------
_default_fig_width = 1500
_default_fig_height = 400
_default_fig_pad = 100
# Importing Collider and Twiss
#-------------------------------------
collider = xt.Multiline.from_json('MiniHC/JSON/MiniHC.json')
twiss = {}
twiss['lhcb1'] = collider['lhcb1'].twiss(method='4d').to_pandas()
twiss['lhcb2'] = collider['lhcb2'].twiss(method='4d').reverse().to_pandas()
#-------------------------------------
# Filtering twiss to get rid of slices, entries and exits
#-------------------------------------
light_twiss = {}
for sequence in ['lhcb1','lhcb2']:
light_twiss[sequence] = xPlus.filter_twiss(twiss[sequence].set_index('name'),entries=['drift','_entry','_exit']).reset_index()
#-------------------------------------
# Making figures
#-------------------------------------
BOKEH_FIGS = {}
BOKEH_FIGS['twiss'] = bkpresets.make_Twiss_Fig(collider,light_twiss,width=_default_fig_width,height=_default_fig_height,
twiss_columns=['x','y','px','py','betx','bety','alfx','alfy','dx','dy','dpx','dpy','mux','muy'])
BOKEH_FIGS['lattice'] = bkpresets.make_LHC_Layout_Fig(collider,twiss,width=_default_fig_width,height=_default_fig_height)
#-------------------------------------
# Setting up axes
#-------------------------------------
BOKEH_FIGS['lattice'].xaxis[1].visible = False
BOKEH_FIGS['twiss'].x_range = BOKEH_FIGS['lattice'].x_range
#-------------------------------------
# Adding space to twiss fig for the legend, then adding pad
#-------------------------------------
BOKEH_FIGS['twiss'].height = 3*_default_fig_height
BOKEH_FIGS['twiss'].min_border_bottom = 2*_default_fig_height
for name,_fig in BOKEH_FIGS.items():
if 'widget' in name.lower():
continue
_fig.min_border_left = _default_fig_pad
_fig.min_border_right = _default_fig_pad
#-------------------------------------
# Final layout
#=====================================
HTML_LAYOUT = bklay.column(BOKEH_FIGS['lattice'],BOKEH_FIGS['twiss'])
#=====================================
if not Path('MiniHC/HTML').exists():
Path('MiniHC/HTML').mkdir()
# Exporting to HTML
#=====================================
bktools.export_HTML(HTML_LAYOUT,'MiniHC/HTML/MiniHC.html',f'MiniHC rendering')
#=====================================