示例#1
0
def fitall(proc,plot=False,pp=None):
    ''' Fits SOLPNT data for all antennas contained in 
        processed data proc, returned from process_solpnt()
        Prints results to terminal and optionally plots
        the gaussian fits.  It also returns the fitted offsets. 
        If pp is provided and is not None, the plots are
        written to a multipage PDF file.
    '''
    t = util.Time(proc['Timestamp'],format='lv')
    nant = len(proc['antlist'])

    if plot:
        # row and column sharing
        f, ax = plt.subplots(7, 2, sharex='col', sharey='row')
        f.set_size_inches(10,14,forward=True)
        f.suptitle('Fits for SOLPNT scan at '+t.iso+' UT',fontsize=18)
        ax[0,0].set_title('RA Offset [blue=HPol, red=VPol]')
        ax[0,1].set_title('Dec Offset [blue=HPol, red=VPol]')

    # Temporary statement to make this work with no more than 7 antennas.
    if nant > 7: nant = 7
    raoh =  np.zeros(nant,dtype='float')
    decoh = np.zeros(nant,dtype='float')
    raov =  np.zeros(nant,dtype='float')
    decov = np.zeros(nant,dtype='float')
    xeloh = np.zeros(nant,dtype='float')
    xelov = np.zeros(nant,dtype='float')
    eloh =  np.zeros(nant,dtype='float')
    elov =  np.zeros(nant,dtype='float')
    print 'SOLPNT solution for',t.iso
    print 'Ant       XELO (deg)             ELO (deg)'
    print '      HPol   VPol   Avg      HPol   VPol   Avg'
    print '---- ------ ------ ------   ------ ------ ------'
    for i in range(nant):
        ant = proc['antlist'][i]
        [A, hrao, w, b], x, y = gausfit(proc['rao'],proc['hrao'][i,:])
        if plot: ax[i,0].plot(x,y,proc['rao'],proc['hrao'][i,:],'o',label='Hpol')
        [A, vrao, w, b], x, y = gausfit(proc['rao'],proc['vrao'][i,:])
        if plot: 
            ax[i,0].plot(x,y,proc['rao'],proc['vrao'][i,:],'o',label='VPol')
            ax[i,0].text(0.05,0.8,'Ant '+str(ant+1),transform=ax[i,0].transAxes,fontsize=14)
            ax[i,0].text(0.05,0.65,'H = {:6.3f}'.format(hrao/10000.),transform=ax[i,0].transAxes)
            ax[i,0].text(0.05,0.5,'V = {:6.3f}'.format(vrao/10000.),transform=ax[i,0].transAxes)
        [A, hdeco, w, b], x, y = gausfit(proc['deco'],proc['hdeco'][i,:])
        if plot: ax[i,1].plot(x,y,proc['deco'],proc['hdeco'][i,:],'o',label='HPol')
        [A, vdeco, w, b], x, y = gausfit(proc['deco'],proc['vdeco'][i,:])
        if plot: 
            ax[i,1].plot(x,y,proc['deco'],proc['vdeco'][i,:],'o',label='VPol')
            ax[i,1].text(0.05,0.8,'Ant '+str(ant+1),transform=ax[i,1].transAxes,fontsize=14)
            ax[i,1].text(0.05,0.65,'H = {:6.3f}'.format(hdeco/10000.),transform=ax[i,1].transAxes)
            ax[i,1].text(0.05,0.5,'V = {:6.3f}'.format(vdeco/10000.),transform=ax[i,1].transAxes)
        if sys.platform[:5] == 'linux':
            # Convert rao, deco to azo, elo (returned in radians)
            cosdec = np.cos(proc['dec0'])
            hxelo, helo = dradec2dazel(proc['ra0'],proc['dec0'],
                                      t,hrao*np.pi/10000./180./cosdec,hdeco*np.pi/10000./180.)
            vxelo, velo = dradec2dazel(proc['ra0'],proc['dec0'],
                                      t,vrao*np.pi/10000./180./cosdec,vdeco*np.pi/10000./180.)
        else:
            hxelo, helo = hrao*np.pi/10000./180., hdeco*np.pi/10000./180.
            vxelo, velo = vrao*np.pi/10000./180., vdeco*np.pi/10000./180. 
        # Print table of XEL and EL offsets as degrees
        print ' {:2d} {:6.3f} {:6.3f} {:6.3f}   {:6.3f} {:6.3f} {:6.3f}'.format(
               proc['antlist'][i]+1, hxelo*180./np.pi, vxelo*180./np.pi,(hxelo + vxelo)*180./np.pi/2.,
                                     helo*180./np.pi,velo*180./np.pi,(helo+velo)*180./np.pi/2.)
        if plot: 
            ax[i,0].text(0.65,0.65,'Hxel = {:6.3f}'.format(hxelo*180./np.pi),transform=ax[i,0].transAxes)
            ax[i,0].text(0.65,0.5,'Vxel = {:6.3f}'.format(vxelo*180./np.pi),transform=ax[i,0].transAxes)
            ax[i,1].text(0.65,0.65,'Hel = {:6.3f}'.format(helo*180./np.pi),transform=ax[i,1].transAxes)
            ax[i,1].text(0.65,0.5,'Vel = {:6.3f}'.format(velo*180./np.pi),transform=ax[i,1].transAxes)
        raoh[i] = hrao/10000.  # degrees
        raov[i] = vrao/10000.  # degrees
        decoh[i] = hdeco/10000.  # degrees
        decov[i] = vdeco/10000.  # degrees
        xeloh[i] = hxelo*180./np.pi  # degrees
        xelov[i] = vxelo*180./np.pi  # degrees
        eloh[i] = helo*180./np.pi  # degrees
        elov[i] = velo*180./np.pi  # degrees

    if plot:
        ax[nant-1,0].set_xlabel('RA Offset [0.0001 deg]') 
        ax[nant-1,1].set_xlabel('Dec Offset [0.0001 deg]') 
        if pp:
            pp.savefig(f)
            plt.close()
        else:
            plt.show()
    return {'Timestamp':proc['Timestamp'],'antlist':proc['antlist'],
            'HPol':{'rao':raoh, 'deco':decoh, 'elo':eloh, 'xelo':xeloh},
            'VPol':{'rao':raov, 'deco':decov, 'elo':elov, 'xelo':xelov}}
示例#2
0
def multi_mountcal(filename, ant_str=None):
    ''' Process an entire set of calpnt data
    '''
    import coord_conv as cc
    from util import ant_str2list

    outdict = rd_calpnt(filename)
    indict_list = []
    if ant_str:
        antlist = ant_str2list(ant_str) + 1
    else:
        antlist = outdict['antlist']
    for ant in antlist:
        #i = ant - 1
        i, = np.where(np.array(outdict['antlist']) == ant)[
            0]  # Index in outdict for specified ant
        if ant in [9, 10, 11, 13, 14]:
            # This is an equatorial mount
            mount = 'EQ'
        elif ant in [1, 2, 3, 4, 5, 6, 7, 8, 12]:
            # This is an azimuth-elevation mount
            mount = 'AZEL'
        # Reprocess coordinates, plus remove any -99 points
        good, = np.where(
            np.logical_and(outdict['dra'][i] > -90, outdict['ddec'][i] > -90))
        npt = len(good)
        az = np.zeros(npt)
        el = np.zeros(npt)
        dxel = np.zeros(npt)
        d_el = np.zeros(npt)
        dra = outdict['dra'][i, good]
        ddec = outdict['ddec'][i, good]
        ra = outdict['ra'][good]
        dec = outdict['dec'][good]
        ha = outdict['ha'][good]
        times = outdict['time'][good]
        params_old = outdict['params_old'][:, i]
        # el_r = []
        for k in range(npt):
            # Convert RA, Dec to Az, El, and dRA, dDec to dxel and d_el
            azk, elk = cc.radec2azel(ra[k], dec[k], times[k])
            # Apply refraction correction (assumes elevation in degrees)
            # This is commented out, pending determination of whether refraction is already
            # accounted for in the measurements (I think it is...)
            #elk /= dtor  # Convert to degrees
            #elp = elk+(1/60.)*(0.0019279 + 1.02/tan((elk + 10.3/(el+5.1))*dtor))
            #elp *= dtor # Convert back to radians
            #el_r.append(elp)
            # Adjust coordinates (only needed for AZEL, but do for EQ, too for consistency)
            dxelk, d_elk = cc.dradec2dazel(ra[k], dec[k], times[k],
                                           dra[k] * dtor, ddec[k] * dtor)
            az[k] = azk
            el[k] = elk
            dxel[k] = dxelk / dtor
            d_el[k] = d_elk / dtor
        indict = {
            'filename': outdict['filename'],
            'ant': ant,
            'dra': dra,
            'ddec': ddec,
            'dxel': dxel,
            'd_el': d_el,
            'ra': ra,
            'dec': dec,
            'ha': ha,
            'az': az,
            'el': el,
            'mount': mount,
            'times': times,
            'params_old': params_old
        }
        # indict.update({'el_r':el_r})    # Refraction-corrected elevation
        indict = mntcal(indict)
        indict = checkfit(indict)
        indict_list.append(indict.copy())
    return indict_list  # Temporary