Пример #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])
 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_orbitsQ.des'))
     self.orbitsKEP = Orbits()
     self.orbitsKEP.readOrbits(
         os.path.join(self.testdir, 'test_orbitsA.des'))
     self.ephems = PyOrbEphemerides()
Пример #3
0
 def testEqualNotEqual(self):
     orbits = Orbits()
     orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsQ.des'))
     self.assertEqual(len(orbits), 4)
     orbits2 = Orbits()
     orbits2.readOrbits(os.path.join(self.testdir, 'test_orbitsQ.des'))
     self.assertEqual(orbits, orbits2)
     orbits3 = Orbits()
     orbits3.readOrbits(os.path.join(self.testdir, 'test_orbitsA.des'))
     self.assertNotEqual(orbits, orbits3)
Пример #4
0
def readOrbits(orbitfile):
    if not os.path.isfile(orbitfile):
        print("Could not find orbit file %s" % (orbitfile))
    orbits = Orbits()
    orbits.readOrbits(orbitfile)
    print("Read orbit information from %s" % (orbitfile))
    return orbits
Пример #5
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)
Пример #6
0
 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'))
Пример #7
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)
Пример #8
0
 def testReadOrbits(self):
     orbits = Orbits()
     orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsQ.des'))
     self.assertEqual(len(orbits), 4)
     orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsA.des'))
     self.assertEqual(len(orbits), 4)
     with self.assertRaises(ValueError):
         orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsBad.des'))
 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)
 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)
Пример #11
0
 def testSetSeds(self):
     """
     Test that the self-assignment of SEDs works as expected.
     """
     orbits = Orbits()
     # Test with a range of a values.
     a = np.arange(0, 5, .05)
     orbs = pd.DataFrame(a, columns=['a'])
     seds = orbits.assignSed(orbs)
     self.assertEqual(np.unique(seds[np.where(a < 2)]), 'S.dat')
     self.assertEqual(np.unique(seds[np.where(a > 4)]), 'C.dat')
     # Test when read a values.
     orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsA.des'))
     sedvals = orbits.assignSed(orbits.orbits, randomSeed=42)
     orbits2 = Orbits()
     orbits2.readOrbits(os.path.join(self.testdir, 'test_orbitsQ.des'))
     sedvals2 = orbits2.assignSed(orbits2.orbits, randomSeed=42)
     np.testing.assert_array_equal(sedvals, sedvals2)
Пример #12
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)
 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.coeffFile = 'tmpCoeff'
     self.residFile = 'tmpResid'
     self.failedFile = 'tmpFailed'
Пример #14
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)
 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
Пример #16
0
 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.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)
Пример #18
0
    def testSlicing(self):
        """
        Test that we can slice a collection of orbits
        """
        orbits = Orbits()
        orbits.readOrbits(os.path.join(self.testdir, 'test_orbitsNEO.s3m'))
        orbit_slice = orbits[2:6]
        self.assertEqual(orbit_slice[0], orbits[2])
        self.assertEqual(orbit_slice[1], orbits[3])
        self.assertEqual(orbit_slice[2], orbits[4])
        self.assertEqual(orbit_slice[3], orbits[5])
        self.assertEqual(len(orbit_slice), 4)

        orbit_slice = orbits[1:7:2]
        self.assertEqual(orbit_slice[0], orbits[1])
        self.assertEqual(orbit_slice[1], orbits[3])
        self.assertEqual(orbit_slice[2], orbits[5])
        self.assertEqual(len(orbit_slice), 3)
Пример #19
0
def readOrbits(orbitfile):
    """Read the orbits from the orbitfile.

    Parameters
    ----------
    orbitfile: str
        Name (and path) of the orbit file.

    Returns
    -------
    lsst.sims.movingObjects.Orbits
        The orbit object.
    """
    if not os.path.isfile(orbitfile):
        logging.critical("Could not find orbit file %s" % (orbitfile))
    orbits = Orbits()
    orbits.readOrbits(orbitfile)
    logging.info("Read orbit information from %s" % (orbitfile))
    return orbits
Пример #20
0
 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']
Пример #21
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)
Пример #22
0
import warnings
import numpy as np
from lsst.sims.movingObjects import Orbits
from itertools import repeat

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Add SEDs to a series of orbits.")
    parser.add_argument("--orbitFile", type=str, default=None,
                        help="File containing the orbits.")
    parser.add_argument("--outFile", type=str, default=None,
                        help="Output orbit file.")
    args = parser.parse_args()

    # Parse orbit file input values.
    if args.orbitFile is None:
        print("Must specify orbit file to use.")
        exit()

    if not os.path.isfile(args.orbitFile):
        print("Could not find orbit file %s" % (args.orbitFile))

    # Read orbits. This adds SEDs with the default setup automatically.
    orbits = Orbits()
    orbits.readOrbits(args.orbitFile)

    # An alternative method to assign the seds:
    # sedfilenames = orbits.assignSed(orbits.orbits, randomSeed=None)
    formatcol = np.array([x for x in repeat(orbits.format, len(orbits.orbits))])
    orbits.orbits.insert(1, 'FORMAT', formatcol)
    orbits.orbits.to_csv(args.outFile, sep=' ', index=False, header=True)
    # Parse orbit file input values.
    if args.orbitFile is None:
        print("Must specify orbit file to use.")
        exit()

    if not os.path.isfile(args.orbitFile):
        print("Could not find orbit file %s" % (args.orbitFile))

    # Check that basic information about tSpan or tEnd is available.
    if args.tEnd is None and args.tSpan is None:
        print("Must specify at least one of tSpan or tEnd")
        exit()

    # Read orbits.
    orbits = Orbits()
    orbits.readOrbits(args.orbitFile)

    # Pull out only objStart to objEnd, if either of these is specified.
    if args.objStart is not None or args.objEnd is not None:
        if args.objStart is None:
            args.objStart = 0
        if args.objEnd is None:
            args.objEnd = len(orbits) - 1
        orbits = orbits[args.objStart:args.objEnd + 1]
        fileSuffix = 'obj%d_%d' % (args.objStart, args.objEnd)
    else:
        fileSuffix = ''

    if args.nObj is None:
        nObj = len(orbits)