Пример #1
0
 def testNsecsDefault(self):
     ts = DateTime(1192755506000000000)
     self.assertEqual(ts.nsecs(DateTime.UTC), 1192755473000000000)
     self.assertEqual(ts.nsecs(DateTime.TAI), 1192755506000000000)
     self.assertEqual(ts.nsecs(), 1192755506000000000)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 54392.040196759262)
     self.assertTrue(ts.isValid())
Пример #2
0
 def testNsecsDefault(self):
     ts = DateTime(1192755506000000000)
     self.assertEqual(ts.nsecs(DateTime.UTC), 1192755473000000000)
     self.assertEqual(ts.nsecs(DateTime.TAI), 1192755506000000000)
     self.assertEqual(ts.nsecs(), 1192755506000000000)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 54392.040196759262)
     self.assertTrue(ts.isValid())
Пример #3
0
 def testLeapSecond(self):
     trials = ((45205., 21), (41498.99, 10), (41499.01, 11), (57203.99, 35),
               (57204.01, 36), (57000., 35), (57210., 36))
     for mjd, diff in trials:
         ts = DateTime(mjd, DateTime.MJD, DateTime.UTC)
         delta = ts.nsecs(DateTime.TAI) - ts.nsecs(DateTime.UTC)
         self.assertEqual(delta / 1E9, diff)
Пример #4
0
 def testNsecsTT(self):
     ts = DateTime(long(1192755538184000000), DateTime.TT)
     self.assertEqual(ts.nsecs(DateTime.UTC), long(1192755473000000000))
     self.assertEqual(ts.nsecs(DateTime.TAI), long(1192755506000000000))
     self.assertEqual(ts.nsecs(), long(1192755506000000000))
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC),
                            54392.040196759262)
     self.assertTrue(ts.isValid())
Пример #5
0
 def testIsoUTCBasic(self):
     """Test basic ISO string input and output of UTC dates"""
     for dateSep in ("-", ""):  # "-" date separator is optional
         for timeSep in (":", ""):  # ":" time separator is optional
             for decPt in (".", ","):  # "." or "," may be used as decimal point
                 dateStr = "2009{0}04{0}02T07{1}26{1}39{2}314159265Z".format(dateSep, timeSep, decPt)
                 ts = DateTime(dateStr, DateTime.UTC)
                 self.assertEqual(ts.nsecs(DateTime.TT), 1238657265498159265)
                 self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233314159265)
                 self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199314159265)
                 self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.314159265Z")
Пример #6
0
 def testNsecs(self):
     ts = DateTime(1192755473000000000, DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), 1192755473000000000)
     self.assertEqual(ts.nsecs(DateTime.TAI), 1192755506000000000)
     self.assertEqual(ts.nsecs(), 1192755506000000000)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 54392.040196759262)
     ts2 = ts
     self.assertEqual(ts, ts2)
     ts2 = DateTime(1192755473000000000, DateTime.UTC)
     self.assertEqual(ts, ts2)
     ts2 = DateTime(1234567890000000000, DateTime.UTC)
     self.assertNotEqual(ts, ts2)
Пример #7
0
 def testIsoUTCBasic(self):
     """Test basic ISO string input and output of UTC dates
     """
     for dateSep in ("-", ""):  # "-" date separator is optional
         for timeSep in (":", ""):  # ":" time separator is optional
             for decPt in (".", ","):  # "." or "," may be used as decimal point
                 dateStr = "2009{0}04{0}02T07{1}26{1}39{2}314159265Z".format(dateSep, timeSep, decPt)
                 ts = DateTime(dateStr, DateTime.UTC)
                 self.assertEqual(ts.nsecs(DateTime.TT), 1238657265498159265)
                 self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233314159265)
                 self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199314159265)
                 self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.314159265Z")
Пример #8
0
 def testLeapSecond(self):
     trials = ((45205., 21),
               (41498.99, 10),
               (41499.01, 11),
               (57203.99, 35),
               (57204.01, 36),
               (57000., 35),
               (57210., 36))
     for mjd, diff in trials:
         ts = DateTime(mjd, DateTime.MJD, DateTime.UTC)
         delta = ts.nsecs(DateTime.TAI) - ts.nsecs(DateTime.UTC)
         self.assertEqual(delta/1E9, diff)
Пример #9
0
 def testNsecs(self):
     ts = DateTime(1192755473000000000, DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), 1192755473000000000)
     self.assertEqual(ts.nsecs(DateTime.TAI), 1192755506000000000)
     self.assertEqual(ts.nsecs(), 1192755506000000000)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 54392.040196759262)
     ts2 = ts
     self.assertEqual(ts, ts2)
     ts2 = DateTime(1192755473000000000, DateTime.UTC)
     self.assertEqual(ts, ts2)
     ts2 = DateTime(1234567890000000000, DateTime.UTC)
     self.assertNotEqual(ts, ts2)
Пример #10
0
 def testMJD(self):
     ts = DateTime(45205.125, DateTime.MJD, DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), 399006000000000000)
     self.assertEqual(ts.nsecs(DateTime.TAI), 399006021000000000)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 45205.125)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.TAI), 45205.125 + 21.0/86400.0)
     self.assertTrue(ts.isValid())
Пример #11
0
    def setUp(self):
        rawPath = os.path.join(testDataDirectory, "hsc", "raw")
        calibPath = os.path.join(testDataDirectory, "hsc", "calib")
        self.repoPath = createDataRepository("lsst.obs.hsc.HscMapper", rawPath, calibPath)
        self.butler = dafPersist.Butler(root=self.repoPath, calibRoot=calibPath)

        # The following properties of the provided data are known a priori.
        self.visit = 904024
        self.ccdNum = 50
        self.filter = 'i'
        self.rawSize = (2144, 4241)
        self.ccdSize = (2048, 4176)
        self.exptime = 30.0
        self.darktime = self.exptime  # No explicit darktime
        dateBeg = DateTime(56598.26106374757, DateTime.MJD, DateTime.UTC)
        dateAvgNSec = dateBeg.nsecs() + int(0.5e9*self.exptime)
        self.dateAvg = DateTime(dateAvgNSec, DateTime.TAI)
        self.boresightRaDec = afwGeom.SpherePoint(320.7499250000, 0.500019444, degrees)
        self.boresightAzAlt = afwGeom.SpherePoint(226.68922661, 63.04359233, degrees)
        self.boresightAirmass = 1.121626027604189
        self.boresightRotAngle = 270.0*degrees
        self.rotType = RotType.SKY
        self.obs_longitude = -155.476667*degrees
        self.obs_latitude = 19.825556*degrees
        self.obs_elevation = 4139
        self.weath_airTemperature = MakeRawVisitInfo.centigradeFromKelvin(272.35)
        self.weath_airPressure = MakeRawVisitInfo.pascalFromMmHg(621.7)
        self.weath_humidity = 33.1
        # NOTE: if we deal with DM-8053 and get UT1 implemented, ERA will change slightly.
        lst = 340.189608333*degrees
        self.era = lst - self.obs_longitude
Пример #12
0
 def testMJD(self):
     ts = DateTime(45205.125, DateTime.MJD, DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), 399006000000000000)
     self.assertEqual(ts.nsecs(DateTime.TAI), 399006021000000000)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 45205.125)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.TAI), 45205.125 + 21.0/86400.0)
     self.assertTrue(ts.isValid())
Пример #13
0
 def setUp(self):
     datadir = self.getTestDataDir()
     self.repoPath = os.path.join(datadir, "DATA")
     self.calibPath = os.path.join(datadir, "CALIB")
     self.butler = dafPersist.Butler(root=self.repoPath,
                                     calibRoot=self.calibPath)
     self.size = (2112, 4644)
     self.dataId = {'visit': 1038843}
     self.filter = "i2"
     self.exposureTime = 615.037
     self.darkTime = 615.0
     dateObs = DateTime(54771.6066250, DateTime.MJD, DateTime.UTC)
     self.dateAvg = DateTime(
         dateObs.nsecs(DateTime.TAI) + int(0.5e9 * self.exposureTime),
         DateTime.TAI)
     self.boresightRaDec = IcrsCoord(135.409417 * degrees,
                                     -2.400000 * degrees)
     self.boresightAzAlt = Coord(122.34 * degrees, 52.02 * degrees)
     self.boresightAirmass = 1.269
     self.rotType = RotType.UNKNOWN
     self.obs_longitude = -155.468876 * degrees
     self.obs_latitude = 19.825252 * degrees
     self.obs_elevation = 4204
     self.weath_airTemperature = 0.90
     self.weath_airPressure = 617.65 * 100  # 100 Pascal/millibar
     self.weath_humidity = 39.77
     # NOTE: if we deal with DM-8053 and get UT1 implemented, ERA will change slightly.
     lst = 104.16591666666666 * degrees
     self.era = lst - self.obs_longitude
Пример #14
0
 def testMJD(self):
     ts = DateTime(45205.125, DateTime.MJD, DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), 399006000000000000L)
     self.assertEqual(ts.nsecs(DateTime.TAI), 399006021000000000L)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 45205.125)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.TAI), 45205.125 + 21.0/86400.0)
     # Following interface is deprecated
     self.assertAlmostEqual(ts.mjd(DateTime.UTC), 45205.125)
     self.assertAlmostEqual(ts.mjd(DateTime.TAI), 45205.125 + 21.0/86400.0)
Пример #15
0
def _visitTimes(start_time: DateTime, interval_sec: int,
                count: int) -> Iterator[DateTime]:
    """
    Generator for visit times.
    """
    nsec = start_time.nsecs(DateTime.TAI)
    delta = interval_sec * 1_000_000_000
    while count > 0:
        dt = DateTime(nsec, DateTime.TAI)
        if not _isDayTime(dt):
            yield dt
            count -= 1
        nsec += delta
Пример #16
0
    def testGetDR7(self):
        obsSdssDir = lsst.utils.getPackageDir('obs_sdss')
        butler = dafPersist.Butler(
            root=os.path.join(obsSdssDir, "tests", "data", "dr7", "runs"))
        sub = butler.subset("fpC", run=5754, camcol=3, field=280, filter="r")
        self.assertEqual(len(sub), 1)
        for ref in sub:
            im = ref.get("fpC")
            w, h = im.getWidth(), im.getHeight()
            self.assertEqual(im.__class__, lsst.afw.image.ImageU)
            self.assertEqual(w, 2048)
            self.assertEqual(h, 1489)

            im_md = ref.get("fpC_md")
            self.assertEqual(im_md.get("RUN"), 5754)
            self.assertEqual(im_md.get("FRAME"), 280)
            self.assertEqual(im_md.get("STRIPE"), 82)

            msk = ref.get("fpM")
            w, h = msk.getWidth(), msk.getHeight()
            self.assertEqual(msk.__class__,
                             lsst.afw.image.Mask[lsst.afw.image.MaskPixel])
            self.assertEqual(w, 2048)
            self.assertEqual(h, 1489)

            psf = ref.get("psField")
            k = psf.getKernel()
            w, h = k.getWidth(), k.getHeight()
            self.assertEqual(psf.__class__, lsst.meas.algorithms.PcaPsf)
            self.assertEqual(w, 31)
            self.assertEqual(h, 31)

            wcs = ref.get("asTrans")
            self.assertIsInstance(wcs, SkyWcs)
            self.assertFalse(wcs.isFlipped)
            # comparison is to results from lsst.afw.image.TanWcs class
            self.assertCoordsAlmostEqual(
                wcs.pixelToSky(700, 1000),
                IcrsCoord(343.6507738304687 * degrees,
                          -0.3509870420713227 * degrees))

            tsField = ref.get("tsField")
            self.assertAlmostEqual(tsField.gain, 4.72, 2)
            self.assertAlmostEqual(tsField.airmass, 1.2815132857671601)
            self.assertAlmostEqual(tsField.exptime, 53.907456)
            predDateStart = DateTime(53664.226070589997, DateTime.MJD,
                                     DateTime.TAI)
            predDateAvg = DateTime(
                predDateStart.nsecs(DateTime.TAI) +
                int(0.5e9 * tsField.exptime), DateTime.TAI)
            self.assertAlmostEqual(tsField.dateAvg.get(), predDateAvg.get())
Пример #17
0
    def testDM7622(self):
        """Test DM-7622: date with unix time = -1 seconds must be usable

        Note that the call in question parses the ISO string without paying
        attention to the scale (it applies the scale later),
        so the same ISO string is wanted in all cases
        (except with a trailing Z for UTC, and without for TAI and TT)
        """
        negOneSecIso = "1969-12-31T23:59:59.000000000"
        for scale in self.timeScales:
            dateStr = negOneSecIso + ("Z" if scale == DateTime.UTC else "")
            try:
                dt = DateTime(dateStr, scale)
            except Exception:
                self.fail("Date {} in scale {} unusable".format(dateStr, scale))
            self.assertEqual(dt.nsecs(scale), int(-1e9))
Пример #18
0
    def testDM7622(self):
        """Test DM-7622: date with unix time = -1 seconds must be usable

        Note that the call in question parses the ISO string without paying
        attention to the scale (it applies the scale later),
        so the same ISO string is wanted in all cases
        (except with a trailing Z for UTC, and without for TAI and TT)
        """
        negOneSecIso = "1969-12-31T23:59:59.000000000"
        for scale in self.timeScales:
            dateStr = negOneSecIso + ("Z" if scale == DateTime.UTC else "")
            try:
                dt = DateTime(dateStr, scale)
            except Exception:
                self.fail("Date {} unusable; DM-7622 is still with us".format(dateStr, scale))
            self.assertEqual(dt.nsecs(scale), int(-1e9))
Пример #19
0
 def setUp(self):
     self.butler = dafPersist.Butler(root=os.path.join(os.path.dirname(__file__), "data"))
     self.exposureTime = 15.0
     self.darkTime = 15.0
     dateObs = DateTime(49552.28496, DateTime.MJD, DateTime.TAI)
     self.dateAvg = DateTime(dateObs.nsecs(DateTime.TAI) + int(0.5e9*self.exposureTime), DateTime.TAI)
     self.boresightRaDec = SpherePoint(359.936019771151, -2.3356222648145, degrees)
     self.boresightAzAlt = SpherePoint(127.158246182602, 90 - 40.6736117075876, degrees)
     self.boresightAirmass = 1.31849492005496
     self.boresightRotAngle = -3.43228*degrees
     self.rotType = RotType.SKY
     self.obs_longitude = -70.749417*degrees
     self.obs_latitude = -30.244633*degrees
     self.obs_elevation = 2663.0
     self.weath_airTemperature = 5.0
     self.weath_airPressure = MakeRawVisitInfo.pascalFromMmHg(520.0)
     self.weath_humidity = 40.
Пример #20
0
 def testInvalid(self):
     ts = DateTime()
     self.assertFalse(ts.isValid())
     for scale in self.timeScales:
         self.assertEqual(ts.nsecs(scale), DateTime.invalid_nsecs)
         for system in self.dateSystems:
             with self.assertRaises(pexExcept.RuntimeError):
                 ts.get(system, scale)
         with self.assertRaises(pexExcept.RuntimeError):
             ts.gmtime(scale)
         with self.assertRaises(pexExcept.RuntimeError):
             ts.timespec(scale)
         with self.assertRaises(pexExcept.RuntimeError):
             ts.timeval(scale)
         with self.assertRaises(pexExcept.RuntimeError):
             ts.toString(scale)
     self.assertEqual(repr(ts), "DateTime()")
Пример #21
0
 def testInvalid(self):
     ts = DateTime()
     self.assertFalse(ts.isValid())
     for scale in self.timeScales:
         self.assertEqual(ts.nsecs(scale), DateTime.invalid_nsecs)
         for system in self.dateSystems:
             with self.assertRaises(RuntimeError):
                 ts.get(system, scale)
         with self.assertRaises(RuntimeError):
             ts.gmtime(scale)
         with self.assertRaises(RuntimeError):
             ts.timespec(scale)
         with self.assertRaises(RuntimeError):
             ts.timeval(scale)
         with self.assertRaises(RuntimeError):
             ts.toString(scale)
     self.assertEqual(repr(ts), "DateTime()")
Пример #22
0
    def testGetDR7(self):
        obsSdssDir = lsst.utils.getPackageDir('obs_sdss')
        butler = dafPersist.Butler(
            root=os.path.join(obsSdssDir, "tests", "data", "dr7", "runs"))
        sub = butler.subset("fpC", run=5754, camcol=3, field=280, filter="r")
        self.assertEqual(len(sub), 1)
        for ref in sub:
            im = ref.get("fpC")
            w, h = im.getWidth(), im.getHeight()
            self.assertEqual(im.__class__, lsst.afw.image.ExposureU)
            self.assertEqual(w, 2048)
            self.assertEqual(h, 1489)

            im_md = ref.get("fpC_md")
            self.assertEqual(im_md.getScalar("RUN"), 5754)
            self.assertEqual(im_md.getScalar("FRAME"), 280)
            self.assertEqual(im_md.getScalar("STRIPE"), 82)

            msk = ref.get("fpM")
            w, h = msk.getWidth(), msk.getHeight()
            self.assertEqual(msk.__class__, lsst.afw.image.Mask[lsst.afw.image.MaskPixel])
            self.assertEqual(w, 2048)
            self.assertEqual(h, 1489)

            psf = ref.get("psField")
            k = psf.getKernel()
            w, h = k.getWidth(), k.getHeight()
            self.assertEqual(psf.__class__, lsst.meas.algorithms.PcaPsf)
            self.assertEqual(w, 31)
            self.assertEqual(h, 31)

            wcs = ref.get("asTrans")
            self.assertIsInstance(wcs, SkyWcs)
            self.assertFalse(wcs.isFlipped)
            # comparison is to results from lsst.afw.image.TanWcs class
            self.assertSpherePointsAlmostEqual(wcs.pixelToSky(700, 1000),
                                               SpherePoint(343.6507738304687, -0.3509870420713227, degrees))

            tsField = ref.get("tsField")
            self.assertAlmostEqual(tsField.gain, 4.72, 2)
            self.assertAlmostEqual(tsField.airmass, 1.2815132857671601)
            self.assertAlmostEqual(tsField.exptime, 53.907456)
            predDateStart = DateTime(53664.226070589997, DateTime.MJD, DateTime.TAI)
            predDateAvg = DateTime(predDateStart.nsecs(DateTime.TAI) + int(0.5e9*tsField.exptime),
                                   DateTime.TAI)
            self.assertAlmostEqual(tsField.dateAvg.get(), predDateAvg.get())
Пример #23
0
 def setUp(self):
     self.butler = dafPersist.Butler(root=os.path.join(os.path.dirname(__file__), "data"))
     self.exposureTime = 15.0
     self.darkTime = 15.0
     dateObs = DateTime(49552.28496, DateTime.MJD, DateTime.TAI)
     self.dateAvg = DateTime(dateObs.nsecs(DateTime.TAI) + int(0.5e9*self.exposureTime), DateTime.TAI)
     self.boresightRaDec = SpherePoint(359.936019771151, -2.3356222648145, degrees)
     self.boresightAzAlt = SpherePoint(127.158246182602, 90 - 40.6736117075876, degrees)
     self.boresightAirmass = 1.31849492005496
     self.boresightRotAngle = -3.43228*degrees
     self.rotType = RotType.SKY
     self.obs_longitude = -70.749417*degrees
     self.obs_latitude = -30.244633*degrees
     self.obs_elevation = 2663.0
     self.weath_airTemperature = 5.0
     self.weath_airPressure = MakeRawVisitInfo.pascalFromMmHg(520.0)
     self.weath_humidity = 40.
Пример #24
0
    def testGetDR7(self):
        obsSdssDir = lsst.utils.getPackageDir('obs_sdss')
        butler = dafPersist.Butler(
            root=os.path.join(obsSdssDir, "tests", "data", "dr7", "runs"))
        sub = butler.subset("fpC", run=5754, camcol=3, field=280, filter="r")
        self.assertEqual(len(sub), 1)
        for ref in sub:
            im = ref.get("fpC")
            w, h = im.getWidth(), im.getHeight()
            self.assertEqual(im.__class__, lsst.afw.image.ImageU)
            self.assertEqual(w, 2048)
            self.assertEqual(h, 1489)

            im_md = ref.get("fpC_md")
            self.assertEqual(im_md.get("RUN"), 5754)
            self.assertEqual(im_md.get("FRAME"), 280)
            self.assertEqual(im_md.get("STRIPE"), 82)

            msk = ref.get("fpM")
            w, h = msk.getWidth(), msk.getHeight()
            self.assertEqual(msk.__class__, lsst.afw.image.Mask[lsst.afw.image.MaskPixel])
            self.assertEqual(w, 2048)
            self.assertEqual(h, 1489)

            psf = ref.get("psField")
            k = psf.getKernel()
            w, h = k.getWidth(), k.getHeight()
            self.assertEqual(psf.__class__, lsst.meas.algorithms.PcaPsf)
            self.assertEqual(w, 31)
            self.assertEqual(h, 31)

            wcs = ref.get("asTrans")
            self.assertEqual(wcs.__class__, lsst.afw.image.TanWcs)
            self.assertFalse(wcs.isFlipped())
            self.assertAlmostEqual(wcs.getFitsMetadata().get("CRPIX1"), 1.0, 5)
            self.assertAlmostEqual(wcs.getFitsMetadata().get("CRPIX2"), 1.0, 5)

            tsField = ref.get("tsField")
            self.assertAlmostEqual(tsField.gain, 4.72, 2)
            self.assertAlmostEqual(tsField.airmass, 1.2815132857671601)
            self.assertAlmostEqual(tsField.exptime, 53.907456)
            predDateStart = DateTime(53664.226070589997, DateTime.MJD, DateTime.TAI)
            predDateAvg = DateTime(predDateStart.nsecs(DateTime.TAI) + int(0.5e9*tsField.exptime),
                                   DateTime.TAI)
            self.assertAlmostEqual(tsField.dateAvg.get(), predDateAvg.get())
Пример #25
0
 def testCrossBoundaryNsecs(self):
     ts = DateTime(631151998000000000, DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), 631151998000000000)
     self.assertEqual(ts.nsecs(DateTime.TAI), 631152022000000000)
Пример #26
0
 def testIsoEpoch(self):
     ts = DateTime("19700101T000000Z", DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), long(0))
     self.assertEqual(ts.toString(ts.UTC), "1970-01-01T00:00:00.000000000Z")
Пример #27
0
 def testBoundaryMJD(self):
     ts = DateTime(47892.0, DateTime.MJD, DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), 631152000000000000)
     self.assertEqual(ts.nsecs(DateTime.TAI), 631152025000000000)
     self.assertEqual(ts.get(DateTime.MJD, DateTime.UTC), 47892.0)
Пример #28
0
 def testIsoNoNSecs(self):
     ts = DateTime("2009-04-02T07:26:39Z", DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.TAI), long(1238657233000000000))
     self.assertEqual(ts.nsecs(DateTime.UTC), long(1238657199000000000))
     self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.000000000Z")
     self.assertTrue(ts.isValid())
Пример #29
0
 def testIsoExpanded(self):
     ts = DateTime("2009-04-02T07:26:39.314159265Z", DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.TAI), long(1238657233314159265))
     self.assertEqual(ts.nsecs(DateTime.UTC), long(1238657199314159265))
     self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.314159265Z")
     self.assertTrue(ts.isValid())
Пример #30
0
 def testIsoBasic(self):
     ts = DateTime("20090402T072639.314159265Z")
     self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233314159265L)
     self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199314159265L)
     self.assertEqual(ts.toString(), "2009-04-02T07:26:39.314159265Z")
Пример #31
0
 def testCrossBoundaryNsecs(self):
     ts = DateTime(long(631151998000000000), DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), long(631151998000000000))
     self.assertEqual(ts.nsecs(DateTime.TAI), long(631152022000000000))
Пример #32
0
 def testIsoNoNSecs(self):
     ts = DateTime("2009-04-02T07:26:39Z", DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233000000000)
     self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199000000000)
     self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.000000000Z")
     self.assertTrue(ts.isValid())
Пример #33
0
 def testIsoExpanded(self):
     ts = DateTime("2009-04-02T07:26:39.314159265Z", DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.TAI), 1238657233314159265)
     self.assertEqual(ts.nsecs(DateTime.UTC), 1238657199314159265)
     self.assertEqual(ts.toString(ts.UTC), "2009-04-02T07:26:39.314159265Z")
     self.assertTrue(ts.isValid())
Пример #34
0
    def testPolicies(self):
        ps = orcaProv.Provenance(self.user, self.runId, self.dbLoc,
                self.globalDbLoc)
        paths = ("tests/policy/dc2pipe.paf",
                "tests/policy/imageSubtractionDetection.paf")
        for p in paths:
            ps.recordPolicy(p)

        db = DbStorage()
        db.setRetrieveLocation(LogicalLocation(self.dbLoc))

        for p in paths:
            md5 = hashlib.md5()
            f = open(p, 'r')
            for line in f:
                md5.update(line)
            f.close()
            hash = md5.hexdigest()
            mod = DateTime(os.stat(p)[8] * 1000000000L, DateTime.UTC)

            pol = pexPolicy.Policy(p)
            names = pol.paramNames()

            db.startTransaction()

            db.setTableListForQuery(
                    ("prv_PolicyFile", "prv_PolicyKey", "prv_cnf_PolicyKey"))
            db.outColumn("hashValue")
            db.outColumn("modifiedDate")
            db.outColumn("keyName")
            db.outColumn("keyType")
            db.outColumn("value")
            db.setQueryWhere(
                """pathname = '%s'
                AND prv_PolicyFile.policyFileId = prv_PolicyKey.policyFileId
                AND prv_PolicyKey.policyKeyId = prv_cnf_PolicyKey.policyKeyId
                """ % (p))
            db.query()

            while db.next():
                self.assert_(not db.columnIsNull(0))
                self.assert_(not db.columnIsNull(1))
                self.assert_(not db.columnIsNull(2))
                self.assert_(not db.columnIsNull(3))
                self.assert_(not db.columnIsNull(4))
                self.assertEqual(db.getColumnByPosString(0), hash)
                self.assertEqual(db.getColumnByPosInt64(1), mod.nsecs())
                key = db.getColumnByPosString(2)
                self.assert_(pol.exists(key))
                self.assert_(key in names)
                names.remove(key)
                self.assertEqual(db.getColumnByPosString(3),
                        pol.getTypeName(key))
                correct = pol.str(key)
                correct = re.sub(r'\0', r'', correct)
                self.assertEqual(db.getColumnByPosString(4), correct)

            db.finishQuery()

            db.endTransaction()

            self.assertEqual(len(names), 0)
Пример #35
0
 def testIsoEpoch(self):
     ts = DateTime("19700101T000000Z", DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), 0)
     self.assertEqual(ts.toString(ts.UTC), "1970-01-01T00:00:00.000000000Z")
Пример #36
0
 def testNsecsTAI(self):
     ts = DateTime(1192755506000000000L, DateTime.TAI)
     self.assertEqual(ts.nsecs(DateTime.UTC), 1192755473000000000L)
     self.assertEqual(ts.nsecs(DateTime.TAI), 1192755506000000000L)
     self.assertEqual(ts.nsecs(), 1192755506000000000L)
     self.assertAlmostEqual(ts.get(DateTime.MJD, DateTime.UTC), 54392.040196759262)
Пример #37
0
    def testMakeRawVisitInfo(self):
        """Test base class functor MakeRawVisitInfo

        The base class only sets date and exposureTime fields,
        reads DATE-OBS, TIMESYS and EXPTIME,
        and deletes DATE-OBS and EXPTIME, but not TIMESYS.
        """
        exposureTime = 6.2  # arbitrary value in seconds
        date = DateTime("2001-01-02T03:04:05.123456789", DateTime.TAI)
        dateNsec = date.nsecs(DateTime.TAI)
        startDate = DateTime(dateNsec - int(exposureTime*1e9/2), DateTime.TAI)

        exposureId = 54321  # an arbitrary value
        md = getMetadata({
            "DATE-OBS": startDate.toString(DateTime.UTC),
            "TIMESYS": "UTC",
            "EXPTIME": exposureTime,
            "EXTRA1": "an abitrary key and value",
            "EXTRA2": 5,
        })
        length = len(md)
        visitInfo = self.makeRawVisitInfo(md=md, exposureId=exposureId)
        self.assertEqual(visitInfo.getExposureId(), exposureId)
        self.assertEqual(md.nameCount(), length)  # No stripping
        self.assertEqual(visitInfo.getExposureTime(), exposureTime)
        self.assertEqual(visitInfo.getDate(), date)

        # Test stripping keywords
        visitInfo = SimpleMakeRawVisitInfo(doStripHeader=True)(md=md, exposureId=exposureId)
        self.assertEqual(md.nameCount(), 3)  # TIMESYS and two EXTRAn keywords

        # try TIMESYS=TAI
        md = getMetadata({
            "DATE-OBS": startDate.toString(DateTime.TAI),
            "TIMESYS": "TAI",
            "EXPTIME": exposureTime,
        })
        length = len(md)
        visitInfo = self.makeRawVisitInfo(md=md, exposureId=exposureId)
        self.assertEqual(md.nameCount(), length)
        self.assertEqual(visitInfo.getExposureTime(), exposureTime)
        self.assertEqual(visitInfo.getDate(), date)

        # try omitting TIMESYS, which defaults to UTC
        md = getMetadata({
            "DATE-OBS": startDate.toString(DateTime.UTC),
            "EXPTIME": exposureTime,
        })
        length = len(md)
        visitInfo = self.makeRawVisitInfo(md=md, exposureId=exposureId)
        self.assertEqual(md.nameCount(), length)
        self.assertEqual(visitInfo.getExposureTime(), exposureTime)
        self.assertEqual(visitInfo.getDate(), date)

        # omit DATE-OBS; date should be default-constructed
        md = getMetadata({
            "EXPTIME": exposureTime,
        })
        length = len(md)
        visitInfo = self.makeRawVisitInfo(md=md, exposureId=exposureId)
        self.assertEqual(md.nameCount(), length)
        self.assertEqual(visitInfo.getExposureTime(), exposureTime)
        self.assertEqual(visitInfo.getDate(), DateTime())

        # omit EXPTIME; date should be start date, not avg date, and
        # exposureTime should be nan
        md = getMetadata({
            "DATE-OBS": startDate.toString(DateTime.UTC),
        })
        length = len(md)
        visitInfo = self.makeRawVisitInfo(md=md, exposureId=exposureId)
        self.assertEqual(md.nameCount(), length)
        self.assertTrue(math.isnan(visitInfo.getExposureTime()))
        self.assertEqual(visitInfo.getDate(), startDate)
Пример #38
0
 def testBoundaryMJD(self):
     ts = DateTime(47892.0, DateTime.MJD, DateTime.UTC)
     self.assertEqual(ts.nsecs(DateTime.UTC), long(631152000000000000))
     self.assertEqual(ts.nsecs(DateTime.TAI), long(631152025000000000))
     self.assertEqual(ts.get(DateTime.MJD, DateTime.UTC), 47892.0)