def plotVelVsRadius(): cc = objects.Constants() gm = cc.mass * cc.msun * cc.G # Radius vector from 0-30 arcsec in 0.1 arcsec increments r = arange(0.1, 30, 0.1) r_cm = r * cc.dist * cc.cm_in_au vesc_cms = sqrt(2.0 * gm / r_cm) vesc = vesc_cms / 1.0e5 vcirc = vesc / sqrt(2.0) # Plot clf() plot(r, vesc, 'k-') plot(r, vcirc, 'k--') xlabel('Radius (arcsec)') ylabel('Velocity (km/s)') # Approximation for inclination uncertainty # 2GM/v^2 < 1.02 * r2D vincl = vesc / 1.11 plot(r, vincl, 'b--') rng = axis() axis([0, rng[1], 1, 1000])
def loadAllYoungStars(root, radiusCut=0.8, withRVonly=False): cc = objects.Constants() # Use our data if available. Otherwise use Paumards. ours = loadYoungStars(root, radiusCut=radiusCut, withRVonly=withRVonly) # Now get all other young star info from Paumard2006 paum = tabs.Paumard2006() # Paumard doesn't have positional uncertainties so we # need to figure out what to use. Do this by comparing # to stars that are in both. ourNames = ours.getArray('name') for ii in range(len(ourNames)): star = ours.stars[ii] # Find the star in our star lists try: #idx = paum.ourName.index(ourNames[ii]) idx = np.where(paum.ourName == ourNames[ii])[0] star.paumDiffX = paum.x[idx] - star.fitXa.p star.paumDiffY = paum.y[idx] - star.fitYa.p star.paumDiff = sqrt(star.paumDiffX**2 + star.paumDiffY**2) except ValueError, e: continue
def matchNames(self, labelFile=tablesDir + 'label.dat'): cc = objects.Constants() # Load up our label.dat file labels = Labels(labelFile) # Convert Paumard Velocities to asec/yr. vxPaum = self.vx / cc.asy_to_kms vyPaum = self.vy / cc.asy_to_kms # Epoch to match at: t = 2008.0 t0Paum = 2005.0 # just a guess xPaum = self.x + vxPaum * (t - t0Paum) yPaum = self.y + vyPaum * (t - t0Paum) xOurs = labels.x + (labels.vx * (t - labels.t0) / 1.0e3) yOurs = labels.y + (labels.vy * (t - labels.t0) / 1.0e3) for ii in range(len(xPaum)): # if self.ourName[ii] is not '-': # continue dr = np.hypot(xOurs - xPaum[ii], yOurs - yPaum[ii]) dm = labels.mag - self.Kmag[ii] # Find the closest source rdx = dr.argsort()[0] # Find thoses sources within 0.1" cdx = np.where(dr < 0.1)[0] print('') print('Match %10s at [%5.2f, %5.2f] and mag = %5.2f (ourName = %s)' % \ (self.name[ii], xPaum[ii], yPaum[ii], self.Kmag[ii], self.ourName[ii])) print(' Closest Star:') print(' %10s at [%5.2f, %5.2f] and mag = %5.2f' % \ (labels.name[rdx], xOurs[rdx], yOurs[rdx], labels.mag[rdx])) print(' Stars within 0.1"') for kk in cdx: print(' %10s at [%5.2f, %5.2f] and mag = %5.2f' % \ (labels.name[kk], xOurs[kk], yOurs[kk], labels.mag[kk]))
def xyz2kep(self, r, v, re, ve, epoch, mass=None, dist=None): """ Converts from cartesian (position, velocity) elements to Keplerian elements (inclination, eccentricity, omega, bigOmega, t0, period). @param r: 3D vector containing position of secondary (arcsec). @type r: numarray @param v: 3D vector containing velocity of secondary (km/s). @type v: numarray @param re: 3D vector containing position errors (arcsec). @type re: numarray @param ve: 3D vector containing velocity errors (km/s). @type veh: numarray @param epoch: The epoch at which the r and v vectors were observed. @type epoch: float @kwparam mass: Black hole mass in solar mass units (default pulled from Constants). @kwparam dist: Black hole distance in parsec (default pulled from Constants). @return elements: object containing orbital elements """ cc = objects.Constants() if (mass != None): cc.mass = mass if (dist != None): cc.dist = dist cc.asy_to_kms = cc.dist * cc.cm_in_au / (1.0e5 * cc.sec_in_yr) GM = cc.msun * cc.mass * cc.G # Convert position from arcsec to cm r *= cc.dist * cc.cm_in_au re *= cc.dist * cc.cm_in_au # Convert velocity from km/s to cm/s v = v * 1.0e5 ve = ve * 1.0e5 r_mag = sqrt((r**2).sum()) v_mag = sqrt((v**2).sum()) re_mag = sqrt(((r * re)**2).sum()) / r_mag ve_mag = sqrt(((v * ve)**2).sum()) / v_mag ### --- Now everything should be in CGS ---### # Check for unbound orbits... we don't handle those here if (v_mag > sqrt(2.0 * GM / r_mag)): raise ValueError( 'Velocity exceeds escape velocity: v_mag = %e vs. v_esc = %e, mass=%e' % (v_mag, sqrt(2.0 * GM / r_mag), mass)) # Angular momentum vector h = util.cross_product(r, v) h_mag = sqrt((h**2).sum()) he = zeros(3, dtype=float64) he[0] = (re[1] * v[2])**2 + (r[1] * ve[2])**2 he[0] += (re[2] * v[1])**2 + (r[2] * ve[1])**2 he[1] = (re[0] * v[2])**2 + (r[0] * ve[2])**2 he[1] += (re[2] * v[0])**2 + (r[2] * ve[0])**2 he[2] = (re[0] * v[1])**2 + (r[0] * ve[1])**2 he[2] += (re[1] * v[0])**2 + (r[1] * ve[0])**2 he = sqrt(he) he_mag = sqrt(((h * he)**2).sum()) / h_mag # Inclination u = -h[2] / h_mag incl = math.degrees(arccos(u)) dudx = h[2] * (v[1] * h[2] - v[2] * h[1]) / h_mag**3 dudx = dudx - (v[1] / h_mag) dudy = h[2] * (v[2] * h[0] - v[0] * h[2]) / h_mag**3 dudy = dudy + (v[0] / h_mag) dudz = h[2] * (v[0] * h[1] - v[1] * h[0]) / h_mag**3 dudvx = h[2] * (r[2] * h[1] - r[1] * h[2]) / h_mag**3 dudvx = dudvx + (r[1] / h_mag) dudvy = h[2] * (r[0] * h[2] - r[2] * h[0]) / h_mag**3 dudvy = dudvy - (r[0] / h_mag) dudvz = h[2] * (r[1] * h[0] - r[0] * h[1]) / h_mag**3 incl_err = (dudvx * ve[0])**2 + (dudvy * ve[1])**2 + (dudvz * ve[2])**2 incl_err += (dudx * re[0])**2 + (dudy * re[1])**2 + (dudz * re[2])**2 incl_err = incl_err / (1.0 - u**2) # derivative of acos incl_err = math.degrees(sqrt(incl_err)) # eccentricity e = (util.cross_product(v, h) / GM) - (r / r_mag) e_mag = sqrt((e**2).sum()) dedx = zeros(3, dtype=float64) dedx[0] = (v[1]**2 + v[2]**2) / GM dedx[0] += (r[0]**2 / r_mag**3) - (1.0 / r_mag) dedx[1] = (-v[0] * v[1] / GM) + (r[0] * r[1] / r_mag**3) dedx[2] = (-v[0] * v[2] / GM) + (r[0] * r[2] / r_mag**3) dedy = zeros(3, dtype=float64) dedy[0] = (-v[1] * v[0] / GM) + (r[1] * r[1] / r_mag**3) dedy[1] = ((v[0]**2 + v[2]**2) / GM) dedy[1] += (r[1]**2 / r_mag**3) - (1.0 / r_mag) dedy[2] = (-v[1] * v[2] / GM) + (r[1] * r[2] / r_mag**3) dedz = zeros(3, dtype=float64) dedz[0] = (-v[2] * v[0] / GM) + (r[2] * r[0] / r_mag**3) dedz[1] = (-v[2] * v[1] / GM) + (r[2] * r[1] / r_mag**3) dedz[2] = ((v[0]**2 + v[1]**2) / GM) dedz[2] += (r[2]**2 / r_mag**3) - (1.0 / r_mag) dedvx = zeros(3, dtype=float64) dedvx[0] = -(v[1] * r[1] + v[2] * r[2]) / GM dedvx[1] = (2.0 * v[0] * r[1] - v[1] * r[0]) / GM dedvx[2] = (2.0 * v[0] * r[2] - v[2] * r[0]) / GM dedvy = zeros(3, dtype=float64) dedvy[0] = (2.0 * v[1] * r[0] - v[0] * r[1]) / GM dedvy[1] = -(v[0] * r[0] + v[2] * r[2]) / GM dedvy[2] = (2.0 * v[1] * r[2] - v[2] * r[1]) / GM dedvz = zeros(3, dtype=float64) dedvz[0] = (2.0 * v[2] * r[0] - v[0] * r[2]) / GM dedvz[1] = (2.0 * v[2] * r[1] - v[1] * r[2]) / GM dedvz[2] = -(v[0] * r[0] + v[1] * r[1]) / GM ee_mag = ((dedx * e).sum() * re[0] / e_mag)**2 ee_mag += ((dedy * e).sum() * re[1] / e_mag)**2 ee_mag += ((dedz * e).sum() * re[2] / e_mag)**2 ee_mag += ((dedvx * e).sum() * ve[0] / e_mag)**2 ee_mag += ((dedvy * e).sum() * ve[1] / e_mag)**2 ee_mag += ((dedvz * e).sum() * ve[2] / e_mag)**2 ee = zeros(3, dtype=float64) ee[0] = (v[1] * he[2])**2 + (ve[1] * h[2])**2 ee[0] += (v[2] * he[1])**2 + (ve[2] * h[1])**2 ee[1] = (v[2] * he[0])**2 + (ve[2] * h[0])**2 ee[1] += (v[0] * he[2])**2 + (ve[0] * h[2])**2 ee[2] = (v[0] * he[1])**2 + (ve[0] * h[1])**2 ee[2] += (v[1] * he[0])**2 + (ve[1] * h[0])**2 ee /= GM**2 ee += (r / r_mag)**2 * ((re / r)**2 + (re_mag / r_mag)**2) ee = sqrt(ee) ee_mag2 = sqrt(((e * ee)**2).sum()) / e_mag # Line of nodes vector Om = util.cross_product(array([0.0, 0.0, 1.0]), h) Om_mag = sqrt((Om**2).sum()) Ome = array([he[1], he[2], 0.0]) Ome_mag = sqrt(((Om * Ome)**2).sum()) / Om_mag # bigOmega = PA to the ascending node bigOm = math.degrees(arctan2(Om[0], Om[1])) bigOme = v[2]**2 * ((re * h)**2).sum() bigOme += r[2]**2 * ((ve * h)**2).sum() bigOme /= Om_mag**4 bigOme = math.degrees(sqrt(bigOme)) # omega = angle from bigOmega to periapse cos_om = ((Om / Om_mag) * (e / e_mag)).sum() omega = math.degrees(arccos(cos_om)) # dot product of Om and e Om_e = (Om * e).sum() dodx = -(Om_e * Om[0] * v[2]) / (e_mag * Om_mag**3) dodx += ((e[0] * v[2]) + (Om * dedx).sum()) / (e_mag * Om_mag) dodx -= (Om_e * (e * dedx).sum()) / (e_mag**3 * Om_mag) dody = -(Om_e * Om[1] * v[2]) / (e_mag * Om_mag**3) dody += ((e[1] * v[2]) + (Om * dedy).sum()) / (e_mag * Om_mag) dody -= (Om_e * (e * dedy).sum()) / (e_mag**3 * Om_mag) dodz = (Om_e * (Om * v).sum()) / (e_mag * Om_mag**3) dodz += ((-e[0] * v[0]) + (-e[1] * v[1]) + (Om * dedz).sum()) / (e_mag * Om_mag) dodz -= (Om_e * (e * dedz).sum()) / (e_mag**3 * Om_mag**3) dodvx = (Om_e * Om[0] * r[2]) / (e_mag * Om_mag**3) dodvx += ((-e[0] * r[2]) + (Om * dedvx).sum()) / (e_mag * Om_mag) dodvx -= (Om_e * (e * dedvx).sum()) / (e_mag**3 * Om_mag) dodvy = (Om_e * Om[1] * r[2]) / (e_mag * Om_mag**3) dodvy += ((-e[1] * r[2]) + (Om * dedvy).sum()) / (e_mag * Om_mag) dodvy -= (Om_e * (e * dedvy).sum()) / (e_mag**3 * Om_mag) dodvz = (-Om_e * (Om * r).sum()) / (e_mag * Om_mag**3) dodvz += ((e[0] * r[0]) + (e[1] * r[1]) + (Om * dedvz).sum()) / (e_mag * Om_mag) dodvz -= (Om_e * (e * dedvz).sum()) / (e_mag**3 * Om_mag) omega_err = (dodvx * ve[0])**2 + (dodvy * ve[1])**2 + (dodvz * ve[2])**2 omega_err += (dodx * re[0])**2 + (dody * re[1])**2 + (dodz * re[2])**2 omega_err = omega_err / (1.0 - cos_om**2) omega_err = math.degrees(sqrt(omega_err)) if (omega_err > 180.0): omega_err = 179.999 if (e[2] < 0): omega = 360.0 - omega # Semi major axis tmp = (2.0 / r_mag) - (v_mag**2 / GM) if (tmp == 0): tmp = 0.00001 a = 1.0 / tmp ae = ((r * re / r_mag**3)**2).sum() + ((v * ve / GM)**2).sum() ae = sqrt(ae) * 2.0 * a**2 # Period a_AU = a / cc.cm_in_au ae_AU = ae / cc.cm_in_au p = sqrt((a_AU / cc.mass) * a_AU**2) pe = (3.0 / 2.0) * p * ae_AU / a_AU #---------- # Thiele-Innes Constants #---------- cos_om = cos(math.radians(omega)) sin_om = sin(math.radians(omega)) cos_bigOm = cos(math.radians(bigOm)) sin_bigOm = sin(math.radians(bigOm)) cos_i = cos(math.radians(incl)) sin_i = sin(math.radians(incl)) conA = a * (cos_om * cos_bigOm - sin_om * sin_bigOm * cos_i) conB = a * (cos_om * sin_bigOm + sin_om * cos_bigOm * cos_i) conC = a * (sin_om * sin_i) conF = a * (-sin_om * cos_bigOm - cos_om * sin_bigOm * cos_i) conG = a * (-sin_om * sin_bigOm + cos_om * cos_bigOm * cos_i) conH = a * (cos_om * sin_i) # Eccentric Anomaly cos_E = (r[1] * conG - r[0] * conF) / (conA * conG - conF * conB) cos_E += e_mag sin_E = (r[0] * conA - r[1] * conB) / (conA * conG - conF * conB) sin_E /= sqrt(1.0 - e_mag**2) eccA = arctan2(sin_E, cos_E) # Eccentric Anomaly eccAe = (r_mag / (e_mag * a))**2 * ((re_mag / r_mag)**2 + (ae / a)**2) eccAe += (tmp * ee_mag / e_mag)**2 eccAe /= (1.0 - tmp**2) eccAe = sqrt(eccAe) # Time of periapse passage tmp = p / (2.0 * math.pi) t0 = tmp * (eccA - e_mag * sin_E) t0 = epoch - t0 deedv = array([(e * dedvx).sum(), (e * dedvy).sum(), (e * dedvz).sum()]) deedr = array([(e * dedx).sum(), (e * dedy).sum(), (e * dedz).sum()]) t0e3 = (tmp * (eccA - e_mag * sin_E) * pe / p)**2 t0e3 = t0e3 + (tmp * (1 - e_mag * cos_E) * eccAe)**2 t0e3 = t0e3 + (tmp * sin_E * ee_mag)**2 t0e3 = sqrt(t0e3) t0e = t0e3 phase = abs(epoch - t0) * 2.0 / p phaseErr = sqrt((2.0 * t0e / p)**2 + (phase * pe / p)**2) eccA = math.degrees(eccA) eccAe = math.degrees(eccAe) # Fix bigOmega if (bigOm < 0.0): bigOm = bigOm + 360.0 # Orbital Parameters self.w = omega self.we = omega_err self.o = bigOm self.oe = bigOme self.i = incl self.ie = incl_err self.e = e_mag self.ee = ee_mag self.p = p self.pe = pe self.t0 = t0 self.t0e = t0e self.ph = phase self.phe = phaseErr self.a = a # Vectors useful for later calculations self.hvec = h self.hevec = he self.evec = e self.eevec = ee self.ovec = Om self.oevec = Ome # Thiele-Innes Constants - convert from cm to AU self.conA = conA / cc.cm_in_au self.conB = conB / cc.cm_in_au self.conC = conC / cc.cm_in_au self.conF = conF / cc.cm_in_au self.conG = conG / cc.cm_in_au self.conH = conH / cc.cm_in_au
def kep2xyz(self, epochs, mass=None, dist=None): """ After setting all the orbital elements on this orbit object, call kep2xyz in order to return a tuple containing: r -- radius vector [arcsec] v -- velocity vector [mas/yr] a -- acceleration vector [mas/yr^2] An example call is: orb = orbits.Orbit() orb.w = omega orb.o = bigOm orb.i = incl orb.e = e_mag orb.p = p orb.t0 = t0 (r, v, a) = orb.kep2xyz(array([refTime])) """ cc = objects.Constants() if (mass != None): cc.mass = mass if (dist != None): cc.dist = dist cc.asy_to_kms = cc.dist * cc.cm_in_au / (1.0e5 * cc.sec_in_yr) GM = cc.mass * cc.msun * cc.G ecnt = len(epochs) # Semi-major axis in AU axis = (self.p**2 * cc.mass)**(1.0 / 3.0) # meanMotion in radians per year meanMotion = 2.0 * math.pi / self.p ecc_sqrt = sqrt(1.0 - self.e**2) #---------- # Now for each epoch we compute the x and y positions #---------- # Mean anomaly M = meanMotion * (epochs - self.t0) #print 't0: ', self.t0, ' meanMotion: ', meanMotion #print 'M should be ', meanMotion * (epochs[0] - self.t0) # Eccentric anomaly E = self.eccen_anomaly(M, self.e) #for ee in range(len(E)): # print 'Epoch[ee] = ', epochs[ee] # print 'E: %7.4f\t meanAnom: %7.4f' % (E[ee], M[ee]) #E = zeros(len(M), dtype=float64) #for ii in range(len(M)): # E[ii] = self.eccen_anomaly2(M[ii], self.e) # print E[ii] cos_E = cos(E) sin_E = sin(E) Edot = meanMotion / (1.0 - (self.e * cos_E)) X = cos_E - self.e Y = ecc_sqrt * sin_E #---------- # Calculate Thiele-Innes Constants #---------- cos_om = cos(math.radians(self.w)) sin_om = sin(math.radians(self.w)) cos_bigOm = cos(math.radians(self.o)) sin_bigOm = sin(math.radians(self.o)) cos_i = cos(math.radians(self.i)) sin_i = sin(math.radians(self.i)) self.conA = axis * (cos_om * cos_bigOm - sin_om * sin_bigOm * cos_i) self.conB = axis * (cos_om * sin_bigOm + sin_om * cos_bigOm * cos_i) self.conC = axis * (sin_om * sin_i) self.conF = axis * (-sin_om * cos_bigOm - cos_om * sin_bigOm * cos_i) self.conG = axis * (-sin_om * sin_bigOm + cos_om * cos_bigOm * cos_i) self.conH = axis * (cos_om * sin_i) r = zeros((ecnt, 3), dtype=float64) v = zeros((ecnt, 3), dtype=float64) a = zeros((ecnt, 3), dtype=float64) r[:, 0] = (self.conB * X) + (self.conG * Y) r[:, 1] = (self.conA * X) + (self.conF * Y) r[:, 2] = (self.conC * X) + (self.conH * Y) v[:, 0] = Edot * ((-self.conB * sin_E) + (self.conG * ecc_sqrt * cos_E)) v[:, 1] = Edot * ((-self.conA * sin_E) + (self.conF * ecc_sqrt * cos_E)) v[:, 2] = Edot * ((-self.conC * sin_E) + (self.conH * ecc_sqrt * cos_E)) # Calculate accleration for ii in range(ecnt): rmag_cm = sqrt((r[ii, :]**2).sum()) * cc.cm_in_au a[ii, :] = -GM * r[ii, :] * cc.cm_in_au / rmag_cm**3 # Unit conversions # r from AU to arcsec # v from AU/yr to mas/yr # a from cm/s^2 to mas/yr^2 r /= cc.dist v *= 1000.0 / cc.dist a *= 1000.0 * cc.sec_in_yr**2 / (cc.cm_in_au * cc.dist) return (r, v, a)
def loadYoungStars(root, align='align/align_d_rms_1000_abs_t', fit='polyfit_c/fit', points='points_c/', radiusCut=0.8, relErr=1, verbose=False, withRVonly=False, silent=False, mosaic=False): if not os.path.exists(root + align + '.trans'): align = 'align/align_d_rms_100_abs_t' #align = 'align/align_d_rms1000_t' # Load up the absolute position of Sgr A* based on S0-2's orbit t = objects.Transform() t.loadAbsolute() # Load up position/velocity information s = starset.StarSet(root + align, relErr=relErr, trans=t) s.loadPolyfit(root + fit, arcsec=1, silent=silent) if mosaic == False: s.loadPolyfit(root + fit, arcsec=1, accel=1, silent=silent) yng = youngStarNames() # Tables in database w/ RV information ucla = tabs.UCLAstars() bart = tabs.Bartko2009() paum = tabs.Paumard2006() cc = objects.Constants() # Pull out from the set of stars those that are young # stars. stars = [] names = [star.name for star in s.stars] for name in yng: # Find the star in our star lists try: idx = names.index(name) star = s.stars[idx] if (star.r2d >= radiusCut): stars.append(star) # Number of Epochs Detected should be corrected # for epochs trimmed out of the *.points files. pntsFile = '%s%s%s.points' % (root, points, star.name) _pnts = asciidata.open(pntsFile) star.velCnt = _pnts.nrows pntDate = _pnts[0].tonumpy() pntX = _pnts[1].tonumpy() pntY = _pnts[2].tonumpy() pntXe = _pnts[3].tonumpy() pntYe = _pnts[4].tonumpy() # Load up data from the points files. for ee in range(len(star.years)): tt = (where(abs(pntDate - star.years[ee]) < 0.001))[0] if (len(tt) == 0): star.e[ee].x_pnt = -1000.0 star.e[ee].y_pnt = -1000.0 star.e[ee].xe_pnt = -1000.0 star.e[ee].ye_pnt = -1000.0 else: tt = tt[0] star.e[ee].x_pnt = pntX[tt] star.e[ee].y_pnt = pntY[tt] star.e[ee].xe_pnt = pntXe[tt] star.e[ee].ye_pnt = pntYe[tt] if mosaic == True: # We only have 3 epochs (as of 2011) star.fitXv.v *= cc.asy_to_kms star.fitYv.v *= cc.asy_to_kms star.fitXv.verr *= cc.asy_to_kms star.fitYv.verr *= cc.asy_to_kms star.vx = star.fitXv.v star.vy = star.fitYv.v star.vxerr = star.fitXv.verr star.vyerr = star.fitYv.verr else: star.fitXa.v *= cc.asy_to_kms star.fitYa.v *= cc.asy_to_kms star.fitXa.verr *= cc.asy_to_kms star.fitYa.verr *= cc.asy_to_kms star.vx = star.fitXa.v star.vy = star.fitYa.v star.vxerr = star.fitXa.verr star.vyerr = star.fitYa.verr star.rv_ref = 'None' def other_RV_tables(): # If not found in UCLA tables, then check Bartko+2009 idx = np.where(bart.ourName == name)[0] if len(idx) > 0: star.vz = bart.vz[idx][0] star.vzerr = bart.vzerr[idx][0] star.vzt0 = bart.t0_spectra[idx][0] star.rv_ref = 'Bartko+2009' else: # Next check Paumard+2006 idx = np.where(paum.ourName == name)[0] if len(idx) > 0: star.vz = paum.vz[idx][0] star.vzerr = paum.vzerr[idx][0] star.vzt0 = paum.t0_spectra[idx][0] star.altName = paum.name[idx][0] star.rv_ref = 'Paumard+2006' #else: # print 'Could not find radial velocity for %s' % name # Find the radial velocity for each star # First look in OSIRIS data, then Bartko, then Paumard idx = np.where(ucla.ourName == name)[0] if len(idx) > 0: star.vz = ucla.vz[idx][0] star.vzerr = ucla.vzerr[idx][0] star.vzt0 = ucla.t0_spectra[idx][0] star.rv_ref = 'UCLA' # A star could be in the stars table but still not have vz if star.vz == None: # then check other tables star.rv_ref = None other_RV_tables() else: other_RV_tables() if withRVonly == True: if star.rv_ref == None: # remove this star stars.remove(star) if (verbose == True): print('Matched %15s to %12s' % (name, star.rv_ref)) star.jz = (star.x * star.vy) - (star.y * star.vx) star.jz /= (star.r2d * hypot(star.vx, star.vy)) except ValueError as e: # Couldn't find the star in our lists continue # Set the starset's star list s.stars = stars print('Found %d young stars' % len(stars)) return s
def loadAllYoungStars(root, radiusCut=0.8, withRVonly=False): cc = objects.Constants() # Use our data if available. Otherwise use Paumards. ours = loadYoungStars(root, radiusCut=radiusCut, withRVonly=withRVonly) # Now get all other young star info from Paumard2006 paum = tabs.Paumard2006() # Paumard doesn't have positional uncertainties so we # need to figure out what to use. Do this by comparing # to stars that are in both. ourNames = ours.getArray('name') for ii in range(len(ourNames)): star = ours.stars[ii] # Find the star in our star lists try: #idx = paum.ourName.index(ourNames[ii]) idx = np.where(paum.ourName == ourNames[ii])[0] star.paumDiffX = paum.x[idx] - star.fitXa.p star.paumDiffY = paum.y[idx] - star.fitYa.p star.paumDiff = sqrt(star.paumDiffX**2 + star.paumDiffY**2) except ValueError as e: continue # We now have young stars that are not in Paumard, so must account # for this diff = ours.getArray('paumDiff') mtch = np.where(diff > 0)[0] # This will find all but the NaN's avgDiff = diff[mtch].mean() print('The average error in Paumard distances is', avgDiff) # Loop through all the young stars in Paumard's list. for ii in range(len(paum.name)): name = paum.ourName[ii] # Find the star in our star lists try: #idx = ourNames.index(name) idx = np.where(ourNames == name)[0] star = ours.stars[idx] except ValueError as e: # Couldn't find the star in our lists. Use Paumard info. if (name == ' ' or name == ''): name = 'paum' + paum.name[ii] # Only keep if there is 3D velocity if (paum.vx[ii] == 0 and paum.vy[ii] == 0): continue if (sqrt(paum.x[ii]**2 + paum.y[ii]**2) < radiusCut): continue star = objects.Star(name) ours.stars.append(star) star.x = paum.x[ii] star.y = paum.y[ii] star.vx = paum.vx[ii] star.vy = paum.vy[ii] star.vz = paum.vz[ii] star.mag = paum.mag[ii] star.xerr = avgDiff star.yerr = avgDiff star.vxerr = paum.vxerr[ii] star.vyerr = paum.vyerr[ii] star.vzerr = paum.vzerr[ii] star.velCnt = 0 # Proper motions need to be fixed for a different distance. # Paumard assumed 8kpc. star.vx *= cc.dist / 8000.0 star.vy *= cc.dist / 8000.0 star.vxerr *= cc.dist / 8000.0 star.vyerr *= cc.dist / 8000.0 # Need to set the positional errors to something. # We don't know the epoch of the Paumard measurements: t0 = 2005.495 star.setFitXv(t0, star.x, star.xerr, star.vx/cc.asy_to_kms, star.vxerr/cc.asy_to_kms) star.setFitYv(t0, star.y, star.yerr, star.vy/cc.asy_to_kms, star.vyerr/cc.asy_to_kms) star.jz = (star.x * star.vy) - (star.y * star.vx) star.jz /= (star.r2d * hypot(star.vx, star.vy)) # Return the starlist return ours