Source code for nicer.mcc

"""ISS position from an MCC (Mission Control Center) ephemeris file."""

import numpy as np
import astropy.units as u
from astropy.time import Time
from scipy.interpolate import InterpolatedUnivariateSpline
from astropy.coordinates import (
    GCRS,
    ITRS,
    EarthLocation,
    CartesianRepresentation,
    get_body_barycentric_posvel,
)

from nicer.values import *

# Enable imperial units for MCC!
u.imperial.enable()


[docs] class MCC: """Interpolate the ISS position from an MCC ephemeris. The ephemeris gives ECI positions in feet; these are interpolated with splines and converted to latitude and longitude with astropy. Times outside the ephemeris raise an error. Parameters ---------- mccname : str MCC ephemeris file. """ def __init__(self, mccname): with open(mccname) as mccfile: header1 = mccfile.readline().strip() header2 = mccfile.readline().strip() self.mcc_epoch_year = float(header2.split()[0]) self.mcc_epoch = Time( "{0:4.0f}-01-01T00:00:00".format(self.mcc_epoch_year), format="isot", scale="utc", ) cols = np.loadtxt(mccfile, usecols=(0, 1, 2, 3), unpack=True) self.t = cols[0] * u.s + self.mcc_epoch self.met = (self.t - MET0).to(u.s).value self.eci_x = (cols[1] * u.imperial.foot).to(u.m) self.eci_y = (cols[2] * u.imperial.foot).to(u.m) self.eci_z = (cols[3] * u.imperial.foot).to(u.m) self.eci_x_interp = InterpolatedUnivariateSpline( self.met, self.eci_x, ext="raise" ) self.eci_y_interp = InterpolatedUnivariateSpline( self.met, self.eci_y, ext="raise" ) self.eci_z_interp = InterpolatedUnivariateSpline( self.met, self.eci_z, ext="raise" ) # Convert ECI positions to lat, long using astropy cart = CartesianRepresentation(self.eci_x, self.eci_y, self.eci_z) eci = GCRS(cart, obstime=self.t) ecef = eci.transform_to(ITRS(obstime=self.t)) self.lat = ecef.earth_location.lat self.lon = ecef.earth_location.lon
[docs] def latlon(self, met): """Return the interpolated latitude and longitude. Parameters ---------- met : float or array_like Time(s), in MET seconds. Returns ------- lat : astropy.coordinates.Latitude lon : astropy.coordinates.Longitude """ x = self.eci_x_interp(met) y = self.eci_y_interp(met) z = self.eci_z_interp(met) cart = CartesianRepresentation(x, y, z, unit=u.m) eci = GCRS(cart, obstime=MET0 + met * u.s) ecef = eci.transform_to(ITRS(obstime=MET0 + met * u.s)) lat = ecef.earth_location.lat lon = ecef.earth_location.lon return (lat, lon)
[docs] def plot(self): """Plot the ECI x, y and z positions against time.""" import matplotlib.pyplot as plt plt.plot(self.met, self.eci_x) plt.plot(self.met, self.eci_y) plt.plot(self.met, self.eci_z) plt.show()