Bases: object
Represent and manipulate times and dates for astronomy.
A Time object is initialized with one or more times in the val argument. The input times in val must conform to the specified format and must correspond to the specified time scale. The optional val2 time input should be supplied only for numeric input formats (e.g. JD) where very high precision (better than 64-bit precision) is required.
The allowed values for format can be listed with:
>>> list(Time.FORMATS)
['jd', 'mjd', 'decimalyear', 'unix', 'cxcsec', 'gps', 'plot_date',
'datetime', 'iso', 'isot', 'yday', 'fits', 'byear', 'jyear', 'byear_str',
'jyear_str']
Parameters: | val : sequence, str, number, or Time object
val2 : sequence, str, or number; optional
format : str, optional
scale : str, optional
precision : int, optional
in_subfmt : str, optional
out_subfmt : str, optional
location : EarthLocation or tuple, optional
copy : bool, optional
|
---|
Attributes Summary
FORMATS | Dict of time formats |
SCALES | List of time scales |
T | Return a time instance with the data transposed. |
delta_tdb_tt | TDB - TT time scale offset |
delta_ut1_utc | UT1 - UTC time scale offset |
format | Get or set time format. |
in_subfmt | Unix wildcard pattern to select subformats for parsing string input times. |
info | Container for meta information like name, description, format. |
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. |
ndim | |
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. |
size | |
value | 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 a time instance with the specified diagonals. |
flatten(*args, **kwargs) | Return a copy with the time array collapsed into one dimension. |
get_delta_ut1_utc([iers_table, return_status]) | Find UT1 - UTC differences by interpolating in IERS Table. |
max([axis, out, keepdims]) | Maximum along a given axis. |
min([axis, out, keepdims]) | Minimum along a given axis. |
now() | Creates a new object corresponding to the instant in time this method is called. |
ptp([axis, out, keepdims]) | Peak to peak (maximum - minimum) along a given axis. |
ravel(*args, **kwargs) | Return an instance with the time array collapsed into one dimension. |
replicate([format, copy]) | Return a replica of the Time object, optionally changing the format. |
reshape(*args, **kwargs) | Returns a time instance containing the same data with a new shape. |
sidereal_time(kind[, longitude, model]) | Calculate sidereal time. |
sort([axis]) | Return a copy sorted along the specified axis. |
squeeze(*args, **kwargs) | Return a time instance with single-dimensional shape entries removed |
swapaxes(*args, **kwargs) | Return a time instance with the given axes interchanged. |
take(indices[, axis, mode]) | Return a Time object formed from the elements the given indices. |
to_datetime([timezone]) | Convert to (potentially timezone-aware) datetime object. |
transpose(*args, **kwargs) | Return a time instance with the data transposed. |
Attributes Documentation
Dict of time formats
List of time scales
Return a time instance with the data transposed.
Parameters are as for T. All internal data are views of the data of the original.
TDB - TT time scale offset
UT1 - UTC time scale offset
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 the Time 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', 'cxcsec', 'gps', 'plot_date',
'datetime', 'iso', 'isot', 'yday', 'fits', 'byear', 'jyear', 'byear_str',
'jyear_str']
Unix wildcard pattern to select subformats for parsing string input times.
Container for meta information like name, description, format. This is required when the object is used as a mixin column within a table, but can be used as a general way to store meta information.
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.
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.
Like shape, can be set to a new shape by assigning a tuple.
Raises: | AttributeError: if the shape of the ``jd1``, ``jd2``, ``location``, ``delta_ut1_utc``, or ``delta_tdb_tt`` attributes cannot be changed without the arrays being copied. For these cases, use the `Time.reshape` method. |
---|
Time value(s) in current format
Methods Documentation
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 doubles jd1 and jd2 is used. See argmax() for detailed documentation.
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 doubles jd1 and jd2 is used. See argmin() for detailed documentation.
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 doubles jd1 and jd2 is used, and that corresponding attributes are copied. Internally, it uses lexsort(), and hence no sort method can be chosen.
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 : str, optional
|
---|---|
Returns: | tm : Time object
|
Return a time instance with the specified diagonals.
Parameters are as for diagonal(). All internal data are views of the data of the original.
Return a copy with the time array collapsed into one dimension.
Parameters are as for flatten().
Find UT1 - UTC differences by interpolating in IERS Table.
Parameters: | iers_table : astropy.utils.iers.IERS table, optional
return_status : bool
|
---|---|
Returns: | ut1_utc : float or float array
status : int or int array
|
Notes
In normal usage, UT1-UTC differences are calculated automatically on the first instance ut1 is needed.
Examples
To check in code whether any times are before the IERS table range:
>>> from astropy.utils.iers import TIME_BEFORE_IERS_RANGE
>>> t = Time(['1961-01-01', '2000-01-01'], scale='utc')
>>> delta, status = t.get_delta_ut1_utc(return_status=True)
>>> status == TIME_BEFORE_IERS_RANGE
array([ True, False], dtype=bool)
To use an updated IERS A bulletin to calculate UT1-UTC (see also astropy.utils.iers):
>>> from astropy.utils.iers import IERS_A, IERS_A_URL
>>> from astropy.utils.data import download_file
>>> t = Time(['1974-01-01', '2000-01-01'], scale='utc')
>>> iers_a_file = download_file(IERS_A_URL,
... cache=True)
Downloading ... [Done]
>>> iers_a = IERS_A.open(iers_a_file)
>>> t.delta_ut1_utc = t.get_delta_ut1_utc(iers_a)
The delta_ut1_utc property will be used to calculate t.ut1; raises IndexError if any of the times is out of range.
Maximum along a given axis.
This is similar to max(), but adapted to ensure that the full precision given by the two doubles jd1 and jd2 is used, and that corresponding attributes are copied.
Note that the out argument is present only for compatibility with np.max; since Time instances are immutable, it is not possible to have an actual out to store the result in.
Minimum along a given axis.
This is similar to min(), but adapted to ensure that the full precision given by the two doubles jd1 and jd2 is used, and that corresponding attributes are copied.
Note that the out argument is present only for compatibility with np.min; since Time instances are immutable, it is not possible to have an actual out to store the result in.
Creates a new object corresponding to the instant in time this method is called.
Note
“Now” is determined using the utcnow function, so its accuracy and precision is determined by that function. Generally that means it is set by the accuracy of your system clock.
Returns: | nowtime |
---|
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 doubles jd1 and jd2 is used.
Note that the out argument is present only for compatibility with ptp; since Time instances are immutable, it is not possible to have an actual out to store the result in.
Return an instance with the time 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.
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 to True 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 set copy to True.
The convenience method copy() is available in which copy is True by default.
Parameters: | format : str, optional
copy : bool, optional
|
---|---|
Returns: | tm : Time object
|
Returns a time 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. If you want an error to be raise if the data is copied, you should assign the new shape to the shape attribute.
Calculate sidereal time.
Parameters: | kind : str
longitude : Quantity, str, or None; optional
model : str or None; optional
|
---|---|
Returns: | sidereal time : Longitude
|
Return a copy sorted along the specified axis.
This is similar to sort(), but internally uses indexing with lexsort() to ensure that the full precision given by the two doubles jd1 and jd2 is kept, and that corresponding attributes are properly sorted and copied as well.
Parameters: | axis : int or None
|
---|
Return a time instance with single-dimensional shape entries removed
Parameters are as for squeeze(). All internal data are views of the data of the original.
Return a time instance with the given axes interchanged.
Parameters are as for swapaxes(). All internal data are views of the data of the original.
Return a Time object formed from the elements the given indices.
Parameters are as for take(), except that, obviously, no output array can be given.
Convert to (potentially timezone-aware) datetime object.
If timezone is not None, return a timezone-aware datetime object.
Parameters: | timezone : {tzinfo, None} (optional)
|
---|---|
Returns: | datetime
|
Return a time instance with the data transposed.
Parameters are as for transpose(). All internal data are views of the data of the original.