def testRunThrough(self): # Set up chebyshev fitter. tStart = self.orbits.orbits.epoch.iloc[0] interval = 30 cheb = ChebyFits(self.orbits, tStart, interval, ngran=64, skyTolerance=2.5, nDecimal=10) # Set granularity. Use an value that will be too long, to trigger recursion below. cheb.calcSegmentLength(length=10.0) # Run through segments. cheb.calcSegments() self.assertEqual(len(np.unique(cheb.coeffs['objId'])), len(self.orbits)) # Write outputs. cheb.write(self.coeffFile, self.residFile, self.failedFile) # Test that the segments for each individual object fit together start/end. for k in cheb.coeffs: cheb.coeffs[k] = np.array(cheb.coeffs[k]) for objId in np.unique(cheb.coeffs['objId']): condition = (cheb.coeffs['objId'] == objId) te_prev = tStart for ts, te in zip(cheb.coeffs['tStart'][condition], cheb.coeffs['tEnd'][condition]): # Test that the start of the current interval = the end of the previous interval. self.assertEqual(te_prev, ts) te_prev = te # Test that the end of the last interval is equal to the end of the total interval self.assertEqual(te, tStart + interval)
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)
def testSetSegmentLength(self): # Expect MBAs with standard ngran and tolerance to have length ~2.0 days. self.cheb.calcSegmentLength() self.assertAlmostEqual(self.cheb.length, 2.0) # Test that we can set it to other values which fit into the 30 day window. self.cheb.calcSegmentLength(length=1.5) self.assertEqual(self.cheb.length, 1.5) # Test that we if we try to set it to a value which does not fit into the 30 day window, # that the actual value used is different - and smaller. self.cheb.calcSegmentLength(length=1.9) self.assertTrue(self.cheb.length < 1.9) # Test that we get a warning about the residuals if we try to set the length to be too long. with warnings.catch_warnings(record=True) as w: self.cheb.calcSegmentLength(length=5.0) self.assertTrue(len(w), 1) # Now check granularity works for other orbit types (which would have other standard lengths). # Check for multiple orbit types. for orbitFile in ([ 'test_orbitsMBA.s3m', 'test_orbitsOuter.s3m', 'test_orbitsNEO.s3m' ]): self.orbits.readOrbits(os.path.join(self.testdir, orbitFile), skiprows=1) tStart = self.orbits.orbits['epoch'].iloc[0] cheb = ChebyFits(self.orbits, tStart, 30, ngran=64, nDecimal=2) # And that we should converge for a variety of other tolerances. for skyTolerance in (2.5, 5.0, 10.0, 100.0, 1000.0, 20000.0): cheb.skyTolerance = skyTolerance cheb.calcSegmentLength() pos_resid, ratio = cheb._testResiduals(cheb.length) self.assertTrue(pos_resid < skyTolerance) self.assertEqual((cheb.length * 100) % 1, 0) # print('final', orbitFile, skyTolerance, pos_resid, cheb.length, ratio) # And check for challenging 'impactors'. for orbitFile in (['test_orbitsImpactors.s3m']): self.orbits.readOrbits(os.path.join(self.testdir, orbitFile), skiprows=1) tStart = self.orbits.orbits['epoch'].iloc[0] cheb = ChebyFits(self.orbits, tStart, 30, ngran=64, nDecimal=10) # And that we should converge for a variety of other tolerances. for skyTolerance in (2.5, 10.0, 100.0): cheb.skyTolerance = skyTolerance cheb.calcSegmentLength() pos_resid, ratio = cheb._testResiduals(cheb.length) self.assertTrue(pos_resid < skyTolerance)
def setUp(self): self.testdir = os.path.join(getPackageDir('sims_movingObjects'), 'tests/orbits_testdata') self.orbits = Orbits() self.orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsMBA.s3m'), skiprows=1) self.cheb = ChebyFits(self.orbits, 54800, 30, ngran=64, skyTolerance=2.5, nDecimal=10, nCoeff_position=14) self.assertEqual(self.cheb.ngran, 64)
def setUp(self): self.testdir = os.path.join(getPackageDir('sims_movingObjects'), 'tests/orbits_testdata') self.scratch_dir = tempfile.mkdtemp(dir=ROOT, prefix='TestChebyFits-') self.orbits = Orbits() self.orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsMBA.s3m')) self.cheb = ChebyFits(self.orbits, 54800, 30, ngran=64, skyTolerance=2.5, nDecimal=10, nCoeff_position=14) self.assertEqual(self.cheb.ngran, 64)
def setUp(self): self.testdatadir = os.path.join(getPackageDir('sims_movingObjects'), 'tests/orbits_testdata') self.coeffFile = 'test_coeffs' self.residFile = 'test_resids' self.failedFile = 'test_failed' self.orbits = Orbits() self.orbits.readOrbits(os.path.join(self.testdatadir, 'test_orbitsNEO.s3m'), skiprows=1) self.pyephems = PyOrbEphemerides(os.path.join(os.getenv('OORB_DATA'), 'DE405.dat')) self.pyephems.setOrbits(self.orbits) self.tStart = self.orbits.orbits.epoch.iloc[0] self.interval = 15 self.nCoeffs = 14 self.nDecimal = 13 self.chebyFits = ChebyFits(self.orbits, self.tStart, self.interval, ngran=64, skyTolerance=2.5, nDecimal=self.nDecimal, nCoeff_position=self.nCoeffs, obscode=807, timeScale='TAI') self.setLength = 0.5 self.chebyFits.calcSegmentLength(length=self.setLength) self.chebyFits.calcSegments() self.chebyFits.write(self.coeffFile, self.residFile, self.failedFile, append=False) self.coeffKeys = ['objId', 'tStart', 'tEnd', 'ra', 'dec', 'delta', 'vmag', 'elongation']
# 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], subsetOrbits.orbits.objId.iloc[-1], n, n + nObj, t, t + tSpan, ve.message), UserWarning, "generateCoefficients.py", 132, file=log) # Put this in a separate try/except block, because errors here can mask errors in the previous