Example #1
0
def format_long_line(satrec, mu, r, v):
    """Long line, using the same format string that testcpp.cpp uses."""

    short = format_short_line(satrec, r, v).strip("\n")

    jd = satrec.jdsatepoch + satrec.t / 1440.0
    year, mon, day, hr, minute, sec = invjday(jd)

    (p, a, ecc, incl, node, argp, nu, m, arglat, truelon, lonper) = rv2coe(r, v, mu)

    return short + (" %14.6f %8.6f %10.5f %10.5f %10.5f %10.5f %10.5f" " %5i%3i%3i %2i:%2i:%9.6f\n") % (
        a,
        ecc,
        incl * rad,
        node * rad,
        argp * rad,
        nu * rad,
        m * rad,
        year,
        mon,
        day,
        hr,
        minute,
        sec,
    )
Example #2
0
def format_long_line(satrec, tsince, mu, r, v):
    """Long line, using the same format string that testcpp.cpp uses."""

    short = format_short_line(tsince, r, v).strip('\n')

    jd = satrec.jdsatepoch + satrec.jdsatepochF + tsince / 1440.0
    year, mon, day, hr, minute, sec = invjday(jd)

    (p, a, ecc, incl, node, argp, nu, m, arglat, truelon,
     lonper) = rv2coe(r, v, mu)

    return short + (' %14.6f %8.6f %10.5f %10.5f %10.5f %10.5f %10.5f'
                    ' %5i%3i%3i %2i:%2i:%9.6f\n') % (
                        a,
                        ecc,
                        incl * rad,
                        node * rad,
                        argp * rad,
                        nu * rad,
                        m * rad,
                        year,
                        mon,
                        day,
                        hr,
                        minute,
                        sec,
                    )
 def Position_and_Velocity(self, time):
   '''This function generates the barycentric position and velocity of
   the orbital body at a specified time with the use of the
   SGP4 propogator.'''
   #The time to find the position and velocity at
   t = time
   #The first line of the orbital body's TLE
   line1 = self.TLE_line1
   #The second line of the orbital body's TLE
   line2 = self.TLE_line2
   #Fictitiously instantiate a SGP4 satellite object
   sat = twoline2rv(line1, line2, gravity_constant)
   #Convert Julian date to conventional
   time_conv = invjday(time)
   #Compute the geocentric position and velocity of the orbital body
   p, v = sat.propagate(*time_conv)
   #Turn the tuples into arrays
   p = np.asarray(p)
   v = np.asarray(v)
   #Convert km to m
   p = p * 1e3
   #Convert km/s to m/s
   v = v * 1e3
   #Compute the barycentric position and velocity of the attracting body
   P, V = self.attracting_body.Position_and_Velocity(time)
   #Compute the barycentric position of the orbital body
   p = p + P
   #compute the barycentric velocity of the orbital body
   v = v + V
   return p, v
Example #4
0
def VMS_Julian2Time(inJul, format='%Y%m%d%H%M%S'):

    tFormat = format  #"%d-%b-%Y %H:%M:%S"
    try:  #see if it is a list
        for i in inJul:
            a = invjday(i)
            aTime = dt.datetime.timetuple(
                dt.datetime(a[0], a[1], a[2], a[3], a[4], int(a[5])))
            aStr = time.strftime(tFormat, aTime)
            try:
                out.append(aStr)
            except:
                out = [aStr]
        return out
    except:  #a single shot
        a = invjday(inJul)
        aTime = dt.datetime.timetuple(
            dt.datetime(a[0], a[1], a[2], a[3], a[4], int(a[5])))
        return time.strftime(tFormat, aTime)
Example #5
0
    def sgp4init(self, whichconst, opsmode, satnum, epoch, bstar,
                 ndot, nddot, ecco, argpo, inclo, mo, no_kozai, nodeo):
        whichconst = gravity_constants[whichconst]

        y, m, d, H, M, S = invjday(epoch + 2433281.5)
        jan0epoch = jday(y, 1, 0, 0, 0, 0.0) - 2433281.5

        self.epochyr = y % 1000
        self.epochdays = epoch - jan0epoch
        self.jdsatepoch, self.jdsatepochF = divmod(epoch, 1.0)
        self.jdsatepoch += 2433281.5

        sgp4init(whichconst, opsmode, satnum, epoch, bstar, ndot, nddot,
                 ecco, argpo, inclo, mo, no_kozai, nodeo, self)
def envicosmos(tle1,tle2):
    whichconst = 'wgs72'
    #whichconst = wgs72

    f1=open(tle1+'.tle')
    f2=open(tle2+'.tle')
    out1=open('envi.sal','w+')
    out2=open('cosmos.sal','w+')

    archivos=[f1,f2]
    

    var=0
    for tlefile in archivos:
        var = var + 1
        tlelines = iter(tlefile.readlines())
        for line1 in tlelines:
            if not line1.startswith('1'):
                continue 
            line2 = next(tlelines) 
            satrec = twoline2rv(line1, line2, whichconst) # es un objeto de clase (satelite)
            mu = satrec.whichconst.mu
            epocatle=satrec.jdsatepoch
            print 'epoca del tle [jd] = ', epocatle
            jdini=jday(2008,1,9,18,0,0.0) 
            tini=(jdini-epocatle)*1440.0
            print(tini)
            tintervalo=np.arange(0,7200,1) 
            for t1 in tintervalo:
                t=tini+t1/60.0 
                r, v = sgp4(satrec, t)
                tjd=epocatle+t/1440.0 # dia juliano correspondiente al t en min.

            
                """Impresion de salida"""
                year, mon, day, hr, minute, sec = invjday(tjd)
                fecha = str(year)+'/'+str(mon)+'/'+str(day)+' '+str(hr)+':'+\
                    str(minute)+':'+str(sec)+' '+str(tjd)+' '+str(r[0])+' '+\
                    str(r[1])+' '+str(r[2])+' '+str(v[0])+' '+\
                    str(v[1])+' '+str(v[2])+'\n'
                if var == 1: 
                    out1.write(fecha)
                else:
                    out2.write(fecha)

#    year2,mon2,day2,hr2,minu2,sec2=invjday(2454475.29201)
#    print year2,mon2,day2,hr2,minu2,sec2
        """
Example #7
0
    def test_jday(self):
        print("jday...")
        jd = 2454115.05486 # Sunday 14 January 2007 at 13:18:59.9 

        # Reference Astropy as "answer"
        t_astropy = Time(jd, format='jd')

        jdF = jd-int(jd)
        jd  = int(jd)

        jday_datetime = jday_to_datetime(jd, jdF)
        self.assertRegex(jday_datetime.isoformat(sep=' ',timespec='milliseconds'),t_astropy.iso,msg="jday_to_datetime() failed")

        (year, month, day, hour, minute, second) = invjday(jd)
        jday_jd = jday(year, month, day, hour, minute, second)
        self.assertEqual(jday_jd,jd,"jday() failed")
Example #8
0
def Position_and_Velocity_Satellite(satellite, time):
    # The first line of the TLE
    line1 = satellite.line1
    # The second line
    line2 = satellite.line2
    # Fictitious SGP4 satellite object
    sat = twoline2rv(line1, line2, grav_const)
    # Convert Julian date to conventional
    time_conv = invjday(time)
    # The position and velocity of the satellite
    pv = np.asarray(sat.propagate(*time_conv))
    # Convert km to m and km/s to m/s
    pv = np.multiply(pv, 1e3)
    # The attracting body ephemeris
    PV = satellite.attracting_body.Position_and_Velocity(time)
    # Convert from geocentric to barycentric frame
    pv = np.add(pv, PV)
    return pv
Example #9
0
def twoline2rv(longstr1, longstr2, whichconst, opsmode='i', satrec=None):
    """Return a Satellite imported from two lines of TLE data.

    Provide the two TLE lines as strings `longstr1` and `longstr2`,
    and select which standard set of gravitational constants you want
    by providing `gravity_constants`:

    `sgp4.earth_gravity.wgs72` - Standard WGS 72 model
    `sgp4.earth_gravity.wgs84` - More recent WGS 84 model
    `sgp4.earth_gravity.wgs72old` - Legacy support for old SGP4 behavior

    Normally, computations are made using various recent improvements
    to the algorithm.  If you want to turn some of these off and go
    back into "opsmode" mode, then set `opsmode` to `a`.

    """

    deg2rad = pi / 180.0
    #    0.0174532925199433
    xpdotp = 1440.0 / (2.0 * pi)
    #  229.1831180523293

    # For compatibility with our 1.x API, build an old Satellite object
    # if the caller fails to supply a satrec.  In that case we perform
    # the necessary import here to avoid an import loop.
    if satrec is None:
        from sgp4.model import Satellite
        satrec = Satellite()

    satrec.error = 0
    satrec.whichconst = whichconst  # Python extension: remembers its consts

    line = longstr1.rstrip()

    if (len(line) >= 64 and line.startswith('1 ') and line[8] == ' '
            and line[23] == '.' and line[32] == ' ' and line[34] == '.'
            and line[43] == ' ' and line[52] == ' ' and line[61] == ' '
            and line[63] == ' '):

        _saved_satnum = satrec.satnum = _alpha5(line[2:7])
        satrec.classification = line[7] or 'U'
        satrec.intldesg = line[9:17].rstrip()
        two_digit_year = int(line[18:20])
        satrec.epochdays = float(line[20:32])
        satrec.ndot = float(line[33:43])
        satrec.nddot = float(line[44] + '.' + line[45:50])
        nexp = int(line[50:52])
        satrec.bstar = float(line[53] + '.' + line[54:59])
        ibexp = int(line[59:61])
        satrec.ephtype = line[62]
        satrec.elnum = int(line[64:68])
    else:
        raise ValueError(error_message.format(1, LINE1, line))

    line = longstr2.rstrip()

    if (len(line) >= 69 and line.startswith('2 ') and line[7] == ' '
            and line[11] == '.' and line[16] == ' ' and line[20] == '.'
            and line[25] == ' ' and line[33] == ' ' and line[37] == '.'
            and line[42] == ' ' and line[46] == '.' and line[51] == ' '):

        satrec.satnum = _alpha5(line[2:7])
        if _saved_satnum != satrec.satnum:
            raise ValueError('Object numbers in lines 1 and 2 do not match')

        satrec.inclo = float(line[8:16])
        satrec.nodeo = float(line[17:25])
        satrec.ecco = float('0.' + line[26:33].replace(' ', '0'))
        satrec.argpo = float(line[34:42])
        satrec.mo = float(line[43:51])
        satrec.no_kozai = float(line[52:63])
        satrec.revnum = line[63:68]
    #except (AssertionError, IndexError, ValueError):
    else:
        raise ValueError(error_message.format(2, LINE2, line))

    #  ---- find no, ndot, nddot ----
    satrec.no_kozai = satrec.no_kozai / xpdotp
    #   rad/min
    satrec.nddot = satrec.nddot * pow(10.0, nexp)
    satrec.bstar = satrec.bstar * pow(10.0, ibexp)

    #  ---- convert to sgp4 units ----
    satrec.ndot = satrec.ndot / (xpdotp * 1440.0)
    #   ? * minperday
    satrec.nddot = satrec.nddot / (xpdotp * 1440.0 * 1440)

    #  ---- find standard orbital elements ----
    satrec.inclo = satrec.inclo * deg2rad
    satrec.nodeo = satrec.nodeo * deg2rad
    satrec.argpo = satrec.argpo * deg2rad
    satrec.mo = satrec.mo * deg2rad
    """
    // ----------------------------------------------------------------
    // find sgp4epoch time of element set
    // remember that sgp4 uses units of days from 0 jan 1950 (sgp4epoch)
    // and minutes from the epoch (time)
    // ----------------------------------------------------------------

    // ---------------- temp fix for years from 1957-2056 -------------------
    // --------- correct fix will occur when year is 4-digit in tle ---------
    """
    if two_digit_year < 57:
        year = two_digit_year + 2000
    else:
        year = two_digit_year + 1900

    mon, day, hr, minute, sec = days2mdhms(year, satrec.epochdays)
    sec_whole, sec_fraction = divmod(sec, 1.0)

    satrec.epochyr = year
    satrec.jdsatepoch = jday(year, mon, day, hr, minute, sec)
    try:
        satrec.epoch = datetime(year, mon, day, hr, minute, int(sec_whole),
                                int(sec_fraction * 1000000.0 // 1.0))
    except ValueError:
        # Sometimes a TLE says something like "2019 + 366.82137887 days"
        # which would be December 32nd which causes a ValueError.
        year, mon, day, hr, minute, sec = invjday(satrec.jdsatepoch)
        satrec.epoch = datetime(year, mon, day, hr, minute, int(sec_whole),
                                int(sec_fraction * 1000000.0 // 1.0))

    #  ---------------- initialize the orbit at sgp4epoch -------------------
    sgp4init(whichconst, opsmode, satrec.satnum, satrec.jdsatepoch - 2433281.5,
             satrec.bstar, satrec.ndot, satrec.nddot, satrec.ecco,
             satrec.argpo, satrec.inclo, satrec.mo, satrec.no_kozai,
             satrec.nodeo, satrec)

    return satrec
 def jd2Date(self, jd):
     return invjday(jd)
Example #11
0
def datetime_from_jday(jd, fr):
    year, mon, day, hr, minute, sec_float = invjday(jd + fr)
    sec = int(sec_float)
    microsec = int((sec_float - sec) * 1e6)
    return dt.datetime(year, mon, day, hr, minute, sec, microsec)
Example #12
0
def julian2dt(julday):
    return invjday(inJul)