TimeString#
- class astropy.time.TimeString(val1, val2, scale, precision, in_subfmt, out_subfmt, from_jd=False)[source]#
Bases:
TimeUnique
Base class for string-like time representations.
This class assumes that anything following the last decimal point to the right is a fraction of a second.
Fast C-based parser
Time format classes can take advantage of a fast C-based parser if the times are represented as fixed-format strings with year, month, day-of-month, hour, minute, second, OR year, day-of-year, hour, minute, second. This can be a factor of 20 or more faster than the pure Python parser.
Fixed format means that the components always have the same number of characters. The Python parser will accept
2001-9-2
as a date, but the C parser would require2001-09-02
.A subclass in this case must define a class attribute
fast_parser_pars
which is adict
with all of the keys below. An inherited attribute is not checked, only an attribute in the class__dict__
.delims
(tuple of int): ASCII code for character at correspondingstarts
position (0 => no character)starts
(tuple of int): position where component starts (including delimiter if present). Use -1 for the month component for format that use day of year.stops
(tuple of int): position where component ends. Use -1 to continue to end of string, or for the month component for formats that use day of year.break_allowed
(tuple of int): if true (1) then the time string canlegally end just before the corresponding component (e.g. “2000-01-01” is a valid time but “2000-01-01 12” is not).
has_day_of_year
(int): 0 if dates have year, month, day; 1 if year, day-of-year
Attributes Summary
Time scale.
Methods Summary
fill_value
(subfmt)Return a value corresponding to J2000 (2000-01-01 12:00:00) in this format.
format_string
(str_fmt, **kwargs)Write time to a string using a given format.
get_jds_fast
(val1, val2)Use fast C parser to parse time strings in val1 and get jd1, jd2.
get_jds_python
(val1, val2)Parse the time strings contained in val1 and get jd1, jd2.
parse_string
(timestr, subfmts)Read time from a single string, using a set of possible formats.
set_jds
(val1, val2)Parse the time strings contained in val1 and set jd1, jd2.
Generator that yields a dict of values corresponding to the calendar date and time for the internal JD values.
to_value
([parent, out_subfmt])Return time representation from internal jd1 and jd2 in specified
out_subfmt
.Attributes Documentation
- in_subfmt#
- jd1#
- jd2#
- out_subfmt#
- precision#
- scale#
Time scale.
- subfmts = ()#
- value#
Methods Documentation
- classmethod fill_value(subfmt)#
Return a value corresponding to J2000 (2000-01-01 12:00:00) in this format.
This is used as a fill value for masked arrays to ensure that any ERFA operations on the masked array will not fail due to the masked value.
- format_string(str_fmt, **kwargs)[source]#
Write time to a string using a given format.
By default, just interprets str_fmt as a format string, but subclasses can add to this.
- parse_string(timestr, subfmts)[source]#
Read time from a single string, using a set of possible formats.
- str_kwargs()[source]#
Generator that yields a dict of values corresponding to the calendar date and time for the internal JD values.
- to_value(parent=None, out_subfmt=None)#
Return time representation from internal jd1 and jd2 in specified
out_subfmt
.This is the base method that ignores
parent
and uses thevalue
property to compute the output. This is done by temporarily settingself.out_subfmt
and callingself.value
. This is required for legacy Format subclasses prior to astropy 4.0 New code should instead implement the value functionality into_value()
and then make thevalue
property be a simple call toself.to_value()
.- Parameters:
- Returns:
- value
numpy.array
,numpy.ma.array
Array or masked array of formatted time representation values
- value