TimeBase¶
- class astropy.time.TimeBase[source]¶
Bases:
ShapedLikeNDArray
Base time class from which Time and TimeDelta inherit.
Attributes Summary
Return an instance with the data transposed.
Return the cache associated with this instance.
Get or set time format.
Unix wildcard pattern to select subformats for parsing string input times.
First of the two doubles that internally store time value(s) in JD.
Second of the two doubles that internally store time value(s) in JD.
The number of dimensions of the instance and underlying arrays.
Unix wildcard pattern to select subformats for outputting times.
Decimal precision when outputting seconds as floating point (int value between 0 and 9 inclusive).
Time scale
The shape of the time instances.
The size of the object, as calculated from its shape.
Time value(s) in current format
Methods Summary
argmax
([axis, out])Return indices of the maximum values along the given axis.
argmin
([axis, out])Return indices of the minimum values along the given axis.
argsort
([axis])Returns the indices that would sort the time array.
copy
([format])Return a fully independent copy the Time object, optionally changing the format.
diagonal
(*args, **kwargs)Return an instance with the specified diagonals.
flatten
(*args, **kwargs)Return a copy with the array collapsed into one dimension.
insert
(obj, values[, axis])Insert values before the given indices in the column and return a new
Time
orTimeDelta
object.isclose
(other[, atol])Returns a boolean or boolean array where two Time objects are element-wise equal within a time tolerance.
max
([axis, out, keepdims])Maximum along a given axis.
mean
([axis, dtype, out, keepdims, where])Mean along a given axis.
min
([axis, out, keepdims])Minimum along a given axis.
ptp
([axis, out, keepdims])Peak to peak (maximum - minimum) along a given axis.
ravel
(*args, **kwargs)Return an instance with the array collapsed into one dimension.
replicate
([format, copy, cls])Return a replica of the Time object, optionally changing the format.
reshape
(*args, **kwargs)Returns an instance containing the same data with a new shape.
sort
([axis])Return a copy sorted along the specified axis.
squeeze
(*args, **kwargs)Return an instance with single-dimensional shape entries removed
swapaxes
(*args, **kwargs)Return an instance with the given axes interchanged.
take
(indices[, axis, out, mode])Return a new instance formed from the elements at the given indices.
Output a string representation of the Time or TimeDelta object.
to_value
(format[, subfmt])Get time values expressed in specified output format.
transpose
(*args, **kwargs)Return an instance with the data transposed.
Attributes Documentation
- T¶
Return an instance with the data transposed.
Parameters are as for
T
. All internal data are views of the data of the original.
- cache¶
Return the cache associated with this instance.
- format¶
Get or set time format.
The format defines the way times are represented when accessed via the
.value
attribute. By default it is the same as the format used for initializing theTime
instance, but it can be set to any other value that could be used for initialization. These can be listed with:>>> list(Time.FORMATS) ['jd', 'mjd', 'decimalyear', 'unix', 'unix_tai', 'cxcsec', 'gps', 'plot_date', 'stardate', 'datetime', 'ymdhms', 'iso', 'isot', 'yday', 'datetime64', 'fits', 'byear', 'jyear', 'byear_str', 'jyear_str']
- in_subfmt¶
Unix wildcard pattern to select subformats for parsing string input times.
- isscalar¶
- jd1¶
First of the two doubles that internally store time value(s) in JD.
- jd2¶
Second of the two doubles that internally store time value(s) in JD.
- mask¶
- masked¶
- ndim¶
The number of dimensions of the instance and underlying arrays.
- out_subfmt¶
Unix wildcard pattern to select subformats for outputting times.
- precision¶
Decimal precision when outputting seconds as floating point (int value between 0 and 9 inclusive).
- scale¶
Time scale
- shape¶
The shape of the time instances.
Like
shape
, can be set to a new shape by assigning a tuple. Note that if different instances share some but not all underlying data, setting the shape of one instance can make the other instance unusable. Hence, it is strongly recommended to get new, reshaped instances with thereshape
method.- Raises:
ValueError
If the new shape has the wrong total number of elements.
AttributeError
If the shape of the
jd1
,jd2
,location
,delta_ut1_utc
, ordelta_tdb_tt
attributes cannot be changed without the arrays being copied. For these cases, use theTime.reshape
method (which copies any arrays that cannot be reshaped in-place).
- size¶
The size of the object, as calculated from its shape.
- value¶
Time value(s) in current format
- writeable¶
Methods Documentation
- argmax(axis=None, out=None)[source]¶
Return indices of the maximum values along the given axis.
This is similar to
argmax()
, but adapted to ensure that the full precision given by the two doublesjd1
andjd2
is used. Seeargmax()
for detailed documentation.
- argmin(axis=None, out=None)[source]¶
Return indices of the minimum values along the given axis.
This is similar to
argmin()
, but adapted to ensure that the full precision given by the two doublesjd1
andjd2
is used. Seeargmin()
for detailed documentation.
- argsort(axis=-1)[source]¶
Returns the indices that would sort the time array.
This is similar to
argsort()
, but adapted to ensure that the full precision given by the two doublesjd1
andjd2
is used, and that corresponding attributes are copied. Internally, it useslexsort()
, and hence no sort method can be chosen.
- copy(format=None)[source]¶
Return a fully independent copy the Time object, optionally changing the format.
If
format
is supplied then the time format of the returned Time object will be set accordingly, otherwise it will be unchanged from the original.In this method a full copy of the internal time arrays will be made. The internal time arrays are normally not changeable by the user so in most cases the
replicate()
method should be used.- Parameters:
- format
python:str
, optional Time format of the copy.
- format
- Returns:
- tm
Time
object
Copy of this object
- tm
- diagonal(*args, **kwargs)¶
Return an instance with the specified diagonals.
Parameters are as for
diagonal()
. All internal data are views of the data of the original.
- flatten(*args, **kwargs)¶
Return a copy with the array collapsed into one dimension.
Parameters are as for
flatten()
.
- insert(obj, values, axis=0)[source]¶
Insert values before the given indices in the column and return a new
Time
orTimeDelta
object.The values to be inserted must conform to the rules for in-place setting of
Time
objects (seeGet and set values
in theTime
documentation).The API signature matches the
np.insert
API, but is more limited. The specification of insert indexobj
must be a single integer, and theaxis
must be0
for simple row insertion before the index.- Parameters:
- obj
python:int
Integer index before which
values
is inserted.- valuesnumpy:array_like
Value(s) to insert. If the type of
values
is different from that of quantity,values
is converted to the matching type.- axis
python:int
, optional Axis along which to insert
values
. Default is 0, which is the only allowed value and will insert a row.
- obj
- Returns:
- out
Time
subclass New time object with inserted value(s)
- out
- isclose(other, atol=None)[source]¶
Returns a boolean or boolean array where two Time objects are element-wise equal within a time tolerance.
This evaluates the expression below:
abs(self - other) <= atol
- max(axis=None, out=None, keepdims=False)[source]¶
Maximum along a given axis.
This is similar to
max()
, but adapted to ensure that the full precision given by the two doublesjd1
andjd2
is used, and that corresponding attributes are copied.Note that the
out
argument is present only for compatibility withnp.max
; sinceTime
instances are immutable, it is not possible to have an actualout
to store the result in.
- mean(axis=None, dtype=None, out=None, keepdims=False, *, where=True)[source]¶
Mean along a given axis.
This is similar to
mean()
, but adapted to ensure that the full precision given by the two doublesjd1
andjd2
is used, and that corresponding attributes are copied.Note that the
out
argument is present only for compatibility withnp.mean
; sinceTime
instances are immutable, it is not possible to have an actualout
to store the result in.Similarly, the
dtype
argument is also present for compatibility only; it has no meaning forTime
.- Parameters:
- axis
python:None
orpython:int
orpython:tuple
ofpython:int
, optional Axis or axes along which the means are computed. The default is to compute the mean of the flattened array.
- dtype
python:None
Only present for compatibility with
mean()
, must beNone
.- out
python:None
Only present for compatibility with
mean()
, must beNone
.- keepdimsbool, optional
If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.
- wherenumpy:array_like of bool, optional
Elements to include in the mean. See
reduce
for details.
- axis
- Returns:
- m
Time
A new Time instance containing the mean values
- m
- min(axis=None, out=None, keepdims=False)[source]¶
Minimum along a given axis.
This is similar to
min()
, but adapted to ensure that the full precision given by the two doublesjd1
andjd2
is used, and that corresponding attributes are copied.Note that the
out
argument is present only for compatibility withnp.min
; sinceTime
instances are immutable, it is not possible to have an actualout
to store the result in.
- ptp(axis=None, out=None, keepdims=False)[source]¶
Peak to peak (maximum - minimum) along a given axis.
This is similar to
ptp()
, but adapted to ensure that the full precision given by the two doublesjd1
andjd2
is used.Note that the
out
argument is present only for compatibility withptp
; sinceTime
instances are immutable, it is not possible to have an actualout
to store the result in.
- ravel(*args, **kwargs)¶
Return an instance with the array collapsed into one dimension.
Parameters are as for
ravel()
. Note that it is not always possible to unravel an array without copying the data. If you want an error to be raise if the data is copied, you should should assign shape(-1,)
to the shape attribute.
- replicate(format=None, copy=False, cls=None)[source]¶
Return a replica of the Time object, optionally changing the format.
If
format
is supplied then the time format of the returned Time object will be set accordingly, otherwise it will be unchanged from the original.If
copy
is set toTrue
then a full copy of the internal time arrays will be made. By default the replica will use a reference to the original arrays when possible to save memory. The internal time arrays are normally not changeable by the user so in most cases it should not be necessary to setcopy
toTrue
.The convenience method copy() is available in which
copy
isTrue
by default.- Parameters:
- format
python:str
, optional Time format of the replica.
- copybool, optional
Return a true copy instead of using references where possible.
- format
- Returns:
- tm
Time
object
Replica of this object
- tm
- reshape(*args, **kwargs)¶
Returns an instance containing the same data with a new shape.
Parameters are as for
reshape()
. Note that it is not always possible to change the shape of an array without copying the data (seereshape()
documentation). If you want an error to be raise if the data is copied, you should assign the new shape to the shape attribute (note: this may not be implemented for all classes usingNDArrayShapeMethods
).
- sort(axis=-1)[source]¶
Return a copy sorted along the specified axis.
This is similar to
sort()
, but internally uses indexing withlexsort()
to ensure that the full precision given by the two doublesjd1
andjd2
is kept, and that corresponding attributes are properly sorted and copied as well.- Parameters:
- axis
python:int
orpython:None
Axis to be sorted. If
None
, the flattened array is sorted. By default, sort over the last axis.
- axis
- squeeze(*args, **kwargs)¶
Return an instance with single-dimensional shape entries removed
Parameters are as for
squeeze()
. All internal data are views of the data of the original.
- swapaxes(*args, **kwargs)¶
Return an instance with the given axes interchanged.
Parameters are as for
swapaxes()
:axis1, axis2
. All internal data are views of the data of the original.
- take(indices, axis=None, out=None, mode='raise')¶
Return a new instance formed from the elements at the given indices.
Parameters are as for
take()
, except that, obviously, no output array can be given.
- to_string()[source]¶
Output a string representation of the Time or TimeDelta object.
Similar to
str(self.value)
(which uses numpy array formatting) but array values are evaluated only for the items that actually are output. For large arrays this can be a substantial performance improvement.- Returns:
- out
python:str
String representation of the time values.
- out
- to_value(format, subfmt='*')[source]¶
Get time values expressed in specified output format.
This method allows representing the
Time
object in the desired outputformat
and optional sub-formatsubfmt
. Available built-in formats includejd
,mjd
,iso
, and so forth. Each format can have its own sub-formatsFor built-in numerical formats like
jd
orunix
,subfmt
can be one of ‘float’, ‘long’, ‘decimal’, ‘str’, or ‘bytes’. Here, ‘long’ usesnumpy.longdouble
for somewhat enhanced precision (with the enhancement depending on platform), and ‘decimal’decimal.Decimal
for full precision. For ‘str’ and ‘bytes’, the number of digits is also chosen such that time values are represented accurately.For built-in date-like string formats, one of ‘date_hms’, ‘date_hm’, or ‘date’ (or ‘longdate_hms’, etc., for 5-digit years in
TimeFITS
). For sub-formats including seconds, the number of digits used for the fractional seconds is as set byprecision
.- Parameters:
- format
python:str
The format in which one wants the time values. Default: the current format.
- subfmt
python:str
orpython:None
, optional Value or wildcard pattern to select the sub-format in which the values should be given. The default of ‘*’ picks the first available for a given format, i.e., ‘float’ or ‘date_hms’. If
None
, use the instance’sout_subfmt
.
- format
- transpose(*args, **kwargs)¶
Return an instance with the data transposed.
Parameters are as for
transpose()
. All internal data are views of the data of the original.