Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joleroi committed May 18, 2017
1 parent 46a0743 commit f5fc5d9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions regions/io/ds9/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ def parse_line(self, line):
"the known region types.".format(region_type))
return
else:
# Found region specification
self.parse_region(include, region_type, line)
# Found region specification,
region_end = region_type_search.span()[1]
self.parse_region(region_type, region_end, line)

def _raise_error(self, msg):
if self.errors == 'warn':
Expand Down Expand Up @@ -264,13 +265,13 @@ def parse_meta(meta_str):

return result

def parse_region(self, include, region_type, line):
def parse_region(self, region_type, region_end, line):
"""Extract a Shape from a region string"""
if self.coordsys is None:
raise DS9RegionParserError("No coordinate system specified and a"
" region has been found.")
else:
helper = DS9RegionParser(self.coordsys, region_type,
helper = DS9RegionParser(self.coordsys, region_type, region_end,
self.global_meta, line)
helper.parse()
self.shapes.append(helper.shape)
Expand All @@ -293,10 +294,11 @@ class DS9RegionParser(object):
----------
coordsys : str
Coordinate system
include : str {'', '-'}
Flag at the beginning of the line
region_type : str
Region type
region_end : int
Coordinate of the end of the regions name, this is passed in order to
handle whitespaces correctly
global_meta : dict
Global meta data
line : str
Expand Down Expand Up @@ -328,10 +330,11 @@ class DS9RegionParser(object):
}
"""DS9 language specification. This defines how a certain region is read"""

def __init__(self, coordsys, region_type, global_meta, line):
def __init__(self, coordsys, region_type, region_end, global_meta, line):

self.coordsys = coordsys
self.region_type = region_type
self.region_end = region_end
self.global_meta = global_meta
self.line = line

Expand All @@ -346,6 +349,7 @@ def __init__(self, coordsys, region_type, global_meta, line):
def __str__(self):
ss = self.__class__.__name__
ss += '\nLine : {}'.format(self.line)
ss += '\nRegion end : {}'.format(self.region_end)
ss += '\nMeta string : {}'.format(self.meta_str)
ss += '\nCoord string: {}'.format(self.coord_str)
ss += '\nShape: {}'.format(self.shape)
Expand Down Expand Up @@ -377,12 +381,9 @@ def parse_include(self):

def split_line(self):
"""Split line into coordinates and meta string"""
end_of_region_name = len(self.region_type)
if not self.include:
end_of_region_name += 1
# coordinate of the # symbol or end of the line (-1) if not found
hash_or_end = self.line.find("#")
temp = self.line[end_of_region_name:hash_or_end].strip(" |")
temp = self.line[self.region_end:hash_or_end].strip(" |")
self.coord_str = regex_paren.sub("", temp)
self.meta_str = self.line[hash_or_end:]

Expand Down

0 comments on commit f5fc5d9

Please sign in to comment.