def test_cases_from_file_e2e(self,value): t = 456.63e3 u = np.asarray(value) result = fr.ecef2ecif(u,t) self.assertTrue(type(result),np.ndarray) t = t + (EPOCH - EQUINOX).total_seconds() v = np.array([cos(W_EARTH*t)*value[0]-sin(W_EARTH*t)*value[1],cos(W_EARTH*t)*value[1]+sin(W_EARTH*t)*value[0],value[2]]) self.assertTrue(np.allclose(result,v))
def m_dFdT(v_pos_dL_b, v_dL_cap_i, v_v_sat_i, q, t, dL): qi = qnv.quatInv(q) v_pos_dL_i = qnv.quatRotate(q, v_pos_dL_b) height = np.linalg.norm(v_pos_dL_i) - R height = height / 1e3 v_pos_dL_e = fs.ecif2ecef(v_pos_dL_i, t) lat, lon = fs.latlon(v_pos_dL_e.reshape((3, ))) B = runigrf12(day, 0, 1, height, lat, lon) v_B_n = np.vstack((B[0], B[1], B[2])) v_B_n = v_B_n * 1e-9 #convert from nT to T v_B_e = fs.ned2ecef(v_B_n.reshape((3, )), lat, lon) v_dL_cap_e = fs.ecif2ecef(v_dL_cap_i, t) v_v_sat_e = fs.ecif2ecef(v_v_sat_i, t) e = qnv.dot1(qnv.cross1(v_v_sat_e, v_B_e), v_dL_cap_e) i = e / mu_r v_dF_e = dL * i * qnv.cross1(v_dL_cap_e, v_B_e) v_dF_i = fs.ecef2ecif(v_dF_e, t) v_dF_b = qnv.quatRotate(qi, v_dF_i) v_dL_cap_b = v_L_b / np.linalg.norm(v_L_b) v_dT_b = qnv.cross1(v_dL_cap_b, v_dF_b) return v_dF_i, dL * v_dT_b
import numpy as np import frames as fs ''' This code takes magnetic field in North-East-Down frame (in nT) and transforms it to ECI frame. ''' m_mag_ned = np.genfromtxt('mag_output_ned.csv', delimiter=",") #in nT m_LLA = np.genfromtxt( 'LLA.csv', delimiter="," ) #Lat and Lon in degrees and altitude in m (check frames.latlon for details) N = m_mag_ned.shape[0] #returns no. of rows in m_mag_ned m_mag_i = np.zeros([N, 4]) for k in range(N): T = m_mag_ned[k, 0] m_mag_ecef = fs.ned2ecef(m_mag_ned[k, 1:4].copy(), m_LLA[k, 1], m_LLA[k, 2]) m_mag_i[k, 0] = T m_mag_i[k, 1:4] = fs.ecef2ecif(m_mag_ecef.copy(), T) np.savetxt('mag_output_i.csv', m_mag_i, delimiter=",") print("inertial magnetic field in nano-tesla")
def test_inverse(self): t = 53e2 u = np.array([-1.0, -5.0, 5e6]) v = fr.ecef2ecif(fr.ecif2ecef(u, t), t) self.assertTrue(np.allclose(u, v))
import numpy as np import frames as fs ''' This code takes magnetic field in North-East-Down (NED) frame (in nT) and transforms it to ECI frame. Output - magnetic field in ECI Frame in nanoTesla. ''' m_mag_ned = np.genfromtxt('mag_output_ned.csv', delimiter=",") #in nT m_LLA = np.genfromtxt( 'LLA.csv', delimiter="," ) #Lat and Lon in degrees and altitude in m (check frames.latlon for details) N = m_mag_ned.shape[0] #To get number of rows in array m_mag_ned m_mag_i = np.zeros( [N, 4] ) #no. of rows same as matrix storing NED values, 4 columns for time and 3 components of magnetic field data in ECI frame for k in range(N): T = m_mag_ned[k, 0] m_mag_ecef = fs.ned2ecef( m_mag_ned[k, 1:4].copy(), m_LLA[k, 1], m_LLA[k, 2] ) #calling function of frame which does the conversion from NED to ECEF (Earth centered, Earth fixed frame m_mag_i[k, 0] = T m_mag_i[k, 1:4] = fs.ecef2ecif( m_mag_ecef.copy(), T ) #calling function of frame which does the conversion from ECEF to ECIF np.savetxt('mag_output_i.csv', m_mag_i, delimiter=",") print("inertial magnetic field in nano-tesla")