Skip to content

Commit

Permalink
partially fix 13494
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Feb 21, 2024
1 parent 7a47087 commit 0e7073a
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions astropy/utils/iers/iers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from astropy import units as u
from astropy import utils
from astropy.table import MaskedColumn, QTable
from astropy.table import join as table_join
from astropy.time import Time, TimeDelta
from astropy.utils.data import (
clear_download_cache,
Expand Down Expand Up @@ -589,9 +590,19 @@ 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"):
s1 = ~table["UT1Flag_A"].mask
else:
s1 = slice(None)

Check warning on line 596 in astropy/utils/iers/iers.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/iers/iers.py#L596

Added line #L596 was not covered by tests

if hasattr(table["PolPMFlag_A"], "mask"):
s2 = ~table["PolPMFlag_A"].mask
else:
s2 = slice(None)

Check warning on line 601 in astropy/utils/iers/iers.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/iers/iers.py#L601

Added line #L601 was not covered by tests

p_index = min(
np.searchsorted(table["UT1Flag_A"], "P"),
np.searchsorted(table["PolPMFlag_A"], "P"),
np.searchsorted(table["UT1Flag_A"][s1], "P"),
np.searchsorted(table["PolPMFlag_A"][s2], "P"),
)
table.meta["predictive_index"] = p_index
table.meta["predictive_mjd"] = table["MJD"][p_index].value
Expand Down Expand Up @@ -940,23 +951,29 @@ def _substitute_iers_b(cls, table):
mjd_b = table["MJD"][np.isfinite(table["UT1_UTC_B"])]
i0 = np.searchsorted(iers_b["MJD"], mjd_b[0], side="left")
i1 = np.searchsorted(iers_b["MJD"], mjd_b[-1], side="right")
iers_b = iers_b[i0:i1]
n_iers_b = len(iers_b)
iers_b_overlap = iers_b[i0:i1]
n_iers_b = len(iers_b_overlap)

Check warning on line 955 in astropy/utils/iers/iers.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/iers/iers.py#L954-L955

Added lines #L954 - L955 were not covered by tests
# If there is overlap then replace IERS-A values from available IERS-B
if n_iers_b > 0:
# Sanity check that we are overwriting the correct values
if not u.allclose(table["MJD"][:n_iers_b], iers_b["MJD"]):
if not u.allclose(table["MJD"][:n_iers_b], iers_b_overlap["MJD"]):

Check warning on line 959 in astropy/utils/iers/iers.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/iers/iers.py#L959

Added line #L959 was not covered by tests
raise ValueError(
"unexpected mismatch when copying IERS-B values into IERS-A table."
)
# Finally do the overwrite
table["UT1_UTC_B"][:n_iers_b] = iers_b["UT1_UTC"]
table["PM_X_B"][:n_iers_b] = iers_b["PM_x"]
table["PM_Y_B"][:n_iers_b] = iers_b["PM_y"]
table["dX_2000A_B"][:n_iers_b] = iers_b["dX_2000A"]
table["dY_2000A_B"][:n_iers_b] = iers_b["dY_2000A"]

return table
table["UT1_UTC_B"][:n_iers_b] = iers_b_overlap["UT1_UTC"]
table["PM_X_B"][:n_iers_b] = iers_b_overlap["PM_x"]
table["PM_Y_B"][:n_iers_b] = iers_b_overlap["PM_y"]
table["dX_2000A_B"][:n_iers_b] = iers_b_overlap["dX_2000A"]
table["dY_2000A_B"][:n_iers_b] = iers_b_overlap["dY_2000A"]

Check warning on line 968 in astropy/utils/iers/iers.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/iers/iers.py#L964-L968

Added lines #L964 - L968 were not covered by tests

return table_join(

Check warning on line 970 in astropy/utils/iers/iers.py

View check run for this annotation

Codecov / codecov/patch

astropy/utils/iers/iers.py#L970

Added line #L970 was not covered by tests
table,
iers_b[:i0],
join_type="outer",
keys="MJD",
metadata_conflicts="silent", # tmp filtering
)


class earth_orientation_table(ScienceState):
Expand Down

0 comments on commit 0e7073a

Please sign in to comment.