speasy.core.time module
- speasy.core.time.datetime64_to_epoch(datetime64_array: ndarray) ndarray[source]
Converts an array of numpy datetime64[ns] to an array of floats encoded as Unix Epoch (seconds since 1970)
- Parameters:
- datetime64_arraynp.array
Input array of datetime64[ns]
- Returns:
- np.array
Output array of floats (Epoch)
Examples
>>> datetime64_to_epoch(np.array(['1970-01-01T00:00:00.000000000', '1970-01-01T00:00:01.000000000'], ... dtype='datetime64[ns]')) array([0., 1.])
- speasy.core.time.epoch_to_datetime64(epoch_array: ndarray) ndarray[source]
Converts an array of floats encoded as Unix Epoch (seconds since 1970) to an array of numpy datetime64[ns]
- Parameters:
- epoch_arraynp.array
Input array of folats (Epoch)
- Returns:
- np.array
Output array of datetime64[ns]
Examples
>>> epoch_to_datetime64(np.arange(2)) array(['1970-01-01T00:00:00.000000000', '1970-01-01T00:00:01.000000000'], dtype='datetime64[ns]')
- speasy.core.time.make_utc_datetime(input_dt: str | datetime | float64 | float | datetime64) datetime[source]
Makes UTC datetime from given input.
- Parameters:
- input_dt: str or datetime or np.datetime64 or np.float64 or float
Datetime to convert, can be either an Epoch, a datetime, a numpy datetime64 (any unit) or a string. Naive datetimes and strings without timezone information are assumed to be UTC, timezone aware ones are converted to UTC.
- Returns:
- datetime
A datetime.datetime object forced to UTC time zone
Examples
>>> make_utc_datetime('2018-01-02') datetime.datetime(2018, 1, 2, 0, 0, tzinfo=datetime.timezone.utc)
>>> make_utc_datetime(0.) datetime.datetime(1970, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
>>> from datetime import datetime >>> make_utc_datetime(datetime(2020,1,1)) datetime.datetime(2020, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)
>>> make_utc_datetime(np.datetime64('2016-06-02')) datetime.datetime(2016, 6, 2, 0, 0, tzinfo=datetime.timezone.utc)
>>> make_utc_datetime('2018-01-01T01:00:00+02:00') datetime.datetime(2017, 12, 31, 23, 0, tzinfo=datetime.timezone.utc)
- speasy.core.time.make_utc_datetime64(input_dt: str | datetime | float64 | float | datetime64) datetime64[source]
Makes UTC np.datetime64 from given input.
- Parameters:
- input_dt: str or datetime or np.datetime64 or np.float64 or float
Datetime to convert, can be either an Epoch, a datetime, a numpy datetime64 (any unit) or a string. Naive datetimes and strings without timezone information are assumed to be UTC, timezone aware ones are converted to UTC.
- Returns:
- np.datetime64
A numpy datetime64 object forced to UTC time zone
Examples
>>> make_utc_datetime64('2018-01-02') np.datetime64('2018-01-02T00:00:00.000000000')
>>> make_utc_datetime64(0.) np.datetime64('1970-01-01T00:00:00.000000')
>>> from datetime import datetime >>> make_utc_datetime64(datetime(2020,1,1)) np.datetime64('2020-01-01T00:00:00.000000000')
>>> make_utc_datetime64(np.datetime64('2016-06-02')) np.datetime64('2016-06-02T00:00:00.000000000')
>>> make_utc_datetime64('2018-01-01T01:00:00+02:00') np.datetime64('2017-12-31T23:00:00.000000000')