dstl / Stone-Soup

A software project to provide the target tracking community with a framework for the development and testing of tracking algorithms.
https://stonesoup.rtfd.io
MIT License
403 stars 134 forks source link

Orbital_functions: Keplerian_to_tv ValueError #689

Closed victorzheng1 closed 2 years ago

victorzheng1 commented 2 years ago

File ~\spc_env\Scripts\notebooks\Orbital.py:384, in keplerian_to_rv(state_vector, grav_parameter) 379 vx = perifocal_velocity(state_vector[0], state_vector[1], state_vector[5], 380 grav_parameter=grav_parameter) 382 # Transform position (perifocal) and velocity (perifocal) 383 # into geocentric --> 384 r = perifocal_to_geocentric_matrix(state_vector[2], state_vector[3], state_vector[4]) @ rx 386 v = perifocal_to_geocentric_matrix(state_vector[2], state_vector[3], state_vector[4]) @ vx 388 # And put them into the state vector

ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 3 is different from 1)

victorzheng1 commented 2 years ago

Recreated this bug with Matlab's official code translated into Python:

function [r,v] = oe2rv(a,e,i,lan,w,nu) % Reference: Bate, Mueller & White, Fundamentals of Astrodynamics Sec 2.5

mu = 398600.4405*1e9; % m^3 s^-2

% Express r and v in perifocal system cnu = cosd(nu); snu = sind(nu); p = a(1 - e^2); r = p/(1 + ecnu); r_peri = [rcnu ; rsnu ; 0]; v_peri = sqrt(mu/p)*[-snu ; e + cnu ; 0];

% Tranform into Geocentric Equatorial frame clan = cosd(lan); slan = sind(lan); cw = cosd(w); sw = sind(w); ci = cosd(i); si = sind(i); R = [ clancw-slanswci , -clansw-slancwci , slansi; ... slancw+clanswci , -slansw+clancwci , -clansi; ... swsi , cwsi , ci]; r = Rr_peri; v = Rv_peri; end


ValueError Traceback (most recent call last) Input In [1], in <cell line: 21>() 19 debris_states = [] 21 for i in range(1,numDebris): ---> 22 debris_states.append(StateVector(oe2rv(rng[i], ecc[i], inc[i], lan[i], w[i], nu[i]))) 24 debris_states

File ~\spc_env\Scripts\notebooks\oe2rv.py:27, in oe2rv(a, e, i, lan, w, nu) 23 si = np.sin(i) 24 R = np.array([ clancw-slanswci , -clansw-slancwci , slansi, 25 slancw+clanswci , -slansw+clancwci , -clansi, 26 swsi , cwsi , ci]) ---> 27 r = np.matmul(R,r_peri) 28 v = np.matmul(R,v_peri) 29 return r,v

ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 3 is different from 1)