本文整理汇总了Python中lsst.daf.base.DateTime类的典型用法代码示例。如果您正苦于以下问题:Python DateTime类的具体用法?Python DateTime怎么用?Python DateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMJD
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())
示例2: testNsecsDefault
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: testMJD
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)
示例4: testIsoNonUTCBasics
def testIsoNonUTCBasics(self):
"""Test basic ISO string input and output of TAI and TT dates"""
for scale in (DateTime.TAI, DateTime.TT):
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}314159265".format(dateSep, timeSep, decPt)
ts = DateTime(dateStr, scale)
self.assertEqual(ts.toString(scale), "2009-04-02T07:26:39.314159265")
self.assertTrue(ts.isValid())
示例5: testIsoUTCBasic
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: testLeapSecond
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)
示例7: testNsecs
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)
示例8: testDM7622
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))
示例9: setUp
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
self.dateAvg = DateTime(56598.261654253474, DateTime.MJD, 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 = -0.8
self.weath_airPressure = 62170.
self.weath_humidity = 33.1
# NOTE: if we deal with DM-8053 and get UT1 implemented, ERA will change slightly.
self.era = 2.3659577248977826*radians
示例10: testFracSecs
def testFracSecs(self):
ts = DateTime("2004-03-01T12:39:45.1Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '2004-03-01T12:39:45.100000000Z')
ts = DateTime("2004-03-01T12:39:45.01Z", DateTime.UTC)
self.assertEqual(ts.toString(ts.UTC), '2004-03-01T12:39:45.010000000Z')
ts = DateTime("2004-03-01T12:39:45.000000001Z", DateTime.UTC) # nanosecond
self.assertEqual(ts.toString(ts.UTC), '2004-03-01T12:39:45.000000001Z')
ts = DateTime("2004-03-01T12:39:45.0000000001Z", DateTime.UTC) # too small
self.assertEqual(ts.toString(ts.UTC), '2004-03-01T12:39:45.000000000Z')
示例11: testConvert
def testConvert(self):
year = 2012
month = 7
day = 19
hour = 18
minute = 29
second = 33
ts = DateTime(year, month, day, hour, minute, second, DateTime.UTC)
dt = ts.toPython(DateTime.UTC)
self.assertEqual(dt.year, year)
self.assertEqual(dt.month, month)
self.assertEqual(dt.day, day)
self.assertEqual(dt.hour, hour)
self.assertEqual(dt.minute, minute)
self.assertEqual(dt.second, second)
示例12: testGetDR7
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())
示例13: setUp
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.
示例14: testNow
def testNow(self):
successes = 0
for _ in range(10):
secs = time.time()
ts = DateTime.now()
diff = ts.nsecs(DateTime.UTC)/1.0e9 - secs
if diff > -0.001 and diff < 0.1:
successes += 1
self.assertGreaterEqual(successes, 3)
示例15: testNow
def testNow(self):
successes = 0
for i in xrange(10): # pylint: disable-msg=W0612
secs = time.time()
ts = DateTime.now()
diff = ts.nsecs(DateTime.UTC) / 1.0e9 - secs
if diff > -0.001 and diff < 0.1:
successes += 1
self.assertGreaterEqual(successes, 3)