1
1
# Licensed under a 3-clause BSD style license - see LICENSE.rst
2
+ import pytest
3
+
2
4
import numpy as np
3
5
from astropy import units as u
6
+ from astropy .coordinates import SkyCoord
7
+
8
+ try :
9
+ from regions import CircleSkyRegion
10
+
11
+ HAS_REGIONS = True
12
+ except ImportError :
13
+ HAS_REGIONS = False
4
14
5
15
from .. import utils
6
16
@@ -22,3 +32,68 @@ def test_parse_frequency_support(frq_sup_str=frq_sup_str, result=franges):
22
32
def approximate_primary_beam_sizes (frq_sup_str = frq_sup_str ,
23
33
beamsizes = beamsizes ):
24
34
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
+
45
+ @pytest .mark .skipif (not HAS_REGIONS , reason = "regions is required" )
46
+ def test_footprint_to_reg_mosaic (mosaic_footprint_str = mosaic_footprint_str ):
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
+
84
+ @pytest .mark .skipif (not HAS_REGIONS , reason = "regions is required" )
85
+ def test_footprint_to_reg_pointing (pointing_footprint_str = pointing_footprint_str ):
86
+
87
+ ra , dec , rad = pointing_footprint_str .split ()[2 :]
88
+
89
+ center = SkyCoord (float (ra ) * u .deg , float (dec ) * u .deg , frame = 'icrs' )
90
+
91
+ actual_reg = CircleSkyRegion (center , radius = float (rad ) * u .deg )
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
0 commit comments