Exemplo n.º 1
0
 def testR2D(self):
    """tpm.r2d() => convert radians into degrees."""
    import math
    self.assertAlmostEqual(tpm.r2d(math.pi), 180.0)
    self.assertAlmostEqual(tpm.r2d(4*math.pi), 720.0)
    self.assertAlmostEqual(tpm.r2d(-4*math.pi), -720.0)
    self.assertAlmostEqual(tpm.r2d(-2.5*math.pi), -450.0)
Exemplo n.º 2
0
 def testR2D(self):
     """tpm.r2d() => convert radians into degrees."""
     import math
     self.assertAlmostEqual(tpm.r2d(math.pi), 180.0)
     self.assertAlmostEqual(tpm.r2d(4 * math.pi), 720.0)
     self.assertAlmostEqual(tpm.r2d(-4 * math.pi), -720.0)
     self.assertAlmostEqual(tpm.r2d(-2.5 * math.pi), -450.0)
Exemplo n.º 3
0
 def testazel2hadec(self):
     """tpm.azel2hadec => (AZ,EL) to (HA,DEC)"""
     v6 = tpm.V6S(r=1e9)
     for i,j,k,l in zip(self.az,self.el,self.ha_c,self.dec_c):
         v6.alpha = tpm.d2r(i)
         v6.delta = tpm.d2r(j)
         v61 = tpm.azel2hadec(v6.s2c(), tpm.d2r(self.lat))
         v6 = v61.c2s()
         self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.alpha)), k, 8)
         self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.delta)), l, 8)
Exemplo n.º 4
0
 def testazel2hadec(self):
     """tpm.azel2hadec => (AZ,EL) to (HA,DEC)"""
     v6 = tpm.V6S(r=1e9)
     for i, j, k, l in zip(self.az, self.el, self.ha_c, self.dec_c):
         v6.alpha = tpm.d2r(i)
         v6.delta = tpm.d2r(j)
         v61 = tpm.azel2hadec(v6.s2c(), tpm.d2r(self.lat))
         v6 = v61.c2s()
         self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.alpha)), k, 8)
         self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.delta)), l, 8)
Exemplo n.º 5
0
 def testHadec2azel(self):
     """tpm.hadec2azel => (HA,DEC) to (AZ,EL)"""
     v6 = tpm.V6S(r=1e9)
     for i, j, k, l in zip(self.az, self.el, self.ha_c, self.dec_c):
         j = tpm.r2d(tpm.r2r(tpm.d2r(j)))
         v6.alpha = tpm.d2r(k)
         v6.delta = tpm.d2r(l)
         v61 = tpm.hadec2azel(v6.s2c(), tpm.d2r(self.lat))
         v6 = v61.c2s()
         self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.alpha)), i, 8)
         self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.delta)), j, 8)
Exemplo n.º 6
0
 def testHadec2azel(self):
     """tpm.hadec2azel => (HA,DEC) to (AZ,EL)"""
     v6 = tpm.V6S(r=1e9)
     for i,j,k,l in zip(self.az,self.el,self.ha_c,self.dec_c):
         j = tpm.r2d(tpm.r2r(tpm.d2r(j)))
         v6.alpha = tpm.d2r(k)
         v6.delta = tpm.d2r(l)
         v61 = tpm.hadec2azel(v6.s2c(), tpm.d2r(self.lat))
         v6 = v61.c2s()
         self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.alpha)),
                                i, 8)
         self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.delta)), j, 8)
Exemplo n.º 7
0
    def testToObsAzElDateJ2000ep2000(self):
        """P and V: J2000 (~ICRS) 1991.25 => ObsAzEl Date J2000 ep J2000."""
        # Set s2=TPM_S13 and ep2=J2000 in
        # c_tests/test_conversion_with_pm.c.
        ra = []
        dec = []
        pmra = []
        pmdec = []
        px = []
        f = open(hip_data, "r")
        for i in f:
            x = [float(j) for j in i.split()]
            ra.append(tpm.d2r(x[0]))
            dec.append(tpm.d2r(x[1]))
            # Milli-arcsec/year to arcsec/century.
            pmra.append( ((x[2]/1000.0) / math.cos(tpm.d2r(x[1]))) * 100.0 )
            pmdec.append( (x[3]/1000.0) * 100.0)
            px.append(x[4])
        f.close()
        
        s1 = tpm.TPM_S06
        ep = tpm.y2j(1991.25)
        eq = tpm.J2000
        s2 = tpm.TPM_S13
        ep2 = tpm.J2000

        f = open(os.path.join(c_tests_dir,
                              "hipicrsep1991_ObsAzElDateJ2000ep2000.txt"),
                 "r")

        pvec = tpm.PVEC()
        tstate = get_tstate()
        
        for i in xrange(len(ra)):
            v6 = tpm.cat2v6(ra[i], dec[i], pmra[i], pmdec[i], px[i], 0.0,
                            tpm.CJ)
            pvec[s1] = v6
            tpm.tpm(pvec, s1, s2, ep, eq, tstate)
            v6 = pvec[s2]
            tpm.proper_motion(v6, ep2, ep)
            d = tpm.v62cat(v6, tpm.CJ)
            x = [float(j) for j in f.readline().strip().split()]
            self.assertAlmostEqual(tpm.r2d(tpm.r2r(d['alpha'])), x[0], 8)
            self.assertAlmostEqual(tpm.r2d(d['delta']), x[1], 8)
            self.assertAlmostEqual(d['pma'], x[2], 4)
            self.assertAlmostEqual(d['pmd'], x[3], 4)            
            self.assertAlmostEqual(d['px'], x[4], 8)
            self.assertAlmostEqual(d['rv'], x[5], 2)
            
        f.close()
Exemplo n.º 8
0
    def testConvertv6(self):
        """ConvertV6: J2000 (~ICRS) 1991.25 => FK4 B1950 ep 1950.0."""
        # Set s2=TPM_S05 and ep2=B1950 in
        # c_tests/test_conversion_with_pm.c.
        ra = []
        dec = []
        pmra = []
        pmdec = []
        px = []
        f = open(hip_data_icrs, "r")
        for i in f:
            x = [float(j) for j in i.split()]
            ra.append(tpm.d2r(x[0]))
            dec.append(tpm.d2r(x[1]))
            # Milli-arcsec/year to arcsec/century.
            pmra.append(((x[2] / 1000.0) / math.cos(tpm.d2r(x[1]))) * 100.0)
            pmdec.append((x[3] / 1000.0) * 100.0)
            px.append(x[4])
        f.close()

        s1 = tpm.TPM_S06
        ep = tpm.y2j(1991.25)
        eq = tpm.J2000
        s2 = tpm.TPM_S05
        ep2 = tpm.B1950

        f = open(os.path.join(c_tests_dir, "hipicrsep1991_fk4B1950ep1950.txt"),
                 "r")

        v6_l = []
        for i in range(len(ra)):
            v6 = tpm.cat2v6(ra[i], dec[i], pmra[i], pmdec[i], px[i], 0.0,
                            tpm.CJ)
            v6_l.append(v6)

        v6_out = convert.convertv6(v6_l, epoch=ep, equinox=eq, s1=s1, s2=s2)

        for v in v6_out:
            tpm.proper_motion(v, ep2, ep)
            d = tpm.v62cat(v, tpm.CJ)
            x = [float(j) for j in f.readline().strip().split()]
            self.assertAlmostEqual(tpm.r2d(tpm.r2r(d['alpha'])), x[0], 8)
            self.assertAlmostEqual(tpm.r2d(d['delta']), x[1], 8)
            self.assertAlmostEqual(d['pma'], x[2], 4)
            self.assertAlmostEqual(d['pmd'], x[3], 4)
            self.assertAlmostEqual(d['px'], x[4], 8)
            self.assertAlmostEqual(d['rv'], x[5], 2)

        f.close()
Exemplo n.º 9
0
    def testConvertv6(self):
        """ConvertV6: J2000 (~ICRS) 1991.25 => FK4 B1950 ep 1950.0."""
        # Set s2=TPM_S05 and ep2=B1950 in
        # c_tests/test_conversion_with_pm.c.
        ra = []
        dec = []
        pmra = []
        pmdec = []
        px = []
        f = open(hip_data_icrs, "r")
        for i in f:
            x = [float(j) for j in i.split()]
            ra.append(tpm.d2r(x[0]))
            dec.append(tpm.d2r(x[1]))
            # Milli-arcsec/year to arcsec/century.
            pmra.append(((x[2] / 1000.0) / math.cos(tpm.d2r(x[1]))) * 100.0)
            pmdec.append((x[3] / 1000.0) * 100.0)
            px.append(x[4])
        f.close()

        s1 = tpm.TPM_S06
        ep = tpm.y2j(1991.25)
        eq = tpm.J2000
        s2 = tpm.TPM_S05
        ep2 = tpm.B1950

        f = open(os.path.join(c_tests_dir, "hipicrsep1991_fk4B1950ep1950.txt"), "r")

        v6_l = []
        for i in range(len(ra)):
            v6 = tpm.cat2v6(ra[i], dec[i], pmra[i], pmdec[i], px[i], 0.0, tpm.CJ)
            v6_l.append(v6)

        v6_out = convert.convertv6(v6_l, epoch=ep, equinox=eq, s1=s1, s2=s2)

        for v in v6_out:
            tpm.proper_motion(v, ep2, ep)
            d = tpm.v62cat(v, tpm.CJ)
            x = [float(j) for j in f.readline().strip().split()]
            self.assertAlmostEqual(tpm.r2d(tpm.r2r(d["alpha"])), x[0], 8)
            self.assertAlmostEqual(tpm.r2d(d["delta"]), x[1], 8)
            self.assertAlmostEqual(d["pma"], x[2], 4)
            self.assertAlmostEqual(d["pmd"], x[3], 4)
            self.assertAlmostEqual(d["px"], x[4], 8)
            self.assertAlmostEqual(d["rv"], x[5], 2)

        f.close()
Exemplo n.º 10
0
 def testEllab(self):
     """tpm.ellab => apply elliptic aberration."""
     # pytpm/tests/c_tests/ellab_test.c
     v6 = tpm.V6S(r=1e9, alpha=tpm.h2r(20), delta=tpm.d2r(40.0))
     v6 = v6.s2c()
     v6 = tpm.ellab(tpm.J2000, v6, -1)
     v6 = v6.c2s()
     self.assertAlmostEqual(v6.r, 1e9, 5)
     self.assertAlmostEqual(tpm.r2h(tpm.r2r(v6.alpha)), 20.000007838, 8)
     self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.delta)), 39.999987574, 8)
Exemplo n.º 11
0
 def testEllab(self):
     """tpm.ellab => apply elliptic aberration."""
     # pytpm/tests/c_tests/ellab_test.c
     v6 = tpm.V6S(r=1e9, alpha=tpm.h2r(20), delta=tpm.d2r(40.0))
     v6 = v6.s2c()
     v6 = tpm.ellab(tpm.J2000, v6, -1)
     v6 = v6.c2s()
     self.assertAlmostEqual(v6.r, 1e9,5)
     self.assertAlmostEqual(tpm.r2h(tpm.r2r(v6.alpha)), 20.000007838,8)
     self.assertAlmostEqual(tpm.r2d(tpm.r2r(v6.delta)), 39.999987574,8)
Exemplo n.º 12
0
dec = np.degrees(cat20['delta'])

# Difference in HA and Dec, using TPM and SLALIB.
ha_diff = np.abs(ha[indx] - ha_sla[indx]) * 3600.0
dec_diff = np.abs(dec[indx] - dec_sla[indx]) * 3600.0

# Find RA = LAST - HA.
tstate = tpm.TSTATE()
tpm.tpm_data(tstate, tpm.TPM_INIT)
tstate.utc = utc
tstate.delta_ut = tpm.delta_UT(utc)
tstate.delta_at = tpm.delta_AT(utc)
tstate.lon = tpm.d2r(-111.598333)
tstate.lat = tpm.d2r(31.956389)
tpm.tpm_data(tstate, tpm.TPM_ALL)
last = tpm.r2d(tstate.last)
ra = last - ha
# Have to normalize to 0 - 360.0.
ra = np.array([i if i > 0 else i + 360.0 for i in ra])
ra_diff = np.abs(ra[indx] - ra_sla[indx]) * 3600.0

print("Comparison with SLALIB aop using HIPPARCOS data.")
fs = "{0} {1}\n" + \
    "Min:  {2:.4f} Max: {3:.4f} \nMean: {4:.4f} Std: {5:.4f}\n"
x = stats.describe(az_diff)
print(fs.format("az_diff", "arcsec", x[1][0], x[1][1], x[2], x[3]**0.5))
x = stats.describe(zd_diff)
print(fs.format("zd_diff", "arcsec", x[1][0], x[1][1], x[2], x[3]**0.5))
x = stats.describe(ha_diff)
print(fs.format("ha_diff", "arcsec", x[1][0], x[1][1], x[2], x[3]**0.5))
x = stats.describe(dec_diff)
Exemplo n.º 13
0
dec = np.degrees(cat20['delta'])

# Difference in HA and Dec, using TPM and SLALIB.
ha_diff = np.abs(ha[indx] - ha_sla[indx]) * 3600.0
dec_diff = np.abs(dec[indx] - dec_sla[indx]) * 3600.0

# Find RA = LAST - HA.
tstate = tpm.TSTATE()
tpm.tpm_data(tstate, tpm.TPM_INIT)
tstate.utc = utc
tstate.delta_ut = tpm.delta_UT(utc)
tstate.delta_at = tpm.delta_AT(utc)
tstate.lon = tpm.d2r(-111.598333)
tstate.lat = tpm.d2r(31.956389)
tpm.tpm_data(tstate, tpm.TPM_ALL)
last = tpm.r2d(tstate.last)
ra = last - ha
# Have to normalize to 0 - 360.0.
ra = np.array([i if i > 0 else i + 360.0 for i in ra])
ra_diff = np.abs(ra[indx] - ra_sla[indx]) * 3600.0

print("Comparison with SLALIB aop using HIPPARCOS data.")
fs = "{0} {1}\n" + \
    "Min:  {2:.4f} Max: {3:.4f} \nMean: {4:.4f} Std: {5:.4f}\n"
x = stats.describe(az_diff)
print(fs.format("az_diff", "arcsec", x[1][0], x[1][1], x[2], x[3] ** 0.5))
x = stats.describe(zd_diff)
print(fs.format("zd_diff", "arcsec", x[1][0], x[1][1], x[2], x[3] ** 0.5))
x = stats.describe(ha_diff)
print(fs.format("ha_diff", "arcsec", x[1][0], x[1][1], x[2], x[3] ** 0.5))
x = stats.describe(dec_diff)
Exemplo n.º 14
0
    def test_slalib_hip_fk52obs(self):
        """convert(x, s1=6, s2=19) (+ s2=20) + PM => SLALIB sla_aop HIP."""
        tab = get_sla("slalib_hip_aop.txt")
        az_sla = []
        zd_sla = []
        ha_sla = []
        dec_sla = []
        ra_sla = []
        for i in tab:
            # Convert longitude values to 0 - 360
            az_sla.append(i[0] if i[0] >= 0 else i[0] + 360.0)
            zd_sla.append(i[1])
            ha_sla.append(i[2] if i[2] >= 0 else i[2] + 360.0)
            dec_sla.append(i[3])
            ra_sla.append(i[4] if i[4] >= 0 else i[4] + 360.0)

        v6l = []
        for r, d, pa, pd, px in zip(self.hip_tab['raj2'],
                                    self.hip_tab['decj2'], self.hip_tab['pma'],
                                    self.hip_tab['pmd'], self.hip_tab['px']):
            r = tpm.d2r(r)
            d = tpm.d2r(d)
            # Milli-arcsec / Jul. yr to arcsec per Jul. century.
            pma = pa / math.cos(d) / 1000.0 * 100.0
            pmd = pd / 1000.0 * 100.0
            px /= 1000.0  # mili-arcsec to arc-sec.
            v6 = tpm.cat2v6(r, d, pma, pmd, px, 0.0, tpm.CJ)
            v6l.append(v6)

        utc = tpm.gcal2j(2010, 1, 1) - 0.5  # midnight
        tt = tpm.utc2tdb(utc)

        # Convert to Az-EL.
        v6o = convert.proper_motion(v6l, tt, tpm.J2000)
        v6o = convert.convertv6(v6o, s1=6, s2=19, utc=utc)

        cat = (tpm.v62cat(v, tpm.CJ) for v in v6o)

        az = []
        zd = []
        for i in cat:
            az.append(tpm.r2d(i['alpha']))
            zd.append(90.0 - tpm.r2d(i['delta']))

        # Convert Az-El to HA-Dec.
        v6o = convert.convertv6(v6o, s1=19, s2=20, utc=utc)

        cat = (tpm.v62cat(v, tpm.CJ) for v in v6o)

        # Find LAST.
        tstate = tpm.TSTATE()
        tpm.tpm_data(tstate, tpm.TPM_INIT)
        tstate.utc = utc
        tstate.delta_ut = tpm.delta_UT(utc)
        tstate.delta_at = tpm.delta_AT(utc)
        tstate.lon = tpm.d2r(-111.598333)
        tstate.lat = tpm.d2r(31.956389)
        tpm.tpm_data(tstate, tpm.TPM_ALL)
        last = tpm.r2d(tstate.last)

        ha = []
        dec = []
        ra = []
        for i in cat:
            ha.append(tpm.r2d(i['alpha']))
            dec.append(tpm.r2d(i['delta']))
            # RA = LAST - HA and convert to 0 - 360.
            x = last - tpm.r2d(i['alpha'])
            ra.append(x if x >= 0 else x + 360.0)

        for i in range(len(az)):
            # Test only the coordinates with ZD < 75.0.
            if zd[i] < 75.0:
                self.assertTrue(abs(az[i] - az_sla[i]) * 3600.0 <= 0.25)
                self.assertTrue(abs(zd[i] - zd_sla[i]) * 3600.0 <= 0.04)
                self.assertTrue(abs(ha[i] - ha_sla[i]) * 3600.0 <= 0.28)
                self.assertTrue(abs(dec[i] - dec_sla[i]) * 3600.0 <= 0.04)
                self.assertTrue(abs(ra[i] - ra_sla[i]) * 3600.0 <= 0.33)
Exemplo n.º 15
0
    tstate.utc = tpm.J2000
    tstate.lon = tpm.d2r(-111.598333)
    tstate.lat = tpm.d2r(31.956389)
    tstate.alt = 2093.093
    tstate.delta_ut = tpm.delta_UT(tstate.utc)
    tpm.tpm_data(tstate, tpm.TPM_ALL)

    v6 = tpm.V6S()
    v6.r = 1e9
    v6.alpha = ra
    v6.delta = de
    

    pvec[s1] = v6.s2c()
    s2 = i
    tpm.tpm(pvec, s1, s2, ep, eq, tstate)
    v6 = pvec[s2].c2s()

    ra1 = v6.alpha
    de1 = v6.delta
    ra1_d = tpm.r2d(ra1)
    if ra1_d < 0.0 : ra1_d += 360.0
    de1_d = tpm.r2d(de1)
    if de1_d < 0.0 : de1_d += 360.0

    s = "{0:02d}-{1:02d} {2:<17s} {3:s} {4:s} {5:8.4f} {6:8.4f}"
    print s.format(s1, s2, tpm.tpm_state(s2),
                   tpm.fmt_alpha(ra1), tpm.fmt_delta(de1), ra1_d,
                   de1_d)
    
Exemplo n.º 16
0
    def test_slalib_hip_fk52obs(self):
        """convert(x, s1=6, s2=19) (+ s2=20) + PM => SLALIB sla_aop HIP."""
        tab = get_sla("slalib_hip_aop.txt")
        az_sla = []
        zd_sla = []
        ha_sla = []
        dec_sla = []
        ra_sla = []
        for i in tab:
            # Convert longitude values to 0 - 360
            az_sla.append(i[0] if i[0] >= 0 else i[0] + 360.0)
            zd_sla.append(i[1])
            ha_sla.append(i[2] if i[2] >= 0 else i[2] + 360.0)
            dec_sla.append(i[3])
            ra_sla.append(i[4] if i[4] >= 0 else i[4] + 360.0)

        v6l = []
        for r, d, pa, pd, px in zip(self.hip_tab['raj2'],
                                    self.hip_tab['decj2'],
                                    self.hip_tab['pma'],
                                    self.hip_tab['pmd'],
                                    self.hip_tab['px']):
            r = tpm.d2r(r)
            d = tpm.d2r(d)
            # Milli-arcsec / Jul. yr to arcsec per Jul. century.
            pma = pa / math.cos(d) / 1000.0 * 100.0
            pmd = pd / 1000.0 * 100.0
            px /= 1000.0  # mili-arcsec to arc-sec.
            v6 = tpm.cat2v6(r, d, pma, pmd, px, 0.0, tpm.CJ)
            v6l.append(v6)

        utc = tpm.gcal2j(2010, 1, 1) - 0.5  # midnight
        tt = tpm.utc2tdb(utc)

        # Convert to Az-EL.
        v6o = convert.proper_motion(v6l, tt, tpm.J2000)
        v6o = convert.convertv6(v6o, s1=6, s2=19, utc=utc)

        cat = (tpm.v62cat(v, tpm.CJ) for v in v6o)

        az = []
        zd = []
        for i in cat:
            az.append(tpm.r2d(i['alpha']))
            zd.append(90.0 - tpm.r2d(i['delta']))

        # Convert Az-El to HA-Dec.
        v6o = convert.convertv6(v6o, s1=19, s2=20, utc=utc)

        cat = (tpm.v62cat(v, tpm.CJ) for v in v6o)

        # Find LAST.
        tstate = tpm.TSTATE()
        tpm.tpm_data(tstate, tpm.TPM_INIT)
        tstate.utc = utc
        tstate.delta_ut = tpm.delta_UT(utc)
        tstate.delta_at = tpm.delta_AT(utc)
        tstate.lon = tpm.d2r(-111.598333)
        tstate.lat = tpm.d2r(31.956389)
        tpm.tpm_data(tstate, tpm.TPM_ALL)
        last = tpm.r2d(tstate.last)

        ha = []
        dec = []
        ra = []
        for i in cat:
            ha.append(tpm.r2d(i['alpha']))
            dec.append(tpm.r2d(i['delta']))
            # RA = LAST - HA and convert to 0 - 360.
            x = last - tpm.r2d(i['alpha'])
            ra.append(x if x >= 0  else x + 360.0)

        for i in range(len(az)):
            # Test only the coordinates with ZD < 75.0.
            if zd[i] < 75.0:
                self.assertTrue(abs(az[i] - az_sla[i]) * 3600.0 <= 0.25)
                self.assertTrue(abs(zd[i] - zd_sla[i]) * 3600.0 <= 0.04)
                self.assertTrue(abs(ha[i] - ha_sla[i]) * 3600.0 <= 0.28)
                self.assertTrue(abs(dec[i] - dec_sla[i]) * 3600.0 <= 0.04)
                self.assertTrue(abs(ra[i] - ra_sla[i]) * 3600.0 <= 0.33)