def test_angle_ops(): sign, idmsf = erfa.a2af(6, -np.pi) assert sign == b'-' assert idmsf.item() == (180, 0, 0, 0) sign, ihmsf = erfa.a2tf(6, np.pi) assert sign == b'+' assert ihmsf.item() == (12, 0, 0, 0) rad = erfa.af2a('-', 180, 0, 0.0) np.testing.assert_allclose(rad, -np.pi) rad = erfa.tf2a('+', 12, 0, 0.0) np.testing.assert_allclose(rad, np.pi) rad = erfa.anp(3. * np.pi) np.testing.assert_allclose(rad, np.pi) rad = erfa.anpm(3. * np.pi) np.testing.assert_allclose(rad, -np.pi) sign, ihmsf = erfa.d2tf(1, -1.5) assert sign == b'-' assert ihmsf.item() == (36, 0, 0, 0) days = erfa.tf2d('+', 3, 0, 0.0) np.testing.assert_allclose(days, 0.125)
def apio(frame_or_coord): ''' Slightly modified equivalent of ``erfa.apio``, used in conversions AltAz <-> CIRS. Since we use a topocentric CIRS frame, we have dropped the steps needed to calculate diurnal aberration. Parameters ---------- frame_or_coord : ``astropy.coordinates.BaseCoordinateFrame`` or ``astropy.coordinates.SkyCoord`` Frame or coordinate instance in the corresponding frame for which to calculate the calculate the astrom values. For this function, an AltAz frame is expected. ''' # Calculate erfa.apio input parameters. # TIO locator s' sp = erfa.sp00(*get_jd12(frame_or_coord.obstime, 'tt')) # Earth rotation angle. theta = erfa.era00(*get_jd12(frame_or_coord.obstime, 'ut1')) # Longitude and latitude in radians. lon, lat, height = frame_or_coord.location.to_geodetic('WGS84') elong = lon.to_value(u.radian) phi = lat.to_value(u.radian) # Polar motion, rotated onto local meridian xp, yp = get_polar_motion(frame_or_coord.obstime) # we need an empty astrom structure before we fill in the required sections astrom = np.zeros(frame_or_coord.obstime.shape, dtype=erfa.dt_eraASTROM) # Form the rotation matrix, CIRS to apparent [HA,Dec]. r = (rotation_matrix(elong, 'z', unit=u.radian) @ rotation_matrix( -yp, 'x', unit=u.radian) @ rotation_matrix(-xp, 'y', unit=u.radian) @ rotation_matrix(theta + sp, 'z', unit=u.radian)) # Solve for local Earth rotation angle. a = r[..., 0, 0] b = r[..., 0, 1] eral = np.arctan2(b, a) astrom['eral'] = eral # Solve for polar motion [X,Y] with respect to local meridian. c = r[..., 0, 2] astrom['xpl'] = np.arctan2(c, np.sqrt(a * a + b * b)) a = r[..., 1, 2] b = r[..., 2, 2] astrom['ypl'] = -np.arctan2(a, b) # Adjusted longitude. astrom['along'] = erfa.anpm(eral - theta) # Functions of latitude. astrom['sphi'] = np.sin(phi) astrom['cphi'] = np.cos(phi) # Omit two steps that are zero for a geocentric observer: # Observer's geocentric position and velocity (m, m/s, CIRS). # Magnitude of diurnal aberration vector. # Refraction constants. astrom['refa'], astrom['refb'] = erfa.refco( frame_or_coord.pressure.to_value(u.hPa), frame_or_coord.temperature.to_value(u.deg_C), frame_or_coord.relative_humidity.value, frame_or_coord.obswl.to_value(u.micron)) return astrom