def JNowToJ2000(ra, dec, timeJD): """ :param ra: :param dec: :param timeJD: :return: """ if not isinstance(ra, Angle): return Angle(hours=0), Angle(degrees=0) if not isinstance(dec, Angle): return Angle(hours=0), Angle(degrees=0) with _lock: ra = ra.radians dec = dec.radians ra = ERFA.anp(ra + ERFA.eo06a(timeJD.tt, 0.0)) raConv, decConv, _ = ERFA.atic13(ra, dec, timeJD.ut1, 0.0) ra = Angle(radians=raConv, preference='hours') dec = Angle(radians=decConv, preference='degrees') return ra, dec
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 getAlignStarRaDecFromName(self, name): """ getAlignStarRaDecFromName does calculate the star coordinates from give data out of generated star list. calculation routines are from astropy erfa. atco13 does the results based on proper motion, parallax and radial velocity and need J2000 coordinates. because of using the hipparcos catalogue, which is based on J1991, 25 epoch the pre calculation from J1991,25 to J2000 is done already when generating the alignstars file. there is no refraction data taken into account, because we need this only for display purpose and for this, the accuracy is more than sufficient. the return values are in JNow epoch as the mount only handles this epoch ! :param name: name of star :return: values for ra, dec in hours / degrees in JNow epoch ! """ if name not in self.alignStars: return None, None t = self.app.mount.obsSite.ts.now() values = self.alignStars[name] ra, dec, eo = erfa.atci13( values[0], values[1], values[2], values[3], values[4], values[5], t.ut1, 0.0, ) ra = erfa.anp(ra - eo) * 24 / 2 / np.pi dec = dec * 360 / 2 / np.pi return ra, dec
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
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
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
def J2000ToJNow(ra, dec, timeJD): """ :param ra: :param dec: :param timeJD: :return: """ if not isinstance(ra, Angle): return Angle(hours=0), Angle(degrees=0) if not isinstance(dec, Angle): return Angle(hours=0), Angle(degrees=0) with _lock: ra = ra.radians dec = dec.radians raConv, decConv, eo = ERFA.atci13(ra, dec, 0, 0, 0, 0, timeJD.ut1, 0) raConv = ERFA.anp(raConv - eo) ra = Angle(radians=raConv, preference='hours') dec = Angle(radians=decConv, preference='degrees') return ra, dec
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