Temporal Conversions#

[33]:
import pystare
import datetime
import numpy
import astropy.time
import erfa

Full circle#

[2]:
# Create the TIVs
times = numpy.array(['2021-09-03', '2021-07-17 11:16'], dtype='datetime64')
times = astropy.time.Time(times, scale='utc', format='datetime64')
tivs = pystare.from_julian_date(times.jd1, times.jd2,
                                scale='utc',
                                forward_res=48, reverse_res=48)
tivs
[2]:
array([2276059438861267137, 2275939265676325057])
[3]:
timestamp = '2021-01-11 19:30:00'
jd = astropy.time.Time(numpy.datetime64(timestamp))
pystare.from_julian_date(jd.jd1, jd.jd2, scale='utc', forward_res=22, reverse_res=22)
[3]:
array([2275469239487829593])
[4]:
tivs = pystare.from_julian_date(times.jd1, times.jd2,
                                scale='utc',
                                forward_res=48, reverse_res=48)
[5]:
# Back via JD
jd = pystare.to_julian_date(tivs, scale='utc')
times = astropy.time.Time(val=jd[0], val2=jd[1], format='jd')
times.to_datetime()
[5]:
array([datetime.datetime(2021, 9, 3, 0, 0),
       datetime.datetime(2021, 7, 17, 11, 16)], dtype=object)
[6]:
# Back via MS
mss = pystare.to_ms_since_epoch_utc(tivs)
dts = [datetime.datetime.utcfromtimestamp(ms/1000) for ms in mss]
[dt.isoformat() for dt in dts]
[6]:
['2021-09-03T00:00:00', '2021-07-17T11:16:00']

Valudations#

[7]:
pystare.validate_stare_timestring('2021-01-09T17:47:56.154 (45 12) (1)')
[7]:
True
[8]:
pystare.validate_iso8601_string('2021-01-09T17:47:56.2435+05:00')
[8]:
True

UTC MS coversions#

[9]:
now = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
now = numpy.array([now], dtype='datetime64[ms]')
now = now.astype(numpy.int64)
now
[9]:
array([1653483732000])
[10]:
timestamps = numpy.array(['2021-01-03'], dtype='datetime64[ms]').astype(numpy.int64)
pystare.from_ms_since_epoch_utc(timestamps, 48, 48)
[10]:
array([2275448110396223681])
[11]:
tivs = [2275448110396223681]
ts = pystare.to_ms_since_epoch_utc(tivs).astype('datetime64[ms]')
numpy.datetime_as_string(ts)
[11]:
array(['2021-01-03T00:00:00.000'], dtype='<U42')
[12]:
ts1 = numpy.array(['2021-01-03T01', '1985-01-03T01'], dtype='datetime64[ms]').astype(numpy.int64)
ts2 = numpy.array(['2021-05-01T10', '1986-10-01'], dtype='datetime64[ms]').astype(numpy.int64)
tiv1 = pystare.from_ms_since_epoch_utc(ts1, 10, 10)
tiv2 = pystare.from_ms_since_epoch_utc(ts2, 10, 10)
pystare.cmp_temporal(tiv1, tiv2, flatten=False)
[12]:
array([[1, 0],
       [0, 1]])

Resolutions#

[13]:
millisecond  = 1
second = 1000 * millisecond
minute = 60 * second
hour = 60 * minute
day = 86400 * second
year = 365 * day
times = numpy.array([millisecond, second, minute, hour, day, year], dtype=numpy.int64)
pystare.coarsest_resolution_finer_or_equal_ms(times)
[13]:
array([48, 38, 32, 26, 21, 12])
[14]:
pystare.reverse_resolution(tiv1)
pystare.set_reverse_resolution(tiv1, numpy.array([9, 20]))

pystare.lower_bound_tai(tiv1)
[14]:
array([2270946778511573245, 2230414381613580541])

Iso Strings#

[15]:
time_strings = ['2021-08-26T17:03:56.6']
pystare.from_iso_strings(time_strings, forward_res=20, reverse_res=18)
[15]:
array([2276038620409631817])
[16]:
time_strings = ['2021-08-26T17:03:56.626 (48 48) (1)']
tiv = pystare.from_stare_timestrings(time_strings, scale='TAI')
tiv
[16]:
array([2276038620410065089])
[17]:
pystare.to_stare_timestring(tiv) == time_strings
[17]:
True
[18]:
pystare.to_stare_timestring(tiv)
[18]:
['2021-08-26T17:03:56.626 (48 48) (1)']

JDs#

[26]:
now = datetime.datetime.now()
t = astropy.time.Time(now.isoformat(), format='isot')
jd1 = numpy.array([t.jd1])
jd2 = numpy.array([t.jd2])
print(jd1, jd2)
[2459725.] [0.04371678]
[27]:
tiv = pystare.from_julian_date(jd1, jd2, scale='tai')
[28]:
pystare.to_julian_date(tiv, scale='tai')
[28]:
(array([2459580.5]), array([144.54371678]))

Temporal Triple#

[29]:
triple = pystare.to_temporal_triple_tai(tiv)
triple = pystare.to_temporal_triple_ms(tiv)
triple
[29]:
(array([2276931147908792573]),
 array([2276931147908821185]),
 array([2276931147908841469]))
[30]:
pystare.from_temporal_triple(numpy.array(triple).flatten())
[30]:
array([2276931147908821185])

Julian TAI#

[34]:
time = datetime.datetime(2021,2,1,12,0)
time_tuple = time.timetuple()

time = erfa.dtf2d("UTC", *time_tuple[0:6])
print(time[0], time[1])
2459246.5 0.5
[35]:
tiv_tai = pystare.from_julian_date(jd1=numpy.array([time[0]]),
                                   jd2=numpy.array([time[1]]),
                                   scale='tai')
tiv_tai
[35]:
array([2275521502176620737])
[36]:
tiv_utc = pystare.from_julian_date(jd1=numpy.array([time[0]]),
                                   jd2=numpy.array([time[1]]),
                                   scale='utc')
tiv_utc
[36]:
array([2275521502797377729])
[37]:
pystare.to_julian_date(tiv_tai, scale='tai')
[37]:
(array([2459215.5]), array([31.5]))
[38]:
pystare.to_julian_date(tiv_utc, scale='utc')
[38]:
(array([2459215.5]), array([31.5]))

Bounds#

[39]:
pystare.lower_bound_tai(tiv_tai)
pystare.upper_bound_tai(tiv_tai)
pystare.lower_bound_ms(tiv_utc)
pystare.upper_bound_ms(tiv_utc)
[39]:
array([2275521502797398013])

Resolution#

[40]:
pystare.set_reverse_resolution
pystare.set_forward_resolution
pystare.reverse_resolution
pystare.forward_resolution
pystare.coarsen
pystare.set_temporal_resolutions_from_sorted
pystare.coarsest_resolution_finer_or_equal_ms
[40]:
<function pystare.temporal.coarsest_resolution_finer_or_equal_ms(ms)>

Comparison#

[41]:
pystare.cmp_temporal

pystare.temporal_value_intersection_if_overlap
pystare.temporal_value_union_if_overlap
pystare.temporal_overlap_tai
pystare.temporal_overlap
pystare.temporal_contains_instant
[41]:
<function pystare.temporal.temporal_contains_instant(indices1, indices2)>
[ ]: