Modeling satellite's orbit around earth in python? - python

I've been following along with a tutorial, which models Earth, Venus, and the Sun. The code runs just fine. However, I'm trying to model a satellite's orbit about the earth, where the earth is the center of its "universe" at position (0,0). I'm running into issues as my satellite flies off on a tangent but I'm not sure why.
import numpy as np
import numpy as np
class Planet():
def __init__(self,vx=0.0,vy=0.0,px=0.0,py=0.0,mass=0.0):
self.vx=vx
self.vy=vy
self.px=px
self.py=py
self.mass = mass
def attract(p1,p2,grav=6.67428e-11):
dx = p1.px - p2.px
dy = p1.py - p2.py
d = np.sqrt(dx**2 + dy**2)
force = (grav * p1.mass * p2.mass)/d**2
theta = math.atan2(dy,dx)
fx = math.cos(theta)*force
fy = math.sin(theta)*force
return fx,fy
def loop(bodies,epochs=10,timestep=10):
# compute forces
forces = {}
for i in range(0,len(bodies)):
total_fx = 0
total_fy = 0
for j in range(0,len(bodies)):
if i == j:
continue
fx,fy = attract(bodies[i],bodies[j])
total_fx += fx
total_fy += fy
forces[i] = (total_fx,total_fy)
#apply forces
sat_tups = []
for e in range(epochs):
for i in range(len(bodies)):
if bodies[i] == satellite:
sat_tups.append((bodies[i].px,bodies[i].py))
fx,fy = forces[i]
bodies[i].vx += (fx/bodies[i].mass*timestep)
bodies[i].vy += (fy/bodies[i].mass*timestep)
bodies[i].px += bodies[i].vx*timestep
bodies[i].py += bodies[i].vy*timestep
return sat_tups
earth = Planet(mass = 5.9742 * 10**24)
satellite = Planet(mass= 3000.0, px= 1414.0, py= 1414.0, vx=2300.0,vy=2300.0)
tups = loop(bodies=[earth,satellite])
tups
>>>
[(1414.0, 1414.0),
(7050856421.79636, 7050856421.79636),
(21152543437.38908, 21152543437.38908),
(42305062460.77817, 42305062460.77817),
(70508413491.96361, 70508413491.96361),
(105762596530.9454, 105762596530.9454),
(148067611577.72357, 148067611577.72357),
(197423458632.2981, 197423458632.2981),
(253830137694.66898, 253830137694.66898),
(317287648764.83624, 317287648764.83624)]
I'm not sure what the issue is. Perhaps, centering Earth at (0,0) simply isn't going to work. Or perhaps these laws of physics are only applicable when bodies are of relatively similar sizes (else more intricate rules are at play.)
To answer this question, please address what is causing the satellite to fly off? (I would have guessed that it would crash into earth, not sling-shot away).

Related

Is there a way to dynamically change variables depending on length of list

May seem like a silly question is there any way to create variables depending on the number of objects in a list. The context to this is I am trying to create an n body simulation. One in which the user can manually chose the planets they want in the solar system and then run the script with only those planets. So prior to them running the chosing the planets and running the script I will not know how many variables to create. This problem of how many variables to create is show by:
The mass is created by a class objects:
class Objects():
position = np.full((1, 3), 0)
velocity = np.full((1, 3), 0)
acceleration = np.full((1, 3), 0)
name = ""
mass = np.full((1, 1), 0)
planets_init = np.full((1, 3), 0)
def __init__(self, Name, Mass, initPosition, initVelocity, initAcceleration):
au = 149597870.700e3
v_factor = 1731460
self.name = Name
self.mass = Mass
The function is solved by using scipy.integrate.solve_ivp by:
three_body_sol = sci.integrate.solve_ivp(fun=Objects.ThreeBodyEquations,t_span=domain,y0=init_params,args=(G,planets_mass,N), max_step=max_step)
Where the function is:
def ThreeBodyEquations(t,w,G,mass,N):
# N being the number of objects in the system so in this case 2
m1, m2 = mass
#Unpack all the variables from the array "w"
r1=w[:3]
r2=w[3:6]
v1=w[6:9]
v2=w[9:12]
# Harry's attempt
G = G
planets_pos = np.vstack((r1, r2))
planets_mass = mass # np.vstack((m1, m2))
# positions r = [x,y,z] for all particles
x = planets_pos[:,0:1]
y = planets_pos[:,1:2]
z = planets_pos[:,2:3]
# matrix that stores all pairwise particle separations: r_j - r_i
dx = x.T - x
dy = y.T - y
dz = z.T - z
# matrix that stores 1/r^3 for all particle pairwise particle separations
inv_r3 = (dx**2 + dy**2 + dz**2)
inv_r3[inv_r3>0] = inv_r3[inv_r3>0]**(-1.5)
ax = G * (dx * inv_r3) # planets_mass
ay = G * (dy * inv_r3) # planets_mass
az = G * (dz * inv_r3) # planets_mass
# planets_acceleration = np.sqrt(ax**2 + ay**2 + az**2)
planets_acceleration = np.vstack((ax,ay,az))
planets_acceleration = planets_acceleration.flatten()
dv1bydt=planets_acceleration[0::N]
dv2bydt=planets_acceleration[1::N]
# print(planets_acceleration)
dr1bydt=v1
dr2bydt=v2
#Package the derivatives into one final size-18 array
r12_derivs=np.concatenate((dr1bydt,dr2bydt))
r_derivs = r12derivs
v12_derivs=np.concatenate((dv1bydt,dv2bydt))
v_derivs= v12_derivs
derivs=np.concatenate((r_derivs,v_derivs))
return derivs
My main question centres around this function. When the user defines what planets they want to use I have no idea what the number of planets will be. I know the range which is might be but that’s all. Is there a feasible way to do this or is this a lost cause?
I hope this clarifys the question with some additional code. Sorry about the previous lack of code its, I didn’t realise it was valuable at first and didn’t want to burden with too much code.
I would create a function that calculates the mass first, such as
mass = 0
for planet in planet_list:
mass = mass+ planet.mass
return mass
total_mass = calculate_combined_mass([earth, Mars, jupiter] )
three_body_equations(t,w,G,total_mass,N)

Python implementation of n-body problem issue

I am currently trying to implement the N-body problem using Euler's method for solving differential equations. However, the graphical outputs do not seem correct, and I'm not sure where the issue in my code is after a while of testing. I'm currently using approximate values for Alpha Centauri A and B to test. This is my code:
import numpy as np
import matplotlib.pyplot as plt
from math import floor
# gravitation constant
G = 6.67430e-11
# astronomical units
au = 1.496e11
sec_in_day = 60 * 60 * 24
dt = 1 * sec_in_day
class Body(object):
def __init__(self, name, init_pos, init_vel, mass):
self.name = name
self.p = init_pos
self.v = init_vel
self.m = mass
def run_sim(bodies, t):
mass = np.array([[b.m] for b in bodies], dtype=float) # (n, 1, 1)
vel = np.array([b.v for b in bodies], dtype=float) # (n, 1, 3)
pos = np.array([b.p for b in bodies], dtype=float) # (n, 1, 3)
names = np.array([b.name for b in bodies], dtype=str)
# save positions and velocities for plotting
plt_pos = np.empty((floor(t/dt), pos.shape[0], pos.shape[1]))
plt_vel = np.empty((floor(t/dt), pos.shape[0], pos.shape[1]))
# center of mass
com_p = np.sum(np.multiply(mass, pos),axis=0) / np.sum(mass,axis=0)
curr = 0
i = 0
while curr < t:
dr = np.nan_to_num(pos[None,:] - pos[:,None])
r3 = np.nan_to_num(np.sum(np.abs(dr)**2, axis=-1)**(0.5)).reshape((pos.shape[0],pos.shape[0],1))
a = G * np.sum((np.nan_to_num(np.divide(dr, r3)) * np.tile(mass,(pos.shape[0],1)).reshape(pos.shape[0],pos.shape[0],1)), axis=1)
pos += vel * dt
plt_pos[i] = pos
vel += a * dt
plt_vel[i] = vel
curr += dt
i += 1
fig = plt.figure(figsize=(15,15))
ax = fig.add_subplot()
for i in list(range(plt_pos.shape[1])):
ax.plot(plt_pos[:,i,0], plt_pos[:,i,1], alpha=0.5, label=names[i])
ax.scatter(plt_pos[-1,i,0], plt_pos[-1,i,1], marker="o", label=f'{i}')
plt.legend()
plt.show()
run_sim(bodies = [ Body('Alpha Centauri A', [0, 0, 0], [0,22345,0], 1.989e30*1.1),
Body('Alpha Centauri B', [23 * au, 0, 0], [0,-18100,0], 1.989e30*0.907),
],
t = 100 * 365 * sec_in_day
)
And this is the resulting plot. I would expect their orbits to be less variant and more circular, sort of in a Venn diagram-esque form.
There are 3 steps to a correctly looking plot.
First and most importantly, get the implementation of the physical model right. r3 is supposed to contain the third powers of the distances, thus the third power of the square root has exponent 1.5
r3 = np.nan_to_num(np.sum(np.abs(dr)**2, axis=-1)**(1.5)).reshape((pos.shape[0],pos.shape[0],1))
This then gives the cleaned up plot
Note the differences in the scales in the axes, one would have to horizontally compress the image by a factor of 40 to get the same scale in both directions.
Second, this means that the initial velocity is too large, the stars flee from each other. These velocities might be right in the position where the stars are closest together. As a quick fix, divide the velocities by 10. This gives the plot
Better initial values could be obtained by evaluating and transforming the supposedly more realistic data from https://towardsdatascience.com/modelling-the-three-body-problem-in-classical-mechanics-using-python-9dc270ad7767 or use the Kepler laws with the more general data from http://www.solstation.com/orbits/ac-absys.htm
Third, the mass center is not at the origin and has a non-zero velocity. Normalize the initial values for that
# center of mass
com_p = np.sum(np.multiply(mass, pos),axis=0) / np.sum(mass,axis=0)
com_v = np.sum(np.multiply(mass, vel),axis=0) / np.sum(mass,axis=0)
for p in pos: p -= com_p
for v in vel: v -= com_v
(or apply suitable broadcasting magic instead of the last two lines) to get the plot that you were probably expecting.
That the orbits spiral outwards is typical for the Euler method, as the individual steps move along the tangents to the convex ellipses of the exact solution.
The same only using RK4 with 5-day time steps gives prefect looking ellipses
For the RK4 implementation the most important step is to package the non-trivial derivatives computation into a separate sub-procedure
def run_sim(bodies, t, dt, method = "RK4"):
...
def acc(pos):
dr = np.nan_to_num(pos[None,:] - pos[:,None])
r3 = np.nan_to_num(np.sum(np.abs(dr)**2, axis=-1)**(1.5)).reshape((pos.shape[0],pos.shape[0],1))
return G * np.sum((np.nan_to_num(np.divide(dr, r3)) * np.tile(mass,(pos.shape[0],1)).reshape(pos.shape[0],pos.shape[0],1)), axis=1)
Then one can take the Euler step out of the time loop
def Euler_step(pos, vel, dt):
a = acc(pos);
return pos+vel*dt, vel+a*dt
and similarly implement the RK4 step
def RK4_step(pos, vel, dt):
v1 = vel
a1 = acc(pos)
v2 = vel + a1*0.5*dt
a2 = acc(pos+v1*0.5*dt)
v3 = vel + a2*0.5*dt
a3 = acc(pos+v2*0.5*dt)
v4 = vel + a3*dt
a4 = acc(pos+v3*dt)
return pos+(v1+2*v2+2*v3+v4)/6*dt, vel+(a1+2*a2+2*a3+a4)/6*dt
Select the method like
stepper = RK4_step if method == "RK4" else Euler_step
and then the time loop takes the generic form
N = floor(t/dt)
...
for i in range(1,N+1):
pos, vel = stepper(pos, vel, dt)
plt_pos[i] = pos
plt_vel[i] = vel

Elliptical orbit in vpython

I have the following code. This code is simulation of orbiting objects around other objects, E.g. Solar system. As you run it, the objects orbit in circular trajectory.
import math
from vpython import *
lamp = local_light(pos=vector(0,0,0), color=color.yellow)
# Data in units according to the International System of Units
G = 6.67 * math.pow(10,-11)
# Mass of the Earth
ME = 5.973 * math.pow(10,24)
# Mass of the Moon
MM = 7.347 * math.pow(10,22)
# Mass of the Mars
MMa = 6.39 * math.pow(10,23)
# Mass of the Sun
MS = 1.989 * math.pow(10,30)
# Radius Earth-Moon
REM = 384400000
# Radius Sun-Earth
RSE = 149600000000
RMS = 227900000000
# Force Earth-Moon
FEM = G*(ME*MM)/math.pow(REM,2)
# Force Earth-Sun
FES = G*(MS*ME)/math.pow(RSE,2)
# Force Mars-Sun
FEMa = G*(MMa*MS)/math.pow(RMS,2)
# Angular velocity of the Moon with respect to the Earth (rad/s)
wM = math.sqrt(FEM/(MM * REM))
# Velocity v of the Moon (m/s)
vM = wM * REM
print("Angular velocity of the Moon with respect to the Earth: ",wM," rad/s")
print("Velocity v of the Moon: ",vM/1000," km/s")
# Angular velocity of the Earth with respect to the Sun(rad/s)
wE = math.sqrt(FES/(ME * RSE))
# Angular velocity of the Mars with respect to the Sun(rad/s)
wMa = math.sqrt(FEMa/(MMa * RMS))
# Velocity v of the Earth (m/s)
vE = wE * RSE
# Velocity v of the Earth (m/s)
vMa = wMa * RMS
print("Angular velocity of the Earth with respect to the Sun: ",wE," rad/s")
print("Velocity v of the Earth: ",vE/1000," km/s")
# Initial angular position
theta0 = 0
# Position at each time
def positionMoon(t):
theta = theta0 + wM * t
return theta
def positionMars(t):
theta = theta0 + wMa * t
return theta
def positionEarth(t):
theta = theta0 + wE * t
return theta
def fromDaysToS(d):
s = d*24*60*60
return s
def fromStoDays(s):
d = s/60/60/24
return d
def fromDaysToh(d):
h = d * 24
return h
# Graphical parameters
print("\nSimulation Earth-Moon-Sun motion\n")
days = 365
seconds = fromDaysToS(days)
print("Days: ",days)
print("Seconds: ",seconds)
v = vector(384,0,0)
E = sphere(pos = vector(1500,0,0), color = color.blue, radius = 60, make_trail=True)
Ma = sphere(pos = vector(2300,0,0), color = color.orange, radius = 30, make_trail=True)
M = sphere(pos = E.pos + v, color = color.white,radius = 10, make_trail=True)
S = sphere(pos = vector(0,0,0), color = color.yellow, radius=700)
t = 0
thetaTerra1 = 0
dt = 5000
dthetaE = positionEarth(t+dt)- positionEarth(t)
dthetaM = positionMoon(t+dt) - positionMoon(t)
dthetaMa = positionMars(t+dt) - positionMars(t)
print("delta t:",dt,"seconds. Days:",fromStoDays(dt),"hours:",fromDaysToh(fromStoDays(dt)),sep=" ")
print("Variation angular position of the Earth:",dthetaE,"rad/s that's to say",degrees(dthetaE),"degrees",sep=" ")
print("Variation angular position of the Moon:",dthetaM,"rad/s that's to say",degrees(dthetaM),"degrees",sep=" ")
while t < seconds:
rate(500)
thetaEarth = positionEarth(t+dt)- positionEarth(t)
thetaMoon = positionMoon(t+dt) - positionMoon(t)
thetaMars = positionMars(t+dt) - positionMars(t)
# Rotation only around z axis (0,0,1)
E.pos = rotate(E.pos,angle=thetaEarth,axis=vector(0,1,0))
Ma.pos = rotate(Ma.pos,angle=thetaMars,axis=vector(0,1,0))
v = rotate(v,angle=thetaMoon,axis=vector(0,1,0))
M.pos = E.pos + v
t += dt
I am wondering How to change the path of orbit to elliptical?
I have tried several ways but I could not manage to find any solution.
Thank you.
Thank you
This seems like more of a physics issue as opposed to a programming issue. The problem is that you are assuming that each of the orbits are circular when calculating velocity and integrating position linearly (e.g v * dt). This is not how you would go about calculating the trajectory of an orbiting body.
For the case of simplicity, we will assume all the masses are point masses so there aren't any weird gravity gradients or attitude dynamics to account for.
From there, you can refer to this MIT page. (http://web.mit.edu/12.004/TheLastHandout/PastHandouts/Chap03.Orbital.Dynamics.pdf) on orbit dynamics. On the 7th page, there is an equation relating the radial position from your centerbody as a function of a multitude of orbital parameters. It seems like you have every parameter except the eccentricity of the orbit. You can either look that up online or calculate it if you have detailed ephemeral data or apoapsis/periapsis information.
From that equation, you will see a phi - phi_0 term in the denominator. That is colloquially known as the true anomaly of the satellite. Instead of time, you would iterate on this true anomaly parameter from 0 to 360 to find your radial distance, and from true anomaly, inclination, right angle to the ascending node, and the argument of periapses, you can find the 3D cartesian coordinates at a specific true anomaly.
Going from true anomaly is a little less trivial. You will need to find the eccentric anomaly and then the mean anomaly at each eccentric anomaly step. You now have mean anomaly as a function of time. You can linearly interpolate between "nodes" at which you calculate the position with v * dt. You can calculate the velocity from using the vis-viva equation and dt would be the difference between the calculated time steps.
At each time step you can update the satellite's position in your python program and it will properly draw your trajectories.
For more information of the true anomaly, wikipedia has a good description of it: https://en.wikipedia.org/wiki/True_anomaly
For more information about orbital elements (which are needed to convert from radial position to cartesian coordinates): https://en.wikipedia.org/wiki/Orbital_elements

Balls colliding - vPython problems

So I'm coding a snooker game, and I decided the best way to figure out how to make the balls collide with one another was to do so in a separate program then copy it in. I'm a pretty competent mathematician, so I've sat down, drawn the event and gone through the maths of what's actually happening.
My approach is to break each balls' initial velocity into xr- and yr-components, in a frame of reference in which the xr-component is in line with the vector through the center of each ball, and the yr-component is perpendicular to this. I then do a simple switch of the xr components of the balls and leave the yr components as they are, then calculate what the x- and y- components of the velocity are back in the standard reference frame.
For some reason, whether it be through mathematical or programming error, I can't seem to get it to work. The following is what I have so far and I have looked over virtually every related page on the internet I could find and all the similar-ish questions asked on this site. I'm not exactly a well versed programmer either.
from visual import *
dt = 0.01
r = 5
red = sphere(pos=(-25,25,0),radius = r,color=color.red)
green = sphere(pos=(25,-25,0),radius = r,color=color.green)
red.velocity = vector(10,-10,0)
green.velocity = vector(-10,10,0)
def posupdate(ball):
ball.pos = ball.pos + ball.velocity*dt
def ballhit(ball1,ball2):
v1 = ball1.velocity
v1x = ball1.velocity.x
v1y = ball1.velocity.y
v2 = ball2.velocity
v2x = ball2.velocity.x
v2y = ball2.velocity.y
xaxis = vector(1,0,0)
btb = ball2.pos - ball1.pos
nbtb = btb/abs(btb)
if abs(btb) < 2*r:
phi = acos(dot(nbtb,xaxis)/abs(nbtb)*abs(xaxis))
ang1 = acos(dot(v1,xaxis)/abs(v1)*abs(xaxis))
ang2 = acos(dot(v2,xaxis)/abs(v2)*abs(xaxis))
v1xr = abs(v1)*cos((ang1-phi))
v1yr = abs(v1)*sin((ang1-phi))
v2xr = abs(v2)*cos((ang2-phi))
v2yr = abs(v2)*sin((ang2-phi))
v1fxr = v2xr
v2fxr = v1xr
v1fyr = v1yr
v2fyr = v2yr
v1fx = cos(phi)*v1fxr+cos(phi+pi/2)*v1fyr
v1fy = sin(phi)*v1fxr+sin(phi+pi/2)*v1fyr
v2fx = cos(phi)*v2fxr+cos(phi+pi/2)*v2fyr
v2fy = sin(phi)*v2fxr+sin(phi+pi/2)*v2fyr
ball1.velocity.x = v1fx
ball1.velocity.y = v1fy
ball2.velocity.x = v2fx
ball2.velocity.y = v2fy
return ball1.velocity, ball2.velocity
while 1==1:
rate(100)
posupdate(red)
posupdate(green)
ballhit(red,green)
Thanks in advance for any help you can give.
Edit: The collision detection is no issue, just the calculation of the velocity vectors of the balls after the collision. Apologies, I should have made that clearer.
Check out Physics of Billiards:
Conservation of momentum applies and, assuming inelastic collisions, kinetic energy is conserved. So you get the following vector equations (subscripts _0 and _1 indicate before and after collision):
m1*v1_0 + m2*v2_0 = M1*v1_1 + m2*v2_1
0.5*m1*v1_0**2 + 0.5*m2*v2_0**2 = 0.5*m1*v1_1**2 + 0.5*m2*v2_1**2
Usually m1 == m2, so these simplify to:
v1_0 + v2_0 = v1_1 + v2_1
v1_0**2 + v2_0**2 = v1_1**2 + v2_1**2

Astrometry of a CCD image with python

I am trying to implement a really easy astrometry code. I have manually found the coordinates of a couple of stars in my picture (RA/DEC and x/y in pixel).
Everything seems straight forward but I still get weird results, that are off by a couple of degrees.
I am trying to solve for the plate constants of a CCD image I took, where I found the stars coordinates and position in the picture by hand and now I want to try and find the (0,0) point's real worlds coordinates.
I hope someone can help me with my code or can tell me how to do it properly.
Thanks a lot in advance!
Here is my code:
import numpy as np
import os
def astrometry(star_pos, xpix, ypix, focallength, target_RA, target_DEC):
pi = np.pi
DegToRad = pi / 180
RadToDeg = 180 / pi
n = len(star_pos)
(target_RA, target_DEC) = (target_RA, target_DEC)
print(target_RA, target_DEC)
# 1) Obtain star coordinates in pixel and RA/DEC
x_pix = [row[0] for row in star_pos]
y_pix = [row[1] for row in star_pos]
ra_star = [row[2] for row in star_pos]
dec_star = [row[3] for row in star_pos]
# 2) Calculate the standard coordinates of the stars
X_star = np.zeros(n)
Y_star = np.zeros(n)
for i in range(n):
X_star[i] = -(np.cos(DegToRad*dec_star[i])*np.sin(DegToRad*(ra_star[i] - target_RA)))/(np.cos(DegToRad*target_DEC)*np.cos(DegToRad*dec_star[i])*np.cos(DegToRad*(ra_star[i]-target_RA)) + np.sin(DegToRad*target_DEC)*np.sin(DegToRad*dec_star[i]))
Y_star[i] = -(np.sin(DegToRad*target_DEC)*np.cos(DegToRad*dec_star[i])*np.cos(DegToRad*(ra_star[i]-target_RA)) - np.cos(DegToRad*target_DEC)*np.sin(DegToRad*dec_star[i]))/(np.cos(DegToRad*target_DEC)*np.cos(DegToRad*dec_star[i])*np.cos(DegToRad*(ra_star[i]-target_RA)) + np.sin(DegToRad*target_DEC)*np.sin(DegToRad*dec_star[i]))
# 3) Calculate the plate constants (Check my notes)
def calc_plate_const(k,x,y,X):
c_down = ((x[k+1]-x[k])*(y[k]*x[k+2]-y[k+2]*x[k])-(x[k+2]-x[k])*(y[k]*x[k+1]-y[k+1]*x[k]))
c_up = (X[k]*x[k+1]*(y[k]*x[k+2]-y[k+2]*x[k])-X[k+1]*x[k]*(y[k]*x[k+2]-y[k+2]*x[k])-X[k]*x[k+2]*(y[k]*x[k+1]-y[k+1]*x[k])-X[k+2]*x[k]*(y[k]*x[k+1]-y[k+1]*x[k]))
c = c_up/c_down
print('c',c)
b = ((X[k]*x[k+1]-X[k+1]*x[k])-(x[k+1]-x[k])*c)/(y[k]*x[k+1]-y[k+1]*x[k])
print('b',b)
a = (X[k]-b*y[k]-c)/x[k]
print('a', a)
return(a,b,c)
(a,b,c) = calc_plate_const(0,x_pix,y_pix,X_star)
(d,e,f) = calc_plate_const(0,x_pix,y_pix,Y_star)
print(target_RA,target_DEC)
# 4) Calculate the standard coordinates for the object
# HIER object at (0,0)
(x_ob, y_ob) = (0,0)
X_ob = a*x_ob + b*y_ob + c
Y_ob = d*x_ob + e*y_ob + f
print('x', x_pix, x_ob, 'y', y_pix, y_ob)
print('X', X_star, X_ob, 'Y', Y_star, Y_ob)
print('RA', ra_star, 'DEC', dec_star)
# 5) Calculate the RA/DEC of the objects standard coordinates
a = target_RA + np.arctan(DegToRad*((-X_ob)/(np.cos(DegToRad*target_DEC)- Y_ob*np.sin(DegToRad*target_DEC))))
d = target_DEC - np.arcsin(DegToRad*((np.sin(DegToRad*target_DEC) + Y_ob*np.cos(DegToRad*target_DEC))/(np.sqrt(1 + X_ob**2 + Y_ob**2))))
print('RA in rad', a, 'DEC in rad', d)
print('RA',a,target_RA, 'DEC',d, target_DEC)
return(a,d)
The Input is for example an array with the stars position in pixel of the image and degree of the real world
star pos = [[1948.2, 1205.8, 132.34058333333334, -3.4429722222222225], [153.90000000000001, 1892.5, 131.08620833333333, -5.0947499999999994]
# star_pos [x_pos in pix, y_pos in pix, RA, DEC]
(x_pix, y_pix) = (0.0135, 0.0135)
# pixel size
focallength = 0.7168
(target_RA, target_DEC) = (131.683014444 -3.91890194444)
# But I am not sure how accurate that is, it is more of an assumption. I would say if I look at the star map manually, it looks quite a bit off...
I would expect to see for the (0,0) point RA to be around 133° and DEC -5.75°

Categories