Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add includes_for_obsid helper function #311

Merged
merged 1 commit into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions proseco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1450,3 +1450,34 @@ def get_kwargs_from_starcheck_text(obs_text, include_cat=False, force_catalog=Fa
pass

return kw


def includes_for_obsid(obsid):
"""
Return a dict with the include_ids_acq, include_halfws_acq and include_ids_guide
lists for the as-run flight catalog of ``obsid``. Useful for forcing catalog.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I note that get_starcheck_catalog has both as-run catalogs and has ingested latest-version catalogs for obsids that haven't actually run yet. But that does not apply to this PR.


Example::

>>> from proseco import get_aca_catalog
>>> from proseco.core import includes_for_obsid
>>> obsid = 8008
>>> aca = get_aca_catalog(obsid, **includes_for_obsid(obsid))

:param obsid: int, obsid
"""
from mica.starcheck import get_starcheck_catalog

obs = get_starcheck_catalog(obsid)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use get_starcat here but get_starcheck_catalog is fine.


cat = obs['cat']
out = {}

ok = np.in1d(cat['type'], ('ACQ', 'BOT'))
out['include_ids_acq'] = cat['id'][ok].tolist()
out['include_halfws_acq'] = cat['halfw'][ok].tolist()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good as I don't see any way the ids and the halfwidths can end up with mismatched indexes.


ok = np.in1d(cat['type'], ('GUI', 'BOT'))
out['include_ids_guide'] = cat['id'][ok].tolist()

return out
22 changes: 21 additions & 1 deletion proseco/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import mica.starcheck

from .test_common import STD_INFO, mod_std_info, DARK40, OBS_INFO
from ..core import StarsTable
from ..core import StarsTable, includes_for_obsid
from ..catalog import get_aca_catalog, ACATable
from ..fid import get_fid_catalog
from .. import characteristics as ACA
Expand Down Expand Up @@ -740,3 +740,23 @@ def test_force_catalog_from_starcheck():
120, 120, 120]
assert np.allclose(aca.att.equatorial, [358.341787, -12.949882, 276.997597], rtol=0, atol=1e-6)
assert np.allclose(aca.acqs.man_angle, 89.16)


@pytest.mark.skipif('not HAS_SC_ARCHIVE', reason='Test requires starcheck archive')
def test_includes_for_obsid():
"""
Test helper function to get the include_* kwargs for forcing a catalog.
"""
exp = {'include_halfws_acq': [120, 120, 120, 120, 85, 120, 120, 120],
'include_ids_acq': [31075128,
31076560,
31463496,
31983336,
32374896,
31075368,
31982136,
32375384],
'include_ids_guide': [31075128, 31076560, 31463496, 31983336, 32374896]}

out = includes_for_obsid(8008)
assert out == exp