Esempio n. 1
0
 def testReadCoeffs(self):
     # Test reading the coefficients from disk.
     chebyValues = ChebyValues()
     chebyValues.readCoefficients(self.coeffFile)
     chebyValues2 = ChebyValues()
     chebyValues2.setCoefficients(self.chebyFits)
     for k in chebyValues.coeffs:
         if k == 'objId':
             # Can't test strings with np.test.assert_almost_equal.
             np.testing.assert_equal(chebyValues.coeffs[k], chebyValues2.coeffs[k])
         else:
             # All of these will only be accurate to 2 less decimal places than they are
             # print out with in chebyFits. Since vmag, delta and elongation only use 7
             # decimal places, this means we can test to 5 decimal places for those.
             np.testing.assert_allclose(chebyValues.coeffs[k], chebyValues2.coeffs[k], rtol=0, atol=1e-5)
Esempio n. 2
0
 def testGetEphemerides(self):
     # Test that getEphemerides works and is accurate.
     chebyValues = ChebyValues()
     chebyValues.readCoefficients(self.coeffFile)
     # Multiple times, all objects, all within interval.
     tstep = self.interval/10.0
     time = np.arange(self.tStart, self.tStart + self.interval, tstep)
     # Test for a single time, but all the objects.
     ephemerides = chebyValues.getEphemerides(time)
     pyephemerides = self.pyephems.generateEphemerides(time, obscode=807,
                                                       timeScale='TAI', byObject=True)
     # RA and Dec should agree to 2.5mas (skyTolerance above)
     pos_residuals = np.sqrt((ephemerides['ra'] - pyephemerides['ra']) ** 2 +
                             ((ephemerides['dec'] - pyephemerides['dec']) *
                              np.cos(np.radians(ephemerides['dec']))) ** 2)
     pos_residuals *= 3600.0 * 1000.0
     # Let's just look at the max residuals in all quantities.
     for k in ('ra', 'dec', 'dradt', 'ddecdt', 'geo_dist'):
         resids = np.abs(ephemerides[k] - pyephemerides[k])
         if k != 'geo_dist':
             resids *= 3600.0 * 1000.0
         print('max diff', k, np.max(resids))
     resids = np.abs(ephemerides['elongation'] - pyephemerides['solarelon'])
     print('max diff elongation', np.max(resids))
     resids = np.abs(ephemerides['vmag'] - pyephemerides['magV'])
     print('max diff vmag', np.max(resids))
     self.assertLessEqual(np.max(pos_residuals), 2.5)
     # Test for single time, but for a subset of the objects.
     objIds = self.orbits.orbits.objId.head(3).as_matrix()
     ephemerides = chebyValues.getEphemerides(time, objIds)
     self.assertEqual(len(ephemerides['ra']), 3)
     # Test for time outside of segment range.
     ephemerides = chebyValues.getEphemerides(self.tStart + self.interval * 2, objIds, extrapolate=False)
     self.assertTrue(np.isnan(ephemerides['ra'][0]),
                     msg='Expected Nan for out of range ephemeris, got %.2e' %(ephemerides['ra'][0]))
Esempio n. 3
0
 def setUp(self):
     # Read orbits.
     self.orbits = Orbits()
     self.jplDir = os.path.join(getPackageDir('sims_movingObjects'), 'tests/jpl_testdata')
     self.orbits.readOrbits(os.path.join(self.jplDir, 'S0_n747.des'), skiprows=1)
     # Read JPL ephems.
     self.jpl = pd.read_table(os.path.join(self.jplDir, '807_n747.txt'), delim_whitespace=True)
     # Add times in TAI and UTC, because.
     t = Time(self.jpl['epoch_mjd'], format='mjd', scale='utc')
     self.jpl['mjdTAI'] = t.tai.mjd
     self.jpl['mjdUTC'] = t.utc.mjd
     self.jpl = self.jpl.to_records(index=False)
     # Generate interpolation coefficients for the time period in the JPL catalog.
     self.scratch_dir = tempfile.mkdtemp(dir=ROOT, prefix='TestJPLValues-')
     self.coeffFile = os.path.join(self.scratch_dir, 'test_coeffs')
     self.residFile = os.path.join(self.scratch_dir, 'test_resids')
     self.failedFile = os.path.join(self.scratch_dir, 'test_failed')
     tStart = self.jpl['mjdTAI'].min() - 0.2
     tEnd = self.jpl['mjdTAI'].max() + 0.2 - self.jpl['mjdTAI'].min()
     self.chebyFits = ChebyFits(self.orbits, tStart, tEnd,
                                ngran=64, skyTolerance=2.5,
                                nDecimal=14, obscode=807)
     self.chebyFits.calcSegmentLength()
     self.chebyFits.calcSegments()
     self.chebyFits.write(self.coeffFile, self.residFile, self.failedFile, append=False)
     self.coeffKeys = ['objId', 'tStart', 'tEnd', 'ra', 'dec', 'geo_dist', 'vmag', 'elongation']
     self.chebyValues = ChebyValues()
     self.chebyValues.readCoefficients(self.coeffFile)
Esempio n. 4
0
 def testSetCoeff(self):
     # Test setting coefficients directly from chebyFits outputs.
     chebyValues = ChebyValues()
     chebyValues.setCoefficients(self.chebyFits)
     for k in self.coeffKeys:
         self.assertTrue(k in chebyValues.coeffs)
         self.assertTrue(isinstance(chebyValues.coeffs[k], np.ndarray))
     self.assertEqual(len(np.unique(chebyValues.coeffs['objId'])), len(self.orbits))
     # This will only be true for carefully selected length/orbit type, where subdivision did not occur.
     # For the test MBAs, a len=1day will work.
     # For the test NEOs, a len=0.25 day will work (with 2.5mas skyTol).
     # self.assertEqual(len(chebyValues.coeffs['tStart']),
     #                  (self.interval / self.setLength) * len(self.orbits))
     self.assertEqual(len(chebyValues.coeffs['ra'][0]), self.nCoeffs)
     self.assertTrue('meanRA' in chebyValues.coeffs)
     self.assertTrue('meanDec' in chebyValues.coeffs)