@@ -35,10 +35,8 @@ def icrs_to_cirs(icrs_coo, cirs_frame):
3535
3636 if icrs_coo .data .get_name () == 'unitspherical' or icrs_coo .data .to_cartesian ().x .unit == u .one :
3737 # if no distance, just do the infinite-distance/no parallax calculation
38- usrepr = icrs_coo .represent_as (UnitSphericalRepresentation )
39- i_ra = usrepr .lon .to_value (u .radian )
40- i_dec = usrepr .lat .to_value (u .radian )
41- cirs_ra , cirs_dec = atciqz (i_ra , i_dec , astrom )
38+ srepr = icrs_coo .spherical
39+ cirs_ra , cirs_dec = atciqz (srepr .without_differentials (), astrom )
4240
4341 newrep = UnitSphericalRepresentation (lat = u .Quantity (cirs_dec , u .radian , copy = False ),
4442 lon = u .Quantity (cirs_ra , u .radian , copy = False ),
@@ -51,11 +49,8 @@ def icrs_to_cirs(icrs_coo, cirs_frame):
5149 astrom_eb = CartesianRepresentation (astrom ['eb' ], unit = u .au ,
5250 xyz_axis = - 1 , copy = False )
5351 newcart = icrs_coo .cartesian - astrom_eb
54-
5552 srepr = newcart .represent_as (SphericalRepresentation )
56- i_ra = srepr .lon .to_value (u .radian )
57- i_dec = srepr .lat .to_value (u .radian )
58- cirs_ra , cirs_dec = atciqz (i_ra , i_dec , astrom )
53+ cirs_ra , cirs_dec = atciqz (srepr .without_differentials (), astrom )
5954
6055 newrep = SphericalRepresentation (lat = u .Quantity (cirs_dec , u .radian , copy = False ),
6156 lon = u .Quantity (cirs_ra , u .radian , copy = False ),
@@ -66,18 +61,11 @@ def icrs_to_cirs(icrs_coo, cirs_frame):
6661
6762@frame_transform_graph .transform (FunctionTransformWithFiniteDifference , CIRS , ICRS )
6863def cirs_to_icrs (cirs_coo , icrs_frame ):
69- srepr = cirs_coo .represent_as (SphericalRepresentation )
70- cirs_ra = srepr .lon .to_value (u .radian )
71- cirs_dec = srepr .lat .to_value (u .radian )
72-
7364 # set up the astrometry context for ICRS<->cirs and then convert to
7465 # astrometric coordinate direction
75- jd1 , jd2 = get_jd12 (cirs_coo .obstime , 'tt' )
76- x , y , s = get_cip (jd1 , jd2 )
77- earth_pv , earth_heliocentric = prepare_earth_position_vel (cirs_coo .obstime )
78- # erfa.apci requests TDB but TT can be used instead of TDB without any significant impact on accuracy
79- astrom = erfa .apci (jd1 , jd2 , earth_pv , earth_heliocentric , x , y , s )
80- i_ra , i_dec = aticq (cirs_ra , cirs_dec , astrom )
66+ astrom = erfa_astrom .get ().apci (cirs_coo )
67+ srepr = cirs_coo .represent_as (SphericalRepresentation )
68+ i_ra , i_dec = aticq (srepr .without_differentials (), astrom )
8169
8270 if cirs_coo .data .get_name () == 'unitspherical' or cirs_coo .data .to_cartesian ().x .unit == u .one :
8371 # if no distance, just use the coordinate direction to yield the
@@ -121,27 +109,13 @@ def cirs_to_cirs(from_coo, to_frame):
121109
122110@frame_transform_graph .transform (FunctionTransformWithFiniteDifference , ICRS , GCRS )
123111def icrs_to_gcrs (icrs_coo , gcrs_frame ):
124- # first set up the astrometry context for ICRS<->GCRS. There are a few steps...
125- # get the position and velocity arrays for the observatory. Need to
126- # have xyz in last dimension, and pos/vel in one-but-last.
127- # (Note could use np.stack once our minimum numpy version is >=1.10.)
128- obs_pv = erfa .pav2pv (
129- gcrs_frame .obsgeoloc .get_xyz (xyz_axis = - 1 ).to_value (u .m ),
130- gcrs_frame .obsgeovel .get_xyz (xyz_axis = - 1 ).to_value (u .m / u .s ))
131-
132- # find the position and velocity of earth
133- jd1 , jd2 = get_jd12 (gcrs_frame .obstime , 'tdb' )
134- earth_pv , earth_heliocentric = prepare_earth_position_vel (gcrs_frame .obstime )
135-
136- # get astrometry context object, astrom.
137- astrom = erfa .apcs (jd1 , jd2 , obs_pv , earth_pv , earth_heliocentric )
112+ # first set up the astrometry context for ICRS<->GCRS.
113+ astrom = erfa_astrom .get ().apcs (gcrs_frame )
138114
139115 if icrs_coo .data .get_name () == 'unitspherical' or icrs_coo .data .to_cartesian ().x .unit == u .one :
140116 # if no distance, just do the infinite-distance/no parallax calculation
141- usrepr = icrs_coo .represent_as (UnitSphericalRepresentation )
142- i_ra = usrepr .lon .to_value (u .radian )
143- i_dec = usrepr .lat .to_value (u .radian )
144- gcrs_ra , gcrs_dec = atciqz (i_ra , i_dec , astrom )
117+ srepr = icrs_coo .represent_as (SphericalRepresentation )
118+ gcrs_ra , gcrs_dec = atciqz (srepr .without_differentials (), astrom )
145119
146120 newrep = UnitSphericalRepresentation (lat = u .Quantity (gcrs_dec , u .radian , copy = False ),
147121 lon = u .Quantity (gcrs_ra , u .radian , copy = False ),
@@ -156,9 +130,7 @@ def icrs_to_gcrs(icrs_coo, gcrs_frame):
156130 newcart = icrs_coo .cartesian - astrom_eb
157131
158132 srepr = newcart .represent_as (SphericalRepresentation )
159- i_ra = srepr .lon .to_value (u .radian )
160- i_dec = srepr .lat .to_value (u .radian )
161- gcrs_ra , gcrs_dec = atciqz (i_ra , i_dec , astrom )
133+ gcrs_ra , gcrs_dec = atciqz (srepr .without_differentials (), astrom )
162134
163135 newrep = SphericalRepresentation (lat = u .Quantity (gcrs_dec , u .radian , copy = False ),
164136 lon = u .Quantity (gcrs_ra , u .radian , copy = False ),
@@ -170,10 +142,6 @@ def icrs_to_gcrs(icrs_coo, gcrs_frame):
170142@frame_transform_graph .transform (FunctionTransformWithFiniteDifference ,
171143 GCRS , ICRS )
172144def gcrs_to_icrs (gcrs_coo , icrs_frame ):
173- srepr = gcrs_coo .represent_as (SphericalRepresentation )
174- gcrs_ra = srepr .lon .to_value (u .radian )
175- gcrs_dec = srepr .lat .to_value (u .radian )
176-
177145 # set up the astrometry context for ICRS<->GCRS and then convert to BCRS
178146 # coordinate direction
179147 obs_pv = erfa .pav2pv (
@@ -185,7 +153,8 @@ def gcrs_to_icrs(gcrs_coo, icrs_frame):
185153 earth_pv , earth_heliocentric = prepare_earth_position_vel (gcrs_coo .obstime )
186154 astrom = erfa .apcs (jd1 , jd2 , obs_pv , earth_pv , earth_heliocentric )
187155
188- i_ra , i_dec = aticq (gcrs_ra , gcrs_dec , astrom )
156+ srepr = gcrs_coo .represent_as (SphericalRepresentation )
157+ i_ra , i_dec = aticq (srepr .without_differentials (), astrom )
189158
190159 if gcrs_coo .data .get_name () == 'unitspherical' or gcrs_coo .data .to_cartesian ().x .unit == u .one :
191160 # if no distance, just use the coordinate direction to yield the
@@ -231,21 +200,11 @@ def gcrs_to_hcrs(gcrs_coo, hcrs_frame):
231200 frameattrs ['obstime' ] = hcrs_frame .obstime
232201 gcrs_coo = gcrs_coo .transform_to (GCRS (** frameattrs ))
233202
234- srepr = gcrs_coo .represent_as (SphericalRepresentation )
235- gcrs_ra = srepr .lon .to_value (u .radian )
236- gcrs_dec = srepr .lat .to_value (u .radian )
237-
238203 # set up the astrometry context for ICRS<->GCRS and then convert to ICRS
239204 # coordinate direction
240- obs_pv = erfa .pav2pv (
241- gcrs_coo .obsgeoloc .get_xyz (xyz_axis = - 1 ).to_value (u .m ),
242- gcrs_coo .obsgeovel .get_xyz (xyz_axis = - 1 ).to_value (u .m / u .s ))
243-
244- jd1 , jd2 = get_jd12 (hcrs_frame .obstime , 'tdb' )
245- earth_pv , earth_heliocentric = prepare_earth_position_vel (gcrs_coo .obstime )
246- astrom = erfa .apcs (jd1 , jd2 , obs_pv , earth_pv , earth_heliocentric )
247-
248- i_ra , i_dec = aticq (gcrs_ra , gcrs_dec , astrom )
205+ astrom = erfa_astrom .get ().apcs (gcrs_coo )
206+ srepr = gcrs_coo .represent_as (SphericalRepresentation )
207+ i_ra , i_dec = aticq (srepr .without_differentials (), astrom )
249208
250209 # convert to Quantity objects
251210 i_ra = u .Quantity (i_ra , u .radian , copy = False )
0 commit comments