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 img_size guide parameter to control guide star image readout size #344

Merged
merged 6 commits into from
Sep 29, 2020
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
15 changes: 11 additions & 4 deletions proseco/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def get_aca_catalog(obsid=0, **kwargs):
:param exclude_ids_fid: list of fiducial lights to exclude by index
:param include_ids_guide: list of AGASC IDs of stars to include in guide catalog
:param exclude_ids_guide: list of AGASC IDs of stars to exclude from guide catalog
:param img_size_guide: readout window size for guide stars (6, 8, or ``None``).
For default value ``None`` use 8 for no fids, 6 for fids.
:param optimize: optimize star catalog after initial selection (default=True)
:param verbose: provide extra logging info (mostly calc_p_safe) (default=False)
:param print_log: print the run log to stdout (default=False)
Expand Down Expand Up @@ -102,6 +104,7 @@ def _get_aca_catalog(**kwargs):
assembling the merged aca catalog.
"""
raise_exc = kwargs.pop('raise_exc')
img_size_guide = kwargs.pop('img_size_guide', None)

aca = ACATable()
aca.call_args = kwargs.copy()
Expand Down Expand Up @@ -141,7 +144,8 @@ def _get_aca_catalog(**kwargs):
aca.acqs.fid_set = aca.fids['id']

aca.log('Starting get_guide_catalog')
aca.guides = get_guide_catalog(stars=aca.acqs.stars, fids=aca.fids, **kwargs)
aca.guides = get_guide_catalog(stars=aca.acqs.stars, fids=aca.fids,
img_size=img_size_guide, **kwargs)

# Make a merged starcheck-like catalog. Catch any errors at this point to avoid
# impacting operational work (call from Matlab).
Expand Down Expand Up @@ -439,7 +443,10 @@ def merge_cats(fids=None, guides=None, acqs=None):
fids['p_acq'] = 0
fids['sz'] = '8x8'

guide_size = '8x8' if len(fids) == 0 else '6x6'
# Set guide star image readout size, either from explicit user input or
# using the default rule defined in ``get_img_size()``.
img_size = guides.get_img_size(len(fids))

if len(guides) > 0:
guides['slot'] = 0 # Filled in later
guides['type'] = 'GUI'
Expand All @@ -448,13 +455,13 @@ def merge_cats(fids=None, guides=None, acqs=None):
guides['dim'] = 1
guides['res'] = 1
guides['halfw'] = 25
guides['sz'] = guide_size
guides['sz'] = f'{img_size}x{img_size}'

if len(acqs) > 0:
acqs['type'] = 'ACQ'
acqs['maxmag'] = (acqs['mag'] + 1.5).clip(None, ACA.max_maxmag)
acqs['dim'] = 20
acqs['sz'] = guide_size
acqs['sz'] = f'{img_size}x{img_size}'
acqs['res'] = 1

# Accumulate a list of table Row objects to be assembled into the final table.
Expand Down
34 changes: 34 additions & 0 deletions proseco/guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ def get_guide_catalog(obsid=0, **kwargs):
return guides


class ImgSizeMetaAttribute(MetaAttribute):
def __set__(self, instance, value):
if value not in (4, 6, 8, None):
raise ValueError('img_size must be 4, 6, 8, or None')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks good. I was thinking this would get checked on the sparkles side but fine to do it here.

instance.meta[self.name] = value


class GuideTable(ACACatalogTable):
# Define base set of allowed keyword args to __init__. Subsequent MetaAttribute
# or AliasAttribute properties will add to this.
Expand All @@ -88,6 +95,7 @@ class GuideTable(ACACatalogTable):

cand_guides = MetaAttribute(is_kwarg=False)
reject_info = MetaAttribute(default=[], is_kwarg=False)
img_size = ImgSizeMetaAttribute()

def reject(self, reject):
"""
Expand All @@ -101,6 +109,32 @@ def reject(self, reject):
include_ids = AliasAttribute()
exclude_ids = AliasAttribute()

def get_img_size(self, n_fids):
"""Get guide image readout size from ``img_size`` and ``n_fids``.

If img_size is None (typical case) then this uses the default rule
that OR's get 6x6 and ER's (no fids) get 8x8.

This requires that the ``fids`` attribute has been set, normally by
providing the table as an arg to ``get_guide_catalog()``.

Parameters
----------
n_fids : int
Number of fids in the catalog

Returns
-------
int
Guide star image readout size to be used in a catalog
"""
img_size = self.img_size

if img_size is None:
img_size = 8 if n_fids == 0 else 6

return img_size

def make_report(self, rootdir='.'):
"""
Make summary HTML report for guide selection process and outputs.
Expand Down
37 changes: 37 additions & 0 deletions proseco/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,3 +766,40 @@ def test_dark_date_warning():

assert len(warns) == 1
assert 'Unexpected dark_date: dark_id nearest dark_date' in str(warns[0].message)


def test_img_size_guide():
"""
Test img_size_guide for setting guide star readout image size
"""
dark = DARK40.copy()
stars = StarsTable.empty()
stars.add_fake_constellation(mag=8.0, n_stars=8)

# Confirm that for an inferred ER, boxes are 8x8
aca = get_aca_catalog(**mod_std_info(stars=stars, dark=dark, n_fid=0))
assert np.all(aca.guides['sz'] == '8x8')
assert aca.guides.img_size is None

# Confirm that for an inferred OR, boxes are 6x6
aca = get_aca_catalog(**mod_std_info(stars=stars, dark=dark, n_fid=3))
assert np.all(aca.guides['sz'] == '6x6')
assert aca.guides.img_size is None

# Confirm that for explicit img_size_guide of 8 boxes are '8x8'
aca = get_aca_catalog(**mod_std_info(stars=stars, dark=dark, n_fid=3, img_size_guide=8))
assert np.all(aca.guides['sz'] == '8x8')
assert aca.guides.img_size == 8

# Confirm that for explicit img_size_guide of 6 boxes are '6x6'
aca = get_aca_catalog(**mod_std_info(stars=stars, dark=dark, n_fid=0, img_size_guide=6))
assert np.all(aca.guides['sz'] == '6x6')
assert aca.guides.img_size == 6

# Confirm that for explicit img_size_guide of 6 boxes are '6x6'
aca = get_aca_catalog(**mod_std_info(stars=stars, dark=dark, n_fid=0, img_size_guide=4))
assert np.all(aca.guides['sz'] == '4x4')
assert aca.guides.img_size == 4

with pytest.raises(ValueError, match='img_size must be 4, 6, 8, or None'):
get_aca_catalog(**mod_std_info(stars=stars, dark=dark, img_size_guide=3))