How to use the regions.io.read_ds9.DS9RegionParserError function in regions

To help you get started, we’ve selected a few regions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github astropy / regions / regions / io / read_ds9.py View on Github external
# Reset iterator for ellipse annulus
            if region_type == 'ellipse':
                language_spec[region_type] = itertools.chain((coordinate, coordinate), itertools.cycle((radius,)))

            return region_type, parsed_return, parsed_meta, composite, include
    else:
        # This will raise warnings even if the first line is acceptable,
        # e.g. something like:
        # # Region file format: DS9 version 4.1
        # That behavior is unfortunate, but there's not a great workaround
        # except to let the user set `errors='ignore'`
        if errors in ('warn', 'strict'):
            message = ("Region type '{0}' was identified, but it is not one of "
                       "the known region types.".format(region_type))
            if errors == 'strict':
                raise DS9RegionParserError(message)
            else:
                warn(message, DS9RegionParserWarning)
github astropy / regions / regions / io / read_ds9.py View on Github external
include = region_type_search.groups()[0]
        region_type = region_type_search.groups()[1]
    else:
        # if there's no line, it's just blank, so don't warn
        if line:
            # but otherwise, this should probably always raise a warning?
            # at least until we identify common cases for it
            warn("No region type found for line '{0}'.".format(line),
                 DS9RegionParserWarning)
        return

    if region_type in coordinate_systems:
        return region_type  # outer loop has to do something with the coordinate system information
    elif region_type in language_spec:
        if coordsys is None:
            raise DS9RegionParserError("No coordinate system specified and a"
                                       " region has been found.")

        if "||" in line:
            composite = True
        else:
            composite = False

        # end_of_region_name is the coordinate of the end of the region's name, e.g.:
        # circle would be 6 because circle is 6 characters
        end_of_region_name = region_type_search.span()[1]
        # coordinate of the # symbol or end of the line (-1) if not found
        hash_or_end = line.find("#")
        coords_etc = strip_paren(line[end_of_region_name:hash_or_end].strip(" |"))
        meta_str = line[hash_or_end:]

        parsed_meta = meta_parser(meta_str)
github astropy / regions / regions / io / read_ds9.py View on Github external
else:
                raise DS9RegionParserError("No central coordinate")
        elif region_type in ('rectangle', 'box'):
            if isinstance(coord_list[0], BaseCoordinateFrame):
                reg = rectangle.RectangleSkyRegion(coord_list[0], coord_list[1], coord_list[2], coord_list[3])
            elif isinstance(coord_list[0], PixCoord):
                reg = rectangle.RectanglePixelRegion(coord_list[0], coord_list[1], coord_list[2], coord_list[3])
            else:
                raise DS9RegionParserError("No central coordinate")
        elif region_type == 'point':
            if isinstance(coord_list[0], BaseCoordinateFrame):
                reg = point.PointSkyRegion(coord_list[0])
            elif isinstance(coord_list[0], PixCoord):
                reg = point.PointPixelRegion(coord_list[0])
            else:
                raise DS9RegionParserError("No central coordinate")
        else:
            # Note: this should effectively never happen, because it would
            # imply that the line_parser found a region that didn't match the
            # above region types.  However, this can help with development,
            # since we could in theory implement more region types in the line
            # parser and forget to add them here.
            warn("Skipping region with coords {0} because its type '{1}'"
                 " is not recognized."
                 .format(str(coord_list), region_type),
                 DS9RegionParserWarning
                 )
            continue
        reg.visual = {key: meta[key] for key in meta.keys() if key in viz_keywords}
        reg.meta = {key: meta[key] for key in meta.keys() if key not in viz_keywords}
        output_list.append(reg)
    return output_list
github astropy / regions / regions / io / read_ds9.py View on Github external
else:
                raise DS9RegionParserError("No central coordinate")
        elif region_type == 'polygon':
            if isinstance(coord_list[0], BaseCoordinateFrame):
                reg = polygon.PolygonSkyRegion(coord_list[0])
            elif isinstance(coord_list[0], PixCoord):
                reg = polygon.PolygonPixelRegion(coord_list[0])
            else:
                raise DS9RegionParserError("No central coordinate")
        elif region_type in ('rectangle', 'box'):
            if isinstance(coord_list[0], BaseCoordinateFrame):
                reg = rectangle.RectangleSkyRegion(coord_list[0], coord_list[1], coord_list[2], coord_list[3])
            elif isinstance(coord_list[0], PixCoord):
                reg = rectangle.RectanglePixelRegion(coord_list[0], coord_list[1], coord_list[2], coord_list[3])
            else:
                raise DS9RegionParserError("No central coordinate")
        elif region_type == 'point':
            if isinstance(coord_list[0], BaseCoordinateFrame):
                reg = point.PointSkyRegion(coord_list[0])
            elif isinstance(coord_list[0], PixCoord):
                reg = point.PointPixelRegion(coord_list[0])
            else:
                raise DS9RegionParserError("No central coordinate")
        else:
            # Note: this should effectively never happen, because it would
            # imply that the line_parser found a region that didn't match the
            # above region types.  However, this can help with development,
            # since we could in theory implement more region types in the line
            # parser and forget to add them here.
            warn("Skipping region with coords {0} because its type '{1}'"
                 " is not recognized."
                 .format(str(coord_list), region_type),