Skip to content

Commit

Permalink
Merge db91572 into 79cc8df
Browse files Browse the repository at this point in the history
  • Loading branch information
sushobhana committed Jun 6, 2018
2 parents 79cc8df + db91572 commit 9f15c5d
Show file tree
Hide file tree
Showing 7 changed files with 476 additions and 244 deletions.
45 changes: 44 additions & 1 deletion regions/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from astropy.extern import six

__all__ = ['Region', 'PixelRegion', 'SkyRegion']
__all__ = ['Region', 'PixelRegion', 'SkyRegion', 'RegionMeta', 'RegionVisual']


"""
Expand Down Expand Up @@ -291,3 +291,46 @@ def to_pixel(self, wcs):
The world coordinate system transformation to assume
"""
raise NotImplementedError


class RegionMeta(dict):
"""
A python dictionary subclass which holds the meta attributes of the region.
"""
valid_keys = ['label', 'symbol', 'include', 'frame', 'range', 'veltype', 'restfreq', 'tag', 'comment', 'coord',
'line', 'name', 'select', 'highlite', 'fixed', 'edit', 'move', 'rotate', 'delete', 'source', 'background',
]

key_mapping = {'point': 'symbol', 'text': 'label'}

def __setitem__(self, key, value):
key = self.key_mapping.get(key, key)
if key in self.valid_keys:
super().__setitem__(key, value)
else:
raise KeyError("{} is not a valid meta key for region.".format(key))

def __getitem__(self, item):
item = self.key_mapping.get(item, item)
return super().__getitem__(item)


class RegionVisual(dict):
"""
A python dictionary subclass which holds the visual attributes of the region.
"""
valid_keys = ['color', 'dash', 'font', 'dashlist', 'symsize', 'symthick', 'fontsize', 'fontstyle', 'usetex',
'labelpos', 'labeloff', 'linewidth', 'linestyle', 'fill', 'line']

key_mapping = {'width': 'linewidth'}

def __setitem__(self, key, value):
key = self.key_mapping.get(key, key)
if key in self.valid_keys :
super().__setitem__(key, value)
else:
raise KeyError("{} is not a valid visual meta key for region.".format(key))

def __getitem__(self, item):
item = self.key_mapping.get(item, item)
return super().__getitem__(item)
Loading

0 comments on commit 9f15c5d

Please sign in to comment.