def Pbdot_Gal(pf): try: name = pf.PSRJ except: name = pf.PSR ra = RA(pf.RAJ[0]) dec = Dec(pf.DECJ[0]) pos = coord.FK5Coordinates(str(ra) +' '+ str(dec)) l = pos.galactic.l.radians b = pos.galactic.b.radians Pb = float(pf.PB[0] * secperday) #d = AU * 180 / PI * 3600 / pf.PX[0] * 1000 d = float(1/pf.PX[0]) pf.DIST = d z_kpc = float(d)*(abs(sin(b)))#/kpc must be positive a_z = ((2.27)*z_kpc + (3.68)*(1 - exp((-4.31)*z_kpc)))*(1.e-9) #cm s^-2 #print 'a_z:', a_z A_z = -1 * a_z *abs(sin(b))/c pf.A_z = A_z R0 = (8.34) #* kpc # Reid et al. 2014 beta = float(d/R0) * cos(b) - cos(l) Omega0 = (240. * 1.e5) #240+/-8 km/s; Reid et al 2014 #print b,l, cos(b), cos(l), beta A_x = -1/c * (cos(b)) * (Omega0**2/R0/kpc) * (cos(l) + beta/(sin(l)**2 + beta**2)) pf.A_x = A_x #print 'Ax, Az: ',A_x, A_z fac1 = float(pf.PX[1]/pf.PX[0]) fac2 = 8/240 #Omega_0 fac3 = 0.16/8.34 #R0 Reid et al 2014 val = float(Pb*(A_z + A_x)) err1 = A_x * fac1 err2 = A_z * sqrt(fac1**2 + fac2**2 + fac3**2) err = sqrt(err1**2 + err2**2) * float(Pb) return val, err
def Pbdot_Gal(pf): try: name = pf.PSRJ except: name = pf.PSR ra = RA(pf.RAJ[0]) dec = Dec(pf.DECJ[0]) pos = coord.SkyCoord(str(ra) + ' ' + str(dec)) l = pos.galactic.l.rad b = pos.galactic.b.rad L = pos.galactic.l.deg B = pos.galactic.b.deg Pb = float(pf.PB[0] * secperday) d = float(1 / pf.PX[0]) pf.DIST = d print 'L, B, D:', L, B, d #output = getoutput('./GalPotMcMillan2016/calcGalPdot.exe %s %s %s' % (L, B, d)) output = getoutput('./GalPotMcMillan2016/calcGalAcc.exe %s %s %s' % (L, B, d)) print output, np.sqrt(sum([float(f)**2 for f in output.split(' ')])) px = np.random.normal(float(pf.PX[0]), float(pf.PX[1]), 10000) res = np.array(spamit(McMillanPot, [(L, B, 1 / x) for x in px])) val = res.mean() * Pb fac2 = 8 / 240 #Omega_0 fac3 = 0.16 / 8.34 #R0 Reid et al 2014 fac1 = res.std() / res.mean() err = abs(sqrt(fac1**2 + fac2**2 + fac3**2) * val) return val, err
def addmodeldata(m): value = [] value.append('') for k in Observable: #parameter.append(Observable[k]) if type(m.__dict__[k]) in (tuple, list): val, err = m.__dict__[k] if k == 'RAJ': ra = RA(m.__dict__[k][0]) raerr = m.__dict__[k][1] value.append('%s:%s:%s' % (ra.HH,ra.MM, parseerror(Decimal(ra.SS),Decimal(raerr)))) elif k == 'DECJ': dec = Dec(m.__dict__[k][0]) decerr = m.__dict__[k][1] value.append('%s:%s:%s' % (dec.dd,dec.mm, parseerror(Decimal(dec.ss),Decimal(decerr)))) else: value.append(parseerror(*m.__dict__[k])) else: if k == 'DM': value.append(parseerror(*aveDM(m))) else: value.append((m.__dict__[k])) value.append('') for k in Fixed: #parameter.append(Fixed[k]) try: value.append(parseerror(*m.__dict__[k])) except: if type(m.__dict__[k]) == type(''): value.append(m.__dict__[k]) elif k == 'PEPOCH': value.append(m.__dict__[k].quantize(50000)) elif k == 'OMDOT': value.append(m.__dict__[k].quantize(Decimal(0.0001))) else: value.append(SF(globals()[k](m))) #data = [parameter, value] value.append('') for k in Derived: #parameter.append(Derived[k]) if k == 'PAASCNODE': value.append(m.__dict__[k]) else: try: value.append(parseerror(*m.__dict__[k])) except: value.append(SF(globals()[k](m))) return value
def addmodeldata(m): value = [] value.append('') for k in Observable: if k == 'KIN': try: kin = float(m.__dict__[k][0])/180.*np.pi; kinerr = float(m.__dict__[k][1])/180.*np.pi cosi = Decimal(str(np.cos(kin))) dcosi = Decimal(str(np.sin(kin)*kinerr)) value.append(parseerror(*[cosi, dcosi])) except: k = 'SINI' sini = float(m.__dict__[k][0]); dsini = float(m.__dict__[k][0]) cosi = np.sqrt(1 - sini**2) dcosi = Decimal(str(np.abs(dsini*sini/cosi))) cosi = Decimal(str(cosi)) value.append(parseerror(*[cosi, dcosi])) #parameter.append(Observable[k]) elif type(m.__dict__[k]) in (tuple, list): val, err = m.__dict__[k] if k == 'RAJ': ra = RA(m.__dict__[k][0]) raerr = m.__dict__[k][1] value.append('%s:%s:%s' % (ra.HH,ra.MM, parseerror(Decimal(ra.SS),Decimal(raerr)))) elif k == 'DECJ': dec = Dec(m.__dict__[k][0]) decerr = m.__dict__[k][1] value.append('%s:%s:%s' % (dec.dd,dec.mm, parseerror(Decimal(dec.ss),Decimal(decerr)))) elif k == 'PBDOT': if m.__dict__[k][0] < Decimal(1.e-10): m.__dict__[k][0]/=Decimal(1.e-12) m.__dict__[k][1]/=Decimal(1.e-12) value.append(parseerror(*m.__dict__[k])) else: value.append(parseerror(*m.__dict__[k])) else: value.append(parseerror(*m.__dict__[k])) else: if k == 'DM': value.append(parseerror(*aveDM(m))) else: value.append((m.__dict__[k])) value.append('') for k in Fixed: #parameter.append(Fixed[k]) if k == 'OMDOT': value.append(m.__dict__[k][0].quantize(Decimal(0.00001))) elif not m.__dict__.has_key(k): value.append('--') else: try: value.append(parseerror(*m.__dict__[k])) except: if type(m.__dict__[k]) == type(''): value.append(m.__dict__[k]) elif k == 'PEPOCH': value.append(m.__dict__[k].quantize(50000)) elif k in ['RNAMP', 'RNIDX']: value.append(m.__dict__[k].quantize(Decimal(0.001))) else: value.append(SF(globals()[k](m))) #data = [parameter, value] value.append('') for k in Derived: #parameter.append(Derived[k]) try: value.append(parseerror(*m.__dict__[k])) except: if k == 'M1': value.append(parseerror(*M1(m))) else: value.append(parseerror(*globals()[k](m))) return value
parameter.append(r'\textit{Measured Parameters}') value.append('') for k in Observable: parameter.append(Observable[k]) if type(m.__dict__[k]) in (tuple, list): val, err = m.__dict__[k] #if not all([type(v) is decimal.Decimal for v in m.__dict__[k]]): if k == 'RAJ': #print k, m.__dict__[k], [type(v) is decimal.Decimal for v in m.__dict__[k]] ra = RA(m.__dict__[k][0]) raerr = m.__dict__[k][1] value.append('%s:%s:%s' % (ra.HH,ra.MM, parseerror(Decimal(ra.SS),Decimal(raerr)))) elif k == 'DECJ': dec = Dec(m.__dict__[k][0]) decerr = m.__dict__[k][1] value.append('%s:%s:%s' % (dec.dd,dec.mm, parseerror(Decimal(dec.ss),Decimal(decerr)))) else: value.append(parseerror(*m.__dict__[k])) else: if k == 'DM': value.append(parseerror(*aveDM(m))) else: value.append((m.__dict__[k])) parameter.append(r'\textit{Fixed Parameters}') value.append('') for k in Fixed: parameter.append(Fixed[k])
def addmodeldata(m): value = [] value.append('') for k in Observable: #parameter.append(Observable[k]) if type(m.__dict__[k]) in (tuple, list): val, err = m.__dict__[k] if k == 'RAJ': ra = RA(m.__dict__[k][0]) raerr = m.__dict__[k][1] value.append( '%s:%s:%s' % (ra.HH, ra.MM, parseerror(Decimal(ra.SS), Decimal(raerr)))) elif k == 'DECJ': dec = Dec(m.__dict__[k][0]) decerr = m.__dict__[k][1] value.append('%s:%s:%s' % (dec.dd, dec.mm, parseerror(Decimal(dec.ss), Decimal(decerr)))) elif k == 'PBDOT': if m.__dict__[k][0] < Decimal(1.e-10): m.__dict__[k][0] /= Decimal(1.e-12) m.__dict__[k][1] /= Decimal(1.e-12) value.append(parseerror(*m.__dict__[k])) else: value.append(parseerror(*m.__dict__[k])) else: value.append(parseerror(*m.__dict__[k])) else: if k == 'DM': value.append(parseerror(*aveDM(m))) else: value.append((m.__dict__[k])) value.append('') for k in Fixed: #parameter.append(Fixed[k]) if k == 'OMDOT': value.append(m.__dict__[k][0].quantize(Decimal(0.00001))) elif not m.__dict__.has_key(k): value.append('--') else: try: value.append(parseerror(*m.__dict__[k])) except: if type(m.__dict__[k]) == type(''): value.append(m.__dict__[k]) elif k == 'PEPOCH': value.append(m.__dict__[k].quantize(50000)) elif k in ['RNAMP', 'RNIDX', 'TNRedAmp', 'TNRedGam']: value.append(m.__dict__[k].quantize(Decimal(0.001))) else: value.append(SF(globals()[k](m))) #data = [parameter, value] value.append('') for k in Derived: #parameter.append(Derived[k]) try: value.append(parseerror(*m.__dict__[k])) except: if k == 'M1': value.append(parseerror(*M1(m))) else: value.append(parseerror(*globals()[k](m))) return value
#plt.xlabel('MJD-50000') plt.xlabel('Year') #show() #sys.exit() """plot solar elongation """ import ephem from MJD import * from astropy import coordinates as coord from tools.Coordinate import RA, Dec mjd = np.linspace(50900, 56500, 500) #mjd = np.linspace(53200, 57000, 500) #dates = [MJD_to_datetime(m).strfmt('%Y/%m/%d') for m in mjd] dates = [MJD_to_datetime(jd) for jd in mjd] if type(m.RAJ) == list: ra = RA(m.RAJ[0]) dec = Dec(m.DECJ[0]) #pulsar = ephem.Equatorial(m.RAJ[0], m.DECJ[0], epoch='2000') #psr = coord.FK5Coordinates(str(ra) +' '+str(dec)) #print str(ra) +' '+str(dec) psr = coord.SkyCoord(str(ra) + ' ' + str(dec)) PHI = [] pr = psr.ra.rad pd = psr.dec.rad for date in dates: sun = ephem.Sun() sun.compute(date, epoch='2000') sunstr = str(RA(str(sun.g_ra))) + ' ' + str(Dec(str(sun.g_dec))) sunpos = coord.SkyCoord(sunstr) sr = sunpos.ra.rad sd = sunpos.dec.rad psr = np.array(