def ccFromSCPVOff(pos, pm, parlax, radVel, offDir, offMag): """ Converts spherical to cartesian coordinates, including position, velocity and and a local offset along a great circle from the position vector. See also ccFromSCPV and ccFromSC. Inputs: - pos(2) spherical position (degrees); pos[1] must be in the range [-90,90] - pm(2) proper motion (arcsec per century) - parlax parallax (arcsec) - radVel radial velocity (km/s, positive receding) - offDir offset direction (degrees): dir. of increasing pos[0] = 0, pos[1] = 90 - offMag offset magnitude (degrees on the sky) Returns: - p(3) position vector (au) - v(3) velocity (au per year) - offP(3) offset position vector (au) - atInf true if object is very far away (see Details) Error Conditions: - Raises ValueError if pos[1] is not in the range -90 to 90 deg Warnings: - Negative parallax is silently treated as zero parallax (object at infinity). Details: - See Sph.CCFromSCPV for more information. History 2002-08-22 ROwen Converted to Python from the TCC's sph_SCPVOff2CC 6-1. """ # convert spherical position and velocity to cartesian p, v, atInf = ccFromSCPV(pos, pm, parlax, radVel) # compute spherical coordinates of the offset position; # ignore the case of the offset position being at the pole, # as the standard calculations work fine for that case # (sets side_bb = 0 and ang_A = ang_C = 90) ang_A, side_bb, ang_C, offPosAtPole = angSideAng(90.0 - pos[1], 90.0 - offDir, offMag) offPos = ( pos[0] + ang_C, 90.0 - side_bb, ) # convert the offset position to cartesian coordinates # (the offset is assumed to be long a great circle, # so the magnitude is exactly the same as the un-offset position) magP = RO.MathUtil.vecMag(p) offP = ccFromSC(offPos, magP) return (p, v, offP, atInf)
def ccFromSCPVOff(pos, pm, parlax, radVel, offDir, offMag): """ Converts spherical to cartesian coordinates, including position, velocity and and a local offset along a great circle from the position vector. See also ccFromSCPV and ccFromSC. Inputs: - pos(2) spherical position (degrees); pos[1] must be in the range [-90,90] - pm(2) proper motion (arcsec per century) - parlax parallax (arcsec) - radVel radial velocity (km/s, positive receding) - offDir offset direction (degrees): dir. of increasing pos[0] = 0, pos[1] = 90 - offMag offset magnitude (degrees on the sky) Returns: - p(3) position vector (au) - v(3) velocity (au per year) - offP(3) offset position vector (au) - atInf true if object is very far away (see Details) Error Conditions: - Raises ValueError if pos[1] is not in the range -90 to 90 deg Warnings: - Negative parallax is silently treated as zero parallax (object at infinity). Details: - See Sph.CCFromSCPV for more information. History 2002-08-22 ROwen Converted to Python from the TCC's sph_SCPVOff2CC 6-1. """ # convert spherical position and velocity to cartesian p, v, atInf = ccFromSCPV (pos, pm, parlax, radVel) # compute spherical coordinates of the offset position; # ignore the case of the offset position being at the pole, # as the standard calculations work fine for that case # (sets side_bb = 0 and ang_A = ang_C = 90) ang_A, side_bb, ang_C, offPosAtPole = angSideAng (90.0 - pos[1], 90.0 - offDir, offMag) offPos = ( pos[0] + ang_C, 90.0 - side_bb, ) # convert the offset position to cartesian coordinates # (the offset is assumed to be long a great circle, # so the magnitude is exactly the same as the un-offset position) magP = RO.MathUtil.vecMag(p) offP = ccFromSC(offPos, magP) return (p, v, offP, atInf)
def dcFromSC(pos): """Convert spherical coordinates to direction cosines, i.e. a unit vector. Inputs: - pos(2) spherical coordinates (deg): longitude (increasing x to y), latitude, e.g. (RA, Dec), (-HA, Dec) or (Az, Alt) Returns: - dc(3) direction cosines (rad), as a numpy.array Error Conditions: (none) """ return ccFromSC(pos, 1.0)
def ccFromSCPV( pos, pm, parallax, radVel, ): """ Converts spherical position and velocity to cartesian coordinates. Inputs: - pos(2) spherical position - pm(2) proper motion ("/century) - parallax parallax (arcsec) - radVel radial velocity (km/s, positive receding) Returns a tuple consisting of: - p cartesian position (au) - v cartesian velocity (au/year) - atInf true if object is very far away(see Details) Error Conditions: - Raises ValueError if pos[1] is not in the range -90 to 90 deg Warnings: - Negative parallax is silently treated as zero parallax (object at infinity). Details: - Proper motion is dPos/dt, not rate on the sky; in other words, pm[0] gets large near the pole. - If the star is very far away (parallax < _MinParallax), atInf is set true, the distance is set to that limit and radial velocity is treated as zero. - We could handle any range of pos[1] by checking to see if it's in quadrants ii or iii, and if so, adding 180 degrees to offDir and possibly negating pm[0] and pm[1]. However, it's not certain that's what the user wanted, so for now avoid all that math and just complain. History 2002-07-08 ROwen Converted from TCC's sph_SCPV2CC 1-1. 2002-12-23 ROwen Cosmetic change to make pychecker happy. """ # handle case of parallax too small ("at infinity") if (parallax >= _MinParallax): atInf = 0 else: atInf = 1 parallax = _MinParallax radVel = 0.0 # compute distance in au; note that distance (parsecs) = 1/parallax (") distAU = RO.PhysConst.AUPerParsec / parallax # compute p p = ccFromSC (pos, distAU) # compute useful quantities sinP0 = RO.MathUtil.sind(pos[0]) cosP0 = RO.MathUtil.cosd(pos[0]) sinP1 = RO.MathUtil.sind(pos[1]) cosP1 = RO.MathUtil.cosd(pos[1]) # change units of proper motion from "/cy to au/year # (multiply by distance and fix the units) # pm(au/year) = pm ("/cy) distAU(au) (rad/year) / ("/cy) pmAUPerYr = [x * distAU * _RadPerYear_per_ASPerCy for x in pm] # change units of radial velocity from km/sec to au/year radVelAUPerYr = radVel * _AUPerYear_per_KMPerSec # compute velocity vector in au/year v = ( - pmAUPerYr[0]*cosP1*sinP0 - pmAUPerYr[1]*sinP1*cosP0 + radVelAUPerYr*cosP1*cosP0, pmAUPerYr[0]*cosP1*cosP0 - pmAUPerYr[1]*sinP1*sinP0 + radVelAUPerYr*cosP1*sinP0, pmAUPerYr[1]*cosP1 + radVelAUPerYr*sinP1, ) return (p, v, atInf)
def ccFromSCPV( pos, pm, parallax, radVel, ): """ Converts spherical position and velocity to cartesian coordinates. Inputs: - pos(2) spherical position - pm(2) proper motion ("/century) - parallax parallax (arcsec) - radVel radial velocity (km/s, positive receding) Returns a tuple consisting of: - p cartesian position (au) - v cartesian velocity (au/year) - atInf true if object is very far away(see Details) Error Conditions: - Raises ValueError if pos[1] is not in the range -90 to 90 deg Warnings: - Negative parallax is silently treated as zero parallax (object at infinity). Details: - Proper motion is dPos/dt, not rate on the sky; in other words, pm[0] gets large near the pole. - If the star is very far away (parallax < _MinParallax), atInf is set true, the distance is set to that limit and radial velocity is treated as zero. - We could handle any range of pos[1] by checking to see if it's in quadrants ii or iii, and if so, adding 180 degrees to offDir and possibly negating pm[0] and pm[1]. However, it's not certain that's what the user wanted, so for now avoid all that math and just complain. History 2002-07-08 ROwen Converted from TCC's sph_SCPV2CC 1-1. 2002-12-23 ROwen Cosmetic change to make pychecker happy. """ # handle case of parallax too small ("at infinity") if (parallax >= _MinParallax): atInf = 0 else: atInf = 1 parallax = _MinParallax radVel = 0.0 # compute distance in au; note that distance (parsecs) = 1/parallax (") distAU = RO.PhysConst.AUPerParsec / parallax # compute p p = ccFromSC(pos, distAU) # compute useful quantities sinP0 = RO.MathUtil.sind(pos[0]) cosP0 = RO.MathUtil.cosd(pos[0]) sinP1 = RO.MathUtil.sind(pos[1]) cosP1 = RO.MathUtil.cosd(pos[1]) # change units of proper motion from "/cy to au/year # (multiply by distance and fix the units) # pm(au/year) = pm ("/cy) distAU(au) (rad/year) / ("/cy) pmAUPerYr = [x * distAU * _RadPerYear_per_ASPerCy for x in pm] # change units of radial velocity from km/sec to au/year radVelAUPerYr = radVel * _AUPerYear_per_KMPerSec # compute velocity vector in au/year v = ( -pmAUPerYr[0] * cosP1 * sinP0 - pmAUPerYr[1] * sinP1 * cosP0 + radVelAUPerYr * cosP1 * cosP0, pmAUPerYr[0] * cosP1 * cosP0 - pmAUPerYr[1] * sinP1 * sinP0 + radVelAUPerYr * cosP1 * sinP0, pmAUPerYr[1] * cosP1 + radVelAUPerYr * sinP1, ) return (p, v, atInf)