Beispiel #1
0
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)
Beispiel #2
0
def aticq(ri, di, astrom):
    """
    A slightly modified version of the ERFA function ``eraAticq``.

    ``eraAticq`` performs the transformations between two coordinate systems,
    with the details of the transformation being encoded into the ``astrom`` array.

    The companion function ``eraAtciqz`` is meant to be its inverse. However, this
    is not true for directions close to the Solar centre, since the light deflection
    calculations are numerically unstable and therefore not reversible.

    This version sidesteps that problem by artificially reducing the light deflection
    for directions which are within 90 arcseconds of the Sun's position. This is the
    same approach used by the ERFA functions above, except that they use a threshold of
    9 arcseconds.

    Parameters
    ----------
    ri : float or `~numpy.ndarray`
        right ascension, radians
    di : float or `~numpy.ndarray`
        declination, radians
    astrom : eraASTROM array
        ERFA astrometry context, as produced by, e.g. ``eraApci13`` or ``eraApcs13``

    Returns
    --------
    rc : float or `~numpy.ndarray`
    dc : float or `~numpy.ndarray`
    """
    # RA, Dec to cartesian unit vectors
    pos = erfa.s2c(ri, di)

    # Bias-precession-nutation, giving GCRS proper direction.
    ppr = erfa.trxp(astrom['bpn'], pos)

    # Aberration, giving GCRS natural direction
    d = np.zeros_like(ppr)
    for j in range(2):
        before = norm(ppr - d)
        after = erfa.ab(before, astrom['v'], astrom['em'], astrom['bm1'])
        d = after - before
    pnat = norm(ppr - d)

    # Light deflection by the Sun, giving BCRS coordinate direction
    d = np.zeros_like(pnat)
    for j in range(5):
        before = norm(pnat - d)
        after = erfa.ld(1.0, before, before, astrom['eh'], astrom['em'], 5e-8)
        d = after - before
    pco = norm(pnat - d)

    # ICRS astrometric RA, Dec
    rc, dc = erfa.c2s(pco)
    return erfa.anp(rc), dc
Beispiel #3
0
 def sun(self):
     '''RA and DEC of the Sun'''
     x, y, z = self.eph[0][0], self.eph[0][1], self.eph[0][2]
     self.distances_from_earth.update(
         {'Sun':math.sqrt(x*x + y*y +z*z)}
         )
     a, d = erfa.c2s((-x, -y, -z))
     a = erfa.anp(a)
     self.RA_DEC.update(
         {'Sun':(a, d)}
         )
Beispiel #4
0
 def planets(self):
     '''RA and DEC of major planets and EMB'''
     for i in range(8):
         x = self.p94[i][0][0] - self.eph[0][0]
         y = self.p94[i][0][1] - self.eph[0][1]
         z = self.p94[i][0][2] - self.eph[0][2]
         self.distances_from_earth.update(
             {Planet(i+1).name:math.sqrt(x*x + y*y +z*z)}
             )
         a, d = erfa.c2s((x,y,z))
         a = erfa.anp(a)
         self.RA_DEC.update(
             {Planet(i+1).name:(a, d)}
             )
Beispiel #5
0
def atciqz(rc, dc, astrom):
    """
    A slightly modified version of the ERFA function ``eraAtciqz``.

    ``eraAtciqz`` performs the transformations between two coordinate systems,
    with the details of the transformation being encoded into the ``astrom`` array.

    The companion function ``eraAticq`` is meant to be its inverse. However, this
    is not true for directions close to the Solar centre, since the light deflection
    calculations are numerically unstable and therefore not reversible.

    This version sidesteps that problem by artificially reducing the light deflection
    for directions which are within 90 arcseconds of the Sun's position. This is the
    same approach used by the ERFA functions above, except that they use a threshold of
    9 arcseconds.

    Parameters
    ----------
    rc : float or `~numpy.ndarray`
        right ascension, radians
    dc : float or `~numpy.ndarray`
        declination, radians
    astrom : eraASTROM array
        ERFA astrometry context, as produced by, e.g. ``eraApci13`` or ``eraApcs13``

    Returns
    --------
    ri : float or `~numpy.ndarray`
    di : float or `~numpy.ndarray`
    """
    # BCRS coordinate direction (unit vector).
    pco = erfa.s2c(rc, dc)

    # Light deflection by the Sun, giving BCRS natural direction.
    pnat = erfa.ld(1.0, pco, pco, astrom['eh'], astrom['em'], 5e-8)

    # Aberration, giving GCRS proper direction.
    ppr = erfa.ab(pnat, astrom['v'], astrom['em'], astrom['bm1'])

    # Bias-precession-nutation, giving CIRS proper direction.
    # Has no effect if matrix is identity matrix, in which case gives GCRS ppr.
    pi = erfa.rxp(astrom['bpn'], ppr)

    # CIRS (GCRS) RA, Dec
    ri, di = erfa.c2s(pi)
    return erfa.anp(ri), di
Beispiel #6
0
# Mean obliquity
EPSA = erfa.obl80(DJMJD0, TT)

# Build the rotation matrix
RN = erfa.numat(EPSA, DPSI, DEPS)

# Combine the matrices: PN = N x P
RNPB = erfa.rxr(RN, RP)
print("NPB matrix, equinox based:")
pprint(RNPB)

# Equation of the equinoxes, including nutation correction
EE = erfa.eqeq94(DJMJD0, TT) + DDP80 * math.cos(EPSA)

# Greenwich apparent sidereal time (IAU 1982/1994).
GST = erfa.anp(erfa.gmst82(DJMJD0 + DATE, TUT) + EE)
print("GST = %.17f radians" % GST)
print("    = %.17f degrees" % math.degrees(GST))
print("    = %s%dd%dm%d.%ds" % erfa.a2af(6, GST))
print("    = %s%dh%dm%d.%ds" % erfa.a2tf(6, GST))

# Form celestial-terrestrial matrix (no polar motion yet).
##RC2TI = erfa.cr(RNPB)
##RC2TI = erfa.rz(GST, RC2TI)
RC2TI = erfa.rz(GST, RNPB)
print("celestial to terrestrial matrix (no polar motion)")
pprint(RC2TI)

# Polar motion matrix (TIRS->ITRS, IERS 1996).
RPOM = erfa.ir()
RPOM = erfa.rx(-YP, RPOM)
Beispiel #7
0
def atciqz(srepr, astrom):
    """
    A slightly modified version of the ERFA function ``eraAtciqz``.

    ``eraAtciqz`` performs the transformations between two coordinate systems,
    with the details of the transformation being encoded into the ``astrom`` array.

    There are two issues with the version of atciqz in ERFA. Both are associated
    with the handling of light deflection.

    The companion function ``eraAticq`` is meant to be its inverse. However, this
    is not true for directions close to the Solar centre, since the light deflection
    calculations are numerically unstable and therefore not reversible.

    This version sidesteps that problem by artificially reducing the light deflection
    for directions which are within 90 arcseconds of the Sun's position. This is the
    same approach used by the ERFA functions above, except that they use a threshold of
    9 arcseconds.

    In addition, ERFA's atciqz assumes a distant source, so there is no difference between
    the object-Sun vector and the observer-Sun vector. This can lead to errors of up to a
    few arcseconds in the worst case (e.g a Venus transit).

    Parameters
    ----------
    srepr : `~astropy.coordinates.SphericalRepresentation`
        Astrometric ICRS position of object from observer
    astrom : eraASTROM array
        ERFA astrometry context, as produced by, e.g. ``eraApci13`` or ``eraApcs13``

    Returns
    --------
    ri : float or `~numpy.ndarray`
        Right Ascension in radians
    di : float or `~numpy.ndarray`
        Declination in radians
    """
    # ignore parallax effects if no distance, or far away
    srepr_distance = srepr.distance
    ignore_distance = srepr_distance.unit == u.one

    # BCRS coordinate direction (unit vector).
    pco = erfa.s2c(srepr.lon.radian, srepr.lat.radian)

    # Find BCRS direction of Sun to object
    if ignore_distance:
        # No distance to object, assume a long way away
        q = pco
    else:
        # Find BCRS direction of Sun to object.
        # astrom['eh'] and astrom['em'] contain Sun to observer unit vector,
        # and distance, respectively.
        eh = astrom['em'][..., np.newaxis] * astrom['eh']
        # unit vector from Sun to object
        q = eh + srepr_distance[..., np.newaxis].to_value(u.au) * pco
        sundist, q = erfa.pn(q)
        sundist = sundist[..., np.newaxis]
        # calculation above is extremely unstable very close to the sun
        # in these situations, default back to ldsun-style behaviour,
        # since this is reversible and drops to zero within stellar limb
        q = np.where(sundist > 1.0e-10, q, pco)

    # Light deflection by the Sun, giving BCRS natural direction.
    pnat = erfa.ld(1.0, pco, q, astrom['eh'], astrom['em'], 1e-6)

    # Aberration, giving GCRS proper direction.
    ppr = erfa.ab(pnat, astrom['v'], astrom['em'], astrom['bm1'])

    # Bias-precession-nutation, giving CIRS proper direction.
    # Has no effect if matrix is identity matrix, in which case gives GCRS ppr.
    pi = erfa.rxp(astrom['bpn'], ppr)

    # CIRS (GCRS) RA, Dec
    ri, di = erfa.c2s(pi)
    return erfa.anp(ri), di
Beispiel #8
0
ri, di, eo = erfa.atci13(rc, dc, pr, pd, px, rv, tt1, tt2)
# print('ri, di', ri, di)
#
reprd("catalog -> CIRS:", ri, di)

# CIRS to ICRS (astrometric).
rca, dca, eo = erfa.atic13(ri, di, tt1, tt2)
#
reprd("CIRS -> astrometric:", rca, dca)

# ICRS (astrometric) to CIRS (geocentric observer).
ri, di, eo = erfa.atci13(rca, dca, np.array([0.0]), np.array([0.0]), np.array([0.0]), np.array([0.0]), tt1, tt2)
reprd("astrometric -> CIRS:", ri, di)

# Apparent place.
ra = erfa.anp(ri - eo)
da = di
reprd("geocentric apparent:", ra, da)

# CIRS to topocentric.
aot, zot, hot, dot, rot = erfa.atio13(
    ri, di, utc1, utc2, dut1, elong, phi, hm, xp, yp, np.array([0.0]), np.array([0.0]), np.array([0.0]), np.array([0.0])
)
reprd("CIRS -> topocentric:", rot, dot)

# CIRS to topocentric.
aob, zob, hob, dob, rob = erfa.atio13(ri, di, utc1, utc2, dut1, elong, phi, hm, xp, yp, phpa, tc, rh, wl)
reprd("CIRS -> observed:", rob, dob)

# ICRS to observed.
aob, zob, hob, dob, rob, eo = erfa.atco13(
Beispiel #9
0
# Mean obliquity
EPSA = erfa.obl80(DJMJD0, TT)

# Build the rotation matrix
RN = erfa.numat(EPSA, DPSI, DEPS)

# Combine the matrices: PN = N x P
RNPB = erfa.rxr(RN, RP)
print("NPB matrix, equinox based:")
pprint(RNPB)

# Equation of the equinoxes, including nutation correction
EE = erfa.eqeq94(DJMJD0, TT) + DDP80 * math.cos(EPSA)

# Greenwich apparent sidereal time (IAU 1982/1994).
GST = erfa.anp(erfa.gmst82(DJMJD0+DATE, TUT) + EE)
print("GST = %.17f radians"%GST)
print("    = %.17f degrees"%math.degrees(GST))
print("    = %s%dd%dm%d.%ds"%erfa.a2af(6, GST))
print("    = %s%dh%dm%d.%ds"%erfa.a2tf(6, GST))

# Form celestial-terrestrial matrix (no polar motion yet).
##RC2TI = erfa.cr(RNPB)
##RC2TI = erfa.rz(GST, RC2TI)
RC2TI = erfa.rz(GST, RNPB)
print("celestial to terrestrial matrix (no polar motion)")
pprint(RC2TI)

# Polar motion matrix (TIRS->ITRS, IERS 1996).
RPOM = erfa.ir()
RPOM = erfa.rx(-YP, RPOM)
Beispiel #10
0
ri, di, eo = erfa.atci13(rc, dc, pr, pd, px, rv, tt1, tt2)
#print('ri, di', ri, di)
#
reprd("catalog -> CIRS:", ri, di)

# CIRS to ICRS (astrometric).
rca, dca, eo = erfa.atic13(ri, di, tt1, tt2)
#
reprd("CIRS -> astrometric:", rca, dca)

#ICRS (astrometric) to CIRS (geocentric observer).
ri, di, eo = erfa.atci13(rca, dca, 0.0, 0.0, 0.0, 0.0, tt1, tt2)
reprd("astrometric -> CIRS:", ri, di)

# Apparent place.
ra = erfa.anp(ri - eo)
da = di
reprd("geocentric apparent:", ra, da)

# CIRS to topocentric.
aot, zot, hot, dot, rot = erfa.atio13(ri, di, utc1, utc2, dut1, elong, phi, hm,
                                      xp, yp, 0.0, 0.0, 0.0, 0.0)
reprd("CIRS -> topocentric:", rot, dot)

# CIRS to topocentric.
aob, zob, hob, dob, rob = erfa.atio13(ri, di, utc1, utc2, dut1, elong, phi, hm,
                                      xp, yp, phpa, tc, rh, wl)
reprd("CIRS -> observed:", rob, dob)

# ICRS to observed.
aob, zob, hob, dob, rob, eo = erfa.atco13(rc, dc, pr, pd, px, rv, utc1, utc2,