Commits
Vincent Geers authored 44bf07329dc Merge
1 - | """The antenna module defines the Antenna class. |
2 - | """ |
1 + | """The antenna module defines the Antenna class.""" |
3 2 | import pprint |
4 3 | |
5 4 | from pipeline.infrastructure import casa_tools |
6 5 | |
7 6 | _pprinter = pprint.PrettyPrinter() |
8 7 | |
9 8 | |
10 9 | class Antenna(object): |
11 10 | """ |
12 - | Antenna is a logical representation of an antenna. |
13 - | |
14 - | An Antenna has the following properties: |
15 - | |
16 - | .. py:attribute:: id |
17 - | |
18 - | the numerical identifier of this antenna within the ANTENNA subtable |
19 - | of the measurement set |
20 - | |
21 - | .. py:attribute:: name |
22 - | |
23 - | the (potentially empty) name of this antenna |
24 - | |
25 - | .. py:attribute:: longitude |
26 - | |
27 - | the longitude of this antenna |
28 - | |
29 - | .. py:attribute:: latitude |
30 - | |
31 - | the latitude of this antenna |
32 - | |
33 - | .. py:attribute:: height |
34 - | |
35 - | the radial distance of this antenna from the Earth's centre |
36 - | |
37 - | .. py:attribute:: diameter |
38 - | |
39 - | the physical diameter of this antenna |
40 - | |
41 - | .. py:attribute:: direction |
42 - | |
43 - | the J2000 position on the sky to which this antenna points |
11 + | Antenna is a logical representation of an antenna. |
12 + | |
13 + | Attributes: |
14 + | id: The numerical identifier of this antenna within the ANTENNA subtable |
15 + | of the measurement set. |
16 + | name: The (potentially empty) name of the antenna. |
17 + | station: The station pad on which the antenna is situated. |
18 + | diameter: The physical diameter of the antenna in meters. |
19 + | position: Dictionary with longitude, latitude, and height of the antenna. |
20 + | offset: The offset position of the antenna relative to AntennaArray.position |
21 + | (the antenna array reference position). |
22 + | longitude: The longitude of the antenna. |
23 + | latitude: The latitude of the antenna. |
24 + | height: The radial distance of the antenna from the Earth's centre. |
25 + | direction: The J2000 position on the sky to which the antenna points. |
44 26 | """ |
45 - | def __init__(self, antenna_id, name, station, position, offset, diameter): |
27 + | def __init__(self, antenna_id: int, name: str, station: str, position: dict, offset: dict, diameter: float) -> None: |
28 + | """ |
29 + | Initialize an Antenna object. |
30 + | |
31 + | Args: |
32 + | antenna_id: The numerical identifier of the antenna. |
33 + | name: The name of the antenna. |
34 + | station: The station pad on which the antenna is situated. |
35 + | position: Dictionary with longitude, latitude, and height of the antenna. |
36 + | offset: The offset position of the antenna relative to AntennaArray.position |
37 + | (the antenna array reference position). |
38 + | diameter: The physical diameter of the antenna in meters. |
39 + | """ |
46 40 | self.id = antenna_id |
47 41 | |
48 42 | # work around NumPy bug with empty strings |
49 43 | # http://projects.scipy.org/numpy/ticket/1239 |
50 44 | self.name = str(name) |
51 45 | self.station = str(station) |
52 46 | |
53 47 | self.diameter = diameter |
54 48 | self.position = position |
55 49 | self.offset = offset |
56 50 | |
57 51 | # The longitude, latitude and height of a CASA position are given in |
58 52 | # canonical units, so we don't need to perform any further conversion |
59 53 | self.longitude = position['m0'] |
60 54 | self.latitude = position['m1'] |
61 55 | self.height = position['m2'] |
62 56 | |
63 57 | mt = casa_tools.measures |
64 58 | self.direction = mt.direction(v0=self.longitude, v1=self.latitude) |
65 59 | |
66 - | def __repr__(self): |
60 + | def __repr__(self) -> str: |
67 61 | return '{0}({1}, {2!r}, {3!r}, {4}, {5}, {6})'.format( |
68 62 | self.__class__.__name__, |
69 63 | self.id, |
70 64 | self.name, |
71 65 | self.station, |
72 66 | _pprinter.pformat(self.position), |
73 67 | _pprinter.pformat(self.offset), |
74 68 | self.diameter) |
75 69 | |
76 - | def __str__(self): |
70 + | def __str__(self) -> str: |
77 71 | qt = casa_tools.quanta |
78 72 | lon = qt.tos(self.longitude) |
79 73 | lat = qt.tos(self.latitude) |
80 74 | return '<Antenna {id} (lon={lon}, lat={lat})>'.format( |
81 75 | id=self.identifier, lon=lon, lat=lat) |
82 76 | |
83 77 | |
84 - | def identifier(self): |
85 - | ''' |
86 - | A human-readable identifier for this Antenna. |
87 - | ''' |
88 - | return self.name if self.name else '#{0}'.format(self.id) |
89 - | |
78 + | def identifier(self) -> str: |
79 + | """Return a human-readable identifier for this Antenna.""" |
80 + | return self.name if self.name else f"#{self.id}" |