TimeDeltaQuantityString#
- class astropy.time.TimeDeltaQuantityString(val1, val2, scale, precision, in_subfmt, out_subfmt, from_jd=False)[source]#
Bases:
TimeDeltaFormat
,TimeUnique
Time delta as a string with one or more Quantity components.
This format provides a human-readable multi-scale string representation of a time delta. It is convenient for applications like a configuration file or a command line option.
The format is specified as follows:
The string is a sequence of one or more components.
Each component is a number followed by an astropy unit of time.
For input, whitespace within the string is allowed but optional.
For output, there is a single space between components.
The allowed components are listed below.
The order (yr, d, hr, min, s) is fixed but individual components are optional.
The allowed input component units are shown below:
“yr”: years (365.25 days)
“d”: days (24 hours)
“hr”: hours (60 minutes)
“min”: minutes (60 seconds)
“s”: seconds
Note
These definitions correspond to physical units of time and are NOT calendar date intervals. Thus adding “1yr” to “2000-01-01 00:00:00” will give “2000-12-31 06:00:00” instead of “2001-01-01 00:00:00”.
The
out_subfmt
attribute specifies the components to be included in the string output. The default is"multi"
which represents the time delta as"<days>d <hours>hr <minutes>min <seconds>s"
, where only non-zero components are included.“multi”: multiple components, e.g. “2d 3hr 15min 5.6s”
“yr”: years
“d”: days
“hr”: hours
“min”: minutes
“s”: seconds
Examples
>>> from astropy.time import Time, TimeDelta >>> import astropy.units as u
>>> print(TimeDelta("1yr")) 365d 6hr
>>> print(Time("2000-01-01") + TimeDelta("1yr")) 2000-12-31 06:00:00.000 >>> print(TimeDelta("+3.6d")) 3d 14hr 24min >>> print(TimeDelta("-3.6d")) -3d 14hr 24min >>> print(TimeDelta("1yr 3.6d", out_subfmt="d")) 368.85d
>>> td = TimeDelta(40 * u.hr) >>> print(td.to_value(format="quantity_str")) 1d 16hr >>> print(td.to_value(format="quantity_str", subfmt="d")) 1.667d >>> td.precision = 9 >>> print(td.to_value(format="quantity_str", subfmt="d")) 1.666666667d
Attributes Summary
Time scale.
Methods Summary
fill_value
(subfmt)Return a value corresponding to J2000 (2000-01-01 12:00:00) in this format.
fix_comp_vals_overflow
(comp_vals)get_multi_comps
(jd1, jd2)parse_string
(timestr)Read time from a single string
set_jds
(val1, val2)Parse the time strings contained in val1 and get jd1, jd2.
to_value
([parent, out_subfmt])Return time representation from internal jd1 and jd2 in specified
out_subfmt
.Attributes Documentation
- in_subfmt#
- jd1#
- jd2#
- name = 'quantity_str'#
- out_subfmt#
- precision#
- re_float = '(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?'#
- re_ydhms = re.compile('^ \\s*\n (?P<sign>[-+])? \\s* # Optional sign\n (?=[^-+\\s]) # At least one character which is not a sign or whitespace\n ((?P<yr>(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?) \\s*, re.VERBOSE)#
- scale#
Time scale.
- subfmts = (('multi', None, None), ('yr', None, None), ('d', None, None), ('hr', None, None), ('min', None, None), ('s', None, None))#
- 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.
- to_value(parent=None, out_subfmt=None)[source]#
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