def getGpos(pf): 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.l.radians return l,b
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 read_asas(): """ Read in the ASAS data -- RR Lyrae from the ASAS http://adsabs.harvard.edu/abs/2009AcA....59..137S """ tsv_filename = os.path.join(project_root, "data", "catalog", \ "ASAS_RRab.tsv") data = ascii.read(tsv_filename, data_start=59) ras, decs = [], [] for radec in data["ASAS"]: try: neg = 1. ra, dec = radec.split("+") except: neg = -1 ra, dec = radec.split("-") ra = float(ra[:2]) + float(ra[2:4]) / 60. + float(ra[4:]) / 3600. dec = neg * (float(dec[:2]) + float(dec[2:]) / 60.) fk5 = coord.FK5Coordinates(ra, dec, unit=(u.hour, u.degree)) ras.append(fk5.ra.degrees) decs.append(fk5.dec.degrees) # Map RA/Dec columns to easier names data.add_column(Column(ras, name="ra", dtype=float)) data.add_column(Column(decs, name="dec", dtype=float)) data.add_column(Column(np.array(data['Vavg']).astype(float), name=str("V"))) data.add_column( Column(rrl_photometric_distance(data['V'], -1.5), name="dist", units=u.kpc)) data["ra"].units = u.degree data["dec"].units = u.degree data["dist"].units = u.kpc return data
""" The angular transformations: """ from psrpbdot import M1 from datatools.tempo import * from astropy import coordinates as coord import numpy.linalg as linalg from tools import Coordinate as COORD pf = PARfile('1713.Dec.mcmc.par') pos1713 = coord.FK5Coordinates( str(COORD.RA(pf.RAJ[0])) + ' ' + str(COORD.Dec(pf.DECJ[0]))) GCpos = coord.FK5Coordinates('17h45m40.04s -29d00m28.1s') RA = pos1713.ra.radians Dec = pos1713.dec.radians alpha = np.pi + RA beta = Dec T1 = np.matrix(((np.cos(alpha), np.sin(alpha), 0.), (0. - np.sin(alpha), np.cos(alpha), 0.), (0., 0., 1))) T2 = np.matrix( ((np.cos(beta), 0., 0. - np.sin(beta)), (0., 1., 0.), (np.sin(beta), 0., np.cos(beta)))) T = T2 * T1 GPpos = coord.FK5Coordinates('12h51m26.282s' + ' ' + '27d07m42.01s') Rc, Dc = GCpos.ra.radians, GCpos.dec.radians Rp, Dp = GPpos.ra.radians, GPpos.dec.radians Gc = np.matrix( (np.cos(Rc) * np.cos(Dc), np.sin(Rc) * np.cos(Dc), np.sin(Dc))).T Gp = np.matrix( (np.cos(Rp) * np.cos(Dp), np.sin(Rp) * np.cos(Dp), np.sin(Dp))).T
""" import numpy as np from astropy import coordinates as coord from astropy.time import Time # Read in initial coordinates as J2000 coordinates data_j2000 = np.loadtxt('../initial_coords.txt') f = {} f['galactic'] = open('coords_galactic.txt', 'wb') f['b1950'] = open('coords_b1950.txt', 'wb') for i in range(len(data_j2000)): ra_j2000, dec_j2000 = data_j2000[i, 0], data_j2000[i, 1] fk5 = coord.FK5Coordinates(ra_j2000, dec_j2000, unit='degree') # Convert to Galactic coordinates galactic = fk5.galactic l, b = galactic.l, galactic.b # Wrap longitude to range 0 to 360 l = coord.Angle(l, bounds=(0, 360)) f['galactic'].write("%20.15f %20.15f\n" % (l.degrees, b.degrees)) # Convert to B1950 fk4 = fk5.fk4.precess_to(Time('B1950', scale='utc')) ra_b1950, dec_b1950 = fk4.ra, fk4.dec # Wrap longitude to range 0 to 360 ra_b1950 = coord.Angle(ra_b1950, bounds=(0, 360)) f['b1950'].write("%20.15f %20.15f\n" % (ra_b1950.degrees, dec_b1950.degrees))
dec = Dec(pf.DECJ[0]) pos = coord.FK5Coordinates(str(ra) +' '+ str(dec)) l = pos.galactic.l.radians b = pos.galactic.l.radians return l,b pf = PARfile('1713.Oct.mcmc.par') #print getGpos(pf) gl, gb = getGpos(pf) D = 1./float(pf.PX[0]) x = D * np.cos(gb) * np.sin(gl) y = solardist - D * np.cos(gb) * np.cos(gl) angle = np.arctan(y/x)*180./np.pi GCpos = coord.FK5Coordinates('17h45m40.04s -29d00m28.1s') pos1713 = coord.FK5Coordinates(str(RA(pf.RAJ[0]))+' '+str(Dec(pf.DECJ[0]))) DRA = pos1713.ra.radians - GCpos.ra.radians DDec = pos1713.dec.radians - GCpos.dec.radians Omega = float(pf.PAASCNODE)/180.*np.pi Theta_g = np.pi - np.arctan(np.tan(DRA)/np.sin(DDec)) #print Theta_g*180/np.pi, Omega*180/np.pi z = np.sin(gb) * D R0 = solardist R1 = np.sqrt(R0**2 + (D*np.cos(gb))**2 -2 * R0 * D * np.cos(gb) * np.cos(gl)) lbd = np.arccos((R1**2 + D**2 + z**2 - R0**2)/(2*D*np.sqrt(R1**2 + z**2)))#*180/np.pi print 'lambda: ', lbd, 'R_PSR: ', R1, 'z: ', z rat = np.sqrt(1 - (np.cos(i)*np.cos(lbd) + np.sin(i)*np.sin(lbd)*np.sin(Theta_g - Omega))**2) print 'ratio:',rat
def get_nrao_image(lon, lat, system='galactic', epoch='J2000', size=1.0, max_rms=1e4, band="", verbose=True, savename=None, save=True, overwrite=False, directory='./', get_uvfits=False): """ Search for and download Parameters ---------- lon : float lat : float Right ascension and declination or glon/glat system : ['celestial','galactic'] System of lon/lat. Can be any valid coordinate system supported by the astropy.coordinates package epoch : string Epoch of the coordinate system (e.g., B1950, J2000) savename : None or string filename to save fits file as. If None, will become G###.###p###.###_(survey).fits size : float Size of search radius (arcminutes) max_rms : float Maximum allowable noise level in the image (mJy) verbose : bool Print out extra error messages? save : bool Save FITS file? overwrite : bool Overwrite if file already exists? directory : string Directory to store file in. Defaults to './'. get_uvfits : bool Get the UVfits files instead of the IMfits files? Examples -------- >>> fitsfile = get_nrao_image(49.489,-0.37) """ if band not in valid_bands: raise ValueError("Invalid band. Valid bands are: %s" % valid_bands) if system == 'celestial': radec = coord.FK5Coordinates(lon, lat, unit=('deg', 'deg')) galactic = radec.galactic elif system == 'galactic': galactic = coord.GalacticCoordinates(lon, lat, unit=('deg', 'deg')) radec = galactic.fk5 radecstr = radec.ra.format(sep=' ') + ' ' + radec.dec.format(sep=' ') glon, glat = galactic.lonangle.degrees, galactic.latangle.degrees # Construct request request = {} request["nvas_pos"] = radecstr request["nvas_rad"] = size request["nvas_rms"] = max_rms request["nvas_scl"] = size request["submit"] = "Search" request["nvas_bnd"] = band # create the request header data request = urllib.urlencode(request) # load the URL as text U = urllib.urlopen(request_URL, request) # read results with progressbar results = progressbar.chunk_read(U, report_hook=progressbar.chunk_report) if get_uvfits: links = uvfits_re.findall(results) else: links = imfits_re.findall(results) configurations = config_re.findall(results) if len(links) == 0: if verbose: print "No matches found at ra,dec = %s." % (radecstr) return [] if verbose > 1: print "Configurations: " print "\n".join( ["%40s: %20s" % (L, C) for L, C in zip(links, configurations)]) if save and not os.path.exists(directory): os.mkdir(directory) if save: opener = urllib2.build_opener() if verbose: print "Found %i imfits files" % len(links) images = [] for link, config in zip(links, configurations): # Get the file U = opener.open(link) with aud.get_readable_fileobj(U) as f: results = f.read() S = StringIO.StringIO(results) try: fitsfile = fits.open(S, ignore_missing_end=True) except IOError: S.seek(0) G = gzip.GzipFile(fileobj=S) fitsfile = fits.open(G, ignore_missing_end=True) # Get Multiframe ID from the header images.append(fitsfile) if save: h0 = fitsfile[0].header freq_ghz = h0['CRVAL3'] / 1e9 for bn, bandlimits in band_freqs.iteritems(): if freq_ghz < bandlimits[1] and freq_ghz > bandlimits[0]: bandname = bn obj = str(h0['OBJECT']).strip() program = h0['OBSERVER'].strip() h0['CONFIG'] = config if savename is None: if get_uvfits: filename = "VLA_%s_G%07.3f%+08.3f_%s_%s.uvfits" % ( bandname, glon, glat, obj, program) else: filename = "VLA_%s_G%07.3f%+08.3f_%s_%s.fits" % ( bandname, glon, glat, obj, program) else: filename = savename # Set final directory and file names final_file = directory + '/' + filename if verbose: print "Saving file %s" % final_file fitsfile.writeto(final_file, clobber=overwrite) return images
def GetTransferMatrix(pf): #print getGpos(pf) gl, gb = getGpos(pf) D = 1. / float(pf.PX[0]) x = D * np.cos(gb) * np.sin(gl) y = solardist - D * np.cos(gb) * np.cos(gl) angle = np.arctan(y / x) * 180. / np.pi GCpos = coord.FK5Coordinates('17h45m40.04s -29d00m28.1s') pos1713 = coord.FK5Coordinates( str(COORD.RA(pf.RAJ[0])) + ' ' + str(COORD.Dec(pf.DECJ[0]))) RA = pos1713.ra.radians Dec = pos1713.dec.radians DRA = pos1713.ra.radians - GCpos.ra.radians DDec = pos1713.dec.radians - GCpos.dec.radians Omega = float(pf.PAASCNODE) / 180. * np.pi Theta_g = np.pi - np.arctan(np.tan(DRA) / np.sin(DDec)) """ #Transfer the RA-Dec coordiate to the plane of sky coordiate: Two steps: # 1. rotate to the star # 2. rotate to the plane of the sky #two angles: alpha, beta; alpha = Ra - pi/2, beta = dec """ RA = pos1713.ra.radians Dec = pos1713.dec.radians alpha = np.pi + RA beta = Dec #print 'RA + 180., Dec: ', alpha/np.pi*180, beta/np.pi*180 T1 = np.matrix(((np.cos(alpha), np.sin(alpha), 0.), (0. - np.sin(alpha), np.cos(alpha), 0.), (0., 0., 1))) T2 = np.matrix(((np.cos(beta), 0., 0. - np.sin(beta)), (0., 1., 0.), (np.sin(beta), 0., np.cos(beta)))) T = T2 * T1 """ #Transfer the Galactic plane coordinate to RA-Dec coordinate: Solve the matrix from two equations: # 1. GC is (cos Rc cos Dc, sin Rc cos Dc, sin Dc) # 2. Galactic pole is (cos Rp cos Dp, sin Rp cos Dp, sin Dp) #two angles: alpha, beta; alpha = Ra - pi/2, beta = dec """ GPpos = coord.FK5Coordinates('12h51m26.282s' + ' ' + '27d07m42.01s') #print Galactic_pol.galactic.l.radians/np.pi, Galactic_pol.galactic.b.radians/np.pi Rc, Dc = GCpos.ra.radians, GCpos.dec.radians Rp, Dp = GPpos.ra.radians, GPpos.dec.radians Gc = np.matrix( (np.cos(Rc) * np.cos(Dc), np.sin(Rc) * np.cos(Dc), np.sin(Dc))).T Gp = np.matrix( (np.cos(Rp) * np.cos(Dp), np.sin(Rp) * np.cos(Dp), np.sin(Dp))).T #Gmat = np.vstack((Gp, Gc, np.matrix((1,1,1)))) #RHS = np.matrix((0, coszeta, 1)) #RHS = RHS.T #X = linalg.solve(Gmat, RHS) alpha = Rc beta = Dc GT1 = np.matrix(((np.cos(alpha), np.sin(alpha), 0.), (0. - np.sin(alpha), np.cos(alpha), 0.), (0., 0., 1))) GT2 = np.matrix( ((np.cos(beta), 0., np.sin(beta)), (0., 1, 0.), (0. - np.sin(beta), 0., np.cos(beta)))) Gp_Gal12 = GT2 * GT1 * Gp gamma = np.arctan(Gp_Gal12[1] / Gp_Gal12[2]) GT3 = np.matrix(((1., 0., 0.), (0, np.cos(gamma), 0. - np.sin(gamma)), (0, np.sin(gamma), np.cos(gamma)))) GT = GT3 * GT2 * GT1 #GT = GT1 * GT2 * GT3 #Gp_Gal = GT3 * Gp_Gal12 #print Gp_Gal #sys.exit(0) return T, GT