本文整理汇总了Python中sunpy.time.parse_time函数的典型用法代码示例。如果您正苦于以下问题:Python parse_time函数的具体用法?Python parse_time怎么用?Python parse_time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_time函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_split_series_using_lytaf
def test_split_series_using_lytaf():
'''test the downloading of the LYTAF file and subsequent queries'''
tmp_dir = tempfile.mkdtemp()
lyra.download_lytaf_database(lytaf_dir=tmp_dir)
assert os.path.exists(os.path.join(tmp_dir, 'annotation_ppt.db'))
# test split_series_using_lytaf
# construct a dummy signal for testing purposes
basetime = parse_time('2010-06-13 02:00')
seconds = 3600
dummy_time = [basetime + TimeDelta(s*u.second) for s in range(seconds)]
dummy_data = np.random.random(seconds)
lytaf_tmp = lyra.get_lytaf_events('2010-06-13 02:00', '2010-06-13 06:00',
lytaf_path=tmp_dir,
combine_files=["ppt"])
split = lyra.split_series_using_lytaf(dummy_time, dummy_data, lytaf_tmp)
assert type(split) == list
assert len(split) == 4
assert is_time_equal(split[0]['subtimes'][0], parse_time((2010, 6, 13, 2, 0)))
assert is_time_equal(split[0]['subtimes'][-1], parse_time((2010, 6, 13, 2, 7, 2)))
assert is_time_equal(split[3]['subtimes'][0], parse_time((2010, 6, 13, 2, 59, 42)))
assert is_time_equal(split[3]['subtimes'][-1], parse_time((2010, 6, 13, 2, 59, 58)))
# Test case when no LYTAF events found in time series.
split_no_lytaf = lyra.split_series_using_lytaf(dummy_time,
dummy_data, LYTAF_TEST)
assert type(split_no_lytaf) == list
assert type(split_no_lytaf[0]) == dict
assert not set(split_no_lytaf[0].keys()).symmetric_difference({'subtimes', 'subdata'})
assert split_no_lytaf[0]["subtimes"] == dummy_time
assert split_no_lytaf[0]["subdata"].all() == dummy_data.all()
开发者ID:Cadair,项目名称:sunpy,代码行数:32,代码来源:test_lyra.py
示例2: test_unified_response
def test_unified_response():
start = parse_time("2012/1/1")
end = parse_time("2012/1/2")
qr = Fido.search(a.Instrument('EVE'), a.Level(0), a.Time(start, end))
assert qr.file_num == 2
strings = ['eve', 'SDO', start.strftime(TIMEFORMAT), end.strftime(TIMEFORMAT)]
assert all(s in qr._repr_html_() for s in strings)
开发者ID:Hypnus1803,项目名称:sunpy,代码行数:7,代码来源:test_fido.py
示例3: __init__
def __init__(self, start, end, near=None):
self.start = parse_time(start)
self.end = parse_time(end)
self.near = None if near is None else parse_time(near)
_Range.__init__(self, self.start, self.end, self.__class__)
Attr.__init__(self)
开发者ID:timmie,项目名称:sunpy,代码行数:7,代码来源:attrs.py
示例4: test_parse_observing_summary_dbase_file
def test_parse_observing_summary_dbase_file():
"""
Test that we get the observing summary dbase file with the content
we expect.
"""
obssum = rhessi.parse_observing_summary_dbase_file(get_test_filepath("hsi_obssumm_filedb_201104.txt"))
assert obssum['filename'][0][0:20] == 'hsi_obssumm_20110401'
assert obssum['filename'][1][0:20] == 'hsi_obssumm_20110402'
assert obssum['orb_st'][0] == 0
assert obssum['orb_st'][-1] == 0
assert obssum['orb_end'][0] == 0
assert obssum['orb_end'][-1] == 0
assert obssum['start_time'][0] == parse_time((2011, 4, 1, 0, 0, 0))
assert obssum['start_time'][-1] == parse_time((2011, 4, 30, 0, 0, 0))
assert obssum['end_time'][0] == parse_time((2011, 4, 2, 0, 0, 0))
assert obssum['end_time'][-1] == parse_time((2011, 5, 1, 0, 0, 0))
assert obssum['status_flag'][0] == 0
assert obssum['status_flag'][-1] == 0
assert obssum['npackets'][0] == 0
assert obssum['npackets'][-1] == 0
开发者ID:Cadair,项目名称:sunpy,代码行数:27,代码来源:test_rhessi.py
示例5: from_range
def from_range(cls, from_, to, **kwargs):
url = cls._get_url_for_date_range(parse_time(from_), parse_time(to))
filepath = cls._download(
url, kwargs,
err = "Unable to download data for specified date range"
)
return cls.from_file(filepath)
开发者ID:mjm159,项目名称:sunpy,代码行数:7,代码来源:lightcurve.py
示例6: test_parse_observing_summary_dbase_file_mock
def test_parse_observing_summary_dbase_file_mock():
"""
Ensure that all required data are extracted from the RHESSI
observing summary database file mocked in `hessi_data()`
"""
# We need to mock this test differently for <= 3.7.0 and below.
if LooseVersion(platform.python_version()) <= LooseVersion("3.7.0"):
mock_file = mock.mock_open()
mock_file.return_value.__iter__.return_value = hessi_data().splitlines()
else:
mock_file = mock.mock_open(read_data=hessi_data())
dbase_data = {}
with mock.patch('sunpy.instr.rhessi.open', mock_file, create=True):
dbase_data = rhessi.parse_observing_summary_dbase_file(None)
assert len(dbase_data.keys()) == 7
# verify each of the 7 fields
assert dbase_data['filename'] == ['hsi_obssumm_19721101_139.fit',
'hsi_obssumm_19721102_144.fit']
assert dbase_data['orb_st'] == [7, 9]
assert dbase_data['orb_end'] == [8, 10]
assert dbase_data['start_time'] == [parse_time((1972, 11, 1, 0, 0)),
parse_time((1972, 11, 2, 0, 0))]
assert dbase_data['end_time'] == [parse_time((1972, 11, 2, 0, 0)),
parse_time((1972, 11, 3, 0, 0))]
assert dbase_data['status_flag'] == [3, 4]
assert dbase_data['npackets'] == [2, 1]
开发者ID:Cadair,项目名称:sunpy,代码行数:29,代码来源:test_rhessi.py
示例7: test_parse_time_int_float
def test_parse_time_int_float():
# int and float values are not unique
# The format has to be mentioned
with pytest.raises(ValueError):
parse_time(100)
with pytest.raises(ValueError):
parse_time(100.0)
开发者ID:Cadair,项目名称:sunpy,代码行数:7,代码来源:test_time.py
示例8: test_detector_angles
def test_detector_angles():
#set a test date
date = parse_time('2012-02-15')
file = fermi.download_weekly_pointing_file(date)
det=fermi.get_detector_sun_angles_for_date(date,file)
assert len(det) == 13
#assert type(det) == collections.OrderedDict
assert_almost_equal(det['n0'][0].value, 20.30309,decimal=1)
assert_almost_equal(det['n1'][0].value, 30.30430, decimal=1)
assert_almost_equal(det['n2'][0].value, 74.86032, decimal=1)
assert_almost_equal(det['n3'][0].value, 31.24400, decimal=1)
assert_almost_equal(det['n4'][0].value, 75.10403, decimal=1)
assert_almost_equal(det['n5'][0].value, 60.40967, decimal=1)
assert_almost_equal(det['n6'][0].value, 46.14087, decimal=1)
assert_almost_equal(det['n7'][0].value, 69.71780, decimal=1)
assert_almost_equal(det['n8'][0].value, 106.08064, decimal=1)
assert_almost_equal(det['n9'][0].value, 68.543067, decimal=1)
assert_almost_equal(det['n10'][0].value, 105.76825, decimal=1)
assert_almost_equal(det['n11'][0].value, 119.69057, decimal=1)
det2=fermi.get_detector_sun_angles_for_time(parse_time('2012-02-15 02:00'),file)
assert len(det2) == 13
assert type(det2) == dict
assert_almost_equal(det2['n0'].value, 87.24744,decimal=1)
assert_almost_equal(det2['n1'].value, 69.90883,decimal=1)
assert_almost_equal(det2['n10'].value, 123.56429,decimal=1)
assert_almost_equal(det2['n11'].value, 167.26615,decimal=1)
assert_almost_equal(det2['n2'].value, 59.82642,decimal=1)
assert_almost_equal(det2['n3'].value, 69.18959,decimal=1)
assert_almost_equal(det2['n4'].value, 56.83158,decimal=1)
assert_almost_equal(det2['n5'].value, 12.49959,decimal=1)
assert_almost_equal(det2['n6'].value, 115.31259,decimal=1)
assert_almost_equal(det2['n7'].value, 129.49283,decimal=1)
assert_almost_equal(det2['n8'].value, 121.91083,decimal=1)
assert_almost_equal(det2['n9'].value, 130.04144,decimal=1)
开发者ID:Alex-Ian-Hamilton,项目名称:sunpy,代码行数:35,代码来源:test_fermi.py
示例9: julian_day
def julian_day(t='now'):
"""Returns the (fractional) Julian day defined as the number of days
between the queried day and the reference date of 12:00 (noon) Jan 1, 4713
BC."""
# Good online reference for fractional julian day
# http://www.stevegs.com/jd_calc/jd_calc.htm
JULIAN_REF_DAY = parse_time('1900/1/1 12:00:00')
time = parse_time(t)
tdiff = time - JULIAN_REF_DAY
julian = tdiff.days + JULIAN_DAY_ON_NOON01JAN1900
result = julian + 1 / 24. * (time.hour + time.minute / 60.0 +
time.second / (60. * 60.))
# This is because the days in datetime objects start at 00:00,
# not 12:00 as for Julian days.
if time.hour >= 12:
result = result - 0.5
else:
result = result + 0.5
return result
开发者ID:sharmarahul20,项目名称:sunpy,代码行数:25,代码来源:julian.py
示例10: test_payload_protocol
def test_payload_protocol():
start = parse_time('2012/1/1T00:00:00')
end = parse_time('2012/1/1T00:00:45')
payload = client._make_query_payload(
start, end, 'hmi.M_42s', protocol='as-is')
payload_expected = {
'ds':
'{0}[{1}-{2}]'.format('hmi.M_42s',
start.strftime("%Y.%m.%d_%H:%M:%S_TAI"),
end.strftime("%Y.%m.%d_%H:%M:%S_TAI")),
'format':
'json',
'method':
'url',
'notify':
'',
'op':
'exp_request',
'process':
'n=0|no_op',
'protocol':
'as-is',
'requestor':
'none',
'filenamefmt':
'{0}.{{T_REC:A}}.{{CAMERA}}.{{segment}}'.format('hmi.M_42s')
}
assert payload == payload_expected
开发者ID:narolez571,项目名称:sunpy,代码行数:31,代码来源:test_jsoc.py
示例11: test_detector_angles
def test_detector_angles():
# set a test date
date = parse_time('2012-02-15')
file = fermi.download_weekly_pointing_file(date)
det = fermi.get_detector_sun_angles_for_date(date, file)
assert len(det) == 13
assert_almost_equal(det['n0'][0].value, 21.73944, decimal=1)
assert_almost_equal(det['n1'][0].value, 30.62983, decimal=1)
assert_almost_equal(det['n2'][0].value, 74.67486, decimal=1)
assert_almost_equal(det['n3'][0].value, 30.46062, decimal=1)
assert_almost_equal(det['n4'][0].value, 73.89734, decimal=1)
assert_almost_equal(det['n5'][0].value, 58.99893, decimal=1)
assert_almost_equal(det['n6'][0].value, 47.31091, decimal=1)
assert_almost_equal(det['n7'][0].value, 70.63391, decimal=1)
assert_almost_equal(det['n8'][0].value, 106.30992, decimal=1)
assert_almost_equal(det['n9'][0].value, 70.07033, decimal=1)
assert_almost_equal(det['n10'][0].value, 106.97884, decimal=1)
assert_almost_equal(det['n11'][0].value, 121.09603, decimal=1)
det2 = fermi.get_detector_sun_angles_for_time(
parse_time('2012-02-15 02:00'), file)
assert len(det2) == 13
assert type(det2) == dict
assert_almost_equal(det2['n0'].value, 83.76092, decimal=1)
assert_almost_equal(det2['n1'].value, 66.65847, decimal=1)
assert_almost_equal(det2['n10'].value, 123.28952, decimal=1)
assert_almost_equal(det2['n11'].value, 170.69869, decimal=1)
assert_almost_equal(det2['n2'].value, 58.78532, decimal=1)
assert_almost_equal(det2['n3'].value, 66.69068, decimal=1)
assert_almost_equal(det2['n4'].value, 57.16402, decimal=1)
assert_almost_equal(det2['n5'].value, 9.04924, decimal=1)
assert_almost_equal(det2['n6'].value, 112.21230, decimal=1)
assert_almost_equal(det2['n7'].value, 127.35783, decimal=1)
assert_almost_equal(det2['n8'].value, 122.98894, decimal=1)
assert_almost_equal(det2['n9'].value, 126.95987, decimal=1)
开发者ID:Hypnus1803,项目名称:sunpy,代码行数:35,代码来源:test_fermi.py
示例12: test_parse_time_ISO
def test_parse_time_ISO():
assert parse_time('1966-02-03') == LANDING
assert (
parse_time('1966-02-03T20:17:40') == datetime(1966, 2, 3, 20, 17, 40)
)
assert (
parse_time('19660203T201740') == datetime(1966, 2, 3, 20, 17, 40)
)
lst = [
('2007-05-04T21:08:12.999999', datetime(2007, 5, 4, 21, 8, 12, 999999)),
('20070504T210812.999999', datetime(2007, 5, 4, 21, 8, 12, 999999)),
('2007/05/04 21:08:12.999999', datetime(2007, 5, 4, 21, 8, 12, 999999)),
('2007-05-04 21:08:12.999999', datetime(2007, 5, 4, 21, 8, 12, 999999)),
('2007/05/04 21:08:12', datetime(2007, 5, 4, 21, 8, 12)),
('2007-05-04 21:08:12', datetime(2007, 5, 4, 21, 8, 12)),
('2007-05-04 21:08', datetime(2007, 5, 4, 21, 8)),
('2007-05-04T21:08:12', datetime(2007, 5, 4, 21, 8, 12)),
('20070504T210812', datetime(2007, 5, 4, 21, 8, 12)),
('2007-May-04 21:08:12', datetime(2007, 5, 4, 21, 8, 12)),
('2007-May-04 21:08', datetime(2007, 5, 4, 21, 8)),
('2007-May-04', datetime(2007, 5, 4)),
('2007-05-04', datetime(2007, 5, 4)),
('2007/05/04', datetime(2007, 5, 4)),
('04-May-2007', datetime(2007, 5, 4)),
('20070504_210812', datetime(2007, 5, 4, 21, 8, 12))
]
for k, v in lst:
assert parse_time(k) == v
开发者ID:timmie,项目名称:sunpy,代码行数:30,代码来源:test_time.py
示例13: test_query
def test_query(mock_search):
qr1 = LCClient.search(
Time('2012/8/9', '2012/8/10'), Instrument('noaa-indices'))
assert isinstance(qr1, QueryResponse)
assert len(qr1) == 1
assert qr1.time_range().start == parse_time('2012/08/09')
assert qr1.time_range().end == parse_time('2012/08/10')
开发者ID:drewleonard42,项目名称:sunpy,代码行数:7,代码来源:test_noaa.py
示例14: __init__
def __init__(self, a, b=None):
"""Creates a new TimeRange instance"""
# If a is a TimeRange object, copy attributes to new instance.
if isinstance(a, TimeRange):
self.__dict__ = a.__dict__.copy()
return
# Normalize different input types
if b is None:
x = a[0]
y = a[1]
else:
x = a
y = b
# Start time
self.t1 = parse_time(x)
# End date
if isinstance(y, str):
self.t2 = parse_time(y)
# Datetime
if isinstance(y, datetime):
self.t2 = y
# Timedelta
if isinstance(y, timedelta):
self.t2 = self.t1 + y
# Seconds offset
if isinstance(y, (float, int)):
self.t2 = self.t1 + timedelta(0, y)
self.dt = self.t2 - self.t1
开发者ID:narolez571,项目名称:sunpy,代码行数:35,代码来源:timerange.py
示例15: from_range
def from_range(cls, start, end, **kwargs):
"""Called by Conditional Dispatch object when start and end time are passed as input to create method."""
url = cls._get_url_for_date_range(parse_time(start), parse_time(end), **kwargs)
filepath = cls._download(url, kwargs, err="Unable to download data for specified date range")
result = cls.from_file(filepath)
result.data = result.data.truncate(start, end)
return result
开发者ID:jaylenw,项目名称:sunpy,代码行数:7,代码来源:lightcurve.py
示例16: date
def date(self):
"""Image observation time"""
time = parse_time(self.meta.get('date-obs', 'now'))
if time is None:
warnings.warn_explicit("Missing metadata for observation time. Using current time.",
Warning, __file__, inspect.currentframe().f_back.f_lineno)
return parse_time(time)
开发者ID:bsipocz,项目名称:sunpy,代码行数:7,代码来源:mapbase.py
示例17: from_range
def from_range(cls, instrument, start, end, **kwargs):
""" Automatically download data from instrument between start and
end and join it together.
Parameters
----------
instrument : str
instrument to retrieve the data from
start : parse_time compatible
start of the measurement
end : parse_time compatible
end of the measurement
"""
kw = {
'maxgap': 1,
'fill': cls.JOIN_REPEAT,
}
kw.update(kwargs)
start = parse_time(start)
end = parse_time(end)
urls = query(start, end, [instrument])
data = map(cls.from_url, urls)
freq_buckets = defaultdict(list)
for elem in data:
freq_buckets[tuple(elem.freq_axis)].append(elem)
try:
return cls.combine_frequencies(
[cls.join_many(elem, **kw) for elem in freq_buckets.itervalues()]
)
except ValueError:
raise ValueError("No data found.")
开发者ID:JordanBallew,项目名称:sunpy,代码行数:32,代码来源:callisto.py
示例18: get_times_from_start
def get_times_from_start(mc, start_date=None):
# Get the times of the images
if start_date is None:
start_time = parse_time(mc[0].date)
else:
start_time = parse_time(start_date)
return np.asarray([(parse_time(m.date) - start_time).seconds for m in mc]) * u.s
开发者ID:wafels,项目名称:eitwave,代码行数:7,代码来源:aware2.py
示例19: __init__
def __init__(self, a, b=None, julian_date=False):
"""Creates a new TimeRange instance"""
from sunpy.time import parse_time
# if already a timeRange object just return it
#if isinstance(a, TimeRange):
# return a
# Normalize different input types
if b is None:
x = a[0]
y = a[1]
else:
x = a
y = b
# Start time
self.t1 = parse_time(x)
# End date
if isinstance(y, str):
self.t2 = parse_time(y)
# Timedelta
if isinstance(y, timedelta):
self.t2 = self.t1 + y
# Seconds offset
if isinstance(y, (float, int)):
if julian_date:
self.t2 = parse_time(y)
else:
self.t2 = self.t1 + timedelta(0, y)
self.dt = self.t2 - self.t1
开发者ID:astrofrog,项目名称:sunpy,代码行数:34,代码来源:timerange.py
示例20: time_from_file_name
def time_from_file_name(f, fits_level=1.0):
if fits_level == 1.0:
start = 14
year = f[start:start+4]
month = f[start+5:start+7]
day = f[start+8:start+10]
hour = f[start+11:start+13]
minute = f[start+14:start+16]
second = f[start+17:start+19]
time = '{:s}-{:s}-{:s} {:s}:{:s}:{:s}'.format(year, month, day, hour, minute, second)
try:
return parse_time(time)
except ValueError:
if fits_level == 1.0:
start = 17
year = f[start:start+4]
month = f[start+5:start+7]
day = f[start+8:start+10]
hour = f[start+11:start+13]
minute = f[start+13:start+15]
second = f[start+15:start+17]
time = '{:s}-{:s}-{:s} {:s}:{:s}:{:s}'.format(year, month, day, hour, minute, second)
return parse_time(time)
开发者ID:wafels,项目名称:eitwave,代码行数:28,代码来源:aware_utils.py
注:本文中的sunpy.time.parse_time函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论