DS9Parser

class regions.DS9Parser(region_string, errors='strict')[source]

Bases: object

Parse a DS9 string

This class transforms a DS9 string to a ShapeList. The result is stored as shapes attribute.

Each line is tested for either containing a region type or a coordinate system. If a coordinate system is found the global coordsys state of the parser is modified. If a region type is found the DS9RegionParser is invokes to transform the line into a Shape object.

Parameters:
region_string : str

DS9 region string

errors : warn, ignore, strict, optional

The error handling scheme to use for handling parsing errors. The default is ‘strict’, which will raise a DS9RegionParserError. warn will raise a DS9RegionParserWarning, and ignore will do nothing (i.e., be silent).

Examples

>>> from regions import DS9Parser
>>> reg_str = 'image\n circle(331.00,1091.00,40.00) # dashlist=8 3 select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 source=1 text={Circle} tag={foo} tag={foo bar} This is a Comment color=pink width=3 font="times 10 normal roman"'
>>> regs = DS9Parser(reg_str, errors='warn').shapes.to_regions()
>>> print(regs[0])
Region: CirclePixelRegion
center: PixCoord(x=330.0, y=1090.0)
radius: 40.0

Attributes Summary

coordinate_systems
coordsys_mapping

Methods Summary

parse_line(self, line) Parse one line
parse_meta(meta_str) Parse the metadata for a single ds9 region string.
parse_region(self, include, region_type, …) Extract a Shape from a region string
run(self) Run all steps
set_coordsys(self, coordsys) Transform coordinate system

Attributes Documentation

coordinate_systems = ['fk5', 'fk4', 'icrs', 'galactic', 'wcs', 'physical', 'image', 'ecliptic', 'J2000', 'wcsa', 'wcsb', 'wcsc', 'wcsd', 'wcse', 'wcsf', 'wcsg', 'wcsh', 'wcsi', 'wcsj', 'wcsk', 'wcsl', 'wcsm', 'wcsn', 'wcso', 'wcsp', 'wcsq', 'wcsr', 'wcss', 'wcst', 'wcsu', 'wcsv', 'wcsw', 'wcsx', 'wcsy', 'wcsz']
coordsys_mapping = {'J2000': 'fk5', 'altaz': 'altaz', 'barycentricmeanecliptic': 'barycentricmeanecliptic', 'barycentrictrueecliptic': 'barycentrictrueecliptic', 'cirs': 'cirs', 'custombarycentricecliptic': 'custombarycentricecliptic', 'ecliptic': 'geocentrictrueecliptic', 'fk4': 'fk4', 'fk4noeterms': 'fk4noeterms', 'fk5': 'fk5', 'galactic': 'galactic', 'galacticlsr': 'galacticlsr', 'galactocentric': 'galactocentric', 'gcrs': 'gcrs', 'geocentricmeanecliptic': 'geocentricmeanecliptic', 'geocentrictrueecliptic': 'geocentrictrueecliptic', 'hcrs': 'hcrs', 'heliocentriceclipticiau76': 'heliocentriceclipticiau76', 'heliocentricmeanecliptic': 'heliocentricmeanecliptic', 'heliocentrictrueecliptic': 'heliocentrictrueecliptic', 'icrs': 'icrs', 'itrs': 'itrs', 'lsr': 'lsr', 'precessedgeocentric': 'precessedgeocentric', 'supergalactic': 'supergalactic'}

Methods Documentation

parse_line(self, line)[source]

Parse one line

static parse_meta(meta_str)[source]

Parse the metadata for a single ds9 region string.

Parameters:
meta_str : str

Meta string, the metadata is everything after the close-paren of the region coordinate specification. All metadata is specified as key=value pairs separated by whitespace, but sometimes the values can also be whitespace separated.

Returns:
meta : OrderedDict

Dictionary containing the meta data

parse_region(self, include, region_type, region_end, line)[source]

Extract a Shape from a region string

run(self)[source]

Run all steps

set_coordsys(self, coordsys)[source]

Transform coordinate system

# TODO: needs expert attention