Esempio n. 1
0
def is_bright_source_near(accessor, distance=20):
    """
    Checks if there is any of the bright radio sources defined in targets
    near the center of the image.

    :param accessor: a TKP accessor
    :param distance: maximum allowed distance of a bright source (in degrees)
    :returns: False if not bright source is near, description of source if a
              bright source is near
    """

    #TODO: this function should be split up and tested more atomically
    # The measures object is our interface to casacore
    m = measures()

    # First, you need to set the reference frame -- ie, the time
    # -- used for the calculations to come. Time as MJD in seconds.
    starttime = int(accessor.taustart_ts.strftime("%s"))
    starttime_mjd = unix2julian(starttime)
    m.do_frame(m.epoch("UTC", "%ss" % starttime_mjd))

    # Now check and ensure the ephemeris in use is actually valid for this
    # data.
    if not check_for_valid_ephemeris(m):
        logger.warn("Bright source check failed due to invalid ephemeris")
        return "Invalid ephemeris"

    # Second, you need to set your image pointing.
    pointing = m.direction(
        "J2000", "%sdeg" % accessor.centre_ra,  "%sdeg"  % accessor.centre_decl
    )

    for name, position in targets.items():
        if not position:
            direction = m.direction(name)
        else:
            direction = m.direction(
                "J2000", "%srad" % position['ra'], "%srad" % position['dec']
            )
        separation = m.separation(pointing, direction).get_value("deg")
        if separation < distance:
            return "Pointing is %s degrees from %s." % (separation, name)
    return False
Esempio n. 2
0
def is_bright_source_near(accessor, distance=20):
    """
    Checks if there is any of the bright radio sources defined in targets
    near the center of the image.

    :param accessor: a TKP accessor
    :param distance: maximum allowed distance of a bright source (in degrees)
    :returns: False if not bright source is near, description of source if a
              bright source is near
    """

    #TODO: this function should be split up and tested more atomically
    # The measures object is our interface to casacore
    m = measures()

    # First, you need to set the reference frame -- ie, the time
    # -- used for the calculations to come. Time as MJD in seconds.
    starttime = int(accessor.taustart_ts.strftime("%s"))
    starttime_mjd = unix2julian(starttime)
    m.do_frame(m.epoch("UTC", "%ss" % starttime_mjd))

    # Now check and ensure the ephemeris in use is actually valid for this
    # data.
    if not check_for_valid_ephemeris(m):
        logger.warn("Bright source check failed due to invalid ephemeris")
        return "Invalid ephemeris"

    # Second, you need to set your image pointing.
    pointing = m.direction("J2000", "%sdeg" % accessor.centre_ra,
                           "%sdeg" % accessor.centre_decl)

    for name, position in targets.items():
        if not position:
            direction = m.direction(name)
        else:
            direction = m.direction("J2000", "%srad" % position['ra'],
                                    "%srad" % position['dec'])
        separation = m.separation(pointing, direction).get_value("deg")
        if separation < distance:
            return "Pointing is %s degrees from %s." % (separation, name)
    return False
Esempio n. 3
0
 def test_unix2julian(self):
     self.assertEqual(coordinates.unix2julian(0), coordinates.unix_epoch)