def testSubtraction(self): """DMS.__sub__ => DMS - DMS.""" dms1 = tpm.DMS() dms2 = tpm.DMS() dms1.dd = 1.1 dms1.mm = 1.2 dms1.ss = 1.3 dms2.dd = 2.4 dms2.mm = 2.5 dms2.ss = 2.6 dms = dms1 - dms2 self.assertAlmostEqual(dms.dd, dms1.dd - dms2.dd) self.assertAlmostEqual(dms.mm, dms1.mm - dms2.mm) self.assertAlmostEqual(dms.ss, dms1.ss - dms2.ss)
def testAddition(self): """DMS.__add__ => DMS + DMS.""" dms1 = tpm.DMS() dms2 = tpm.DMS() dms1.dd = 1.1 dms1.mm = 1.2 dms1.ss = 1.3 dms2.dd = 2.4 dms2.mm = 2.5 dms2.ss = 2.6 dms = dms1 + dms2 self.assertAlmostEqual(dms.dd, dms1.dd + dms2.dd) self.assertAlmostEqual(dms.mm, dms1.mm + dms2.mm) self.assertAlmostEqual(dms.ss, dms1.ss + dms2.ss)
def testpm(self): """Proper motion => apply PM to position.""" import math ra = tpm.d2r(269.45402305) de = tpm.d2r(4.66828815) px = 549.01 / 1000.0 # To Arc seconds rv = 0.0 # pmra * cos(de) into pmra pmra = (-797.84 / 1000.0 ) / math.cos(de) pmra *= 100.0 # To Arcseconds per century. pmde = (10326.93 / 1000.0) pmde *= 100.0 # To Arcseconds per century. C = tpm.CJ v6 = tpm.cat2v6(ra, de, pmra, pmde, px, rv, C) v6 = tpm.proper_motion(v6, tpm.J2000, tpm.jyear2jd(1991.25)) v6 = v6.c2s() hms = tpm.HMS(r=v6.alpha) dms = tpm.DMS(r=v6.delta) hms.normalize() dms.normalize() self.assertAlmostEqual(hms.hh, -7.0) self.assertAlmostEqual(hms.mm, 57.0) self.assertAlmostEqual(hms.ss, 48.4986, 3) self.assertAlmostEqual(dms.dd, 4.0) self.assertAlmostEqual(dms.mm, 41.0) self.assertAlmostEqual(dms.ss, 36.1980, 3)
def testUnicodeAndStr(self): """DMS.__str__ => string representation.""" dms = tpm.DMS() dms.dd = 1.0 dms.mm = 2.0 dms.ss = 3.0 self.assertEqual(str(dms), "+01D 02' 03.000\"")
def testProperMotion(self): """Convert.proper_motion: multiple V6C values.""" ra = tpm.d2r(269.45402305) de = tpm.d2r(4.66828815) px = 549.01 / 1000.0 # To Arc seconds rv = 0.0 # pmra * cos(de) into pmra pmra = (-797.84 / 1000.0) / math.cos(de) pmra *= 100.0 # To Arcseconds per century. pmde = (10326.93 / 1000.0) pmde *= 100.0 # To Arcseconds per century. C = tpm.CJ v6 = tpm.cat2v6(ra, de, pmra, pmde, px, rv, C) v6_out = convert.proper_motion([v6, v6], tpm.J2000, tpm.jyear2jd(1991.25)) for i in v6_out: v6 = i.c2s() hms = tpm.HMS(r=v6.alpha) dms = tpm.DMS(r=v6.delta) hms.normalize() dms.normalize() self.assertAlmostEqual(hms.hh, -7.0) self.assertAlmostEqual(hms.mm, 57.0) self.assertAlmostEqual(hms.ss, 48.4986, 3) self.assertAlmostEqual(dms.dd, 4.0) self.assertAlmostEqual(dms.mm, 41.0) self.assertAlmostEqual(dms.ss, 36.1980, 3)
def testAdditionNonHMS(self): """DMS + x => Exception when addition involves non DMS value.""" dms = tpm.DMS() # All zeros. def add_dms(dms, x): return dms + x self.assertRaises(TypeError, add_dms, dms, 1)
def testSubtractionNonDMS(self): """DMS - x => exception when subtraction involves non DMS value.""" dms = tpm.DMS() # All zeros. def sub_dms(dms, x): return dms - x self.assertRaises(TypeError, sub_dms, dms, 1)
def testSetFieldValues(self): """DMS.x = val => set values after creation.""" dms = tpm.DMS() dms.dd = 1.0 dms.mm = 1.0 dms.ss = 1.34 self.assertAlmostEqual(dms.dd, 1.0) self.assertAlmostEqual(dms.mm, 1.0) self.assertAlmostEqual(dms.ss, 1.34)
def testToHMS(self): """DMS.to_hms => DMS to HMS object.""" t = {'dd': 180.0, 'mm': 450.0, 'ss': 0.0} t_hms = {'hh': 12.0, 'mm': 30.0, 'ss': 0.0} dms = tpm.DMS(**t) hms = dms.to_hms() self.assertEqual(type(hms), tpm.HMS) self.assertEqual(hms.hh, t_hms['hh']) self.assertEqual(hms.mm, t_hms['mm']) self.assertEqual(hms.ss, t_hms['ss'])
def testRepr(self): """DMS.__repr__ => dictionary as a string.""" dms = tpm.DMS() dms.dd = 1.1 dms.mm = 1.2 dms.ss = 1.3 d = eval(repr(dms)) self.assertAlmostEqual(d['dd'], dms.dd) self.assertAlmostEqual(d['mm'], dms.mm) self.assertAlmostEqual(d['ss'], dms.ss)
def fB1950toJ2000_main(ra_J2000, dec_J2000): ''' Precess Right Ascension and Declination coordinates from the sexagismal positions in the B1959 system to decimal degrees in the J2000 system. Input ra_J2000: single Right Ascension position in sexagismal J2000 dec_J2000: single Declination position in sexagismal J2000 Output ra_deg: single Right Ascension position in decimal degree dec_deg: single Declination position in decimal degrees ''' # convert decimal degrees to sexagismal format ra_sexa, dec_sexa = degtosexa(ra_J2000, dec_J2000) # extract RA hh:mm:ss and Dec dd:mm:ss components ra_hh = float(ra_sexa.split(" ")[0]) ra_mm = float(ra_sexa.split(" ")[1]) ra_ss = float(ra_sexa.split(" ")[2]) dec_dd = float(dec_sexa.split(" ")[0][1:]) dec_mm = float(dec_sexa.split(" ")[1]) dec_ss = float(dec_sexa.split(" ")[2]) # create RA and Dec objects ra_J2000 = tpm.HMS(hh=ra_hh, mm=ra_mm, ss=ra_ss).to_radians() dec_J2000 = tpm.DMS(dd=dec_dd, mm=dec_mm, ss=dec_ss).to_radians() # velocity vector v5 = convert.cat2v6(ra_J2000, dec_J2000) v5_fk6 = convert.convertv6(v5, s1=5, s2=6, epoch=tpm.B1950, equinox=tpm.B1950) v5_fk6_ep2000 = convert.proper_motion(v5_fk6, tpm.J2000, tpm.B1950) d = convert.v62cat(v5_fk6_ep2000, C=tpm.CJ) ra_new_rad = d["alpha"] ra_deg = ra_new_rad * 180. / np.pi dec_new_rad = d["delta"] dec_deg = dec_new_rad * 180. / np.pi return ra_deg, dec_deg
def testCreate(self): """DMS() => create an DMS object.""" dms = tpm.DMS() self.assertEqual(type(dms), tpm.DMS)
def testInvalidKeywordAtInit(self): """DMS(key=value) => raise TypeError if key is invalid.""" self.assertRaises(TypeError, lambda: tpm.DMS(d=12.0)) self.assertRaises(TypeError, lambda: tpm.DMS(radians=12.0))
def verify(t, t_norm): dms = tpm.DMS(**t) self.assertAlmostEqual(dms.dd, t_norm['dd']) self.assertAlmostEqual(dms.mm, t_norm['mm']) self.assertAlmostEqual(dms.ss, t_norm['ss'])
def verify(t, t_norm): self.assertAlmostEqual(tpm.DMS(**t).to_degrees(), t_norm)
def testGetFields(self): """DMS.x => Retrieve default values of fields.""" dms = tpm.DMS() self.assertAlmostEqual(dms.dd, 0.0) self.assertAlmostEqual(dms.mm, 0.0) self.assertAlmostEqual(dms.ss, 0.0)
def verify(t, t_norm): self.assertAlmostEqual(tpm.DMS(**t).to_radians(), t_norm)
def testTPM(self): """tpm.tpm() => coordinate conversion.""" # M100 FK5 J2000 from SIMBAD. # See pytpm/tests/c_tests/test_conversion.c. results = [ dict(ra_dd=-175.00, ra_mm=43.0, ra_ss=43.4850, de_dd=15.00, de_mm=49.00, de_ss=20.5700), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=42.3616, de_dd=15.00, de_mm=49.00, de_ss=20.4480), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=43.4850, de_dd=15.00, de_mm=49.00, de_ss=20.5700), dict(ra_dd=178.00, ra_mm=46.00, ra_ss=57.2326, de_dd=16.00, de_mm=45.00, de_ss=34.9209), dict(ra_dd=-89.00, ra_mm=8.00, ra_ss=10.1024, de_dd=76.00, de_mm=53.00, de_ss=55.9283), dict(ra_dd=-175.00, ra_mm=5.00, ra_ss=44.0262, de_dd=16.00, de_mm=5.00, de_ss=58.0246 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=43.4850, de_dd=15.00, de_mm=49.00, de_ss=20.5700 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=43.4852, de_dd=15.00, de_mm=49.00, de_ss=20.5699 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=43.4819, de_dd=15.00, de_mm=49.00, de_ss=20.5712 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=44.9349, de_dd=15.00, de_mm=49.00, de_ss=13.4744 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=44.9350, de_dd=15.00, de_mm=49.00, de_ss=13.4743 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=30.6891, de_dd=15.00, de_mm=49.00, de_ss=19.5611 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=43.4852, de_dd=15.00, de_mm=49.00, de_ss=20.5699 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=43.4819, de_dd=15.00, de_mm=49.00, de_ss=20.5712 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=45.2053, de_dd=15.00, de_mm=49.00, de_ss=13.4529 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=45.2054, de_dd=15.00, de_mm=49.00, de_ss=13.4528 ), dict(ra_dd=-175.00, ra_mm=43.00, ra_ss=30.9595, de_dd=15.00, de_mm=49.00, de_ss=19.5396 ), dict(ra_dd=-17.00, ra_mm=8.00, ra_ss=52.8721, de_dd=15.00, de_mm=49.00, de_ss=19.5396 ), dict(ra_dd=132.00, ra_mm=32.00, ra_ss=57.5676, de_dd=67.00, de_mm=45.00, de_ss=9.6836 ), dict(ra_dd=132.00, ra_mm=32.00, ra_ss=57.5676, de_dd=67.00, de_mm=45.00, de_ss=34.3714 ), dict(ra_dd=-17.00, ra_mm=9.00, ra_ss=9.5430, de_dd=15.00, de_mm=49.00, de_ss=38.3077 ), dict(ra_dd=-17.00, ra_mm=14.00, ra_ss=6.8699, de_dd=-15.00, de_mm=10.00, de_ss=13.0062 ) ] ra = tpm.h2r(12+22/60.0+54.899/3600.0) de = tpm.d2r(15+49/60.0+20.57/3600.0) ep = tpm.J2000 eq = tpm.J2000 s1 = tpm.TPM_S06 s2 = tpm.TPM_S00 tstate = tpm.TSTATE() pvec = tpm.PVEC() for i in range(tpm.N_TPM_STATES): tpm.tpm_data(tstate, tpm.TPM_INIT) 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 ra_dms = tpm.DMS(r=ra1) de_dms = tpm.DMS(r=de1) ra_dms.normalize() de_dms.normalize() self.assertAlmostEqual(ra_dms.dd, results[i]['ra_dd'], 4) self.assertAlmostEqual(ra_dms.mm, results[i]['ra_mm'], 4) self.assertAlmostEqual(ra_dms.ss, results[i]['ra_ss'], 4) self.assertAlmostEqual(de_dms.dd, results[i]['de_dd'], 4) self.assertAlmostEqual(de_dms.mm, results[i]['de_mm'], 4) self.assertAlmostEqual(de_dms.ss, results[i]['de_ss'], 4)