In [500]:
import sympy as sym
import numpy as np
sym.init_printing(fontsize='5pt',use_latex='mathjax', wrap_line=True)
sym.init_session()
from sympy.physics.vector import vlatex
from sympy.printing import latex
In [501]:
#symbols
skew, slope, lat, lon = sym.symbols('skew slope lat lon')
#values
consts = dict(skew = 2.3755870374367263e-05,
slope = 0.0034494653328734047,
lat = np.radians(-35.370707),
lon = np.radians(149.424702))
In [502]:
def rotation_matrix(angle,d):
directions = {
"x":[1,0,0],
"y":[0,1,0],
"z":[0,0,1]
}
direction = np.array(directions[d])
sina = sym.sin(angle)
cosa = sym.cos(angle)
# rotation matrix around unit vector
R = sym.Matrix([[cosa,0,0],[0,cosa,0],[0,0,cosa]])
R += sym.Matrix(np.outer(direction, direction)) * (1 - cosa)
direction = sym.Matrix(direction)
direction *= sina
R += sym.Matrix([[ 0, -direction[2], direction[1]],
[ direction[2], 0, -direction[0]],
[-direction[1], direction[0], 0]])
return R
In [503]:
#reflections
def reflection_matrix(d):
m = {
"x":[[-1,0,0],[0, 1,0],[0,0, 1]],
"y":[[1, 0,0],[0,-1,0],[0,0, 1]],
"z":[[1, 0,0],[0, 1,0],[1,0,-1]]
}
return sym.Matrix(m[d])
In [504]:
def position_vector(a,b):
return sym.Matrix([[sym.cos(b)*sym.cos(a)],
[sym.cos(b)*sym.sin(a)],
[sym.sin(b)]])
In [525]:
# z-axis lies along telescope east to west
# using right-hand rule
# thumb is z
# index is x
# middle is y
telescope_to_nsew = (rotation_matrix(-skew,"x") * rotation_matrix(slope,"y"))
telescope_to_nsew
Out[525]:
In [506]:
#use reflecion to convert to left-hand rule
nsew_to_azel = rotation_matrix(-sym.pi/2,"x") * rotation_matrix(sym.pi/2,"y") * reflection_matrix("x")
nsew_to_azel
Out[506]:
In [507]:
telescope_to_azel = (telescope_to_nsew * nsew_to_azel)
telescope_to_azel
Out[507]:
In [508]:
azel_to_hadec = rotation_matrix(sym.pi/2-lat,"y") * rotation_matrix(sym.pi,"z")
azel_to_hadec
Out[508]:
In [550]:
telescope_to_hadec = telescope_to_azel * azel_to_hadec
telescope_to_hadec
Out[550]:
In [510]:
telescope_to_hadec.T
Out[510]:
In [511]:
HA,Dec = sym.symbols('HA Dec')
hadec_vec = position_vector(HA,Dec)
hadec_vec
Out[511]:
In [512]:
ns,ew = sym.symbols('NS EW')
nsew_vec = position_vector(ns,ew)
nsew_vec
Out[512]:
In [537]:
az,el = sym.symbols('Az El')
azel_vec = position_vector(az,el)
azel_vec
Out[537]:
In [513]:
equations = sym.Eq(nsew_vec,(telescope_to_hadec * hadec_vec))
equations
Out[513]:
In [514]:
values = consts.copy()
values.update({HA:1.0,Dec:0.8})
e = equations.subs(values)
e
Out[514]:
In [515]:
# caluclate ew using full matrix
a,b,c = np.array((telescope_to_hadec * hadec_vec).subs(values)).astype('float64').squeeze()
calc_ew = np.arcsin(c)
calc_ns = np.arctan2(b,a)
print "(EB) NS, EW (radians) = ",calc_ns,", ",calc_ew
In [516]:
def jer_delay(ha_source,dec_source, tilt=slope, skew=skew, latitude=lat):
from numpy import sin,cos
return sin(ha_source)*cos(dec_source)*cos(tilt) + \
cos(ha_source)*cos(dec_source)* (skew*sin(latitude)-sin(tilt)*cos(latitude))- \
sin(dec_source)*(skew*cos(latitude)+sin(tilt)*sin(latitude))
In [517]:
# calculate ew using jer delay
calc_ew_jer = jer_delay(values[HA],values[Dec],tilt=values['slope'],skew=values['skew'],latitude=values['lat'])
print "(JER) EW (radians) = ",np.arcsin(calc_ew_jer)
In [518]:
#difference between JER and full matrix
print "Offset between EB and JER of:",np.degrees(calc_ew - np.arcsin(calc_ew_jer))*3600.0,"arcseconds"
In [519]:
#JER equation
sym.Eq(sin(ew),sin(HA)*cos(Dec)*cos(slope) + \
cos(HA)*cos(Dec)* (skew*sin(lat)-sin(slope)*cos(lat))- \
sin(Dec)*(skew*cos(lat)+sin(slope)*sin(lat)))
Out[519]:
In [520]:
new_eq = sym.Eq(nsew_vec[2],(telescope_to_hadec * hadec_vec)[2])
new_eq
Out[520]:
In [521]:
#might not be obvious, but the skew terms now become fractions or go to 1.
simplified = nsimplify(new_eq.subs({skew:values['skew']}),tolerance=0.000000001)
simplified
Out[521]:
In [522]:
simple_ew = float(solve(simplified.subs(values),ew)[0])
print "Offset between EB (simple) and JER of:",np.degrees(simple_ew - np.arcsin(calc_ew_jer))*3600.0,"arcseconds"
In [527]:
new_eq.subs(consts)
Out[527]:
In [528]:
ns_eq = sym.Eq(nsew_vec[0],(telescope_to_hadec * hadec_vec)[0])
ns_eq = ns_eq.subs(consts)
ns_eq
Out[528]:
In [535]:
inv_dec = sym.Eq(hadec_vec[2],(telescope_to_hadec.T * nsew_vec)[2])
inv_dec.subs(consts)
Out[535]:
In [536]:
inv_ha = sym.Eq(hadec_vec[1],(telescope_to_hadec.T * nsew_vec)[1])
inv_ha.subs(consts)
Out[536]:
In [545]:
ew_from_azel = sym.Eq(nsew_vec[2],(telescope_to_azel * azel_vec)[2])
ew_from_azel.subs(consts)
Out[545]:
In [544]:
ns_from_azel = sym.Eq(nsew_vec[1],(telescope_to_azel * azel_vec)[1])
ns_from_azel.subs(consts)
Out[544]:
inverse
In [548]:
el_from_nsew = sym.Eq(azel_vec[2],(telescope_to_azel.T * nsew_vec)[2])
el_from_nsew.subs(consts)
Out[548]:
In [549]:
az_from_nsew = sym.Eq(azel_vec[1],(telescope_to_azel.T * nsew_vec)[1])
az_from_nsew.subs(consts)
Out[549]:
In [574]:
#func_ = (asin((telescope_to_azel.T * nsew_vec)[2])).subs(consts)
#z = sym.lambdify((ns,ew),func_,'numpy',dummify=False)
#z(0.1,0.2)
In [573]:
In [ ]: