-
-
Notifications
You must be signed in to change notification settings - Fork 54
Update vizier example #710
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
base: main
Are you sure you want to change the base?
Changes from all commits
0789a51
0d55080
b15f5e6
6971214
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -89,10 +89,14 @@ def _get_time_instance(self, hk_field, besselian=False): | |||||
| ----- | ||||||
| MappingError: if the Time instance cannot be built for some reason | ||||||
| """ | ||||||
| # Process complex type "mango:DateTime | ||||||
| # Process complex type "mango:DateTime" | ||||||
| if hk_field['dmtype'] == "mango:DateTime": | ||||||
| representation = hk_field['representation']['value'] | ||||||
| timestamp = hk_field['dateTime']['value'] | ||||||
| # Process complex type "coords:epoch" used for the space frame equinox | ||||||
| elif hk_field['dmtype'] == "coords:Epoch": | ||||||
| representation = 'yr' if "unit" not in hk_field else hk_field.get("unit") | ||||||
| timestamp = hk_field['value'] | ||||||
| # Process simple attribute | ||||||
| else: | ||||||
| representation = hk_field.get("unit") | ||||||
|
|
@@ -104,7 +108,8 @@ def _get_time_instance(self, hk_field, besselian=False): | |||||
|
|
||||||
| time_instance = self. _build_time_instance(timestamp, representation, besselian) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this typo, I suspect this line doesn't get test coverage
Suggested change
|
||||||
| if not time_instance: | ||||||
| raise MappingError(f"Cannot build a Time instance from {hk_field}") | ||||||
| mode = "besselian" if besselian else "julian" | ||||||
| raise MappingError(f"Cannot build a Time instance from {hk_field} ({mode} date)") | ||||||
|
|
||||||
| return time_instance | ||||||
|
|
||||||
|
|
@@ -175,7 +180,6 @@ def _get_space_frame(self): | |||||
| coo_sys = self._mivot_instance_dict["spaceSys"]["frame"] | ||||||
| equinox = None | ||||||
| frame = coo_sys["spaceRefFrame"]["value"].lower() | ||||||
|
|
||||||
| if frame == 'fk4': | ||||||
| self._map_coord_names = SkyCoordMapping.default_params | ||||||
| if "equinox" in coo_sys: | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,11 +9,10 @@ | |
| import pytest | ||
| from copy import deepcopy | ||
| from astropy.utils.data import get_pkg_data_filename | ||
| from astropy import units as u | ||
| from pyvo.mivot.version_checker import check_astropy_version | ||
| from pyvo.mivot.viewer.mivot_instance import MivotInstance | ||
| from pyvo.mivot.features.sky_coord_builder import SkyCoordBuilder | ||
| from pyvo.mivot.utils.exceptions import NoMatchingDMTypeError | ||
| from pyvo.mivot.utils.exceptions import NoMatchingDMTypeError, MappingError | ||
| from pyvo.mivot.viewer.mivot_viewer import MivotViewer | ||
| from pyvo.utils import activate_features | ||
|
|
||
|
|
@@ -118,9 +117,8 @@ | |
| "value": "FK5" | ||
| }, | ||
| "equinox": { | ||
| "dmtype": "coords:SpaceFrame.equinox", | ||
| "dmtype": "coords:Epoch", | ||
| "value": "2012", | ||
| "unit": "yr", | ||
| } | ||
| } | ||
| }, | ||
|
|
@@ -176,14 +174,35 @@ | |
| "ref": None, | ||
| }, | ||
| "equinox": { | ||
| "dmtype": "coords:SpaceFrame.equinox", | ||
| "dmtype": "coords:Epoch", | ||
| "value": "2012", | ||
| "unit": "yr", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def check_skycoo(scoo, ra, dec, distance, pm_ra_cosdec, pm_dec, obstime): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there is a better way to compare the values to a SkyCoord object. |
||
| """ | ||
| Check the SkyCoord instance against the constant values given as parameters | ||
| """ | ||
| try: | ||
| assert scoo.ra.degree == pytest.approx(ra) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't noticed this before, but in general we don't really use pytest.approx() but prefer the functionality from numpy.testing. It's not really a big issue here when comparing scalars, but elsewhere the numpy versions may be more preferred. |
||
| assert scoo.dec.degree == pytest.approx(dec) | ||
| if distance: | ||
| assert scoo.distance.pc == pytest.approx(distance) | ||
| if pm_ra_cosdec: | ||
| assert scoo.pm_ra_cosdec.value == pytest.approx(pm_ra_cosdec) | ||
| if pm_dec: | ||
| assert scoo.pm_dec.value == pytest.approx(pm_dec) | ||
| except AttributeError: | ||
| assert scoo.galactic.l.degree == pytest.approx(ra) | ||
| assert scoo.galactic.b.degree == pytest.approx(dec) | ||
|
|
||
| if obstime: | ||
| assert str(scoo.obstime) == obstime | ||
|
|
||
|
|
||
| def test_no_matching_mapping(): | ||
| """ | ||
| Test that a NoMatchingDMTypeError is raised not mapped on mango:EpochPosition | ||
|
|
@@ -201,27 +220,26 @@ def test_vizier_output(): | |
| mivot_instance = MivotInstance(**vizier_dict) | ||
| scb = SkyCoordBuilder(mivot_instance) | ||
| scoo = scb.build_sky_coord() | ||
| assert (str(scoo).replace("\n", "").replace(" ", "") | ||
| == "<SkyCoord (ICRS): (ra, dec) in deg(52.26722684, 59.94033461) " | ||
| "(pm_ra_cosdec, pm_dec) in mas / yr(-0.82, -1.85)>") | ||
| scoo = mivot_instance.get_SkyCoord() | ||
| assert (str(scoo).replace("\n", "").replace(" ", "") | ||
| == "<SkyCoord (ICRS): (ra, dec) in deg(52.26722684, 59.94033461) " | ||
| "(pm_ra_cosdec, pm_dec) in mas / yr(-0.82, -1.85)>") | ||
| check_skycoo(scoo, 52.26722684, 59.94033461, None, | ||
| -0.82, -1.85, | ||
| None) | ||
|
|
||
| vizier_dict["spaceSys"]["frame"]["spaceRefFrame"]["value"] = "Galactic" | ||
| mivot_instance = MivotInstance(**vizier_dict) | ||
| scoo = mivot_instance.get_SkyCoord() | ||
| assert (str(scoo).replace("\n", "").replace(" ", "") | ||
| == "<SkyCoord (Galactic): (l, b) in deg(52.26722684, 59.94033461) " | ||
| "(pm_l_cosb, pm_b) in mas / yr(-0.82, -1.85)>") | ||
| check_skycoo(scoo, 52.26722684, 59.94033461, None, | ||
| -0.82, -1.85, | ||
| None) | ||
|
|
||
| vizier_dict["spaceSys"]["frame"]["spaceRefFrame"]["value"] = "QWERTY" | ||
| mivot_instance = MivotInstance(**vizier_dict) | ||
| scoo = mivot_instance.get_SkyCoord() | ||
| assert (str(scoo).replace("\n", "").replace(" ", "") | ||
| == "<SkyCoord (ICRS): (ra, dec) in deg(52.26722684, 59.94033461) " | ||
| "(pm_ra_cosdec, pm_dec) in mas / yr(-0.82, -1.85)>") | ||
| check_skycoo(scoo, 52.26722684, 59.94033461, None, | ||
| -0.82, -1.85, | ||
| "J1991.250") | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not check_astropy_version(), reason="need astropy 6+") | ||
|
|
@@ -232,19 +250,24 @@ def test_vizier_output_with_equinox_and_parallax(): | |
| mivot_instance = MivotInstance(**vizier_equin_dict) | ||
| scb = SkyCoordBuilder(mivot_instance) | ||
| scoo = scb.build_sky_coord() | ||
| assert (str(scoo).replace("\n", "").replace(" ", "") | ||
| == "<SkyCoord (FK5: equinox=J2012.000): (ra, dec, distance) in " | ||
| "(deg, deg, pc)(52.26722684, 59.94033461, 1666.66666667) " | ||
| "(pm_ra_cosdec, pm_dec) in mas / yr(-0.82, -1.85)>") | ||
| check_skycoo(scoo, 52.26722684, 59.94033461, 1666.66666667, | ||
| -0.82, -1.85, | ||
| "J1991.250") | ||
|
|
||
| mydict = deepcopy(vizier_equin_dict) | ||
| mydict["spaceSys"]["frame"]["spaceRefFrame"]["value"] = "FK4" | ||
| mivot_instance = MivotInstance(**mydict) | ||
| scoo = mivot_instance.get_SkyCoord() | ||
| assert (str(scoo).replace("\n", "").replace(" ", "") | ||
| == "<SkyCoord (FK4: equinox=B2012.000, obstime=B1991.250): (ra, dec, distance) in " | ||
| "(deg, deg, pc)(52.26722684, 59.94033461, 1666.66666667) " | ||
| "(pm_ra_cosdec, pm_dec) in mas / yr(-0.82, -1.85)>") | ||
| check_skycoo(scoo, 52.26722684, 59.94033461, 1666.66666667, | ||
| -0.82, -1.85, | ||
| "B1991.250") | ||
|
|
||
| mydict = deepcopy(vizier_equin_dict) | ||
| mydict["spaceSys"]["frame"]["spaceRefFrame"]["value"] = "FK4" | ||
| mydict["spaceSys"]["frame"]["equinox"]["value"] = "J2012" | ||
| with pytest.raises(MappingError, match=r".*besselian date.*"): | ||
| mivot_instance = MivotInstance(**mydict) | ||
| scoo = mivot_instance.get_SkyCoord() | ||
|
|
||
|
|
||
| @pytest.mark.skipif(not check_astropy_version(), reason="need astropy 6+") | ||
|
|
@@ -257,16 +280,9 @@ def test_simad_cs_output(): | |
| scb = SkyCoordBuilder(mivot_instance) | ||
| scoo = scb.build_sky_coord() | ||
|
|
||
| assert scoo.ra.degree == pytest.approx(269.45207696) | ||
| assert scoo.dec.degree == pytest.approx(4.69336497) | ||
| assert scoo.distance.pc == pytest.approx(1.82823411) | ||
| x = scoo.pm_ra_cosdec.value | ||
| y = (-801.551 * u.mas/u.yr).value | ||
| assert x == pytest.approx(y) | ||
| x = scoo.pm_dec.value | ||
| y = (10362.394 * u.mas/u.yr).value | ||
| assert x == pytest.approx(y) | ||
| assert str(scoo.obstime) == "J2000.000" | ||
| check_skycoo(scoo, 269.45207696, 4.69336497, 1.82823411, | ||
| -801.551, 10362.394, | ||
| "J2000.000") | ||
|
|
||
|
|
||
| def test_time_representation(): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the docs mentions in the changelog, and fix PR number syntax