A. Petrenko (Novosibirsk, 2019)
import numpy as np
import pandas as pd
import geoviews as gv
import geoviews.tile_sources as gts
from cartopy import crs
from io import StringIO
from scipy import interpolate
gv.extension("bokeh")
!pwd
Loading tunnel:
df_wall = pd.read_csv('../drawings_and_maps/results/tunnel.csv')
df_wall.tail(4)
x0 = 9252311.415718
y0 = 7332694.100875
rotation_angle=36.57
def elegantZX2geoxy(Z, X, rotation_angle=rotation_angle, x0=x0, y0=y0, latitude=54.849):
angle = rotation_angle*np.pi/180 # Rotation angle (rad)
scale = np.cos(latitude * np.pi / 180.0)
x = (Z*np.cos(angle) - X*np.sin(angle))/scale
y = (Z*np.sin(angle) + X*np.cos(angle))/scale
return x0 + x, y0 + y
x,y = elegantZX2geoxy(df_wall['Z'].values, df_wall['X'].values)
%opts Path [width=800 height=500 show_grid=True]
%opts Path.Tunnel (color='red', alpha=0.7, line_width=2)
Tunnel = gv.Path((x,y), kdims=['x', 'y'], group='Tunnel', crs = crs.GOOGLE_MERCATOR)
gts.Wikipedia*Tunnel
#gts.EsriImagery*Tunnel
Read accelerator layout:
def read_beamline(magnets, floor_coordinates, DeltaX, DeltaZ, Element_width=0.7):
out = !sdds2stream $magnets -col=ElementName,s,Profile -pipe=out
DATA = StringIO("\n".join(out))
df_mag = pd.read_csv(DATA, names=['ElementName', 's', 'Profile'], delim_whitespace=True)
out = !sdds2stream $floor_coordinates \
-col=ElementName,s,X,Y,Z,theta,phi,psi -pipe=out
DATA = StringIO("\n".join(out))
df_xyz = pd.read_csv(DATA, names=['ElementName','s','X','Y','Z','theta','phi','psi'],
delim_whitespace=True)
df_xyz['X'] = df_xyz['X'] + DeltaX
df_xyz['Z'] = df_xyz['Z'] + DeltaZ
theta = interpolate.interp1d(
df_xyz.s.values, df_xyz.theta.values, bounds_error=False
)
X0 = interpolate.interp1d(
df_xyz.s.values, df_xyz.X.values, bounds_error=False
)
Z0 = interpolate.interp1d(
df_xyz.s.values, df_xyz.Z.values, bounds_error=False
)
s = df_mag.s.values
nx = np.cos(theta(s))
nz = -np.sin(theta(s))
df_mag['X'] = X0(s) + Element_width*df_mag['Profile']*nx
df_mag['Z'] = Z0(s) + Element_width*df_mag['Profile']*nz
df_mag['x'], df_mag['y'] = elegantZX2geoxy(df_mag.Z, df_mag.X)
return gv.Path(df_mag, kdims=['x','y'], vdims=['ElementName'],
crs = crs.GOOGLE_MERCATOR, group='Beamline')
path = "p-linac/FODO_and_e-p_sep/results/"
p_linac = read_beamline(path+'beamline.mag', path+'xyz.sdds', DeltaX=0, DeltaZ=-120)
path = "debuncher/results/"
debuncher = read_beamline(path+'beamline.mag', path+'xyz.sdds', DeltaX=0, DeltaZ=-(120-81.80))
path = "damping_ring/results/"
DampingRing = read_beamline(path+'beamline.mag', path+'xyz.sdds', DeltaX=-12.5, DeltaZ=-1.85)
path = "p-linac/FODO_and_e-p_sep/results/"
p_linac = read_beamline(path+'beamline.mag', path+'xyz.sdds', DeltaX=0, DeltaZ=-120)
p_solenoid_L = 20
path = "e-linac/FODO/results/"
e_linac = read_beamline(path+'beamline.mag', path+'xyz.sdds', DeltaX=0, DeltaZ=-120-138.6-p_solenoid_L)
path = "p-linac_2/results/"
p_linac_2 = read_beamline(path+'beamline.mag', path+'xyz.sdds', DeltaX=0, DeltaZ=+45)
#from bokeh.models import HoverTool
#hover = HoverTool(tooltips="@ElementName")
#%opts Path.Beamline [tools=[hover]] (color='blue', alpha=0.7)
%opts Path.Beamline (color='blue' alpha=0.7 line_width=3)
Beamline = DampingRing*debuncher*p_linac*p_linac_2*e_linac
gts.Wikipedia*Beamline*Tunnel
%opts Path.Beamline (color='yellow' alpha=1.0)
gts.EsriImagery*Beamline*Tunnel