Plot accelerator on the map

A. Petrenko (Novosibirsk, 2019)

In [1]:
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")
Unable to open EPSG support file gcs.csv.  Try setting the GDAL_DATA environment variable to point to the directory containing EPSG csv files.
In [2]:
!pwd
/c/!Work/BINP/c-tau/Injector

Loading tunnel:

In [3]:
df_wall = pd.read_csv('../drawings_and_maps/results/tunnel.csv')
In [4]:
df_wall.tail(4)
Out[4]:
Unnamed: 0 Z X
99 99 25.7405 -2.0714
100 100 NaN NaN
101 101 9.2595 -11.5484
102 102 30.6565 -2.0834
In [5]:
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
In [6]:
x,y = elegantZX2geoxy(df_wall['Z'].values, df_wall['X'].values)
In [7]:
%opts Path [width=800 height=500 show_grid=True]
%opts Path.Tunnel (color='red', alpha=0.7, line_width=2)
In [8]:
Tunnel = gv.Path((x,y), kdims=['x', 'y'], group='Tunnel', crs = crs.GOOGLE_MERCATOR)
In [9]:
gts.Wikipedia*Tunnel
Out[9]:
In [10]:
#gts.EsriImagery*Tunnel

Read accelerator layout:

In [11]:
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')
In [12]:
path = "p-linac/FODO_and_e-p_sep/results/"
p_linac = read_beamline(path+'beamline.mag', path+'xyz.sdds', DeltaX=0, DeltaZ=-120)
In [13]:
path = "debuncher/results/"
debuncher = read_beamline(path+'beamline.mag', path+'xyz.sdds', DeltaX=0, DeltaZ=-(120-81.80))
In [14]:
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)
In [15]:
#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)
In [16]:
Beamline = DampingRing*debuncher*p_linac*p_linac_2*e_linac
In [17]:
gts.Wikipedia*Beamline*Tunnel
Out[17]:
In [18]:
%opts Path.Beamline (color='yellow' alpha=1.0)

gts.EsriImagery*Beamline*Tunnel
Out[18]:
In [ ]: