-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
185 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
""" | ||
Implementation of the EpochPropagation in the MIVOT class with | ||
astropy.coordinates.sky_coordinate.SkyCoord and | ||
astropy.coordinates.sky_coordinate.SkyCoord.apply_space_motion. | ||
""" | ||
from astropy.coordinates import SkyCoord | ||
import astropy.units as u | ||
from pyvo.utils.prototype import prototype_feature | ||
|
||
|
||
@prototype_feature('MIVOT') | ||
class EpochPropagation: | ||
""" | ||
This class allows computing the position of a SkyCoord object at a new time dt. | ||
It builds a SkyCoord object from the data row of the MivotClass, and then applies the space motion. | ||
""" | ||
fields = ["longitude", "latitude", "pm_longitude", "pm_latitude"] | ||
|
||
def __init__(self, name): | ||
self.REFERENCE = {} | ||
self.name = name | ||
|
||
@property | ||
def ref_long(self): | ||
return self.REFERENCE.get("longitude") | ||
|
||
@ref_long.setter | ||
def ref_long(self, value): | ||
self.REFERENCE["longitude"] = value | ||
|
||
@property | ||
def ref_lat(self): | ||
return self.REFERENCE.get("latitude") | ||
|
||
@ref_lat.setter | ||
def ref_lat(self, value): | ||
self.REFERENCE["latitude"] = value | ||
|
||
@property | ||
def ref_pm_long(self): | ||
return self.REFERENCE.get("pm_longitude") | ||
|
||
@ref_pm_long.setter | ||
def ref_pm_long(self, value): | ||
self.REFERENCE["pm_longitude"] = value | ||
|
||
@property | ||
def ref_pm_lat(self): | ||
return self.REFERENCE.get("pm_latitude") | ||
|
||
@ref_pm_lat.setter | ||
def ref_pm_lat(self, value): | ||
self.REFERENCE["pm_latitude"] = value | ||
|
||
def SkyCoordinate(self): | ||
""" | ||
Returns a SkyCoord object from the REFERENCE of the XML object. | ||
""" | ||
if self.REFERENCE["frame"] == ('icrs' or 'fk5' or 'fk4'): | ||
return SkyCoord(distance=(self.REFERENCE["parallax"] / 4) * u.pc, | ||
radial_velocity=self.REFERENCE["radial_velocity"] * u.km / u.s, | ||
ra=self.REFERENCE["longitude"] * u.degree, | ||
dec=self.REFERENCE["latitude"] * u.degree, | ||
pm_ra_cosdec=self.REFERENCE["pm_longitude"] * u.mas / u.yr, | ||
pm_dec=self.REFERENCE["pm_latitude"] * u.mas / u.yr, | ||
frame=self.REFERENCE["frame"], | ||
obstime=self.REFERENCE["epoch"]) | ||
|
||
elif self.REFERENCE["frame"] == 'galatic': | ||
return SkyCoord(distance=self.REFERENCE["parallax"] * u.pc, | ||
l=self.REFERENCE["longitude"] * u.degree, | ||
b=self.REFERENCE["latitude"] * u.degree, | ||
pm_l_cosb=self.REFERENCE["pm_longitude"] * u.mas / u.yr, | ||
pm_b=self.REFERENCE["pm_latitude"] * u.mas / u.yr, | ||
frame=self.REFERENCE["frame"], | ||
obstime=self.REFERENCE["epoch"]) | ||
|
||
def apply_space_motion(self, dt): | ||
""" | ||
Returns ra and dec of a SkyCoord object by computing the position to a new time dt. | ||
Parameters | ||
---------- | ||
dt : float | ||
Time in years. | ||
""" | ||
retour = self.SkyCoordinate().apply_space_motion(dt=dt) | ||
return retour.ra, retour.dec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
""" | ||
Test for mivot.seekers.annotation_seeker.py | ||
""" | ||
import os | ||
|
||
import pytest | ||
from astropy.coordinates import SkyCoord | ||
import astropy.units as u | ||
from astropy.time import Time | ||
|
||
from pyvo.mivot.version_checker import check_astropy_version | ||
from pyvo.mivot.viewer.model_viewer import ModelViewer | ||
from pyvo.utils import activate_features | ||
|
||
activate_features('MIVOT') | ||
|
||
|
||
def test_epoch_propagation(m_viewer): | ||
if check_astropy_version() is False: | ||
pytest.skip("MIVOT test skipped because of the astropy version.") | ||
|
||
row_view = m_viewer.get_next_row_view() | ||
epoch_propagation = row_view.EpochPropagation | ||
sky_coord_to_compare = (SkyCoord(distance=(row_view.parallax.value / 4) * u.pc, | ||
radial_velocity=row_view.radialVelocity.value * u.km / u.s, | ||
ra=row_view.longitude.value * u.degree, | ||
dec=row_view.latitude.value * u.degree, | ||
pm_ra_cosdec=row_view.latitude.value * u.mas / u.yr, | ||
pm_dec=row_view.pmLatitude.value * u.mas / u.yr, | ||
frame=row_view.Coordinate_coosys | ||
.PhysicalCoordSys_frame.spaceRefFrame.value.lower(), | ||
obstime=Time(row_view.epoch.value, format="decimalyear"))) | ||
|
||
assert sky_coord_to_compare == epoch_propagation.SkyCoordinate() | ||
assert ((sky_coord_to_compare.apply_space_motion(dt=-42 * u.year).ra, | ||
sky_coord_to_compare.apply_space_motion(dt=-42 * u.year).dec) | ||
== epoch_propagation.apply_space_motion(dt=-42 * u.year)) | ||
assert epoch_propagation.ref_long == 10.0 | ||
assert epoch_propagation.ref_lat == 10.0 | ||
assert epoch_propagation.ref_pm_long == 10.0 | ||
assert epoch_propagation.ref_pm_lat == -20.0 | ||
|
||
@pytest.fixture | ||
def m_viewer(data_path): | ||
if check_astropy_version() is False: | ||
pytest.skip("MIVOT test skipped because of the astropy version.") | ||
votable = os.path.join(data_path, "data/simple-annotation-votable.xml") | ||
return ModelViewer(votable_path=votable) | ||
|
||
|
||
@pytest.fixture | ||
def data_path(): | ||
return os.path.dirname(os.path.realpath(__file__)) | ||
|
||
|
||
if __name__ == '__main__': | ||
pytest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters