Пример #1
0
def checkRADec(rawRADec):
    """Check and convert a pair of equatorial coordinates.

      [ rawRADec is a string ->
          if rawRADec is a valid set of equatorial coordinates ->
            return those coordinates as a sidereal.RADec instance
          else ->
            sys.stderr  +:=  error message
            stop execution ]
    """
    #-- 1 --
    # [ if rawRADec contains either a '+' or a '-' ->
    #     m  :=  a re.match instance describing the first matching
    #            character
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    m = SIGN_PAT.search(rawRADec)
    if m is None:
        usage("Equatorial coordinates must be separated by " "'+' or '-'.")
    #-- 2 --
    # [ rawRA  :=  rawRADec up to the match described by m
    #   sign  :=  characters matched by m
    #   rawDec  :=  rawRADec past the match described by m ]
    rawRA = rawRADec[:m.start()]
    sign = m.group()
    rawDec = rawRADec[m.end():]
    #-- 3 --
    # [ if rawRA is a valid hours expression ->
    #     ra  :=  rawRA as radians
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        raHours = sidereal.parseHours(rawRA)
        ra = sidereal.hoursToRadians(raHours)
    except SyntaxError as detail:
        usage("Right ascension '%s' should have the form "
              "'NNh[NNm[NN.NNNs]]'." % rawRA)
    #-- 4 --
    # [ if rawDec is a valid angle expression ->
    #     absDec  :=  that angle in radians
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        absDec = sidereal.parseAngle(rawDec)
    except SyntaxError as detail:
        usage("Right ascension '%s' should have the form "
              "'NNd[NNm[NN.NNNs]]'." % rawDec)
    #-- 5 --
    if sign == '-': dec = -absDec
    else: dec = absDec

    #-- 6 --
    return sidereal.RADec(ra, dec)
Пример #2
0
def checkAltAz ( rawAltAz ):
    """Check and convert a pair of horizon py.

      [ rawAltAz is a string ->
          if rawAltAz is a valid set of horizon py ->
            return those py as a sidereal.AltAz instance
          else ->
            sys.stderr  +:=  error message
            stop execution ]
    """
    #-- 1 --
    # [ if rawAltAz contains either a '+' or a '-' ->
    #     m  :=  a re.match instance describing the first matching
    #            character
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    m  =  SIGN_PAT.search ( rawAltAz )
    if  m is None:
        usage ( "Equatorial py must be separated by "
                "'+' or '-'." )
    #-- 2 --
    # [ rawAz  :=  rawAltAz up to the match described by m
    #   sign  :=  characters matched by m
    #   rawAlt  :=  rawAltAz past the match described by m ]
    rawAz  =  rawAltAz[:m.start()]
    sign  =  m.group()
    rawAlt  =  rawAltAz[m.end():]

    #-- 3 --
    # [ if rawAz is a valid angle ->
    #     az  :=  that angle as radians
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        az  =  sidereal.parseAngle ( rawAz )
    except SyntaxError, detail:
        usage ( "Azimuth '%s' should have the form "
                "'NNNd[NNm[NN.NNNs]]'." % rawAz )
Пример #3
0
def checkAltAz(rawAltAz):
    """Check and convert a pair of horizon coordinates.

      [ rawAltAz is a string ->
          if rawAltAz is a valid set of horizon coordinates ->
            return those coordinates as a sidereal.AltAz instance
          else ->
            sys.stderr  +:=  error message
            stop execution ]
    """
    #-- 1 --
    # [ if rawAltAz contains either a '+' or a '-' ->
    #     m  :=  a re.match instance describing the first matching
    #            character
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    m = SIGN_PAT.search(rawAltAz)
    if m is None:
        usage("Equatorial coordinates must be separated by " "'+' or '-'.")
    #-- 2 --
    # [ rawAz  :=  rawAltAz up to the match described by m
    #   sign  :=  characters matched by m
    #   rawAlt  :=  rawAltAz past the match described by m ]
    rawAz = rawAltAz[:m.start()]
    sign = m.group()
    rawAlt = rawAltAz[m.end():]

    #-- 3 --
    # [ if rawAz is a valid angle ->
    #     az  :=  that angle as radians
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        az = sidereal.parseAngle(rawAz)
    except SyntaxError, detail:
        usage("Azimuth '%s' should have the form "
              "'NNNd[NNm[NN.NNNs]]'." % rawAz)
Пример #4
0
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        az  =  sidereal.parseAngle ( rawAz )
    except SyntaxError, detail:
        usage ( "Azimuth '%s' should have the form "
                "'NNNd[NNm[NN.NNNs]]'." % rawAz )

    #-- 4 --
    # [ if rawAlt is a valid angle ->
    #     alt  :=  that angle as radians
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        absAlt  =  sidereal.parseAngle ( rawAlt )
    except SyntaxError, detail:
        usage ( "Altitude '%s' should have the form "
                "'NNd[NNm[NN.NNNs]]'." % rawAlt )

    #-- 5 --
    if  sign == '-':   alt  =  - absAlt
    else:              alt  =  absAlt

    #-- 6 --
    return  sidereal.AltAz ( alt, az )
#================================================================
# Epilogue
#----------------------------------------------------------------

if  __name__ == "__main__":
Пример #5
0
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        raHours  =  sidereal.parseHours ( rawRA )
        ra  =  sidereal.hoursToRadians ( raHours )
    except SyntaxError, detail:
        usage ( "Right ascension '%s' should have the form "
                "'NNh[NNm[NN.NNNs]]'." % rawRA )
    #-- 4 --
    # [ if rawDec is a valid angle expression ->
    #     absDec  :=  that angle in radians
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        absDec  =  sidereal.parseAngle ( rawDec )
    except SyntaxError, detail:
        usage ( "Right ascension '%s' should have the form "
                "'NNd[NNm[NN.NNNs]]'." % rawDec )
    #-- 5 --
    if  sign == '-':   dec  =  - absDec
    else:              dec  =  absDec

    #-- 6 --
    return sidereal.RADec ( ra, dec )
#================================================================
# Epilogue
#----------------------------------------------------------------

if  __name__ == "__main__":
    main()
Пример #6
0
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        az = sidereal.parseAngle(rawAz)
    except SyntaxError, detail:
        usage("Azimuth '%s' should have the form "
              "'NNNd[NNm[NN.NNNs]]'." % rawAz)

    #-- 4 --
    # [ if rawAlt is a valid angle ->
    #     alt  :=  that angle as radians
    #   else ->
    #     sys.stderr  +:=  error message
    #     stop execution ]
    try:
        absAlt = sidereal.parseAngle(rawAlt)
    except SyntaxError, detail:
        usage("Altitude '%s' should have the form "
              "'NNd[NNm[NN.NNNs]]'." % rawAlt)

    #-- 5 --
    if sign == '-': alt = -absAlt
    else: alt = absAlt

    #-- 6 --
    return sidereal.AltAz(alt, az)


#================================================================
# Epilogue
#----------------------------------------------------------------