Exemple #1
0
 def parse_coordinates(self):
     """Returns a WCS object"""
     header = self.header
     wcs = WCS()
     try:
         wcs.crval = header["crval1"], header["crval2"]
         wcs.crpix = header["crpix1"] - 1, header["crpix2"] - 1
         wcs.cdelt = header["cdelt1"], header["cdelt2"]
     except KeyError:
         msg = "Coordinate system not specified in FITS"
         logger.error(msg)
         raise TypeError(msg)
     try:
         wcs.ctype = header["ctype1"], header["ctype2"]
     except KeyError:
         wcs.ctype = "unknown", "unknown"
     try:
         wcs.crota = float(header["crota1"]), float(header["crota2"])
     except KeyError:
         wcs.crota = 0.0, 0.0
     try:
         wcs.cunit = header["cunit1"], header["cunit2"]
     except KeyError:
         # The "Definition of the Flexible Image Transport System", version
         # 3.0, tells us that "units for celestial coordinate systems defined
         # in this Standard must be degrees", so we assume that if nothing else
         # is specifiedj
         msg = "WCS units unknown; using degrees"
         logger.warning(msg)
         wcs.cunit = "deg", "deg"
     return wcs
Exemple #2
0
def make_wcs(crval=None, cdelt=None, crpix=None):
    """
    Make a WCS object for insertion into a synthetic image.

    Args:
        crval (tuple): Tuple of (RA, Dec) in decimal degrees at the reference
            position.
        crpix (tuple): Tuple of (x,y) co-ordinates describing the reference
            pixel location corresponding to the crval sky-position.
        cdelt (tuple): Tuple of (cdelt0, cdelt1) in decimal degrees.
            This is the pixel width in degrees of arc, but not necessarily
            aligned to RA, Dec unless `crota` is (0,0). If that *is* the case,
            then typically cdelt0 is negative since the x-axis is in direction
            of West (decreasing RA).

    """
    # For any arguments not set we simply assign an arbitrary valid value:
    if crval is None:
        crval = 100., 45.
    if cdelt is None:
        pixel_width_arcsec = 40
        pixel_width_deg = pixel_width_arcsec / 3600.
        cdelt = (-pixel_width_deg, pixel_width_deg)
    if crpix is None:
        crpix = (256.0, 256.0)
    wcs = WCS()
    wcs.cdelt = cdelt
    wcs.crota = (0.0, 0.0)
    wcs.crpix = crpix
    wcs.crval = crval
    wcs.ctype = ('RA---SIN', 'DEC--SIN')
    wcs.cunit = ('deg', 'deg')
    return wcs
Exemple #3
0
    def setUp(self):
        # An image pointing at the north celestial pole
        self.ncp_image = DummyImage()
        self.ncp_image.wcs = WCS()
        self.ncp_image.wcs.cdelt = (-0.009722222222222, 0.009722222222222)
        self.ncp_image.wcs.crota = (0.0, 0.0)
        self.ncp_image.wcs.crpix = (1025, 1025)  # Pixel position of reference
        self.ncp_image.wcs.crval = (15.0, 90.0
                                    )  # Celestial position of reference
        self.ncp_image.wcs.ctype = ('RA---SIN', 'DEC--SIN')
        self.ncp_image.wcs.cunit = ('deg', 'deg')

        # And an otherwise identical one at the equator
        self.equator_image = DummyImage()
        self.equator_image.wcs = WCS()
        self.equator_image.wcs.cdelt = self.ncp_image.wcs.cdelt
        self.equator_image.wcs.crota = self.ncp_image.wcs.crota
        self.equator_image.wcs.crpix = self.ncp_image.wcs.crpix
        self.equator_image.wcs.crval = (15.0, 0.0
                                        )  # Celestial position of reference
        self.equator_image.wcs.ctype = self.ncp_image.wcs.ctype
        self.equator_image.wcs.cunit = self.ncp_image.wcs.cunit

        self.p = get_paramset()
Exemple #4
0
def parse_coordinates(table):
    """Returns a WCS object"""
    wcs = WCS()
    my_coordinates = table.getkeyword('coords')['direction0']
    wcs.crval = my_coordinates['crval']
    wcs.crpix = my_coordinates['crpix']
    wcs.cdelt = my_coordinates['cdelt']
    ctype = ['unknown', 'unknown']
    # What about other projections?!
    if my_coordinates['projection'] == "SIN":
        if my_coordinates['axes'][0] == "Right Ascension":
            ctype[0] = "RA---SIN"
        if my_coordinates['axes'][1] == "Declination":
            ctype[1] = "DEC--SIN"
    wcs.ctype = tuple(ctype)
    # Rotation, units? We better set a default
    wcs.crota = (0., 0.)
    wcs.cunit = table.getkeyword('coords')['direction0']['units']
    # Update WCS
    wcs.wcsset()
    return wcs
Exemple #5
0
 def parse_coordinates(self):
     """Returns a WCS object"""
     wcs = WCS()
     my_coordinates = self.table.getkeyword('coords')['direction0']
     wcs.crval = my_coordinates['crval']
     wcs.crpix = my_coordinates['crpix']
     wcs.cdelt = my_coordinates['cdelt']
     ctype = ['unknown', 'unknown']
     # What about other projections?!
     if my_coordinates['projection'] == "SIN":
         if my_coordinates['axes'][0] == "Right Ascension":
             ctype[0] = "RA---SIN"
         if my_coordinates['axes'][1] == "Declination":
             ctype[1] = "DEC--SIN"
     wcs.ctype = tuple(ctype)
     # Rotation, units? We better set a default
     wcs.crota = (0., 0.)
     wcs.cunit = self.table.getkeyword('coords')['direction0']['units']
     return wcs
Exemple #6
0
    def test_brightsource(self):
        wcs = WCS()
        wcs.cdelt = (-0.011111111111111112, 0.011111111111111112)
        wcs.crota = (0.0, 0.0)
        wcs.crpix = (256.0, 256.0)
        wcs.crval = (212.83583333333334, 52.2025)
        wcs.ctype = ('RA---SIN', 'DEC--SIN')
        wcs.cunit = ('deg', 'deg')
        image = MockImage(
            {
                "url": "dummy",
                "tau_time": 58141509,
                "taustart_ts": datetime.datetime(2012, 4, 6, 3, 42, 1),
                "centre_ra": 212.83583333333334,
                "centre_decl": 52.2025,
                "freq_eff": 128613281.25,
                "freq_bw": 1940917.96875,
                "beam":
                (1.9211971282958984, 1.7578132629394532, 1.503223674140207)
            }, wcs)

        # this image is not near any bright sources
        result = tkp.quality.brightsource.is_bright_source_near(image)
        self.assertFalse(result)

        # there is nothing bright here
        image.centre_ra = 90
        image.centre_decl = 0
        result = tkp.quality.brightsource.is_bright_source_near(image)
        self.assertFalse(result)

        # this is near the sun
        image.centre_ra = 0
        image.centre_decl = 0
        result = tkp.quality.brightsource.is_bright_source_near(image)
        self.assertTrue(result)

        # this is near CasA
        image._centre_ra = degrees(6.123487680622104)
        image._centre_decl = degrees(1.0265153995604648)
        result = tkp.quality.brightsource.is_bright_source_near(image)
        self.assertTrue(result)
Exemple #7
0
    def test_brightsource(self):
        wcs = WCS()
        wcs.cdelt = (-0.011111111111111112, 0.011111111111111112)
        wcs.crota = (0.0, 0.0)
        wcs.crpix = (256.0, 256.0)
        wcs.crval = (212.83583333333334, 52.2025)
        wcs.ctype = ('RA---SIN', 'DEC--SIN')
        wcs.cunit = ('deg', 'deg')
        image = MockImage(
            {
                "url": "dummy",
                "tau_time": 58141509,
                "taustart_ts": datetime.datetime(2012, 4, 6, 3, 42, 1),
                "centre_ra": 212.83583333333334,
                "centre_decl": 52.2025,
                "freq_eff": 128613281.25,
                "freq_bw": 1940917.96875,
                "beam": (1.9211971282958984, 1.7578132629394532, 1.503223674140207)
            },
            wcs
        )

        # this image is not near any bright sources
        result = tkp.quality.brightsource.is_bright_source_near(image)
        self.assertFalse(result)

        # there is nothing bright here
        image.centre_ra = 90
        image.centre_decl = 0
        result = tkp.quality.brightsource.is_bright_source_near(image)
        self.assertFalse(result)

        # this is near the sun
        image.centre_ra = 0
        image.centre_decl = 0
        result = tkp.quality.brightsource.is_bright_source_near(image)
        self.assertTrue(result)

        # this is near CasA
        image._centre_ra = degrees(6.123487680622104)
        image._centre_decl = degrees(1.0265153995604648)
        result = tkp.quality.brightsource.is_bright_source_near(image)
        self.assertTrue(result)
Exemple #8
0
def make_wcs(crval=None,
             cdelt=None,
             crpix=None
             ):
    """
    Make a WCS object for insertion into a synthetic image.

    Args:
        crval (tuple): Tuple of (RA, Dec) in decimal degrees at the reference
            position.
        crpix (tuple): Tuple of (x,y) co-ordinates describing the reference
            pixel location corresponding to the crval sky-position.
        cdelt (tuple): Tuple of (cdelt0, cdelt1) in decimal degrees.
            This is the pixel width in degrees of arc, but not necessarily
            aligned to RA, Dec unless `crota` is (0,0). If that *is* the case,
            then typically cdelt0 is negative since the x-axis is in direction
            of West (decreasing RA).

    """
    # For any arguments not set we simply assign an arbitrary valid value:
    if crval is None:
        crval = 100., 45.
    if cdelt is None:
        pixel_width_arcsec = 40
        pixel_width_deg = pixel_width_arcsec / 3600.
        cdelt = (-pixel_width_deg, pixel_width_deg)
    if crpix is None:
        crpix = (256.0, 256.0)
    wcs = WCS()
    wcs.cdelt = cdelt
    wcs.crota = (0.0, 0.0)
    wcs.crpix = crpix
    wcs.crval = crval
    wcs.ctype = ('RA---SIN', 'DEC--SIN')
    wcs.cunit = ('deg', 'deg')
    return wcs
Exemple #9
0
 def parse_coordinates(self):
     """Returns a WCS object"""
     header = self.header
     wcs = WCS()
     try:
         wcs.crval = header['crval1'], header['crval2']
         wcs.crpix = header['crpix1'] - 1, header['crpix2'] - 1
         wcs.cdelt = header['cdelt1'], header['cdelt2']
     except KeyError:
         msg = "Coordinate system not specified in FITS"
         logger.error(msg)
         raise TypeError(msg)
     try:
         wcs.ctype = header['ctype1'], header['ctype2']
     except KeyError:
         wcs.ctype = 'unknown', 'unknown'
     try:
         wcs.crota = float(header['crota1']), float(header['crota2'])
     except KeyError:
         wcs.crota = 0., 0.
     try:
         wcs.cunit = header['cunit1'], header['cunit2']
     except KeyError:
         # The "Definition of the Flexible Image Transport System", version
         # 3.0, tells us that "units for celestial coordinate systems defined
         # in this Standard must be degrees", so we assume that if nothing else
         # is specifiedj
         msg = "WCS units unknown; using degrees"
         logger.warning(msg)
         wcs.cunit = 'deg', 'deg'
     return wcs
Exemple #10
0
def parse_coordinates(header):
    """Returns a WCS object"""
    wcs = WCS()
    try:
        wcs.crval = header['crval1'], header['crval2']
        wcs.crpix = header['crpix1'], header['crpix2']
        wcs.cdelt = header['cdelt1'], header['cdelt2']
    except KeyError:
        logger.warn("Coordinate system not specified in FITS")
        raise
    try:
        wcs.ctype = header['ctype1'], header['ctype2']
    except KeyError:
        wcs.ctype = 'unknown', 'unknown'
    try:
        wcs.crota = float(header['crota1']), float(header['crota2'])
    except KeyError:
        wcs.crota = 0., 0.
    try:
        wcs.cunit = header['cunit1'], header['cunit2']
    except KeyError:
        # Blank values default to degrees.
        logger.warning("WCS units unknown; using defaults")
        wcs.cunit = '', ''

    wcs.wcsset()
    return wcs