From a033aea9a868f55ca4a8ef4345bfd15693d87e80 Mon Sep 17 00:00:00 2001 From: Tom Aldcroft Date: Tue, 19 Feb 2019 21:03:20 -0500 Subject: [PATCH] Always cast 'att' attribute into Quat object --- proseco/core.py | 9 +++++++-- proseco/tests/test_acq.py | 3 +++ proseco/tests/test_catalog.py | 5 ++++- proseco/tests/test_core.py | 2 +- proseco/tests/test_guide.py | 4 ++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/proseco/core.py b/proseco/core.py index 9814b488..92ee09bd 100644 --- a/proseco/core.py +++ b/proseco/core.py @@ -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) + instance.meta[self.name] = value class IntMetaAttribute(MetaAttribute): def __set__(self, instance, value): @@ -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) @@ -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() diff --git a/proseco/tests/test_acq.py b/proseco/tests/test_acq.py index 373c8fd7..88de16a4 100644 --- a/proseco/tests/test_acq.py +++ b/proseco/tests/test_acq.py @@ -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 @@ -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 diff --git a/proseco/tests/test_catalog.py b/proseco/tests/test_catalog.py index fbdbf170..41d1d90e 100644 --- a/proseco/tests/test_catalog.py +++ b/proseco/tests/test_catalog.py @@ -2,6 +2,7 @@ import copy import matplotlib +from Quaternion import Quat matplotlib.use('agg') @@ -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 @@ -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) diff --git a/proseco/tests/test_core.py b/proseco/tests/test_core.py index 8699f3d9..ad02d81e 100644 --- a/proseco/tests/test_core.py +++ b/proseco/tests/test_core.py @@ -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) diff --git a/proseco/tests/test_guide.py b/proseco/tests/test_guide.py index a04c3fe9..ca88f034 100644 --- a/proseco/tests/test_guide.py +++ b/proseco/tests/test_guide.py @@ -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 @@ -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