Skip to content

Commit 40907c0

Browse files
e-kochbsipocz
authored andcommitted
Add tests for alma.utils.footprint_to_reg
1 parent 7830888 commit 40907c0

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

astroquery/alma/tests/test_alma_utils.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2+
import pytest
3+
24
import numpy as np
35
from astropy import units as u
6+
from astropy.coordinates import SkyCoord
7+
8+
try:
9+
from regions import CircleSkyRegion, PolygonSkyRegion
10+
11+
HAS_REGIONS = True
12+
except ImportError:
13+
HAS_REGIONS = False
414

515
from .. import utils
616

@@ -22,3 +32,69 @@ def test_parse_frequency_support(frq_sup_str=frq_sup_str, result=franges):
2232
def approximate_primary_beam_sizes(frq_sup_str=frq_sup_str,
2333
beamsizes=beamsizes):
2434
assert np.all(utils.approximate_primary_beam_sizes(frq_sup_str) == beamsizes)
35+
36+
37+
mosaic_footprint_str = '''Polygon ICRS 266.519781 -28.724666 266.524678 -28.731930 266.536683
38+
-28.737784 266.543860 -28.737586 266.549277 -28.733370 266.558133
39+
-28.729545 266.560136 -28.724666 266.558845 -28.719605 266.560133
40+
-28.694332 266.555234 -28.687069 266.543232 -28.681216 266.536058
41+
-28.681414 266.530644 -28.685630 266.521788 -28.689453 266.519784
42+
-28.694332 266.521332 -28.699778'''
43+
44+
@pytest.mark.skipif(not HAS_REGIONS, reason="regions is required")
45+
def test_footprint_to_reg_mosaic(mosaic_footprint_str=mosaic_footprint_str):
46+
47+
48+
pairs = zip(mosaic_footprint_str.split()[2::2], mosaic_footprint_str.split()[3::2])
49+
vertices = [SkyCoord(float(ra) * u.deg, float(dec) * u.deg, frame='icrs')
50+
for ra, dec in pairs]
51+
52+
reg_output = utils.footprint_to_reg(mosaic_footprint_str)
53+
54+
assert len(reg_output) == 1
55+
56+
for vertex in vertices:
57+
assert vertex in reg_output[0].vertices
58+
59+
60+
@pytest.mark.skipif(not HAS_REGIONS, reason="regions is required")
61+
def test_footprint_to_reg_mosaic_multiple(mosaic_footprint_str=mosaic_footprint_str):
62+
63+
multiple_mosaic_footprint_str = f"{mosaic_footprint_str} {mosaic_footprint_str}"
64+
65+
print(multiple_mosaic_footprint_str)
66+
67+
pairs = zip(mosaic_footprint_str.split()[2::2], mosaic_footprint_str.split()[3::2])
68+
vertices = [SkyCoord(float(ra) * u.deg, float(dec) * u.deg, frame='icrs')
69+
for ra, dec in pairs]
70+
71+
reg_output = utils.footprint_to_reg(multiple_mosaic_footprint_str)
72+
73+
assert len(reg_output) == 2
74+
75+
for this_region in reg_output:
76+
77+
for vertex in vertices:
78+
assert vertex in this_region.vertices
79+
80+
81+
pointing_footprint_str = 'Circle ICRS 266.519781 -28.724666 0.01'
82+
83+
@pytest.mark.skipif(not HAS_REGIONS, reason="regions is required")
84+
def test_footprint_to_reg_pointing(pointing_footprint_str=pointing_footprint_str):
85+
86+
ra, dec, rad = pointing_footprint_str.split()[2:]
87+
88+
center = SkyCoord(float(ra) * u.deg, float(dec) * u.deg, frame='icrs')
89+
90+
actual_reg = CircleSkyRegion(center, radius=float(rad) * u.deg)
91+
92+
93+
reg_output = utils.footprint_to_reg(pointing_footprint_str)
94+
95+
assert len(reg_output) == 1
96+
97+
assert actual_reg.center.ra == reg_output[0].center.ra
98+
assert actual_reg.center.dec == reg_output[0].center.dec
99+
assert actual_reg.radius == reg_output[0].radius
100+

0 commit comments

Comments
 (0)