Esempio n. 1
0
def acs_poly(img_file, coordsys='pixel'):
    """Determine the chip outlines of an ACS FITS image.

    `find_borders` is used to find the borders around all valid data
    pixels, i.e. those not equal to the value of a characteristic non-data
    pixel. The chips are identified as the two border polygons with the
    largest areas, and are returned as a `geoutil.Geoset` in either pixel
    or world coordinates. The image data is assumed to be in the first FITS
    extension.

    Parameters
    ----------
    img_file : str
        Path to the ACS FITS image.
    coordsys : {'pixel', 'WCS'}, optional
        Set the coordinate system of the polygons. Default value is
        'pixel'. If 'WCS', then the coordinates are transformed according
        to the WCS information in the FITS header of the image.

    Returns
    -------
    out : `geoutil.Geoset`
        A `geoutil.Geoset` instance containing the chip outline polygons.

    """
    EXT = 1  # Science data extension for ACS FITS images.

    hdulist = fits.open(img_file)
    img, hdr = hdulist[EXT].data, hdulist[EXT].header

    xrep, yrep = -5, 5  # Representative non-data pixel.
    non_data = img[yrep, xrep]

    boolarr = np.where(img == non_data, False, True)
    poly_list = find_borders(boolarr)

    # Find the largest polygon from the find_borders function:
    area_list = [_area(poly) for poly in poly_list]
    i1, i2 = np.argsort(area_list)[-2:]
    chip1 = poly_list[i1]
    chip1 = geometry.Polygon(chip1.tolist())
    chip1 = geoutil.validate_poly(chip1)
    chip2 = poly_list[i2]
    chip2 = geometry.Polygon(chip2.tolist())
    chip2 = geoutil.validate_poly(chip2)

    # Convert coordinates, if specified:
    if coordsys == 'WCS':
        chip1 = geoutil.poly_pix2world([chip1], hdr)[0]
        chip2 = geoutil.poly_pix2world([chip2], hdr)[0]

    # Build geoset:
    geo1 = geoutil.Geo(chip1, attrs=OrderedDict([('chip', 1)]))
    geo2 = geoutil.Geo(chip2, attrs=OrderedDict([('chip', 2)]))
    item = geoutil.Item([geo1, geo2])
    attrs = OrderedDict([('source', img_file.split('/')[-1]),
                         ('description', 'HST/ACS image outline'),
                         ('coordsys', coordsys)])
    geoset = geoutil.Geoset(item, attrs=attrs, hdr=hdr)
    return geoset
Esempio n. 2
0
def galex_poly(img_file, coordsys='pixel'):
    """Determine the chip outline of a GALEX FITS image.

    `find_borders` is used to find the border polygons around all valid
    data pixels, i.e. those not equal to the value of a characteristic
    non-data pixel. The chip is identified as the border polygon with the
    largest area, and is returned as a `geoutil.Geoset` in either pixel or
    world coordinates. The image data is assumed to be in the primary FITS
    hdu.

    It is highly-recommended to use *rrhr.fits (high-resolution relative
    response) images rather than actual data images. Data images can have
    valid pixels equal to the non-data value, which can make the border
    much more complicated and messy, and thus longer to calculate.

    Parameters
    ----------
    img_file : str
        Path to the GALEX FITS image.
    coordsys : {'pixel', 'WCS'}, optional
        Set the coordinate system of the polygons. Default value is
        'pixel'. If 'WCS', then the coordinates are transformed according
        to the WCS information in the FITS header of the image.

    Returns
    -------
    out : `geoutil.Geoset`
        A `geoutil.Geoset` instance containing the chip outline polygon.

    """
    EXT = 0  # Science data extension for GALEX FITS images

    hdulist = fits.open(img_file)
    img, hdr = hdulist[EXT].data, hdulist[EXT].header

    xrep, yrep = 300, 300  # Representative non-data pixel.
    non_data = img[yrep, xrep]

    boolarr = np.where(img == non_data, False, True)
    poly_list = find_borders(boolarr)

    # Find the largest polygon from the find_borders function:
    area_list = [_area(poly) for poly in poly_list]
    i = np.argmax(area_list)
    chip = poly_list[i]
    chip = geometry.Polygon(chip.tolist())
    chip = geoutil.validate_poly(chip)

    # Convert coordinates, if specified:
    if coordsys == 'WCS':
        chip = geoutil.poly_pix2world([chip], hdr)[0]

    # Build geoset:
    geo = geoutil.Geo(chip)
    item = geoutil.Item(geo)
    attrs = OrderedDict([('source', img_file.split('/')[-1]),
                         ('description', 'GALEX image outline'),
                         ('coordsys', coordsys)])
    geoset = geoutil.Geoset(item, attrs=attrs, hdr=hdr)
    return geoset
Esempio n. 3
0
def wfc3_poly(img_file, coordsys='pixel'):
    """Determine the chip outline of a WFC3 FITS image.

    `find_borders` is used to find the borders around either 1) all pixels
    where the corresponding context ('CTX') image is greater than zero, or,
    2) if a context image is not available, all valid data pixels, i.e.,
    those not equal to the value of a characteristic non-data pixel. The
    chip is identified as the border polygon with the largest area, and is
    returned as a `geoutil.Geoset` in either pixel or world coordinates.
    The image data is assumed to be in the first FITS extension. The
    context image, which is zero where there are no exposures, is assumed
    to be in the third FITS extension.

    Parameters
    ----------
    img_file : str
        Path to the WFC3 FITS image.
    coordsys : {'pixel', 'WCS'}, optional
        Set the coordinate system of the polygons. Default value is
        'pixel'. If 'WCS', then the coordinates are transformed according
        to the WCS information in the FITS header of the image.

    Returns
    -------
    out : `geoutil.Geoset`
        A `geoutil.Geoset` instance containing the chip outline polygon.

    """
    SCIEXT = 1  # Science data extension for WFC3 FITS images
    CTXEXT = 3  # Context data extension for WFC3 FITS images

    hdulist = fits.open(img_file)
    try:
        img, hdr = hdulist[CTXEXT].data, hdulist[SCIEXT].header
        non_data = 0  # Value of non-data pixels in CTX image.
    except IndexError:
        img, hdr = hdulist[SCIEXT].data, hdulist[SCIEXT].header
        xrep, yrep = -5, 5  # Representative non-data pixel.
        non_data = img[yrep, xrep]

    boolarr = np.where(img == non_data, False, True)
    poly_list = find_borders(boolarr)

    # Find the largest polygon from the find_borders function:
    area_list = [_area(poly) for poly in poly_list]
    i = np.argmax(area_list)
    chip = poly_list[i]
    chip = geometry.Polygon(chip.tolist())
    chip = geoutil.validate_poly(chip)

    # Convert coordinates, if specified:
    if coordsys == 'WCS':
        chip = geoutil.poly_pix2world([chip], hdr)[0]

    # Build geoset:
    geo = geoutil.Geo(chip)
    item = geoutil.Item(geo)
    attrs = OrderedDict([('source', img_file.split('/')[-1]),
                         ('description', 'HST/WFC3 image outline'),
                         ('coordsys', coordsys)])
    geoset = geoutil.Geoset(item, attrs=attrs, hdr=hdr)
    return geoset