Ejemplo n.º 1
0
    def testOffsetDataframe(self):
        """
        Test that we can slice and iterate through an orbits
        dataframe that has already been sub-selected from another
        dataframe.
        """
        orbits0 = Orbits()
        orbits0.readOrbits(os.path.join(self.testdir, 'test_orbitsNEO.s3m'))

        orbitsSub = Orbits()
        orbitsSub.setOrbits(orbits0.orbits.query('index>1'))

        self.assertEqual(len(orbitsSub), 6)

        orbit_slice = orbitsSub[2:6]
        self.assertEqual(orbit_slice[0], orbitsSub[2])
        self.assertEqual(orbit_slice[1], orbitsSub[3])
        self.assertEqual(orbit_slice[2], orbitsSub[4])
        self.assertEqual(orbit_slice[3], orbitsSub[5])
        self.assertEqual(len(orbit_slice), 4)

        orbit_slice = orbitsSub[1:5:2]
        self.assertEqual(orbit_slice[0], orbitsSub[1])
        self.assertEqual(orbit_slice[1], orbitsSub[3])
        self.assertEqual(len(orbit_slice), 2)

        for ii, oo in enumerate(orbitsSub):
            self.assertEqual(oo, orbits0[ii+2])
Ejemplo n.º 2
0
 def testRADec(self):
     # We won't compare Vmag, because this also needs information on trailing losses.
     times = self.jpl['mjdUTC'].unique()
     deltaRA = np.zeros(len(times), float)
     deltaDec = np.zeros(len(times), float)
     for i, t in enumerate(times):
         # Find the JPL objIds visible at this time.
         j = self.jpl.query('mjdUTC == @t').sort_values('objId')
         # Set the ephems, using the objects seen at this time.
         suborbits = self.orbits.orbits.query(
             'objId in @j.objId').sort_values('objId')
         subOrbits = Orbits()
         subOrbits.setOrbits(suborbits)
         ephems = PyOrbEphemerides()
         ephems.setOrbits(subOrbits)
         ephs = ephems.generateEphemerides([t],
                                           timeScale='UTC',
                                           obscode=807,
                                           ephMode='N',
                                           ephType='Basic',
                                           byObject=False)
         deltaRA[i] = np.abs(ephs['ra'] - j['ra_deg'].values).max()
         deltaDec[i] = np.abs(ephs['dec'] - j['dec_deg'].values).max()
     # Convert to mas
     deltaRA *= 3600. * 1000.
     deltaDec *= 3600. * 1000.
     # Much of the time we're closer than 1mas, but there are a few which hit higher values.
     print('max JPL errors', np.max(deltaRA), np.max(deltaDec))
     print('std JPL errors', np.std(deltaRA), np.std(deltaDec))
     self.assertLess(np.max(deltaRA), 25)
     self.assertLess(np.max(deltaDec), 25)
     self.assertLess(np.std(deltaRA), 3)
     self.assertLess(np.std(deltaDec), 3)
Ejemplo n.º 3
0
    def testOffsetDataframe(self):
        """
        Test that we can slice and iterate through an orbits
        dataframe that has already been sub-selected from another
        datafram
        """
        orbits0 = Orbits()
        orbits0.readOrbits(os.path.join(self.testdir, 'test_orbitsNEO.s3m'), skiprows=1)

        orbitsSub = Orbits()
        orbitsSub.setOrbits(orbits0.orbits.query('index>1'))

        self.assertEqual(len(orbitsSub), 6)

        orbit_slice = orbitsSub[2:6]
        self.assertEqual(orbit_slice[0], orbitsSub[2])
        self.assertEqual(orbit_slice[1], orbitsSub[3])
        self.assertEqual(orbit_slice[2], orbitsSub[4])
        self.assertEqual(orbit_slice[3], orbitsSub[5])
        self.assertEqual(len(orbit_slice), 4)

        orbit_slice = orbitsSub[1:5:2]
        self.assertEqual(orbit_slice[0], orbitsSub[1])
        self.assertEqual(orbit_slice[1], orbitsSub[3])
        self.assertEqual(len(orbit_slice), 2)

        for ii, oo in enumerate(orbitsSub):
            self.assertEqual(oo, orbits0[ii+2])
Ejemplo n.º 4
0
 def testRADec(self):
     # We won't compare Vmag, because this also needs information on trailing losses.
     times = self.jpl['mjdUTC'].unique()
     deltaRA = np.zeros(len(times), float)
     deltaDec = np.zeros(len(times), float)
     for i, t in enumerate(times):
         # Find the JPL objIds visible at this time.
         j = self.jpl.query('mjdUTC == @t').sort_values('objId')
         # Set the ephems, using the objects seen at this time.
         suborbits = self.orbits.orbits.query('objId in @j.objId').sort_values('objId')
         subOrbits = Orbits()
         subOrbits.setOrbits(suborbits)
         ephems = PyOrbEphemerides()
         ephems.setOrbits(subOrbits)
         ephs = ephems.generateEphemerides([t], timeScale='UTC', obscode=807, byObject=False)
         deltaRA[i] = np.abs(ephs['ra'] - j['ra_deg'].as_matrix()).max()
         deltaDec[i] = np.abs(ephs['dec'] - j['dec_deg'].as_matrix()).max()
     # Convert to mas
     deltaRA *= 3600. * 1000.
     deltaDec *= 3600. * 1000.
     # Much of the time we're closer than 1mas, but there are a few which hit higher values.
     self.assertTrue(np.max(deltaRA) < 18)
     self.assertTrue(np.max(deltaDec) < 6)
     self.assertTrue(np.std(deltaRA) < 2)
     self.assertTrue(np.std(deltaDec) < 1)
     print('max JPL errors', np.max(deltaRA), np.max(deltaDec))
     print('std JPL errors', np.std(deltaRA), np.std(deltaDec))
 def testConvertFromOorbArray(self):
     # Check that we can convert orbital elements TO oorb format and back
     # without losing info (except ObjId -- we will lose that unless we use updateOrbits.)
     self.ephems._convertToOorbElem(self.orbits.orbits, self.orbits.orb_format)
     newOrbits = Orbits()
     newOrbits.setOrbits(self.orbits.orbits)
     newOrbits.updateOrbits(self.ephems.convertFromOorbElem())
     self.assertEqual(newOrbits, self.orbits)
 def testConvertFromOorbArray(self):
     self.ephems._convertToOorbElem(self.orbits.orbits,
                                    self.orbits.orb_format)
     newOrbits = Orbits()
     newOrbits.setOrbits(self.ephems.convertFromOorbElem())
     print(self.orbits.orb_format, self.orbits.orbits)
     print(newOrbits.orb_format, newOrbits.orbits)
     self.assertEqual(newOrbits, self.orbits)
Ejemplo n.º 7
0
 def testSetOrbits(self):
     # Test that we can set orbits.
     self.ephems.setOrbits(self.orbits)
     # Test that setting with an empty orbit object fails.
     # (Avoids hard-to-interpret errors from pyoorb).
     with self.assertRaises(ValueError):
         emptyOrb = Orbits()
         empty = pd.DataFrame([], columns=self.orbits.dataCols['KEP'])
         emptyOrb.setOrbits(empty)
         self.ephems.setOrbits(emptyOrb)
Ejemplo n.º 8
0
 def testSetOrbits(self):
     # Test that we can set orbits.
     self.ephems.setOrbits(self.orbits)
     assert_frame_equal(self.ephems.orbitObj.orbits, self.orbits.orbits)
     # Test that setting with something other than an Orbit object fails.
     with self.assertRaises(ValueError):
         self.ephems.setOrbits(self.orbits.orbits)
     # Test that setting with an empty orbit object fails.
     # (Avoids hard-to-interpret errors from pyoorb).
     with self.assertRaises(ValueError):
         emptyOrb = Orbits()
         empty = pd.DataFrame([], columns=self.orbits.dataCols['KEP'])
         emptyOrb.setOrbits(empty)
         self.ephems.setOrbits(emptyOrb)
Ejemplo n.º 9
0
 def testIterationAndIndexing(self):
     orbits = Orbits()
     orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsNEO.s3m'))
     orbitsSingle = orbits[0]
     assert_frame_equal(orbitsSingle.orbits, orbits.orbits.query('index==0'))
     orbitsSingle = orbits[3]
     assert_frame_equal(orbitsSingle.orbits, orbits.orbits.query('index==3'))
     # Test iteration through all orbits.
     for orb, (i, orbi) in zip(orbits, orbits.orbits.iterrows()):
         self.assertEqual(orb.orbits.objId.values[0], orbi.objId)
         self.assertTrue(isinstance(orb, Orbits))
         self.assertEqual(orb.orbits.index, i)
     # Test iteration through a subset of orbits.
     orbitsSub = Orbits()
     orbitsSub.setOrbits(orbits.orbits.query('index > 4'))
     for orb, (i, orbi) in zip(orbitsSub, orbitsSub.orbits.iterrows()):
         self.assertEqual(orb.orbits.objId.values[0], orbi.objId)
         self.assertTrue(isinstance(orb, Orbits))
         self.assertEqual(orb.orbits.index, i)
Ejemplo n.º 10
0
 def testIterationAndIndexing(self):
     orbits = Orbits()
     orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsNEO.s3m'), skiprows=1)
     orbitsSingle = orbits[0]
     assert_frame_equal(orbitsSingle.orbits, orbits.orbits.query('index==0'))
     orbitsSingle = orbits[3]
     assert_frame_equal(orbitsSingle.orbits, orbits.orbits.query('index==3'))
     # Test iteration through all orbits.
     for orb, (i, orbi) in zip(orbits, orbits.orbits.iterrows()):
         self.assertEqual(orb.orbits.objId.values[0], orbi.objId)
         self.assertTrue(isinstance(orb, Orbits))
         self.assertEqual(orb.orbits.index, i)
     # Test iteration through a subset of orbits.
     orbitsSub = Orbits()
     orbitsSub.setOrbits(orbits.orbits.query('index > 4'))
     for orb, (i, orbi) in zip(orbitsSub, orbitsSub.orbits.iterrows()):
         self.assertEqual(orb.orbits.objId.values[0], orbi.objId)
         self.assertTrue(isinstance(orb, Orbits))
         self.assertEqual(orb.orbits.index, i)
Ejemplo n.º 11
0
 def testSetOrbits(self):
     orbits = Orbits()
     orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsQ.des'))
     # Test that we can set the orbits using a dataframe.
     suborbits = orbits.orbits.head(1)
     newOrbits = Orbits()
     newOrbits.setOrbits(suborbits)
     self.assertEqual(len(newOrbits), 1)
     self.assertEqual(newOrbits.orb_format, 'COM')
     assert_frame_equal(newOrbits.orbits, suborbits)
     # Test that we can set the orbits using a Series.
     for i, sso in suborbits.iterrows():
         newOrbits = Orbits()
         newOrbits.setOrbits(sso)
         self.assertEqual(len(newOrbits), 1)
         self.assertEqual(newOrbits.orb_format, 'COM')
         assert_frame_equal(newOrbits.orbits, suborbits)
     # Test that we can set the orbits using a numpy array with many objects.
     numpyorbits = orbits.orbits.to_records(index=False)
     newOrbits = Orbits()
     newOrbits.setOrbits(numpyorbits)
     self.assertEqual(len(newOrbits), len(orbits))
     self.assertEqual(newOrbits.orb_format, 'COM')
     assert_frame_equal(newOrbits.orbits, orbits.orbits)
     # And test that this works for a single row of the numpy array.
     onenumpyorbits = numpyorbits[0]
     newOrbits = Orbits()
     newOrbits.setOrbits(onenumpyorbits)
     self.assertEqual(len(newOrbits), 1)
     self.assertEqual(newOrbits.orb_format, 'COM')
     assert_frame_equal(newOrbits.orbits, suborbits)
     # And test that it fails appropriately when columns are not correct.
     neworbits = pd.DataFrame(orbits.orbits)
     newcols = neworbits.columns.values.tolist()
     newcols[0] = 'ssmId'
     newcols[3] = 'ecc'
     neworbits.columns = newcols
     newOrbits = Orbits()
     with self.assertRaises(ValueError):
         newOrbits.setOrbits(neworbits)
Ejemplo n.º 12
0
 def testSetOrbits(self):
     orbits = Orbits()
     orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsQ.des'))
     # Test that we can set the orbits using a dataframe.
     suborbits = orbits.orbits.head(1)
     newOrbits = Orbits()
     newOrbits.setOrbits(suborbits)
     self.assertEqual(len(newOrbits), 1)
     self.assertEqual(newOrbits.format, 'COM')
     assert_frame_equal(newOrbits.orbits, suborbits)
     # Test that we can set the orbits using a Series.
     for i, sso in suborbits.iterrows():
         newOrbits = Orbits()
         newOrbits.setOrbits(sso)
         self.assertEqual(len(newOrbits), 1)
         self.assertEqual(newOrbits.format, 'COM')
         assert_frame_equal(newOrbits.orbits, suborbits)
     # Test that we can set the orbits using a numpy array with many objects.
     numpyorbits = orbits.orbits.to_records(index=False)
     newOrbits = Orbits()
     newOrbits.setOrbits(numpyorbits)
     self.assertEqual(len(newOrbits), len(orbits))
     self.assertEqual(newOrbits.format, 'COM')
     assert_frame_equal(newOrbits.orbits, orbits.orbits)
     # And test that this works for a single row of the numpy array.
     onenumpyorbits = numpyorbits[0]
     newOrbits = Orbits()
     newOrbits.setOrbits(onenumpyorbits)
     self.assertEqual(len(newOrbits), 1)
     self.assertEqual(newOrbits.format, 'COM')
     assert_frame_equal(newOrbits.orbits, suborbits)
     # And test that it fails appropriately when columns are not correct.
     neworbits = pd.DataFrame(orbits.orbits)
     newcols = neworbits.columns.values.tolist()
     newcols[0] = 'ssmId'
     newcols[3] = 'ecc'
     neworbits.columns = newcols
     newOrbits = Orbits()
     with self.assertRaises(ValueError):
         newOrbits.setOrbits(neworbits)
    log = open(logFile, 'w')

    timespans = np.arange(tStart, tEnd, tSpan)
    for t in timespans:
        # Set output file names.
        timestring = '%.2f_%.2f' % (t, t + tSpan)
        coeffFile = '__'.join([fileRoot, 'coeffs', timestring, fileSuffix]).rstrip('_')
        residFile = '__'.join([fileRoot, 'resids', timestring, fileSuffix]).rstrip('_')
        failedFile = '__'.join([fileRoot, 'failed', timestring, fileSuffix]).rstrip('_')

        # Cycle through nObj at a time, to fit and write data files.
        append = False
        for n in range(0, len(orbits), nObj):
            subset = orbits.orbits[n:n + nObj]
            subsetOrbits = Orbits()
            subsetOrbits.setOrbits(subset)
            # Fit chebyshev polynomials.
            print("Working on objects %d to %d in timespan %f to %f" % (n, n + nObj, t, t + tSpan), file=log)
            cheb = ChebyFits(subsetOrbits, t, tSpan, skyTolerance=args.skyTol,
                             nDecimal=args.nDecimal, nCoeff_position=args.nCoeff,
                             ngran=64, nCoeff_vmag=9, nCoeff_delta=5, nCoeff_elongation=6,
                             obscode=807, timeScale='TAI')

            try:
                cheb.calcSegmentLength(length=args.length)
            except ValueError as ve:
                cheb.length = None
                for objId in subsetOrbits.orbits['objId'].as_matrix():
                    cheb.failed.append((objId, tStart, tEnd))
                    warnings.showwarning("Objid %s to %s (n %d to %d), segment %f to %f - error: %s"
                                         % (subsetOrbits.orbits.objId.iloc[0],
Ejemplo n.º 14
0
    log = open(logFile, 'w')

    timespans = np.arange(tStart, tEnd, tSpan)
    for t in timespans:
        # Set output file names.
        timestring = '%.2f_%.2f' % (t, t + tSpan)
        coeffFile = '__'.join([fileRoot, 'coeffs', timestring, fileSuffix]).rstrip('_')
        residFile = '__'.join([fileRoot, 'resids', timestring, fileSuffix]).rstrip('_')
        failedFile = '__'.join([fileRoot, 'failed', timestring, fileSuffix]).rstrip('_')

        # Cycle through nObj at a time, to fit and write data files.
        append = False
        for n in range(0, len(orbits), nObj):
            subset = orbits.orbits[n:n + nObj]
            subsetOrbits = Orbits()
            subsetOrbits.setOrbits(subset)
            # Fit chebyshev polynomials.
            print("Working on objects %d to %d in timespan %f to %f" % (n, n + nObj, t, t + tSpan), file=log)
            cheb = ChebyFits(subsetOrbits, t, tSpan, skyTolerance=args.skyTol,
                             nDecimal=args.nDecimal, nCoeff_position=args.nCoeff,
                             ngran=64, nCoeff_vmag=9, nCoeff_delta=5, nCoeff_elongation=6,
                             obscode=807, timeScale='TAI')

            try:
                cheb.calcSegmentLength(length=args.length)
            except ValueError as ve:
                cheb.length = None
                for objId in subsetOrbits.orbits['objId'].as_matrix():
                    cheb.failed.append((objId, tStart, tEnd))
                    warnings.showwarning("Objid %s to %s (n %d to %d), segment %f to %f - error: %s"
                                         % (subsetOrbits.orbits.objId.iloc[0],