Example #1
0
def projBaseline(T1, T2, target, lst, ip1=1, ip2=3, min_altitude=20, max_OPD=95):
    """
    T1, T2: telescopes stations (e.g. 'A0', 'U1', etc.)
    target : [ra, dec] in decimal hour and decimal deg or name for SIMBAD
    lst   : decimal hour (scalar or array)
    ip1, ip2: input channels (optional)

    min_altitude (default 30 degrees) sets the minimum altitude for
    observation. Checks also for shadowinf from the UTs.

    max_OPD (default 95m) maximum OPD stroke of the delay lines.

    return a dictionnary. units are m and degrees 
    """
    if isinstance(target, str):
        s = simbad.query(target)[0]
        radec = [s['RA.h'], s['DEC.d']]
    else:
        radec = target
       
    # -- hour angle
    ha = (np.array(lst) - radec[0]) *360/24.0

    # -- alt-az
    dec = radec[1]
    d2r = lambda x: x*np.pi/180
    tmp1 =  np.sin(d2r(dec)) * np.sin(d2r(vlti_latitude)) +\
           np.cos(d2r(dec)) * np.cos(d2r(vlti_latitude)) *\
           np.cos(d2r(ha))
    alt = np.arcsin(tmp1)*180/np.pi
    
    tmp1 = np.cos(d2r(dec)) * np.sin(d2r(ha))
    tmp2 = -np.cos(d2r(vlti_latitude)) * np.sin(d2r(dec)) + \
           np.sin(d2r(vlti_latitude)) * np.cos(d2r(dec)) * \
           np.cos(d2r(ha));  
    az = (360-np.arctan2(tmp1, tmp2)*180/np.pi)%360

    b = [layout[T1][2]-layout[T2][2],
         layout[T1][3]-layout[T2][3],
         0.0] # assumes you *DO NOT* combine ATs and UTs
    
    # projected baseline
    ch_ = np.cos(ha*np.pi/180.)
    sh_ = np.sin(ha*np.pi/180.)
    cl_ = np.cos(vlti_latitude*np.pi/180.)
    sl_ = np.sin(vlti_latitude*np.pi/180.)
    cd_ = np.cos(radec[1]*np.pi/180.)
    sd_ = np.sin(radec[1]*np.pi/180.)

    # (u,v) coordinates in m
    u = ch_ * b[0] -  sl_*sh_ * b[1] + cl_*sh_ * b[2]
    v = sd_*sh_ * b[0] + (sl_*sd_*ch_+cl_*cd_) * b[1] -\
        (cl_*sd_*ch_ - sl_*cd_) * b[2] 
  
    # optical delay, in m
    d = -b[0]*cd_*sh_ -\
        b[1]*(sl_*cd_*ch_ - cl_*sd_) +\
        b[2]*(cl_*cd_*ch_ + sl_*sd_)
    d = np.array(d)
    
    opl1 = layout[T1][4] + 0.12*(ip1-1)
    opl2 = layout[T2][4] + 0.12*(ip2-1)
    opd = d+opl2-opl1

    observable = (alt>min_altitude)* \
                 (np.abs(opd) < max_OPD)*\
                 (alt>np.interp(az%360, horizon[T1][0], horizon[T1][1]))*\
                 (alt>np.interp(az%360, horizon[T2][0], horizon[T2][1]))

    if isinstance(alt, np.ndarray):
        observable = np.array(observable)

    airmass = alt*0+99
    czt = np.cos(np.pi*(90-alt)/180.)
    airmass = 1/czt*(1-.0012*(1/czt**2-1))

    if np.cos(d2r(dec))!=0:
        parang = 180*np.arcsin(np.sin(d2r(az))*
                               np.cos(d2r(vlti_latitude))/np.cos(d2r(dec)))/np.pi
    else:
        parang = 0.
    
    res = {'u':u, 'v':v, 'opd':opd, 'alt':alt, 'az':az,
           'observable':observable, 'parang':parang,
           'lst':lst, 'ra':radec[0],
           'dec':radec[1], 'B':np.sqrt(u**2+v**2),
           'PA':np.arctan2(u, v)*180/np.pi,
           'airmass':airmass, 'baseline':T1+T2,
           'opd':opd}
    
    return res
Example #2
0
def nTelescopes(telescopes, target, lst, ip=None, plot=False,
                min_altitude=20, max_OPD=95):
    """
    target can be a string with the name of the target resolvable by
    simbad.
    """
    tmp = []
    if ip is None:
        ip = range(2*len(telescopes))[1::2]
    if isinstance(target, str):
        s = simbad.query(target)
        target_name=target
        target = [s[0]['RA.h'], s[0]['DEC.d']]
    else:
        # assume [ra dec]
        target_name = '%2d:%2d %3d:%2d' % (int(target[0]),
                                           int(60*(target[0]-int(target[0]))),
                                           int(target[1]),
                                           int(60*(abs(target[1])-int(abs(target[1]))))
                                           )
    res = {}
    for i in range(len(telescopes)+1):
        for j in range(len(telescopes))[i+1:]:
            tmp = projBaseline(telescopes[i],telescopes[j],
                               target, lst,ip1=ip[i], ip2=ip[j],
                               min_altitude=min_altitude, max_OPD=max_OPD)
            if not 'lst' in res.keys():
                # init
                for k in ['lst', 'airmass', 'observable',
                          'ra', 'dec', 'alt', 'az', 'parang']:
                    res[k] = tmp[k]
                res['baseline'] = [tmp['baseline']]
                for k in ['B', 'PA', 'u', 'v', 'opd']:
                    res[k] = {}
            else:
                # update
                res['observable'] = res['observable']*tmp['observable']
                res['baseline'].append(tmp['baseline'])
                
            for k in ['B', 'PA', 'u', 'v', 'opd']:
                res[k][tmp['baseline']] = tmp[k]
    
    if plot:
        where = lambda key: [res[key][k] for k in range(len(res[key])) 
                             if res['observable'][k]]  
        where2 = lambda key1, key2: [res[key1][key2][k] for k in range(len(res['lst']))
                                     if res['observable'][k]]
        pyplot.figure(0, figsize=(12,5))
        pyplot.clf()
        pyplot.subplot(121)
        pyplot.plot(res['lst'], res['alt'], '.', color='0.5')
        pyplot.plot(where('lst'), where('alt'), 'ko')
        pyplot.ylim(0,90)
        pyplot.xlabel('lst (h)')
        pyplot.ylabel('altitude (deg)')
        pyplot.title(target_name)
        ax = pyplot.subplot(122, polar=True)
        for b in res['baseline']:
            B = where2('B', b)
            B.extend(where2('B', b))
            PA = where2('PA', b)
            PA.extend([180+x for x in where2('PA', b)])
            pyplot.plot([x*3.1415/180 for x in PA],B, '.', label=b)
        pyplot.legend(ncol=1, prop={'size':8}, numpoints=1)
        ax.get_xaxis().set_visible(False)
    else:
        return res