Finds the elements in a list of datetime objects present in another
Parameters: | ts1 : list or array-like
ts2 : list or array-like
|
---|---|
Returns: | out : tuple
|
See also
Examples
>>> import spacepy.toolbox as tb
>>> import numpy as np
>>> import datetime as dt
>>> ts1 = np.array([dt.datetime(2001,3,10)+dt.timedelta(hours=a) for a in range(20)])
>>> ts2 = np.array([dt.datetime(2001,3,10,2)+dt.timedelta(hours=a*0.5) for a in range(20)])
>>> common_inds = tb.tCommon(ts1, ts2)
>>> common_inds[0] #mask of values in ts1 common with ts2
array([False, False, True, True, True, True, True, True, True,
True, True, True, False, False, False, False, False, False,
False, False], dtype=bool)
>>> ts2[common_inds[1]] #values of ts2 also in ts1
The latter can be found more simply by setting the mask_only keyword to False
>>> common_vals = tb.tCommon(ts1, ts2, mask_only=False)
>>> common_vals[1]
array([2001-03-10 02:00:00, 2001-03-10 03:00:00, 2001-03-10 04:00:00,
2001-03-10 05:00:00, 2001-03-10 06:00:00, 2001-03-10 07:00:00,
2001-03-10 08:00:00, 2001-03-10 09:00:00, 2001-03-10 10:00:00,
2001-03-10 11:00:00], dtype=object)