Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip some characters from STC-S string definitions #5

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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