Skip to content

Commit

Permalink
Merge pull request #5 from gbrammer/strip-stcs
Browse files Browse the repository at this point in the history
Strip some characters from STC-S string definitions
  • Loading branch information
gbrammer committed Aug 17, 2023
2 parents 3808f48 + 35b715b commit 5925904
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
19 changes: 17 additions & 2 deletions sregion/sregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def _wrap_xy(xy):
return wxy


def _parse_sregion(sregion, ncircle=32, **kwargs):
def _parse_sregion(sregion, ncircle=32, verbose=False, **kwargs):
"""
Parse an S_REGION string with CIRCLE or POLYGON
Expand All @@ -97,7 +97,22 @@ def _parse_sregion(sregion, ncircle=32, **kwargs):
decoded = sregion.decode('utf-8').strip().upper()
else:
decoded = sregion.strip().upper()


# Strip out prefix for some STS-C regions
for strip_string in ['UNION','ICRS','FK5', 'IMAGE', 'WORLD']:
if (strip_string in decoded) & verbose:
print('Strip {0} from {1}'.format(strip_string, sregion))

decoded = decoded.replace(strip_string, '')

decoded = decoded.strip()
if decoded.startswith('('):
decoded = decoded[1:]

if decoded.endswith(')'):
decoded = decoded[:-1]

decoded = decoded.strip()
polyspl = decoded.replace('POLYGON', 'xxx').replace('CIRCLE', 'xxx')
polyspl = polyspl.split('xxx')

Expand Down
14 changes: 14 additions & 0 deletions sregion/tests/test_sregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ def test_circles():
np.pi*u.deg**2, rtol=1.e-3))


def test_stcs():
"""
Test stripping values from STC-S specified strings
"""
stcs = """Union ICRS ( Polygon 239.807341 -18.296691 239.803564 -18.300277 239.799786 -18.296691 239.803563
-18.293105 Polygon 239.797826 -18.295944 239.794049 -18.299530 239.790272 -18.295944 239.794049
-18.292358)"""

sr = SRegion(stcs, verbose=False)

assert(len(sr.xy) == 2)
assert(np.allclose(sr.area, 2.709e-5, rtol=0.01))


def test_whitespace():
"""
"""
Expand Down

0 comments on commit 5925904

Please sign in to comment.