Commits
Darrell Schiebel authored 2769f8946dd
2321 2321 | if (nPolarizations == 1): |
2322 2322 | pb.plot(frequenciesGHz[index], amplitudeSolutionX, '%s%s'%(xcolor,bpolymarkstyle),markeredgewidth=markeredgewidth) |
2323 2323 | else: |
2324 2324 | pb.plot(frequenciesGHz[index], amplitudeSolutionX, '%s%s'%(xcolor,bpolymarkstyle), frequenciesGHz[index], amplitudeSolutionY, '%s%s'%(ycolor,bpolymarkstyle),markeredgewidth=markeredgewidth) |
2325 2325 | if (plotrange[0] != 0 or plotrange[1] != 0): |
2326 2326 | SetNewXLimits([plotrange[0],plotrange[1]]) |
2327 2327 | if (plotrange[2] != 0 or plotrange[3] != 0): |
2328 2328 | SetNewYLimits([plotrange[2],plotrange[3]]) |
2329 2329 | xlim=pb.xlim() |
2330 2330 | ylim=pb.ylim() |
2331 - | ResizeFonts(adesc,mysize) |
2332 - | adesc.xaxis.grid(True,which='major') |
2333 - | adesc.yaxis.grid(True,which='major') |
2331 + | ResizeFontsSetGrid(adesc,mysize) |
2334 2332 | if (yaxis.lower().find('db')>=0): |
2335 2333 | pb.ylabel('Amplitude (dB)', size=mysize) |
2336 2334 | else: |
2337 2335 | pb.ylabel('Amplitude', size=mysize) |
2338 2336 | pb.xlabel('Frequency (GHz)', size=mysize) |
2339 2337 | if (xframe == firstFrame): |
2340 2338 | DrawBottomLegendPageCoords(msName, uniqueTimes[mytime], mysize, figfile) |
2341 2339 | pb.text(xstartTitle, ystartTitle, |
2342 2340 | '%s (degamp=%d, degphase=%d)'%(caltableTitle,nPolyAmp[index]-1, |
2343 2341 | nPolyPhase[index]-1),size=mysize, |
2402 2400 | uniqueFields[fieldIndex],fieldString,timeString), size=titlesize) |
2403 2401 | else: |
2404 2402 | pb.title("%sspw%2d (%d), field %d: %s%s" % (antennaString,ispw,originalSpw[ispw], |
2405 2403 | uniqueFields[fieldIndex],fieldString,timeString), size=titlesize) |
2406 2404 | phaseSolutionX = calcChebyshev(polynomialPhase[index][0:nPolyPhase[index]], validDomain, frequenciesGHz[index]*1e+9) * 180/math.pi |
2407 2405 | phaseSolutionY = calcChebyshev(polynomialPhase[index][nPolyPhase[index]:2*nPolyPhase[index]], validDomain, frequenciesGHz[index]*1e+9) * 180/math.pi |
2408 2406 | if (nPolarizations == 1): |
2409 2407 | pb.plot(frequenciesGHz[index], phaseSolutionX, '%s%s'%(xcolor,bpolymarkstyle),markeredgewidth=markeredgewidth) |
2410 2408 | else: |
2411 2409 | pb.plot(frequenciesGHz[index], phaseSolutionX, '%s%s'%(xcolor,bpolymarkstyle), frequenciesGHz[index], phaseSolutionY, '%s%s'%(ycolor,bpolymarkstyle),markeredgewidth=markeredgewidth) |
2412 - | ResizeFonts(adesc,mysize) |
2413 - | adesc.xaxis.grid(True,which='major') |
2414 - | adesc.yaxis.grid(True,which='major') |
2410 + | ResizeFontsSetGrid(adesc,mysize) |
2415 2411 | pb.ylabel('Phase (deg)', size=mysize) |
2416 2412 | pb.xlabel('Frequency (GHz)', size=mysize) |
2417 2413 | if (plotrange[0] != 0 or plotrange[1] != 0): |
2418 2414 | SetNewXLimits([plotrange[0],plotrange[1]]) |
2419 2415 | if (plotrange[2] != 0 or plotrange[3] != 0): |
2420 2416 | SetNewYLimits([plotrange[2],plotrange[3]]) |
2421 2417 | if (amplitudeWithPhase and phase != ''): |
2422 2418 | if (phase[0] != 0 or phase[1] != 0): |
2423 2419 | SetNewYLimits(phase) |
2424 2420 | if (xframe == firstFrame): |
3311 3307 | # mytime, scansToPlot, scansForUniqueTimes, # task version |
3312 3308 | mytime, scansToPlotPerSpw[ispw], scansForUniqueTimes, # au version |
3313 3309 | myprint=debugSloppyMatch |
3314 3310 | ) |
3315 3311 | if (sm): |
3316 3312 | if (debug): |
3317 3313 | print("1)setting myUniqueTime to %d" % (mytime)) |
3318 3314 | myUniqueTime = mytime |
3319 3315 | ctr += 1 |
3320 3316 | if (ctr > len(fieldIndicesToPlot) and bOverlay==False): |
3321 - | print("multi-field time overlay *************** why are there 2 matches?") |
3317 + | if (debug): print("multi-field time overlay *************** why are there 2 matches?") |
3322 3318 | # # # # if (ctr == 0): |
3323 3319 | # # # # print("No match for %.1f in "%(t), uTPFPS) |
3324 3320 | |
3325 3321 | # # # # print("Overlay antenna %d, myUniqueTime=%d" % (xctr, myUniqueTime)) |
3326 3322 | if (xframe == xframeStart): |
3327 3323 | safe_pb_clf() |
3328 3324 | xflag = [item for sublist in xflag for item in sublist] |
3329 3325 | yflag = [item for sublist in yflag for item in sublist] |
3330 3326 | # # pflag = [xflag, yflag] |
3331 3327 | # # flagfrequencies = [frequencies, frequencies2] |
4041 4037 | else: |
4042 4038 | SetNewXLimits([frequencies[0], frequencies[-1]],8) |
4043 4039 | if (bOverlay): |
4044 4040 | if (xrange2 > myxrange+0.1 and zoom != 'intersect'): |
4045 4041 | TDMisSecond = True |
4046 4042 | if (abs(plotrange[2]) > 0 or abs(plotrange[3]) > 0): |
4047 4043 | SetNewYLimits([plotrange[2],plotrange[3]]) |
4048 4044 | |
4049 4045 | xlim = pb.xlim() |
4050 4046 | ylim = pb.ylim() |
4051 - | ResizeFonts(adesc,mysize) |
4052 - | adesc.xaxis.grid(True,which='major') |
4053 - | adesc.yaxis.grid(True,which='major') |
4047 + | ResizeFontsSetGrid(adesc,mysize) |
4054 4048 | pb.ylabel(yAmplitudeLabel, size=mysize) |
4055 4049 | pb.subplots_adjust(hspace=myhspace, wspace=mywspace) |
4056 4050 | myxrange = xlim[1]-xlim[0] |
4057 4051 | yrange = ylim[1]-ylim[0] |
4058 4052 | if (debug): print(("amp: ylim, yrange = ", ylim, yrange)) |
4059 4053 | if (overlayAntennas == False and overlayTimes == False and bOverlay == False and |
4060 4054 | ((overlaySpws == False and overlayBasebands == False) or spwctr==spwctrFirstToPlot)): |
4061 4055 | # draw polarization labels for no overlay |
4062 4056 | x0 = xstartPolLabel |
4063 4057 | y0 = ystartPolLabel |
4814 4808 | |
4815 4809 | (y0,y1) = pb.ylim() |
4816 4810 | if (y1-y0 < minPhaseRange): |
4817 4811 | # this must come before defining ticks |
4818 4812 | SetNewYLimits([-minPhaseRange,minPhaseRange]) |
4819 4813 | SetNewYLimits(newylimits) # added 10/2/2012 for the case of only 1 data point |
4820 4814 | if (amplitudeWithPhase and phase != ''): |
4821 4815 | if (phase[0] != 0 or phase[1] != 0): |
4822 4816 | SetNewYLimits(phase) |
4823 4817 | (y0,y1) = pb.ylim() |
4824 - | ResizeFonts(adesc,mysize) |
4825 - | adesc.xaxis.grid(True,which='major') |
4826 - | adesc.yaxis.grid(True,which='major') |
4818 + | ResizeFontsSetGrid(adesc,mysize) |
4827 4819 | pb.ylabel(yPhaseLabel, size=mysize) |
4828 4820 | pb.subplots_adjust(hspace=myhspace, wspace=mywspace) |
4829 4821 | ylim = pb.ylim() |
4830 4822 | xlim = pb.xlim() |
4831 4823 | myxrange = xlim[1]-xlim[0] |
4832 4824 | yrange = ylim[1]-ylim[0] |
4833 4825 | # # # # print("phase: ylim, yrange = ", ylim, yrange) |
4834 4826 | myap = 0 |
4835 4827 | if (overlayAntennas == False and overlayTimes == False and bOverlay == False and |
4836 4828 | ((overlaySpws == False and overlayBasebands == False) or spwctr==spwctrFirstToPlot)): |
5531 5523 | v += coeff[7] * (64*x**7 -112*x**5 + 56*x**3 - 7*x) |
5532 5524 | if (len(coeff) > 8): |
5533 5525 | v += coeff[8] * (128*x**8 -256*x**6 +160*x**5 - 32*x**2 + 1) |
5534 5526 | if (len(coeff) > 9): |
5535 5527 | v += coeff[9] * (256*x**9 -576*x**7 +432*x**5 - 120*x**3 + 9*x) |
5536 5528 | if (len(coeff) > 10): |
5537 5529 | print("Chebyshev polynomials with degree > 10 are not implemented") |
5538 5530 | |
5539 5531 | return(v) |
5540 5532 | |
5541 - | def ResizeFonts(adesc,fontsize): |
5542 - | # print("Called ResizeFonts()") |
5533 + | def ResizeFontsSetGrid(adesc,fontsize): |
5534 + | # print("Called ResizeFontsSetGrid()") |
5543 5535 | yFormat = ScalarFormatter(useOffset=False) |
5544 - | adesc.yaxis.set_major_formatter(yFormat) |
5545 - | adesc.xaxis.set_major_formatter(yFormat) |
5546 - | pb.setp(adesc.get_xticklabels(), fontsize=fontsize) |
5547 - | pb.setp(adesc.get_yticklabels(), fontsize=fontsize) |
5536 + | if adesc: |
5537 + | adesc.yaxis.set_major_formatter(yFormat) |
5538 + | adesc.xaxis.set_major_formatter(yFormat) |
5539 + | pb.setp(adesc.get_xticklabels(), fontsize=fontsize) |
5540 + | pb.setp(adesc.get_yticklabels(), fontsize=fontsize) |
5541 + | adesc.xaxis.grid(True,which='major') |
5542 + | adesc.yaxis.grid(True,which='major') |
5548 5543 | |
5549 5544 | def complexMeanRad(phases): |
5550 5545 | # convert back to real and imaginary, take mean, then convert back to phase |
5551 5546 | meanSin = np.mean(np.sin(phases)) |
5552 5547 | meanCos = np.mean(np.cos(phases)) |
5553 5548 | return(180*np.arctan2(meanSin, meanCos)/math.pi) |
5554 5549 | |
5555 5550 | def complexMeanDeg(phases): |
5556 5551 | # convert back to real and imaginary, take mean, then convert back to phase |
5557 5552 | phases *= math.pi/180 |
6035 6030 | mymatch = i |
6036 6031 | if (matched == False and myprint==True): |
6037 6032 | print("sloppyMatch: %.0f is not within %.0f of anything in %s" % (newvalue,threshold, str([int(round(b)) for b in mylist]))) |
6038 6033 | elif (myprint==True): |
6039 6034 | print("sloppyMatch: %.0f is within %.0f of something in %s" % (newvalue,threshold, str([int(round(b)) for b in mylist]))) |
6040 6035 | if (whichone == False): |
6041 6036 | return(matched) |
6042 6037 | else: |
6043 6038 | return(matched,mymatch) |
6044 6039 | |
6045 - | def sloppyUniqueOLD(t, thresholdSeconds): |
6046 - | """ |
6047 - | Takes a list of numbers and returns a list of unique values, subject to a threshold difference. |
6048 - | """ |
6049 - | # start with the first entry, and only add a new entry if it is more than the threshold from prior |
6050 - | sloppyList = [t[0]] |
6051 - | for i in range(1,len(t)): |
6052 - | keepit = True |
6053 - | for uniqueValue in sloppyList: |
6054 - | if (abs(t[i] - uniqueValue) < thresholdSeconds): |
6055 - | keepit = False |
6056 - | if (keepit): |
6057 - | sloppyList.append(t[i]) |
6058 - | # print("sloppyUnique returns %d values from the original %d" % (len(sloppyList), len(t))) |
6059 - | return(sloppyList) |
6060 - | |
6061 6040 | def sloppyUnique(t, thresholdSeconds): |
6062 6041 | """ |
6063 6042 | Takes a list of numbers and returns a list of unique values, subject to a threshold difference. |
6064 6043 | """ |
6065 6044 | # start with the first entry, and only add a new entry if it is more than the threshold from prior |
6066 - | BANNER = f'''sloppyUnique( {repr(t)}, {thresholdSeconds} )''' |
6067 - | ORIG_t = copy.deepcopy(t) |
6068 - | ORIG_thresh = copy.deepcopy(thresholdSeconds) |
6069 6045 | sloppyList = [t[0]] |
6070 6046 | for i in range(1,len(t)): |
6071 6047 | keepit = True |
6072 6048 | for j in range(0,i): |
6073 6049 | if (abs(t[i]-t[j]) < thresholdSeconds): |
6074 6050 | keepit = False |
6075 6051 | if (keepit): |
6076 6052 | sloppyList.append(t[i]) |
6077 6053 | # print("sloppyUnique returns %d values from the original %d" % (len(sloppyList), len(t))) |
6078 - | casalogPost( True, BANNER + f'''\n>>>>---->> NEW: {repr(sloppyList)}\nOLD: {repr(sloppyUniqueOLD(ORIG_t,ORIG_thresh))}''' ) |
6079 6054 | return(sloppyList) |
6080 6055 | |
6081 6056 | def SetLimits(plotrange, chanrange, newylimits, channels, frequencies, pfrequencies, |
6082 6057 | ampMin, ampMax, xaxis, pxl, chanrangeSetXrange, chanrangePercent=None): |
6083 6058 | """ |
6084 6059 | This is the place where chanrange actually takes effect. |
6085 6060 | """ |
6086 6061 | if (abs(plotrange[0]) > 0 or abs(plotrange[1]) > 0): |
6087 6062 | SetNewXLimits([plotrange[0],plotrange[1]]) |
6088 6063 | if (plotrange[2] == 0 and plotrange[3] == 0): |