本文整理汇总了Python中pyiem.util.utc函数的典型用法代码示例。如果您正苦于以下问题:Python utc函数的具体用法?Python utc怎么用?Python utc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了utc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_valid_nomnd
def test_valid_nomnd():
""" check valid (no Mass News) Parsing """
utcnow = utc(2012, 11, 27)
tp = product.TextProduct(
get_test_file('AFD_noMND.txt'), utcnow=utcnow)
ts = utc(2012, 11, 27, 0, 1)
assert tp.valid == ts
示例2: test_mcdparser
def test_mcdparser(dbcursor):
''' Test Parsing of MCD Product '''
prod = parser(get_test_file('MCD_MPD/SWOMCD.txt'))
assert abs(prod.geometry.area - 4.302) < 0.001
assert prod.discussion_num == 1525
assert prod.attn_wfo[2] == 'DLH'
ans = "PORTIONS OF NRN WI AND THE UPPER PENINSULA OF MI"
assert prod.areas_affected == ans
# With probability this time
prod = parser(get_test_file('MCD_MPD/SWOMCDprob.txt'))
assert abs(prod.geometry.area - 2.444) < 0.001
assert prod.watch_prob == 20
jmsg = prod.get_jabbers('http://localhost')
ans = (
'<p>Storm Prediction Center issues '
'<a href="http://www.spc.noaa.gov/'
'products/md/2013/md1678.html">Mesoscale Discussion #1678</a> '
'[watch probability: 20%] (<a href="http://localhost'
'?pid=201308091725-KWNS-ACUS11-SWOMCD">View text</a>)</p>')
assert jmsg[0][1] == ans
ans = (
'Storm Prediction Center issues Mesoscale Discussion #1678 '
'[watch probability: 20%] '
'http://www.spc.noaa.gov/products/md/2013/md1678.html')
assert jmsg[0][0] == ans
ans = utc(2013, 8, 9, 17, 25)
assert prod.sts == ans
ans = utc(2013, 8, 9, 19, 30)
assert prod.ets == ans
prod.database_save(dbcursor)
示例3: test_utc
def test_utc():
"""Does the utc() function work as expected."""
answer = datetime.datetime(2017, 2, 1, 2, 20).replace(tzinfo=pytz.UTC)
res = util.utc(2017, 2, 1, 2, 20)
assert answer == res
answer = datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)
assert answer.year == util.utc().year
示例4: test_01
def test_01():
"""LSR.txt process a valid LSR without blemish """
utcnow = utc(2013, 7, 23, 23, 54)
prod = parser(get_test_file("LSR.txt"), utcnow=utcnow)
assert len(prod.lsrs) == 58
assert abs(prod.lsrs[57].magnitude_f - 73) < 0.01
assert prod.lsrs[57].county == "MARION"
assert prod.lsrs[57].state == "IA"
assert abs(prod.lsrs[57].get_lon() - -93.11) < 0.01
assert abs(prod.lsrs[57].get_lat() - 41.3) < 0.01
assert prod.is_summary()
assert prod.lsrs[57].wfo == 'DMX'
answer = utc(2013, 7, 23, 3, 55)
assert prod.lsrs[57].valid == answer
j = prod.get_jabbers('http://iem.local/')
assert j[57][0], (
"Knoxville Airport [Marion Co, IA] AWOS reports NON-TSTM WND "
"GST of M73 MPH at 22 Jul, 10:55 PM CDT -- HEAT BURST. "
"TEMPERATURE ROSE FROM 70 TO 84 IN 15 MINUTES AND DEW POINT "
"DROPPED FROM 63 TO 48 IN 10 MINUTES. "
"http://iem.local/#DMX/201307230355/201307230355")
ans = (
"At 4:45 PM CDT, Dows [Wright Co, IA] LAW ENFORCEMENT "
"reports TSTM WND DMG. DELAYED REPORT. LARGE TREE "
"BRANCH DOWN IN TOWN THAT TOOK OUT A POWER LINE "
"AND BLOCKING PART OF A ROAD."
)
assert prod.lsrs[5].tweet() == ans
示例5: find_time
def find_time(self):
"""Find the start and end valid time of this watch
Returns:
(datetime, datetime): representing the time of this watch
"""
if self.action == self.CANCELS:
return (None, None)
sts = self.utcnow
ets = self.utcnow
tokens = re.findall(("([0-3][0-9])([0-2][0-9])([0-6][0-9])Z - "
"([0-3][0-9])([0-2][0-9])([0-6][0-9])Z"),
self.unixtext)
day1 = int(tokens[0][0])
hour1 = int(tokens[0][1])
minute1 = int(tokens[0][2])
day2 = int(tokens[0][3])
hour2 = int(tokens[0][4])
minute2 = int(tokens[0][5])
sts = utc(self.utcnow.year, self.utcnow.month, day1, hour1, minute1)
ets = utc(self.utcnow.year, self.utcnow.month, day2, hour2, minute2)
# If we are near the end of the month and the day1 is 1, add 1 month
if self.utcnow.day > 27 and day1 == 1:
sts += datetime.timedelta(days=+35)
sts = sts.replace(day=1)
if self.utcnow.day > 27 and day2 == 1:
ets += datetime.timedelta(days=+35)
ets = ets.replace(day=1)
return (sts, ets)
示例6: test_sigpat
def test_sigpat():
""" Make sure we don't have another failure with geom parsing """
utcnow = utc(2014, 8, 11, 12, 34)
tp = parser(get_test_file('SIGMETS/SIGPAT.txt'), utcnow)
j = tp.get_jabbers('http://localhost', 'http://localhost')
assert abs(tp.sigmets[0].geom.area - 33.71) < 0.01
assert tp.sigmets[0].sts == utc(2014, 8, 11, 12, 35)
assert tp.sigmets[0].ets == utc(2014, 8, 11, 16, 35)
assert j[0][0] == 'PHFO issues SIGMET TANGO 1 till 1635 UTC'
示例7: test_171121_issue45
def test_171121_issue45(dbcursor):
"""Do we alert on duplicated ETNs?"""
utcnow = utc(2017, 4, 20, 21, 33)
prod = vtecparser(get_test_file('vtec/NPWDMX_0.txt'), utcnow=utcnow)
prod.sql(dbcursor)
utcnow = utc(2017, 11, 20, 21, 33)
prod = vtecparser(get_test_file('vtec/NPWDMX_1.txt'), utcnow=utcnow)
prod.sql(dbcursor)
warnings = filter_warnings(prod.warnings)
assert len(warnings) == 1
示例8: test_170406_day48
def test_170406_day48(dbcursor):
"""Can we parse a present day days 4-8"""
spc = parser(get_test_file('SPCPTS/PTSD48.txt'))
# spc.draw_outlooks()
outlook = spc.get_outlook('ANY SEVERE', '0.15', 4)
assert abs(outlook.geometry.area - 40.05) < 0.01
spc.sql(dbcursor)
collect = spc.get_outlookcollection(4)
assert collect.issue == utc(2017, 4, 9, 12)
assert collect.expire == utc(2017, 4, 10, 12)
示例9: test_daily_offset
def test_daily_offset():
""" Compute the offsets """
ts = utc(2013, 1, 1, 0, 0)
offset = iemre.daily_offset(ts)
assert offset == 0
ts = datetime.date(2013, 2, 1)
offset = iemre.daily_offset(ts)
assert offset == 31
ts = utc(2013, 1, 5, 12, 0)
offset = iemre.daily_offset(ts)
assert offset == 4
示例10: test_vtec_series
def test_vtec_series(dbcursor):
"""Test a lifecycle of WSW products """
prod = vtecparser(get_test_file('WSWDMX/WSW_00.txt'))
assert prod.afos == 'WSWDMX'
prod.sql(dbcursor)
# Did Marshall County IAZ049 get a ZR.Y
dbcursor.execute("""
SELECT issue from warnings_2013 WHERE
wfo = 'DMX' and eventid = 1 and phenomena = 'ZR' and
significance = 'Y' and status = 'EXB'
and ugc = 'IAZ049'
""")
assert dbcursor.rowcount == 1
prod = vtecparser(get_test_file('WSWDMX/WSW_01.txt'))
assert prod.afos == 'WSWDMX'
prod.sql(dbcursor)
# Is IAZ006 in CON status with proper end time
answer = utc(2013, 1, 28, 6)
dbcursor.execute("""SELECT expire from warnings_2013 WHERE
wfo = 'DMX' and eventid = 1 and phenomena = 'WS' and
significance = 'W' and status = 'CON'
and ugc = 'IAZ006' """)
assert dbcursor.rowcount == 1
row = dbcursor.fetchone()
assert row[0] == answer
# No change
for i in range(2, 9):
prod = vtecparser(get_test_file('WSWDMX/WSW_%02i.txt' % (i,)))
assert prod.afos == 'WSWDMX'
prod.sql(dbcursor)
prod = vtecparser(get_test_file('WSWDMX/WSW_09.txt'))
assert prod.afos == 'WSWDMX'
prod.sql(dbcursor)
# IAZ006 should be cancelled
answer = utc(2013, 1, 28, 5, 38)
dbcursor.execute("""SELECT expire from warnings_2013 WHERE
wfo = 'DMX' and eventid = 1 and phenomena = 'WS' and
significance = 'W' and status = 'CAN'
and ugc = 'IAZ006' """)
assert dbcursor.rowcount == 1
row = dbcursor.fetchone()
assert row[0] == answer
示例11: test_str1
def test_str1(dbcursor):
""" check spcpts parsing """
spc = parser(get_test_file('SPCPTS/SPCPTS.txt'))
# spc.draw_outlooks()
assert spc.valid == utc(2013, 7, 19, 19, 52)
assert spc.issue == utc(2013, 7, 19, 20, 0)
assert spc.expire == utc(2013, 7, 20, 12, 0)
spc.sql(dbcursor)
spc.compute_wfos(dbcursor)
# It is difficult to get a deterministic result here as in Travis, we
# don't have UGCS, so the WFO lookup yields no results
j = spc.get_jabbers("")
assert len(j) >= 1
示例12: test_hourly_offset
def test_hourly_offset():
""" Compute the offsets """
ts = utc(2013, 1, 1, 0, 0)
offset = iemre.hourly_offset(ts)
assert offset == 0
ts = utc(2013, 1, 1, 6, 0)
ts = ts.astimezone(pytz.timezone("America/Chicago"))
offset = iemre.hourly_offset(ts)
assert offset == 6
ts = utc(2013, 1, 5, 12, 0)
offset = iemre.hourly_offset(ts)
assert offset == 4*24 + 12
示例13: test_simple
def test_simple(month):
"""Can we walk before we run."""
text = (
"KCVG DS 24/%02i 590353/ 312359// 53/ 48/"
"/9470621/T/T/00/00/00/00/00/00/"
"00/00/00/00/00/00/00/00/00/00/00/00/00/00/00/00/00/225/26381759/"
"26500949="
) % (month, )
tzprovider = {'KCVG': pytz.timezone("America/New_York")}
dsm = process(text)
dsm.compute_times(utc(2019, month, 25))
dsm.tzlocalize(tzprovider['KCVG'])
assert dsm.date == datetime.date(2019, month, 24)
assert dsm.station == 'KCVG'
assert dsm.time_sped_max == utc(2019, month, 24, 22, 59)
示例14: test_140610_no_vtec_time
def test_140610_no_vtec_time(dbcursor):
""" A VTEC Product with both 0000 for start and end time, sigh """
utcnow = utc(2014, 6, 10, 0, 56)
prod = vtecparser(get_test_file('FLSLZK_notime.txt'), utcnow=utcnow)
prod.sql(dbcursor)
assert prod.segments[0].vtec[0].begints is None
assert prod.segments[0].vtec[0].endts is None
示例15: test_150102_multiyear
def test_150102_multiyear(dbcursor):
""" WSWOUN See how well we span multiple years """
for i in range(13):
print(datetime.datetime.utcnow())
print('Parsing Product: %s.txt' % (i,))
prod = vtecparser(get_test_file('WSWOUN/%i.txt' % (i,)))
prod.sql(dbcursor)
# Make sure there are no null issue times
dbcursor.execute("""
SELECT count(*) from warnings_2014
where wfo = 'OUN' and eventid = 16
and phenomena = 'WW' and significance = 'Y'
and issue is null
""")
assert dbcursor.fetchone()[0] == 0
if i == 5:
dbcursor.execute("""
SELECT issue from warnings_2014
WHERE ugc = 'OKZ036' and wfo = 'OUN' and eventid = 16
and phenomena = 'WW' and significance = 'Y'
""")
row = dbcursor.fetchone()
assert row[0] == utc(2015, 1, 1, 6, 0)
warnings = filter_warnings(prod.warnings)
warnings = filter_warnings(warnings, "Segment has duplicated")
warnings = filter_warnings(warnings, "VTEC Product appears to c")
assert not warnings