Commits
36 36 | warnings.filterwarnings("ignore",category=matplotlib.cbook.MatplotlibDeprecationWarning) |
37 37 | |
38 38 | PLOTBANDPASS_REVISION_STRING = "$Id: task_plotbandpass.py,v 1.102 2018/01/21 14:45:41 thunter Exp $" |
39 39 | TOP_MARGIN = 0.25 # Used if showatm=T or showtksy=T |
40 40 | BOTTOM_MARGIN = 0.25 # Used if showfdm=T |
41 41 | MAX_ATM_CALC_CHANNELS = 512 |
42 42 | |
43 43 | markeredgewidth = 0.0 |
44 44 | |
45 45 | # This is a color sequence found online which has distinguishable colors |
46 - | overlayColors = [ |
46 + | overlayColorsSequence = [ |
47 47 | [0.00, 0.00, 0.00], |
48 48 | [0.00, 0.00, 1.00], |
49 49 | [0.00, 0.50, 0.00], |
50 50 | [1.00, 0.00, 0.00], |
51 51 | [0.00, 0.75, 0.75], |
52 52 | # [0.75, 0.00, 0.75], # magenta, same as atmcolor |
53 53 | [0.25, 0.25, 0.25], |
54 54 | [0.75, 0.25, 0.25], |
55 55 | [0.95, 0.95, 0.00], |
56 56 | [0.25, 0.25, 0.75], |
57 57 | # [0.75, 0.75, 0.75], this color is invisible for some reason |
58 58 | [0.00, 1.00, 0.00], |
59 59 | [0.76, 0.57, 0.17], |
60 60 | [0.54, 0.63, 0.22], |
61 61 | [0.34, 0.57, 0.92], |
62 62 | [1.00, 0.10, 0.60], |
63 63 | # [0.88, 0.75, 0.73], invisible |
64 64 | [0.10, 0.49, 0.47], |
65 65 | [0.66, 0.34, 0.65], |
66 66 | [0.99, 0.41, 0.23]] |
67 - | overlayColors += overlayColors + overlayColors # 17*3 = 51 total colors |
68 - | overlayColors += overlayColors + overlayColors # try to support antenna,time |
69 - | overlayColors += overlayColors + overlayColors # try to support antenna,time |
70 - | overlayColors += overlayColors + overlayColors # try to support antenna,time |
71 - | overlayColors += overlayColors + overlayColors # try to support antenna,time |
67 + | overlayColorsList = overlayColorsSequence.copy() |
68 + | overlayColorsList += overlayColorsList + overlayColorsList # 17*3 = 51 total colors |
69 + | overlayColorsList += overlayColorsList + overlayColorsList # try to support antenna,time |
70 + | overlayColorsList += overlayColorsList + overlayColorsList # try to support antenna,time |
71 + | overlayColorsList += overlayColorsList + overlayColorsList # try to support antenna,time |
72 + | overlayColorsList += overlayColorsList + overlayColorsList # try to support antenna,time |
72 73 | |
73 74 | # Enumeration to keep track of plot pages |
74 75 | PAGE_ANT = 0 |
75 76 | PAGE_SPW = 1 |
76 77 | PAGE_TIME = 2 |
77 78 | PAGE_AP = 3 |
78 79 | |
79 80 | # Used to parse command line arguments |
80 81 | myValidCharacterList = ['~', ',', ' ', '*',] + [str(m) for m in range(10)] |
81 82 | myValidCharacterListWithBang = ['~', ',', ' ', '*', '!',] + [str(m) for m in range(10)] |
1901 1902 | # remove spws that do not have any scans to be plotted |
1902 1903 | # but only for tables that have a scan number column, and not filled with all -1 |
1903 1904 | if (tableFormat > 33 and scansForUniqueTimes != []): |
1904 1905 | for myspw in np.unique(cal_desc_id): |
1905 1906 | if (debug): |
1906 1907 | print("scans to plot for spw %d: %s" % (myspw, scansToPlotPerSpw[myspw])) |
1907 1908 | if (scansToPlotPerSpw[myspw] == []): |
1908 1909 | indexDelete = np.where(spwsToPlot==myspw)[0] |
1909 1910 | if (len(indexDelete) > 0): |
1910 1911 | spwsToPlot = np.delete(spwsToPlot, indexDelete[0]) |
1911 - | print(("spwsToPlot = ", spwsToPlot)) |
1912 + | print("spws to plot = ", spwsToPlot) |
1912 1913 | casalogPost(debug,"scans to plot: %s" % (str(scansToPlot))) |
1913 1914 | casalogPost(debug,"UT times to plot: %s" % (timerangeListTimesString)) |
1914 1915 | casalogPost(debug,"Corresponding time IDs (0-based): %s" % (str(timerangeList))) |
1915 1916 | if (len(timerangeListTimes) > len(np.unique(scansToPlot))): |
1916 1917 | # fix for CAS-9474 |
1917 1918 | uniqueScansToPlot, idx = np.unique(scansToPlot, return_index=True) |
1918 1919 | if (len(uniqueScansToPlot) < len(scansToPlot)): |
1919 1920 | # If the solution time for one spw differs by more than solutionTimeThresholdSeconds from |
1920 1921 | # another spw, then we will get 2 identical entries for the same scan, and thus duplicate |
1921 1922 | # plots. So, remove one. |
1922 1923 | if debug: print("Engaging fix for CAS-9474") |
1923 1924 | scansToPlot = uniqueScansToPlot |
1924 1925 | timerangeListTimes = list(np.array(timerangeListTimes)[idx]) |
1925 1926 | timerangeList = list(np.array(timerangeList)[idx]) |
1926 1927 | timerangeListTimesString = mjdsecArrayToUTString(timerangeListTimes) |
1927 1928 | casalogPost(debug,"Revised scans to plot: %s" % (str(scansToPlot))) |
1928 1929 | casalogPost(debug,"Revised UT times to plot: %s" % (timerangeListTimesString)) |
1929 1930 | casalogPost(debug,"Corresponding time IDs (0-based): %s" % (str(timerangeList))) |
1930 - | |
1931 + | |
1932 + | # Reassign overlay colors list if time overlays use a single color |
1933 + | overlayColors = overlayColorsList |
1934 + | if (overlayTimes and not overlayAntennas and len(timerangeList) > 1): |
1935 + | timeOverlayColors = [overlayColors[idx] for idx in timerangeList] |
1936 + | uniqueTimeColors = np.unique(timeOverlayColors) |
1937 + | if (len(uniqueTimeColors) == 1): |
1938 + | # Redo overlay colors list with shift |
1939 + | if debug: print("Shifting overlay colors list to avoid repeats") |
1940 + | shiftOverlayColors = overlayColorsSequence |
1941 + | while len(shiftOverlayColors) <= timerangeList[-1]: |
1942 + | shiftOverlayColors += shiftOverlayColors[1:] |
1943 + | overlayColors = shiftOverlayColors |
1944 + | |
1931 1945 | # Check for mismatch |
1932 1946 | if (bpolyOverlay): |
1933 1947 | if (len(timerangeListTimes) > nUniqueTimesBP): |
1934 1948 | print("There are more timeranges (%d) to plot from %s than exist in the caltable2=%s (%d)" % (len(timerangeListTimes), caltable,caltable2, nUniqueTimesBP)) |
1935 1949 | for i in timerangeList: |
1936 1950 | if (sloppyMatch(timerangeListTimes[i],uniqueTimesBP[0], |
1937 1951 | solutionTimeThresholdSeconds, mytime, |
1938 1952 | scansToPlot, scansForUniqueTimes, myprint=False)): |
1939 1953 | print("Try adding 'timeranges=%d'" % (i+1)) |
1940 1954 | return() |
1941 1955 | if (bpolyOverlay2): |
1942 1956 | if (len(timerangeListTimes) > nUniqueTimesBP2): |
1943 1957 | print("There are more timeranges to plot (%d) from %s than exist in the caltable3=%s (%d)" % (len(timerangeListTimes), caltable, caltable3, nUniqueTimesBP2)) |
1944 1958 | return() |
1945 - | |
1959 + | |
1946 1960 | # Parse the antenna string to emulate plotms |
1947 1961 | if (type(antenna) == str): |
1948 1962 | if (len(antenna) == sum([m in myValidCharacterListWithBang for m in antenna])): |
1949 1963 | # a simple list of antenna numbers was given |
1950 1964 | tokens = antenna.split(',') |
1951 1965 | antlist = [] |
1952 1966 | removeAntenna = [] |
1953 1967 | for token in tokens: |
1954 1968 | if (len(token) > 0): |
1955 1969 | if (token.find('*')==0 and len(token)==1): |
4027 4041 | color=overlayColors[0],size=mysize, transform=pb.gca().transAxes) |
4028 4042 | pdesc = pb.plot([x0-0.01], [y0-0.03*subplotRows], '%sk'%ampmarkstyle2, |
4029 4043 | markersize=markersize, scalex=False,scaley=False,markeredgewidth=markeredgewidth) |
4030 4044 | if (debug): print("3) overlayAntennas=True") |
4031 4045 | if (xframe == firstFrame): |
4032 4046 | # draw title including caltable name |
4033 4047 | if (debug): print("4) overlayAntennas=True") |
4034 4048 | pb.text(xstartTitle, ystartTitle, caltableTitle, size=titlesize, color='k', |
4035 4049 | transform=pb.gcf().transFigure) |
4036 4050 | if (debug): print("5) overlayAntennas=True") |
4037 - | DrawAntennaNames(msAnt, antennasToPlot, msFound, mysize) |
4051 + | DrawAntennaNames(msAnt, antennasToPlot, msFound, mysize, overlayColors) |
4038 4052 | if (debug): print("6) overlayAntennas=True") |
4039 4053 | elif (overlayTimes==True and bOverlay == False |
4040 4054 | and overlayAntennas==False): # try to support antenna,time |
4041 4055 | doneOverlayTime = True # assumed until proven otherwise in the 'for' loop |
4042 4056 | for f in fieldIndicesToPlot: |
4043 4057 | if (len(uniqueTimesPerFieldPerSpw[ispwInCalTable][f]) > 0): |
4044 4058 | if ((uniqueTimes[mytime] < uniqueTimesPerFieldPerSpw[ispwInCalTable][f][-1]-solutionTimeThresholdSeconds) and |
4045 4059 | scansForUniqueTimes[mytime] != scansForUniqueTimes[-1] and # fix for CAS-14096 |
4046 4060 | (uniqueTimes[mytime] < timerangeListTimes[-1])): |
4047 4061 | if (debug): |
4834 4848 | fontsize=mysize, transform=pb.gca().transAxes) |
4835 4849 | else: |
4836 4850 | pb.text(x0+0.02, y0-0.03*subplotRows*1, corrTypeToString(corr_type[1]), color=overlayColors[0], |
4837 4851 | fontsize=mysize, transform=pb.gca().transAxes) |
4838 4852 | pdesc = pb.plot([x0], [y0+0.015*subplotRows-0.03*subplotRows*1],'%sk'%phasemarkstyle2, markersize=markersize, |
4839 4853 | scalex=False,scaley=False, transform=pb.gca().transAxes,markeredgewidth=markeredgewidth) |
4840 4854 | if (xframe == firstFrame): |
4841 4855 | # draw title including caltable name |
4842 4856 | pb.text(xstartTitle, ystartTitle, caltableTitle, size=titlesize, color='k', |
4843 4857 | transform=pb.gcf().transFigure) |
4844 - | DrawAntennaNames(msAnt, antennasToPlot, msFound, mysize) |
4858 + | DrawAntennaNames(msAnt, antennasToPlot, msFound, mysize, overlayColors) |
4845 4859 | elif (overlayTimes==True and bOverlay == False |
4846 4860 | and overlayAntennas==False): # try to support antenna,time |
4847 4861 | doneOverlayTime = True # assumed until proven otherwise in the 'for' loop |
4848 4862 | for f in fieldIndicesToPlot: |
4849 4863 | if (uniqueTimes[mytime] < uniqueTimesPerFieldPerSpw[ispwInCalTable][f][-1]-solutionTimeThresholdSeconds and |
4850 4864 | scansForUniqueTimes[mytime] != scansForUniqueTimes[-1] and # fix for CAS-14096 |
4851 4865 | uniqueTimes[mytime] < timerangeListTimes[-1]): |
4852 4866 | doneOverlayTime = False |
4853 4867 | if (doneOverlayTime): |
4854 4868 | # either it is the last time of any times in solution, or the last time in the list of times to plot |
6253 6267 | regression = False |
6254 6268 | if (regression == False): |
6255 6269 | bottomLegend += ' plotbandpass v' \ |
6256 6270 | + PLOTBANDPASS_REVISION_STRING.split()[2] + ' = ' \ |
6257 6271 | + PLOTBANDPASS_REVISION_STRING.split()[3] + ' ' \ |
6258 6272 | + PLOTBANDPASS_REVISION_STRING.split()[4] |
6259 6273 | # The following should be used going forward, as it is better for long VLA names |
6260 6274 | pb.text(0.04, 0.02, bottomLegend, size=mysize, transform=pb.gcf().transFigure) |
6261 6275 | # pb.text(0.1, 0.02, bottomLegend, size=mysize, transform=pb.gcf().transFigure) |
6262 6276 | |
6263 - | def DrawAntennaNames(msAnt, antennasToPlot, msFound, mysize): |
6277 + | def DrawAntennaNames(msAnt, antennasToPlot, msFound, mysize, overlayColors): |
6264 6278 | for a in range(len(antennasToPlot)): |
6265 6279 | if (msFound): |
6266 6280 | legendString = msAnt[antennasToPlot[a]] |
6267 6281 | else: |
6268 6282 | legendString = str(antennasToPlot[a]) |
6269 6283 | if (a<maxAntennaNamesAcrossTheTop): |
6270 6284 | x0 = xstartTitle+(a*antennaHorizontalSpacing) |
6271 6285 | y0 = ystartOverlayLegend |
6272 6286 | else: |
6273 6287 | # start going down the righthand side |