Commits
Kazuhiko Shimada authored 71a4046c0cb
1 1 | import datetime |
2 2 | import math |
3 3 | import operator |
4 4 | import os |
5 - | from typing import TYPE_CHECKING, Generator, List, Tuple |
5 + | from typing import TYPE_CHECKING, Generator, List, Optional, Tuple |
6 6 | |
7 7 | import matplotlib |
8 8 | import matplotlib.dates as dates |
9 9 | import matplotlib.figure as figure |
10 10 | import matplotlib.pyplot as plt |
11 11 | import matplotlib.ticker as ticker |
12 12 | import numpy as np |
13 13 | |
14 14 | import pipeline.infrastructure as infrastructure |
15 15 | import pipeline.infrastructure.renderer.logger as logger |
1138 1138 | Yields: |
1139 1139 | List of SPW IDs for a tuning, for scan_intent='TARGET'. |
1140 1140 | """ |
1141 1141 | ms = self.inputs.ms |
1142 1142 | request_spws = ms.get_spectral_windows() |
1143 1143 | targeted_scans = ms.get_scans(scan_intent='TARGET') |
1144 1144 | scan_spws = {spw for scan in targeted_scans for spw in scan.spws if spw in request_spws} |
1145 1145 | for spwid_list in utils.get_spectralspec_to_spwid_map(scan_spws).values(): |
1146 1146 | yield spwid_list |
1147 1147 | |
1148 - | def plot(self) -> logger.Plot: |
1148 + | def plot(self) -> Optional[logger.Plot]: |
1149 1149 | """Create the plot. |
1150 1150 | |
1151 1151 | Returns: |
1152 1152 | Plot object |
1153 1153 | """ |
1154 1154 | filename = self.inputs.output |
1155 1155 | if os.path.exists(filename): |
1156 1156 | return self._get_plot_object() |
1157 1157 | ms = self.inputs.ms |
1158 1158 | request_spws = ms.get_spectral_windows() |
1159 1159 | targeted_scans = ms.get_scans(scan_intent='TARGET') |
1160 + | if len(targeted_scans) == 0: |
1161 + | LOG.warning(f'No TARGET scans found in MS {ms.name}. Cannot plot SPW ID vs. Frequency coverage.') # PIPE-2284 |
1162 + | return None |
1160 1163 | antid = 0 |
1161 1164 | if hasattr(ms, 'reference_antenna') and isinstance(ms.reference_antenna, str): |
1162 1165 | antid = ms.get_antenna(search_term=ms.reference_antenna.split(',')[0])[0].id |
1163 1166 | # prepare axes |
1164 1167 | fig = figure.Figure(figsize=(9.6, 7.2)) |
1165 1168 | ax_spw = fig.add_axes([0.1, 0.1, 0.8, 0.8]) |
1166 1169 | bar_height = 0.4 |
1167 1170 | max_spws_to_annotate_VLA = 16 # request for VLA, PIPE-1415. |
1168 1171 | max_spws_to_annotate_ALMA_NRO = np.inf # annotate all spws for ALMA/NRO |
1169 1172 | colorcycle = matplotlib.rcParams['axes.prop_cycle']() |
1192 1195 | bw = float(spwdata.bandwidth.to_units(FrequencyUnits.GIGAHERTZ)) |
1193 1196 | fmin = float(spwdata.min_frequency.to_units(FrequencyUnits.GIGAHERTZ)) |
1194 1197 | xmin, xmax = min(xmin, fmin), max(xmax, fmin+bw) |
1195 1198 | ax_spw.barh(idx, bw, height=bar_height, left=fmin, color=color) |
1196 1199 | |
1197 1200 | # 2. annotate each bars |
1198 1201 | if totalnum_spws <= max_spws_to_annotate or spwid in [spwid_list[0], spwid_list[-1]]: |
1199 1202 | ax_spw.annotate(str(spwid), (fmin + bw/2, idx - bar_height/2), fontsize=14, ha='center', va='bottom') |
1200 1203 | idx += 1 |
1201 1204 | rmin = min(rmin, abs(atmutil.get_spw_spec(vis=ms.name, spw_id=spwid)[2])) |
1202 - | |
1205 + | |
1203 1206 | # 3. Frequency vs. ATM transmission |
1204 1207 | center_freq = (xmin + xmax) / 2.0 |
1205 1208 | # Determining the resolution value so that generates fine ATM transmission curve: it is set |
1206 1209 | # to smaller than 500 kHz but is set to larger than that corresponding to 48001 data points. |
1207 1210 | default_resolution = 5e-4 # To have 5 data points within the ozone feature of 2 MHz FWHM: |
1208 1211 | # 2 MHz/(5-1) = 500 kHz. |
1209 1212 | max_nchan = 48001 # 24 GHz/500 kHz, where 24 GHz covers both sidebands of a 4-12 GHz IF |
1210 1213 | # for a single LO tuning. |
1211 1214 | fspan = xmax - xmin |
1212 1215 | resolution = min(default_resolution, rmin) |