def selfcalSource( ) : sourceName = SAC.queryString("Control.Subarray1.Source") try : for n in range (1,33) : if ( sourceName == SAC.queryString("Control.SpectralLineCorrelator.Obsblock.ObsObject"+str(n)+".name") ) : return SAC.queryBool("Control.SpectralLineCorrelator.Obsblock.ObsObject"+str(n)+".selfCalibratable") return False except : return False
def makeMpNameLists( ) : config = SAC.queryString("SignalPath.Mapping.Astroband1.confName") mpNameList = [] tsysNameList = [] sb = [".Lsb", ".Usb"] for nsb in range (0,2) : for nband in range(0,8) : for antnum in range (1,16) : nlabel = nband + 1 pol = ".Leftpol" if ( (config == "FULLSTOKES") and (nlabel % 2 == 0) ) : # should add DUALPOL too nlabel = nlabel - 1 pol = ".Rightpol" mpNameList.append( "Astro.Antenna" + str(antnum) + ".Band" + str(nlabel) + pol + sb[nsb] +".Selfcal.Antvis" ) tsysNameList.append( "Astro.Antenna" + str(antnum) + ".Band" + str(nlabel) + pol + sb[nsb] +".Tsys" ) return [ mpNameList, tsysNameList ]
def plotVec( pbCorrectedVis, tsysMatrix, timeString, antList=phasedAnts, nseq=0 ) : hue = ['b','g','r','c','m','y','b','g','r','c','m','y','b','g','r'] vecList = numpy.zeros( [15,17], dtype=complex ) # ... list of (x,y) values, as complex numbers, for each vector, beginning with (0,0) sourceName = SAC.queryString("Control.Subarray1.Source") pylab.ion() pylab.clf() # create vecList for each antenna maxScalarSum = 0. grandScalarSum = 0. grandVectorSum = 0.+0.j for n in range(0,15) : scalarSum = 0. for m in range (0,16) : if (numpy.isnan( pbCorrectedVis[m][n] )) or (numpy.abs( pbCorrectedVis[m][n] ) < 1.e-10 ) : vecList[n][m+1] = vecList[n][m] # if nan or 0, repeat last value else : scalingFactor = math.sqrt(numpy.abs(pbCorrectedVis[m][n]) * jyPerK[n]) * tsysMatrix[m][n] * 16. vecList[n][m+1] = vecList[n][m] + pbCorrectedVis[m][n] / scalingFactor scalarSum += numpy.abs( pbCorrectedVis[m][n] ) / scalingFactor #print "\nvecList for ant %d:" % (n+1) #print numpy.array_str( vecList[n], precision=2, max_line_width=200 ) if (scalarSum > maxScalarSum) : maxScalarSum = scalarSum # ... will be used to set plot scale if (n+1) in antList : grandScalarSum = grandScalarSum + scalarSum grandVectorSum = grandVectorSum + vecList[n][16] # ... will be used to compute overall phasing effic if maxScalarSum < .00001 : maxScalarSum = .00001 pylab.axis( [-1.05*maxScalarSum,1.05*maxScalarSum,-1.05*maxScalarSum,1.05*maxScalarSum] ) # vectorSum = 0.+0.j # scalarSum = 0. for n in range(0,15) : x = numpy.real( vecList[n] ) y = numpy.imag( vecList[n] ) color = 'm' if (n+1) in antList : color = 'r' # vectorSum = vectorSum + vecList[n][16] # scalarSum = scalarSum + numpy.abs( vecList[n][16] ) pylab.plot( x, y, color=color, linestyle='solid', linewidth=4 ) pylab.annotate(str(n+1), [x[15],y[15]] ) pylab.grid(True) pylab.axes().set_aspect('equal') # effic = numpy.abs(vectorSum) / scalarSum effic = numpy.abs(grandVectorSum) / grandScalarSum pylab.text( -.92*maxScalarSum, 0.9*maxScalarSum, timeString, size="x-large" ) pylab.text( 0.6*maxScalarSum, 0.9*maxScalarSum, str(effic)[0:5], size="x-large" ) pylab.text( -.92*maxScalarSum, 0.78*maxScalarSum, sourceName, size="x-large" ) pylab.draw() plotname = "/home/obs/plambeck/vlbi/2013/movie/d%05d.png" % nseq pylab.savefig(plotname) return effic
def refocus( antList, outfile, startNominal=True, apply=False ) : """ Syntax: refocus( antList, outfile, startNominal=True, apply=False ) Performs refocusing on all antennas included in 'antList'. Allows outputting the results to a text file 'outfile'. If startNominal is chosen 'False', the script starts from the most recent focus values (the nominal focus values are fixed, hardcoded numbers for the moment). If apply=False, measurements will be taken (and output), but no changes will be made to the focus of any antenna. Example: refocus([1,2,3,10,15],"refocus-2013-03-19.txt",startNominal=False,apply=True) """ pylab.clf() pylab.ion() outfile="/array/rt/focus/focusCurves" offsets = numpy.array( [ -.9, -.6, -.3, 0., .3, .6, .9 ] ) offsets = numpy.array( [ -3., -2., -1.5, -1., -.5, 0., .5, 1., 1.5, 2.0, 3.0 ] ) timeout = 20. numpy.set_printoptions(precision=2) # for ease in querying focus values and focus status, make list of monitor point names focusNameList = [] focusStatusNameList = [] focusOK = [] ampNameList = [] for ant in antList : if (ant < 7) : focusNameList.append( "Ovro%d.Secondary.zPosition" % ant ) focusStatusNameList.append( "Ovro%d.Secondary.zMovementStatus" % ant ) focusOK.append( 1 ) else : focusNameList.append( "Bima%d.AntennaCommon.Secondary.focusZ" % (ant-6) ) focusStatusNameList.append( "Bima%d.AntennaCommon.Secondary.focusState" % (ant-6) ) focusOK.append( 0 ) ampNameList.append( 'Astro.Antenna%d.MedianAmp' % ant ) focusOK = numpy.array( focusOK ) #print focusNameList #print focusStatusNameList #print ampNameList #print focusOK # save starting focus values for all ants in subarray if startNominal : startFocus = numpy.zeros( len(antList), dtype=float ) j = 0 for ant in antList: startFocus[j] = f0[ant-1] j = j + 1 else : startFocus = numpy.array( SAC.queryMpValues( focusNameList, nothrow=True ) ) print "startfocus : ", startFocus fout=open( outfile, "a" ) fout.write("\n# %s\n" % (time.strftime( "%Y-%b-%d %H:%M", time.gmtime())) ) elev = SAC.queryDouble("Ovro1.AntennaCommon.Drive.Track.actualElevation", 20) fout.write("# elev = %.2f\n" % elev) source = SAC.queryString("Control.Subarray1.source", 20) fout.write("# source = %s\n" % source) lo1 = SAC.queryDouble("Control.Subarray1.loFreq", 20) fout.write("# LO1 = %.2f\n#\n" % lo1) fout.write("# "); for ant in antList : fout.write(" %7d" % ant) fout.write("\n") # now generate array of target focus positions zTarg = numpy.empty( [len(offsets), len(antList)], dtype=float ) amps = numpy.zeros( [len(offsets), len(antList)], dtype=float ) # Preload all focus positions for i in range(0, len(offsets)) : j = 0 for ant in antList: zTarg[i][j] = startFocus[j] + offsets[i] j = j + 1 # now step through the focus ranges, recording selfcal amps for i in range(0, len(offsets)) : j = 0 for ant in antList: #zTarg[i][j] = startFocus[j] + offsets[i] #print "focus %d to %.3f" % (ant, zTarg[i][j]) SAC.focus( None, None, zTarg[i][j], ant ) j = j + 1 print "focus to:", zTarg[i] t0 = time.time() stillTuning = True while ( (time.time() - t0) < timeout) and stillTuning : time.sleep(4.) zState = numpy.array( SAC.queryMpValues( focusStatusNameList, nothrow=True ), dtype=int ) print "waiting for : ", (zState - focusOK) if numpy.array_equiv( zState, focusOK ) : stillTuning = False print "begin integration" SAC.integrate( integTime=10., reps=1 ) time.sleep(1) amps[i] = SAC.queryMpValues( ampNameList, nothrow=True ) print amps ######## Plot amps retrieved so far ########### plotamps(zTarg,amps,antList) ############################################### fout.write(" %5.2f" % offsets[i] ) j = 0 for ant in antList : fout.write(" %7.3f" % amps[i][j] ) j = j + 1 fout.write("\n") bestGaussians = plotamps(zTarg, amps, antList, fitGaussian=True, plotCurves=True, returnSolutions=True) print bestGaussians bestFocus = numpy.zeros( [len(antList)], dtype=float ) fout.write("#\n# orig") j = 0 for ant in antList: fout.write(" %7.3f" % startFocus[j] ) j = j+1 fout.write("\n") fout.write("# gfit") j = 0 for ant in antList: fout.write(" %7.3f" % bestGaussians[j] ) j = j+1 fout.write("\n") fout.write("# best") j = 0 for ant in antList: try: bestFocus[j] = numpy.average( zTarg[:,j], weights=amps[:,j] ) except: print "Cannot average when all weights are zero, leaving focus position alone for antenna " + str(ant) bestFocus[j] = startFocus[j] bestGaussians[j] = startFocus[j] # We now have the weighted average of amplitudes for a best focus estimate, # as well as the gaussian fits. Time to judge the gaussian fits and see if they make sense, # if so: adopt them if not: stick with the weighted average. thresholdFocusChange = 0.7 if (numpy.abs(bestGaussians[j] - startFocus[j]) < thresholdFocusChange): # We'll trust the Gaussian fit bestFocus[j] = bestGaussians[j] else: # Can't trust the Gaussian fit print "FOCUS: Antenna: %2d, Current focus: %2.1f, Gaussian fit: %2.1f" % (float(ant),startFocus[j],bestGaussians[j]) print "FOCUS: Gaussian fit recommends a change in focus above the threshold of %1.1f mm! Not using that value." % thresholdFocusChange if (numpy.abs(bestFocus[j] - startFocus[j]) > thresholdFocusChange): # Weighted average is too far off as well! print "FOCUS: Antenna: %2d, Current focus: %2.1f, Weighted average: %2.1f" % (float(ant),startFocus[j],bestFocus[j]) print "FOCUS: Weighted average focus is also above threshold!" print "FOCUS: Not changing focus." bestFocus[j] = startFocus[j] if (apply == True): SAC.focus( None, None, bestFocus[j], ant ) fout.write(" %7.3f" % bestFocus[j] ) j = j+1 fout.write("\n") fout.write("# chng") j = 0 for ant in antList: if (apply == True): fout.write(" %7.3f" % (bestFocus[j]-startFocus[j]) ) else: fout.write(" %7.3f" % 0.) j = j+1 fout.write("\n\n") fout.close() print "" print "startFocus = ", startFocus print "bestFocus = ", bestFocus print "change = ", (bestFocus-startFocus)