Пример #1
0
 def test(self):
     a = gpstk.CommonTime()
     a.addDays(1234)
     b = gpstk.CommonTime(a)
     b.addSeconds(123.4)
     c = b - a
     self.assertAlmostEqual(1234.0, a.getDays())
     self.assertEqual('0001234 00000000 0.000000000000000 UNK', str(a))
     self.assertAlmostEqual(1234.0014282407408, b.getDays())
     self.assertEqual('0001234 00123400 0.000000000000000 UNK', str(b))
     self.assertAlmostEqual(123.4, c)
Пример #2
0
 def test_times_gen(self):
     start = gpstk.CommonTime()
     start.addSeconds(100.0)
     end = gpstk.CommonTime()
     end.addSeconds(900.0)
     times = gpstk.times(start, end, seconds=200.0)
     self.assertEqual(100.0, times.next().getSecondOfDay())
     self.assertEqual(300.0, times.next().getSecondOfDay())
     self.assertEqual(500.0, times.next().getSecondOfDay())
     self.assertEqual(700.0, times.next().getSecondOfDay())
     self.assertEqual(900.0, times.next().getSecondOfDay())
     self.assertRaises(StopIteration, times.next)
Пример #3
0
 def test(self):
     t1 = gpstk.CommonTime()
     t2 = gpstk.CommonTime()
     t2.addDays(1)
     t3 = gpstk.CommonTime()
     t3.addSeconds(60)
     obs = gpstk.ObsID(gpstk.ObsID.otRange, gpstk.ObsID.cbAny, gpstk.ObsID.tcA)
     b = gpstk.BrcKeplerOrbit('GPS', obs, 10, t1, t2, t3,
                        5, True, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                        0.0, 1.1, 0.0, 0.0, 0.0, 0.0, 0.0, 1.2, 1.3, 0.0)
     self.assertEqual(1.1, b.getEcc())
     self.assertEqual(1.2, b.getW())
     self.assertEqual(1.3, b.getOmegaDot())
Пример #4
0
 def test_times_gen(self):
     start = gpstk.CommonTime()
     start.addSeconds(100.0)
     end = gpstk.CommonTime()
     end.addSeconds(900.0)
     times = gpstk.times(start, end, seconds=200.0)
     self.assertEqual(100.0, next(times).getSecondOfDay())
     self.assertEqual(300.0, next(times).getSecondOfDay())
     self.assertEqual(500.0, next(times).getSecondOfDay())
     self.assertEqual(700.0, next(times).getSecondOfDay())
     self.assertEqual(900.0, next(times).getSecondOfDay())
     if sys.version_info[0] < 3:
         self.assertRaises(StopIteration, times.next)
     else:
         self.assertRaises(StopIteration, times.__next__)
Пример #5
0
    def test_times_list(self):
        start = gpstk.CommonTime()
        start.addSeconds(100.0)
        end = gpstk.CommonTime()
        end.addSeconds(900.0)
        times = list(gpstk.times(start, end, seconds=200.0))
        self.assertEqual(100.0, times[0].getSecondOfDay())
        self.assertEqual(300.0, times[1].getSecondOfDay())
        self.assertEqual(500.0, times[2].getSecondOfDay())
        self.assertEqual(700.0, times[3].getSecondOfDay())
        self.assertEqual(900.0, times[4].getSecondOfDay())

        times = list(gpstk.times(start, end))
        self.assertEqual(2, len(times))
        self.assertEqual(times[0], start)
        self.assertEqual(times[1], end)
Пример #6
0
    def test_equal_common_times(self):
        timeSystem = gpstk.TimeSystem('GPS')

        t1 = gpstk.CommonTime(timeSystem)
        t1.addDays(3)

        t2 = gpstk.CommonTime(timeSystem)
        t2.addSeconds(2 * gpstk.constants.SEC_PER_DAY)  # add 2 days
        t2 += (2 * gpstk.constants.SEC_PER_DAY)  # add 2 more days
        t2 -= (1 * gpstk.constants.SEC_PER_DAY)  # subtract a day

        self.assertEqual(False, t1 < t2)
        self.assertEqual(True, t1 <= t2,)
        self.assertEqual(False, t1 > t2)
        self.assertEqual(True, t1 >= t2)
        self.assertEqual(True, t1 == t2)
        self.assertEqual(False, t1 != t2)
Пример #7
0
 def test_ephemeris(self):
     g = gpstk.GloEphemeris()
     g.setRecord('mySys', 1, gpstk.CommonTime(), gpstk.Triple(100, 200, 300),
         gpstk.Triple(10, 20, 30), gpstk.Triple(1, 2, 3),
         0.0,  0.0, 1, 2, 3, 1.1, 1.0)
     expected = ("Sys:mySys, PRN:1, Epoch:0000000 00000000 0.000000000000000 UNK, pos:(100, 200, 300), "
         "vel:(10, 20, 30), acc:(1, 2, 3), TauN:0, GammaN:0, MFTime:1, health:2, freqNum:3, ageOfInfo:1.1")
     self.assertEqual(expected, str(g))
Пример #8
0
def main():
    # Read in data, strict=True makes dataSets a list rather than a generator:
    header, dataSets = gpstk.readSEM('sem_data.txt', strict=True)

    # Write the data back to a different file (their contents should match):
    gpstk.writeSEM('sem_data.txt.new', header, dataSets)

    # Read the orbit out of the data:
    orbit = dataSets[0].toAlmOrbit()  # alm orbit of first data point

    austin = gpstk.Position(30, 97, 0, gpstk.Position.Geodetic)  # Austin, TX

    starttime = gpstk.CommonTime()  # iterator time to start at
    starttime.setTimeSystem(gpstk.TimeSystem('GPS'))
    endtime = gpstk.CommonTime()  # end time, 1 day later (see below)
    endtime.setTimeSystem(gpstk.TimeSystem('GPS'))
    endtime.addDays(1)

    X = []
    Y = []

    # Step through a day, adding plot points:
    for t in gpstk.times(starttime, endtime, seconds=1000):
        xvt = orbit.svXvt(t)
        location = gpstk.Position(xvt.x)
        elevation = austin.elevation(location)
        X.append(t.getDays())
        Y.append(elevation)

    # Make the plot
    fig = plt.figure()
    fig.suptitle('Elevation of a GPS satellite throughout the day',
                 fontsize=14,
                 fontweight='bold')
    ax = fig.add_subplot(111)
    ax.set_xlabel('Time (days)')
    ax.set_ylabel('Elevation (degrees)')
    plt.plot(X, Y, 'r')
    plt.show()
Пример #9
0
 def test_stream(self):
     header, data = gpstk.readRinex3Obs('rinex3obs_data.txt', strict=True)
     self.assertEqual(0L, header.numSVs)
     self.assertEqual('NATIONAL IMAGERY AND MAPPING AGENCY', header.agency)
     self.assertEqual(120, len(data))
     dataPoint = data[0]
     datum = dataPoint.getObs(gpstk.SatID(4), header.getObsIndex("C1"))
     self.assertAlmostEqual(24236698.057, datum.data)
     self.assertEqual(0, dataPoint.clockOffset)
     expectedTime = gpstk.CommonTime()
     expectedTime.set(2453167)
     expectedTime.setTimeSystem(gpstk.TimeSystem(gpstk.TimeSystem.GPS))
     self.assertEqual(expectedTime, dataPoint.time)
Пример #10
0
 def test_functions(self):
     c = gpstk.CommonTime()
     c.addSeconds(12345678)
     self.assertAlmostEqual(10.934294925420545, gpstk.UTC2SID(c))
Пример #11
0
def process(input_file, output_file):
    try:
        print 'Reading {}.'.format(input_file)
        header, data = gpstk.readRinex3Obs(input_file)  # read in everything
        #print header

        new_header = gpstk.Rinex3ObsHeader()

        # Initially, valid = 0L, but other values get masked into it.
        new_header.version = header.version
        new_header.fileType = header.fileType
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validVersion

        new_header.fileProgram = header.fileProgram
        new_header.date = header.date
        new_header.fileAgency = header.fileAgency
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validRunBy

        new_header.markerName = header.markerName
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validMarkerName

        new_header.observer = header.observer
        new_header.agency = header.agency
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validObserver

        new_header.recNo = header.recNo
        new_header.recType = header.recType
        new_header.recVers = header.recVers
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validReceiver

        new_header.antNo = header.antNo
        new_header.antType = header.antType
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validAntennaType

        newAntPosition = gpstk.Triple(header.antennaPosition[0],
                                      header.antennaPosition[1],
                                      header.antennaPosition[2])
        new_header.antennaPosition = newAntPosition
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validAntennaPosition

        newAntDelta = gpstk.Triple(header.antennaDeltaHEN[0],
                                   header.antennaDeltaHEN[1],
                                   header.antennaDeltaHEN[2])
        new_header.antennaDeltaHEN = newAntDelta
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validAntennaDeltaHEN

        # This is kind of odd.  The Rinex3ObsHeader can handle both V3 and V2
        # formatted files.  The two versions handle observation types differently.
        # - The first structure "mapObsTypes" holds the V3 definitions in a
        # "dictionary of lists" (or "map of vectors" in c++)
        # - The second structure "R2ObsTypes" holds the V2 definitions and is
        # stored as list of strings (or Vector of Strings in c++)
        # It's not clear whether either or both are necessary to write a file.
        # It DOES seem to be clear that both will be available after reading a file.

        for rinObsType in header.mapObsTypes:
            #print "Found obs-type:{}".format(rinObsType)
            newObsIds = []
            for rinObsId in header.mapObsTypes[rinObsType]:
                #print "Found obs-id:{}".format(str(rinObsId))
                #print " --type={} code={} band={}".format(rinObsId.type, rinObsId.code, rinObsId.band)
                newObsId = gpstk.RinexObsID(str(rinObsId))
                newObsIds.append(newObsId)
            new_header.mapObsTypes[rinObsType] = tuple(newObsIds)
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validNumObs

        for rin_obs_id in header.R2ObsTypes:
            #print "Found obs-id:{}".format(rin_obs_id)
            new_header.R2ObsTypes.append(rin_obs_id)
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validNumObs

        # This creates a new CivilTime object that we can populate
        new_header.firstObs = gpstk.CivilTime()
        new_header.firstObs.year = header.firstObs.year
        new_header.firstObs.month = header.firstObs.month
        new_header.firstObs.day = header.firstObs.day
        new_header.firstObs.hour = header.firstObs.hour
        new_header.firstObs.minute = header.firstObs.minute
        new_header.firstObs.second = header.firstObs.second
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validFirstTime

        new_header.markerNumber = header.markerNumber
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validMarkerNumber

        new_header.interval = header.interval
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validInterval

        #####
        # Unfortunately, sigStrengthUnit is tied to the wavelengthFactor property,
        # We cannot set the latter due to a missing SWIG Python adapter, and
        # because the same "validity flag" governs both, we can't output
        # sigStrengthUnit without inadvertently outputting a bogus wavelengthFactor.
        #####
        #new_header.wavelengthFactor = header.wavelengthFactor
        #new_header.sigStrengthUnit = header.sigStrengthUnit
        #new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validSigStrengthUnit

        for comment in header.commentList:
            new_header.commentList.append(comment)
        new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validComment

        new_header.validEoH = True

        # This method is a huge hack to get around a problem in the Rinex3ObsData
        # writer.  See the method for details.
        new_header = tweakInternalHeaderState(new_header)
        #print new_header

        processed_data = []
        # Now we loop through all the epochs and process the data for each one
        for d in data:

            # This creates a new CommonTime object with the system set to GPS.
            timec = gpstk.CommonTime(gpstk.TimeSystem(gpstk.TimeSystem.GPS))
            # This creates a new CommonTime object with the system set to GPS.
            mjd = int(d.time.getDays())
            sod = float(d.time.getSecondOfDay())
            timec.set(mjd, sod, gpstk.TimeSystem(gpstk.TimeSystem.GPS))

            # Assign values to a new Rinex Obs Data object
            nd = gpstk.Rinex3ObsData()
            nd.time = timec
            nd.auxHeader = d.auxHeader
            nd.clockOffset = d.clockOffset
            nd.epochFlag = d.epochFlag
            nd.numSVs = d.numSVs

            for satkey in d.obs.keys():
                newSatKey = gpstk.RinexSatID(satkey.toString())
                satObss = d.obs[newSatKey]
                # satObss is a tuple of  RinexDatum
                newSatObss = []
                for satObs in satObss:
                    #print "{} {} {} {}".format(satkey.toString(), satObs.data, satObs.lli, satObs.ssi)
                    newSatObs = gpstk.RinexDatum()
                    newSatObs.data = satObs.data
                    newSatObs.lli = satObs.lli
                    newSatObs.ssi = satObs.ssi
                    newSatObss.append(newSatObs)

                nd.obs[newSatKey] = tuple(newSatObss)

            #print "O{}".format(d)
            #print "S{}".format(nd)
            processed_data.append(nd)

        gpstk.writeRinex3Obs(output_file, new_header, processed_data)
        print "Wrote output file: {}".format(output_file)

    # We can catch any custom gpstk exception like this:
    except gpstk.Exception as e:
        print e
Пример #12
0
 def daytostring(x):
     t = gpstk.CommonTime()
     t.set(x)
     return gpstk.CivilTime(t).printf(args.format)
# these to be set. Since the input to this program is RINEX v2.11,
# what should happen is that the Rinex3ObsHeader should fill in default values
# for the SystemPhaseShift and not require the two glonass since there is no
# glonass data in the source
new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validSystemPhaseShift
new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validGlonassSlotFreqNo
new_header.valid = new_header.valid | gpstk.Rinex3ObsHeader.validGlonassCodPhsBias

print new_header

new_data = []
# Now we loop through all the epochs and process the data for each one
for d in data:

    # This creates a new CommonTime object with the system set to GPS.
    timec = gpstk.CommonTime(gpstk.TimeSystem(gpstk.TimeSystem.GPS))
    # This creates a new CommonTime object with the system set to GPS.
    mjd = int(d.time.getDays())
    sod = float(d.time.getSecondOfDay())
    timec.set(mjd, sod, gpstk.TimeSystem(gpstk.TimeSystem.GPS))

    # Assign values to a new Rinex Obs Data object
    nd = gpstk.Rinex3ObsData()
    nd.time = timec
    nd.auxHeader = d.auxHeader
    nd.clockOffset = d.clockOffset
    nd.epochFlag= d.epochFlag
    nd.numSVs = d.numSVs

    for satkey in d.obs.keys():
        newSatKey = gpstk.RinexSatID(satkey.toString())
Пример #14
0
 def test_exception(self):
     # subtracting 2 CommonTimes throws an InvalidRequest
     a = gpstk.CommonTime(gpstk.TimeSystem('GPS'))
     b = gpstk.CommonTime(gpstk.TimeSystem('GLO'))
     self.assertRaises(gpstk.InvalidRequest, a.__sub__, b)
Пример #15
0
"""
import gpstk
from matplotlib.pyplot import figure, show

# Read in data, strict=True makes dataSets a list rather than a generator:
header, dataSets = gpstk.readSEM("data/sem_data.txt", strict=True)

# Write the data back to a different file (their contents should match):
gpstk.writeSEM("sem_data.txt.new", header, dataSets)

# Read the orbit out of the data:
orbit = dataSets[0].toAlmOrbit()  # alm orbit of first data point

austin = gpstk.Position(30, 97, 0, gpstk.Position.Geodetic)  # Austin, TX

starttime = gpstk.CommonTime()  # iterator time to start at
starttime.setTimeSystem(gpstk.TimeSystem("GPS"))
endtime = gpstk.CommonTime()  # end time, 1 day later (see below)
endtime.setTimeSystem(gpstk.TimeSystem("GPS"))
endtime.addDays(1)
# %% Step through a day, adding plot points:
d = []
el = []
for t in gpstk.times(starttime, endtime, seconds=1000):
    d.append(t.getDays())
    xvt = orbit.svXvt(t)
    location = gpstk.Position(xvt.x)
    el.append(austin.elevation(location))

# Make the plot
fig = figure()