Skip to content

Commit

Permalink
Merge pull request #81 from sot/n-fid
Browse files Browse the repository at this point in the history
 Support specifying number of fids
  • Loading branch information
taldcroft authored Sep 14, 2018
2 parents 07d460b + 5465724 commit 87a3827
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
16 changes: 11 additions & 5 deletions proseco/fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def get_fid_catalog(*, detector=None, focus_offset=0, sim_offset=0,
acqs=None, stars=None, dither=None,
acqs=None, stars=None, dither=None, n_fid=3,
print_log=None):
"""
Get a catalog of fid lights.
Expand Down Expand Up @@ -46,7 +46,7 @@ def get_fid_catalog(*, detector=None, focus_offset=0, sim_offset=0,
"""
fids = FidTable(detector=detector, focus_offset=focus_offset,
sim_offset=sim_offset, acqs=acqs, stars=stars,
dither=dither, print_log=print_log)
dither=dither, n_fid=n_fid, print_log=print_log)

fids.meta['cand_fids'] = fids.get_fid_candidates()

Expand All @@ -59,8 +59,13 @@ def get_fid_catalog(*, detector=None, focus_offset=0, sim_offset=0,
# Add a `slot` column that makes sense
fids.set_slot_column()

# Set fid thumbs_up to just be True for now
fids.thumbs_up = True
# TO DO: remove temporary stub to simply clip the number of returned
# fids to n_fid
if len(fids) > n_fid:
fids = fids[:n_fid]

# Set fid thumbs_up if fids has the number of requested fid lights
fids.thumbs_up = len(fids) == n_fid

return fids

Expand All @@ -76,7 +81,7 @@ class FidTable(ACACatalogTable):

def __init__(self, data=None, *, # Keyword only from here
detector=None, focus_offset=0, sim_offset=0,
acqs=None, stars=None, dither=None,
acqs=None, stars=None, dither=None, n_fid=3,
print_log=None, **kwargs):
"""
Table of fid lights, with methods for selection.
Expand Down Expand Up @@ -126,6 +131,7 @@ def __init__(self, data=None, *, # Keyword only from here
'sim_offset': sim_offset,
'acqs': acqs,
'dither': dither,
'n_fid': n_fid,
'stars': stars})

@property
Expand Down
19 changes: 9 additions & 10 deletions proseco/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,21 @@ 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], raise_exc=True)
# Expected
aca = get_aca_catalog(20603, exclude_ids=[40113544], n_fid=2, n_guide=6, n_acq=7,
raise_exc=True)
# Expected 2 fids, 6 guide, 7 acq
exp = ['slot idx id type sz p_acq mag maxmag yang zang dim res halfw',
'---- --- --------- ---- --- ----- ----- ------ -------- -------- --- --- -----',
' 0 1 2 FID 8x8 0.000 7.00 8.00 -773.20 -1742.03 1 1 25',
' 1 2 4 FID 8x8 0.000 7.00 8.00 2140.23 166.63 1 1 25',
' 2 3 5 FID 8x8 0.000 7.00 8.00 -1826.28 160.17 1 1 25',
' 3 4 116791824 BOT 6x6 0.958 9.01 10.51 622.00 -953.60 20 1 160',
' 4 5 40114416 BOT 6x6 0.912 9.78 11.28 394.22 1204.43 20 1 140',
' 5 6 116923528 BOT 6x6 0.593 9.84 11.34 -2418.65 1088.40 20 1 160',
' 6 7 40112304 BOT 6x6 0.687 9.79 11.29 -1644.35 2032.47 20 1 160',
' 2 3 116791824 BOT 6x6 0.958 9.01 10.51 622.00 -953.60 20 1 160',
' 3 4 40114416 BOT 6x6 0.912 9.78 11.28 394.22 1204.43 20 1 140',
' 4 5 116923528 BOT 6x6 0.593 9.84 11.34 -2418.65 1088.40 20 1 160',
' 5 6 40112304 BOT 6x6 0.687 9.79 11.29 -1644.35 2032.47 20 1 160',
' 6 7 116791744 BOT 6x6 0.347 10.29 11.79 985.38 -1210.19 20 1 140',
' 7 8 40113544 GUI 6x6 0.000 7.91 9.41 102.74 1133.37 1 1 25',
' 7 9 116923496 ACQ 6x6 0.970 9.14 10.64 -1337.79 1049.27 20 1 120',
' 0 10 116791744 ACQ 6x6 0.347 10.29 11.79 985.38 -1210.19 20 1 140',
' 1 11 40108048 ACQ 6x6 0.072 10.46 11.96 2.21 1619.17 20 1 60',
' 2 12 116785920 ACQ 6x6 0.136 10.50 12.00 -673.94 -1575.87 20 1 60']
' 0 10 116785920 ACQ 6x6 0.136 10.50 12.00 -673.94 -1575.87 20 1 60']
repr(aca) # Apply default formats
assert aca.pformat(max_width=-1) == exp

Expand Down
18 changes: 14 additions & 4 deletions proseco/tests/test_fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def test_get_fid_position():

def test_get_initial_catalog():
# Basic catalog with no stars in field. Standard 2-4-5 config.
fids = get_fid_catalog(detector='ACIS-S')
exp = ['<FidTable length=6>',
' id yang zang row col mag spoiler_score slot',
'int64 float64 float64 float64 float64 float64 int64 str3',
Expand All @@ -57,12 +56,12 @@ def test_get_initial_catalog():
' 4 2140.23 166.63 -424.51 39.13 7.00 0 1',
' 5 -1826.28 160.17 372.97 36.47 7.00 0 2',
' 6 388.59 803.75 -71.49 166.10 7.00 0 ...']
assert repr(fids.meta['cand_fids']).splitlines() == exp
assert np.all(fids['id'] == [2, 4, 5])
assert repr(FIDS.meta['cand_fids']).splitlines() == exp
assert np.all(FIDS['id'] == [2, 4, 5])

# Make catalogs with some fake stars (at exactly fid positions) that spoil
# the fids.
stars = fids.meta['cand_fids'].copy()
stars = FIDS.meta['cand_fids'].copy()
stars['mag_err'] = 0.1

# Spoil fids 1, 2
Expand All @@ -83,10 +82,21 @@ def test_get_initial_catalog():
# Spoil fids 1, 2, 3
fids3 = get_fid_catalog(detector='ACIS-S', stars=stars[:3], dither=8)
assert np.all(fids3['id'] == [4, 5, 6])
assert fids3.thumbs_up

# Spoil fids 1, 2, 3, 4 => no initial catalog gets found
fids4 = get_fid_catalog(detector='ACIS-S', stars=stars[:4], dither=8)
assert len(fids4) == 0
assert not fids4.thumbs_up


def test_n_fid():
"""Test specifying number of fids.
"""
# Get only 2 fids
fids = get_fid_catalog(detector='ACIS-S', dither=8, n_fid=2)
assert len(fids) == 2
assert fids.thumbs_up


def test_fid_spoiling_acq():
Expand Down

0 comments on commit 87a3827

Please sign in to comment.