CRTFParser

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

Bases: object

Parses a CRTF string.

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

Each line is tested for either containing a region with meta attributes or global parameters. If global parameters are found then, it is stored in the global_meta attribute. If a region is found the CRTFRegionParser is invoked to transform the line into a Shape object.

Parameters:
region_string : str

CRTF 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 CRTFRegionParserError. warn will raise a CRTFRegionParserWarning, and ignore will do nothing (i.e., be silent).

Examples

>>> from regions import CRTFParser
>>> reg_str = "ann circle[[18h12m24s, -23d11m00s], 2.3arcsec], coord=B1950, frame=BARY, corr=[I, Q], color=blue"
>>> regs = CRTFParser(reg_str, errors='warn').shapes.to_regions()
>>> print(regs[0].visual)
{'color': 'blue'}

Attributes Summary

valid_definition
valid_global_keys

Methods Summary

parse_global_meta(self, global_meta_str) Parses the line starting with global to extract all the valid meta key/value pair.
parse_line(self, line) Parses a single line.
run(self) Run all the steps.

Attributes Documentation

valid_definition = ('box', 'centerbox', 'rotbox', 'poly', 'circle', 'annulus', 'ellipse', 'line', 'vector', 'text', 'symbol')
valid_global_keys = ('coord', 'frame', 'corr', 'veltype', 'restfreq', 'linewidth', 'linestyle', 'symsize', 'symthick', 'color', 'font', 'fontsize', 'fontstyle', 'usetex', 'labelpos', 'labelcolor', 'labeloff', 'range')

Methods Documentation

parse_global_meta(self, global_meta_str)[source]

Parses the line starting with global to extract all the valid meta key/value pair.

parse_line(self, line)[source]

Parses a single line.

run(self)[source]

Run all the steps. Splits the regions into line and calls parse_line for each line.