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

Implement include/exclude_ids in guide star selection #176

Merged
merged 4 commits into from
Dec 5, 2018
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
40 changes: 40 additions & 0 deletions proseco/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def run_search_stages(self):
# cand_guides as the 'selected' stars.
return cand_guides
cand_guides['stage'] = -1
# Force stars in include_ids to be selected at stage 0
for star_id in self.include_ids:
cand_guides['stage'][cand_guides['id'] == star_id] = 0
self.log(f'{star_id} selected in stage 0 via include_ids', level=1)
n_guide = self.n_guide
for idx, stage in enumerate(GUIDE_CHAR.stages, 1):
already_selected = np.count_nonzero(cand_guides['stage'] != -1)
Expand Down Expand Up @@ -254,6 +258,30 @@ def search_stage(self, stage):
ok = ok & ~bad_color
return ok

def process_include_ids(self, cand_guides, stars):
"""Ensure that the cand_guides table has stars that were forced to be included.

Also do validation of include_ids

:param cand_guides: candidate guide stars table
:param stars: stars table

"""
for include_id in self.include_ids:
if include_id not in cand_guides['id']:
try:
star = stars.get_id(include_id)
if ((star['CLASS'] != 0) |
(np.abs(star['row']) >= CHAR.max_ccd_row) |
(np.abs(star['col']) >= CHAR.max_ccd_col)):
raise ValueError("Not a valid candidate")
except (ValueError, KeyError):
raise ValueError(f'cannot include star id={include_id} that is not '
f'a valid star in the ACA field of view')
else:
cand_guides.add_row(star)
self.log(f'Included star id={include_id} put in cand_guides')

def get_initial_guide_candidates(self):
"""
Create a candidate list from the available stars in the field.
Expand Down Expand Up @@ -330,6 +358,18 @@ def get_initial_guide_candidates(self):
self.reject(rej)
cand_guides = cand_guides[~fid_trap_spoilers]

# Deal with include_ids by putting them back in candidate table if necessary
self.process_include_ids(cand_guides, stars)

# Deal with exclude_ids by cutting from the candidate list
for star_id in self.exclude_ids:
if star_id in cand_guides['id']:
self.reject({'stage': 0,
'type': 'exclude_id',
'id': star_id,
'text': f'Cand {star_id} rejected. In exclude_ids'})
cand_guides = cand_guides[cand_guides['id'] != star_id]

# Get the brightest 2x2 in the dark map for each candidate and save value and location
imp_mag, imp_row, imp_col = get_imposter_mags(cand_guides, dark, self.dither)
cand_guides['imp_mag'] = imp_mag
Expand Down
2 changes: 1 addition & 1 deletion proseco/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_get_aca_catalog_20603():
"""Put it all together. Regression test for selected stars.
"""
# Force not using a bright star so there is a GUI-only (not BOT) star
aca = get_aca_catalog(20603, exclude_ids=[40113544], n_fid=2, n_guide=6, n_acq=7,
aca = get_aca_catalog(20603, exclude_ids_acq=[40113544], n_fid=2, n_guide=6, n_acq=7,
Copy link
Member

Choose a reason for hiding this comment

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

Related to the discussion in #178, maybe revert this test and then fix the expected catalog to show both guide and acq exclusion of ..3544?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I was thinking that the test coverage of the supported interface was actually better this way ( test_aca_acqs_include_exclude seems to include and exclude the same stars for guide and acq, only via the separate kwargs).

Copy link
Member

Choose a reason for hiding this comment

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

OK fair enough.

raise_exc=True)
# Expected 2 fids, 6 guide, 7 acq
exp = ['slot idx id type sz yang zang dim res halfw',
Expand Down
18 changes: 10 additions & 8 deletions proseco/tests/test_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,26 @@ def test_guides_include_exclude():
size=1500, n_stars=3)

# Make sure baseline catalog is working like expected
guides = get_guide_catalog(**STD_INFO, stars=stars)
assert np.all(guides['id'] == np.arange(1, 6))
std_info = STD_INFO.copy()
std_info.update(n_guide=8)
guides = get_guide_catalog(**std_info, stars=stars)
assert np.all(guides['id'] == np.arange(1, 9))

# Define includes and excludes.
include_ids = [9, 11]
exclude_ids = [1]

guides = get_guide_catalog(**STD_INFO, stars=stars,
guides = get_guide_catalog(**std_info, stars=stars,
include_ids=include_ids,
exclude_ids=exclude_ids)

assert guides.include_ids == include_ids
assert guides.exclude_ids == exclude_ids

# assert all(id_ in guides.cand_guides['id'] for id_ in include_ids)
assert all(id_ in guides.cand_guides['id'] for id_ in include_ids)

# assert all(id_ in guides['id'] for id_ in include_ids)
# assert all(id_ not in guides['id'] for id_ in exclude_ids)
assert all(id_ in guides['id'] for id_ in include_ids)
assert all(id_ not in guides['id'] for id_ in exclude_ids)

# assert np.all(guides['id'] == [2, 3, 4, 5, 6, 7, 9, 11])
# assert np.allclose(guides['mag'], [7.1, 7.2, 7.3, 7.4, 7.5, 7.6, 10.0, 12.0])
assert np.all(guides['id'] == [9, 11, 2, 3, 4, 5, 6, 7])
assert np.allclose(guides['mag'], [10.0, 12.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.6])