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

Always cast 'att' attribute into Quat object #281

Merged
merged 1 commit into from
Feb 20, 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
9 changes: 7 additions & 2 deletions proseco/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ def __repr__(self):
return (f'<{self.__class__.__name__} name={self.name} default={self.default} '
f'pickle={self.pickle}>')

class QuatMetaAttribute(MetaAttribute):
def __set__(self, instance, value):
if not isinstance(value, Quat):
value = Quat(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems fine. I've sometimes run into issues with the not-quite-normalized Quat, but hopefully anything that reaches this point will be fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Default handling of a not-quite-normalized Quat should be handled upstream by Quat. Maybe auto-fix if within some threshold? Is there something like that already?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right now there's just a good error message. For proseco I had the MATLAB side explicitly normalize to avoid the possibility of it being a problem with these attitudes (relying on later checking to catch any problem).

instance.meta[self.name] = value

class IntMetaAttribute(MetaAttribute):
def __set__(self, instance, value):
Expand Down Expand Up @@ -524,7 +529,7 @@ class ACACatalogTable(BaseCatalogTable):
required_attrs = ('dither_acq', 'dither_guide', 'date')

obsid = MetaAttribute(default=0)
att = MetaAttribute()
att = QuatMetaAttribute()
n_acq = MetaAttribute(default=8)
n_guide = MetaAttribute()
n_fid = MetaAttribute(default=3)
Expand Down Expand Up @@ -965,7 +970,7 @@ class StarsTable(BaseCatalogTable):
- empty() : empty catalog, then use add_* methods to add stars

"""
att = MetaAttribute()
att = QuatMetaAttribute()

# StarsTable attributes, gets set in MetaAttribute or AliasAttribute
allowed_kwargs = set()
Expand Down
3 changes: 3 additions & 0 deletions proseco/tests/test_acq.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from pathlib import Path

from Quaternion import Quat
from chandra_aca.aca_image import AcaPsfLibrary
from chandra_aca.transform import mag_to_count_rate, yagzag_to_pixels

Expand Down Expand Up @@ -558,6 +559,8 @@ def test_make_report(tmpdir):
val2 = getattr(acqs2, attr)
if isinstance(val, float):
assert np.isclose(val, val2)
elif isinstance(val, Quat):
assert np.allclose(val.q, val2.q)
else:
assert val == val2

Expand Down
5 changes: 4 additions & 1 deletion proseco/tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import copy

import matplotlib
from Quaternion import Quat

matplotlib.use('agg')

Expand Down Expand Up @@ -217,6 +218,8 @@ def test_pickle():
val2 = getattr(obj2, attr)
if isinstance(val, float):
assert np.isclose(val, val2)
elif isinstance(val, Quat):
assert np.allclose(val.q, val2.q)
else:
assert val == val2

Expand Down Expand Up @@ -706,5 +709,5 @@ def test_force_catalog_from_starcheck():
assert aca['halfw'].tolist() == [25, 25, 25,
120, 160, 160, 120, 160,
120, 120, 120]
assert np.allclose(aca.att, [358.341787, -12.949882, 276.997597], rtol=0, atol=1e-6)
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)
2 changes: 1 addition & 1 deletion proseco/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def test_pickle_stars():
att = [1, 2, 3]
stars = StarsTable.from_agasc(att)
stars2 = pickle.loads(pickle.dumps(stars))
assert stars2.att == att
assert np.allclose(stars2.att.equatorial, att)
assert stars2.colnames == stars.colnames
assert repr(stars) == repr(stars2)

Expand Down
4 changes: 4 additions & 0 deletions proseco/tests/test_guide.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from pathlib import Path
import numpy as np
import itertools

from Quaternion import Quat
from astropy.table import Table
import pytest

Expand Down Expand Up @@ -577,5 +579,7 @@ def test_make_report_guide(tmpdir):
val2 = getattr(guides2, attr)
if isinstance(val, float):
assert np.isclose(val, val2)
elif isinstance(val, Quat):
assert np.allclose(val.q, val2.q)
else:
assert val == val2