Beispiel #1
0
def azAltFromHADec(haDec, lat):
    """Converts HA/Dec position to az/alt.

    Inputs:
     - haDec    (ha, dec) (degrees)
     - lat  latitude (degrees)
    
    Returns a tuple containing:
      (az, alt) (degrees)
      atPole    true => object near the pole (see Error Conditions)
    
    Error Conditions:
    - If converted position is too near the pole, atPole is true and ha is undefined.
    
    Sign convention: azimuth is 0 south and 90 east.
    
    History:
    2002-07-23 ROwen  Converted from TCC's sph_HADec2AzAlt 1-2.
    2003-05-06 ROwen    Modified test data to match new scFromCC.
    """
    # convert spherical -ha/dec to direction cosines
    negHADec = (-haDec[0], haDec[1])
    haDecDC = dcFromSC(negHADec)

    # convert ha/dec direction cosines to az/alt direction cosines
    azAltDC = Cnv.azAltFromHADec(haDecDC, lat)

    # convert az/alt direction cosines to spherical az/alt (deg)
    return scFromDC(azAltDC)
Beispiel #2
0
def azAltFromHADec(haDec, lat):
    """Converts HA/Dec position to az/alt.

    Inputs:
     - haDec    (ha, dec) (degrees)
     - lat  latitude (degrees)
    
    Returns a tuple containing:
      (az, alt) (degrees)
      atPole    true => object near the pole (see Error Conditions)
    
    Error Conditions:
    - If converted position is too near the pole, atPole is true and ha is undefined.
    
    Sign convention: azimuth is 0 south and 90 east.
    
    History:
    2002-07-23 ROwen  Converted from TCC's sph_HADec2AzAlt 1-2.
    2003-05-06 ROwen    Modified test data to match new scFromCC.
    """
    # convert spherical -ha/dec to direction cosines
    negHADec = (-haDec[0], haDec[1])
    haDecDC = dcFromSC (negHADec)

    # convert ha/dec direction cosines to az/alt direction cosines
    azAltDC = Cnv.azAltFromHADec (haDecDC, lat)

    # convert az/alt direction cosines to spherical az/alt (deg)
    return scFromDC (azAltDC)
Beispiel #3
0
def angSep(posA, posB):
    """Computes the angular separation between two points on a sphere.

    Inputs:
    - posA(2)   one spherical coordinate (deg)
                longitude (increasing x to y), latitude,
                e.g. (RA, Dec), (-HA, Dec) or (Az, Alt)
    - posB(2)   the other spherical coordinate (deg)
    
    Returns:
    - angSep    the angular separation between the two points (deg)
    
    Error Conditions:
    (none)
        
    Details:
    Convert to Cartesian vectors and go from there.
    The simplest method is to take the arc cosine of the dot product,
    but this works poorly for small angles. To avoid this problem,
    construct a triangle from the origin to one of the vectors
    to the halfway point between the vectors, then use atan2
    to compute the angle at the origin (half the desired angle)
    
    Based on Pat Wallace's SEP routine.
    """
    # convert from sherical to Cartesian coordinates
    vecA = dcFromSC(posA)
    vecB = dcFromSC(posB)
    
    # compute the magnitude squared of half the difference vector
    diffMagSqQuarter = numpy.sum((vecA - vecB)**2) * 0.25
    
    # compute the angle
    return 2.0 * RO.MathUtil.atan2d (
        math.sqrt(diffMagSqQuarter),
        math.sqrt(max(0.0, 1.0-diffMagSqQuarter))
    )
Beispiel #4
0
def angSep(posA, posB):
    """Computes the angular separation between two points on a sphere.

    Inputs:
    - posA(2)   one spherical coordinate (deg)
                longitude (increasing x to y), latitude,
                e.g. (RA, Dec), (-HA, Dec) or (Az, Alt)
    - posB(2)   the other spherical coordinate (deg)
    
    Returns:
    - angSep    the angular separation between the two points (deg)
    
    Error Conditions:
    (none)
        
    Details:
    Convert to Cartesian vectors and go from there.
    The simplest method is to take the arc cosine of the dot product,
    but this works poorly for small angles. To avoid this problem,
    construct a triangle from the origin to one of the vectors
    to the halfway point between the vectors, then use atan2
    to compute the angle at the origin (half the desired angle)
    
    Based on Pat Wallace's SEP routine.
    """
    # convert from sherical to Cartesian coordinates
    vecA = dcFromSC(posA)
    vecB = dcFromSC(posB)

    # compute the magnitude squared of half the difference vector
    diffMagSqQuarter = numpy.sum((vecA - vecB)**2) * 0.25

    # compute the angle
    return 2.0 * RO.MathUtil.atan2d(
        math.sqrt(diffMagSqQuarter), math.sqrt(max(0.0,
                                                   1.0 - diffMagSqQuarter)))
Beispiel #5
0
def haDecFromAzAlt (azAlt, lat):
    """Converts alt/az position to ha/dec position.

    Inputs:
     - azAlt    (az, alt) (deg)
     - lat      latitude (degrees);
                >0 is north of the equator, <0 is south
    
    Returns a tuple containing:
    - haDec     (HA, Dec) (deg), a tuple;
                HA is in the range (-180, 180]
    - atPole    true => object near the pole (see Error Conditions)
    
    Error Conditions:
    - If converted position is too near the north or south pole,
    atPole is set true and HA is some arbitrary value.
    
    Details:
      Sign conventions:
      - azimuth is 0 south and 90 east
      - ha/dec is the usual left-handed coordinate system
    
    History:
    3/01 ROwen  Converted to Python from TCC's sph_AzAlt2HADec 1-2.
    2/02 ROwen  Minor tweaks to header.
    2002-07-02 ROwen    Renamed from azAltToHADec.
    2003-05-06 ROwen    Changed HA range from [0, 360) to (-180, 180]
    """
    # convert spherical az/alt (deg) to direction cosines
    azAltDC = dcFromSC (azAlt)

    # convert az/alt direction cosines to -ha/dec direction cosines
    negHADecDC = Cnv.haDecFromAzAlt (azAltDC, lat)

    # convert -ha/dec direction cosines to spherical -ha/dec (deg)
    ((negHA, dec), atPole) = scFromDC (negHADecDC)

    return ((RO.MathUtil.wrapCtr(-negHA), dec), atPole)
Beispiel #6
0
def haDecFromAzAlt(azAlt, lat):
    """Converts alt/az position to ha/dec position.

    Inputs:
     - azAlt    (az, alt) (deg)
     - lat      latitude (degrees);
                >0 is north of the equator, <0 is south
    
    Returns a tuple containing:
    - haDec     (HA, Dec) (deg), a tuple;
                HA is in the range (-180, 180]
    - atPole    true => object near the pole (see Error Conditions)
    
    Error Conditions:
    - If converted position is too near the north or south pole,
    atPole is set true and HA is some arbitrary value.
    
    Details:
      Sign conventions:
      - azimuth is 0 south and 90 east
      - ha/dec is the usual left-handed coordinate system
    
    History:
    3/01 ROwen  Converted to Python from TCC's sph_AzAlt2HADec 1-2.
    2/02 ROwen  Minor tweaks to header.
    2002-07-02 ROwen    Renamed from azAltToHADec.
    2003-05-06 ROwen    Changed HA range from [0, 360) to (-180, 180]
    """
    # convert spherical az/alt (deg) to direction cosines
    azAltDC = dcFromSC(azAlt)

    # convert az/alt direction cosines to -ha/dec direction cosines
    negHADecDC = Cnv.haDecFromAzAlt(azAltDC, lat)

    # convert -ha/dec direction cosines to spherical -ha/dec (deg)
    ((negHA, dec), atPole) = scFromDC(negHADecDC)

    return ((RO.MathUtil.wrapCtr(-negHA), dec), atPole)