Skip to content

Commit

Permalink
fixup! ENH: include exclusive values from IERS_B in IERS_Auto
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Feb 29, 2024
1 parent 975fc61 commit b3ebcfb
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions astropy/utils/iers/iers.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,26 +590,25 @@ def _combine_a_b_columns(cls, iers_a):
# Since only 'P' and 'I' are possible and 'P' is guaranteed to come
# after 'I', we can use searchsorted for 100 times speed up over
# finding the first index where the flag equals 'P'.
if hasattr(table["UT1Flag_A"], "mask"):
mask = table["UT1Flag_A"].mask
s1 = ~mask
# a hacky way to get the position of first non-masked value
offset1 = np.searchsorted(s1, True)
else:
s1 = slice(None)
offset1 = 0

if hasattr(table["PolPMFlag_A"], "mask"):
mask = table["PolPMFlag_A"].mask
s2 = ~mask
offset2 = np.searchsorted(s1, True)
else:
s2 = slice(None)
offset2 = 0
def select_offset(array):
if not hasattr(array, "mask"):
return slice(None), 0

s = ~array.mask
# Get the position of first non-masked value.
# This is a bit of a hack since s isn't necessarily sorted, but we
# get the correct result by letting np.searchsorted *assuming* it is.
offset = np.searchsorted(s, True)

return s, offset

select1, offset1 = select_offset(table["UT1Flag_A"])
select2, offset2 = select_offset(table["PolPMFlag_A"])

p_index = min(
offset1 + np.searchsorted(table["UT1Flag_A"][s1], "P"),
offset2 + np.searchsorted(table["PolPMFlag_A"][s2], "P"),
offset1 + np.searchsorted(table["UT1Flag_A"][select1], "P"),
offset2 + np.searchsorted(table["PolPMFlag_A"][select2], "P"),
)
table.meta["predictive_index"] = p_index
table.meta["predictive_mjd"] = table["MJD"][p_index].value
Expand Down

0 comments on commit b3ebcfb

Please sign in to comment.