1313from .. import SkyCoord
1414from ...tests .helper import (pytest , quantity_allclose as allclose ,
1515 assert_quantity_allclose as assert_allclose )
16- from .. import EarthLocation
16+ from .. import EarthLocation , CartesianRepresentation
1717from ...time import Time
1818
1919# used below in the next parametrized test
@@ -176,6 +176,66 @@ def test_supergalactic():
176176 assert supergalactic .separation (icrs ) < 0.005 * u .degree
177177
178178
179+ class TestHCRS ():
180+ """
181+ Check HCRS<->ICRS coordinate conversions.
182+
183+ Uses ICRS Solar positions predicted by get_body_barycentric; with `t1` and
184+ `tarr` as defined below, the ICRS Solar positions were predicted using, e.g.
185+ coord.ICRS(coord.get_body_barycentric(tarr, 'sun')).
186+ """
187+ def setup (self ):
188+ self .t1 = Time ("2013-02-02T23:00" )
189+ self .t2 = Time ("2013-08-02T23:00" )
190+ self .tarr = Time (["2013-02-02T23:00" , "2013-08-02T23:00" ])
191+
192+ self .sun_icrs_scalar = ICRS (ra = 244.52984668 * u .deg ,
193+ dec = - 22.36943723 * u .deg ,
194+ distance = 406615.66347377 * u .km )
195+ # array of positions corresponds to times in `tarr`
196+ self .sun_icrs_arr = ICRS (ra = [244.52989062 , 271.40976248 ]* u .deg ,
197+ dec = [- 22.36943605 , - 25.07431079 ]* u .deg ,
198+ distance = [406615.66347377 , 375484.13558956 ]* u .km )
199+
200+ # corresponding HCRS positions
201+ self .sun_hcrs_t1 = HCRS (CartesianRepresentation ([0.0 , 0.0 , 0.0 ] * u .km ),
202+ obstime = self .t1 )
203+ self .sun_hcrs_tarr1 = HCRS (CartesianRepresentation ([0.0 , 0.0 , 0.0 ] * u .km ),
204+ obstime = self .tarr )
205+ twod_rep = CartesianRepresentation ([[0.0 , 0.0 ], [0.0 , 0.0 ], [0.0 , 0.0 ]] * u .km )
206+ self .sun_hcrs_tarr1 = HCRS (CartesianRepresentation ([0.0 , 0.0 , 0.0 ] * u .km ),
207+ obstime = self .tarr )
208+ self .sun_hcrs_tarr2 = HCRS (twod_rep ,
209+ obstime = self .tarr )
210+ self .tolerance = 5 * u .km
211+
212+ def test_from_hcrs (self ):
213+ # test scalar transform
214+ transformed = self .sun_hcrs_t1 .transform_to (ICRS ())
215+ separation = transformed .separation_3d (self .sun_icrs_scalar )
216+ assert_allclose (separation , 0 * u .km , atol = self .tolerance )
217+
218+ # test scalar position and non-scalar time
219+ transformed = self .sun_hcrs_tarr1 .transform_to (ICRS ())
220+ separation = transformed .separation_3d (self .sun_icrs_arr )
221+ assert_allclose (separation , 0 * u .km , atol = self .tolerance )
222+
223+ # test non-scalar positions and times
224+ transformed = self .sun_hcrs_tarr2 .transform_to (ICRS ())
225+ separation = transformed .separation_3d (self .sun_icrs_arr )
226+ assert_allclose (separation , 0 * u .km , atol = self .tolerance )
227+
228+ def test_from_icrs (self ):
229+ # scalar positions
230+ transformed = self .sun_icrs_scalar .transform_to (HCRS (obstime = self .t1 ))
231+ separation = transformed .separation_3d (self .sun_hcrs_t1 )
232+ assert_allclose (separation , 0 * u .km , atol = self .tolerance )
233+ # nonscalar positions
234+ transformed = self .sun_icrs_arr .transform_to (HCRS (obstime = self .tarr ))
235+ separation = transformed .separation_3d (self .sun_hcrs_tarr1 )
236+ assert_allclose (separation , 0 * u .km , atol = self .tolerance )
237+
238+
179239class TestHelioBaryCentric ():
180240 """
181241 Check GCRS<->Heliocentric and Barycentric coordinate conversions.
@@ -188,7 +248,8 @@ def setup(self):
188248 self .wht_itrs = wht .get_itrs (obstime = self .obstime )
189249
190250 def test_heliocentric (self ):
191- helio = self .wht_itrs .transform_to (HCRS (obstime = self .obstime ))
251+ gcrs = self .wht_itrs .transform_to (GCRS (obstime = self .obstime ))
252+ helio = gcrs .transform_to (HCRS (obstime = self .obstime ))
192253 # Check it doesn't change from previous times.
193254 previous = [- 1.02597256e+11 , 9.71725820e+10 , 4.21268419e+10 ] * u .m
194255 assert_allclose (helio .cartesian .xyz , previous )
0 commit comments