Skip to content

Instantly share code, notes, and snippets.

@LeoHuckvale
Last active August 29, 2015 14:06
Show Gist options
  • Save LeoHuckvale/132197408345d6daa3b3 to your computer and use it in GitHub Desktop.
Save LeoHuckvale/132197408345d6daa3b3 to your computer and use it in GitHub Desktop.
Joining two lists of MJDs (or any two lists of floats) to within some tolerance
def mjd_join(mjd1, mjd2, tol=0.0001):
"""
Return indices of rows in mjd1 and mjd2 matching within tol
"""
diff = abs(mjd1 - mjd2[:, np.newaxis])
match = diff < tol
idx1 = np.mgrid[:len(mjd1), :len(mjd2)][0].T[match]
idx2 = np.mgrid[:len(mjd1), :len(mjd2)][1].T[match]
return idx1, idx2
@LeoHuckvale
Copy link
Author

Example use with two similar lightcurves, lc1 and lc2:

idx1, idx2 = mjd_join(lc1['mjd'], lc2['mjd'], 0.001)
flux1 = lc1['flux'][idx1]
flux2 = lc2['flux'][idx2]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment