コード例 #1
0
def whenup(date=None,verbose=False):
    ''' Find out the times when preferred sources are up for a given date. 
        Prints the result of source rise and set times for preferred sources:
        Sun, 0319+415, 1229+020, 1331+305, 2136+006, 2253+161
        
        Optional arguments:
           date: Time() object giving start date (time of day is ignored) 
                 or None for current date.
           verbose: If True, actually print the table of times to the screen
           
        Returns: dictionary of time objects with keys 'taz', 'teq', 'tgap', each
                 being a two-element Time() object, where first time is
                 start (rise) and second is end (set), and 'lines', which is a
                 printable table of times.
    '''
    srclist = ['Sun     ', '0319+415', '1229+020', '1331+305', '2136+006', '2253+161']

    # Use the 24-h day specified by date (i.e. drop the time of day)
    if date is None:
        # Use today's date
        mjd = int(Time.now().mjd)
    else:
        mjd = int(date.mjd)
    t = Time(mjd,format='mjd')

    # Add times in 1-min steps up to duration dur (hours)
    ts = t + TimeDelta(np.arange(0.,24.,1./60.)/24.,format='jd')

    aa = eovsa_cat.eovsa_array_with_cat()

    nt = len(ts)
    ra = np.zeros((len(srclist),nt))
    ha = np.zeros((len(srclist),nt))
    dec = np.zeros((len(srclist),nt))
    alt = np.zeros((len(srclist),nt))
    az = np.zeros((len(srclist),nt))
    taz = []
    teq = []
    tgap = []
    lines = []
    for i in range(nt):
        aa.set_jultime(ts[i].jd)    
        lst = aa.sidereal_time()

        for j,srcname in enumerate(srclist):
            src = aa.cat[srcname.split()[0]]
            src.compute(aa)
            ra[j,i] = src.ra
            ha[j,i] = lst - src.ra
            dec[j,i] = src.dec
            alt[j,i] = src.alt
            az[j,i] = src.az

    ra_deg = deg(ra)
    ha_deg = deg(ha)
    dec_deg = deg(dec)
    alt = deg(alt)
    az_deg = deg2(az)
    lines.append('Source     Alt-Az    Equatorial     Gap')
    lines.append(' Name    Rise   Set  Rise   Set  Start  End')
    lines.append('-------- ----- ----- ----- ----- ----- -----')
    for j in range(len(srclist)):
        iset_eq = np.where(np.abs(ha_deg[j] - 55.0) < 0.15)[0][0]
        irise_eq = np.where(np.abs(ha_deg[j] + 55.0) < 0.15)[0][0]
        trise_eq = ts[irise_eq]
        tset_eq = ts[iset_eq]
        if iset_eq < irise_eq:
            if j == 0:
                tset_eq += TimeDelta(1,format='jd')
            else:
                tset_eq += TimeDelta(1436./60./24.,format='jd')
        for iwindow in np.arange(0.1,0.2,0.01):
            try:
                i1 = np.where(np.abs(alt[j] - 10.0) < iwindow)[0][0]
                i2 = np.where(np.abs(alt[j] - 10.0) < iwindow)[0][1]
                if i2 == i1+1:
                    i2 = np.where(np.abs(alt[j] - 10.0) < iwindow)[0][2]
                break
            except:
                print 'Window',iwindow,'did not work.  Trying again'
        if alt[j,i1] < alt[j,i1+1]:
            irise_az = i1
            iset_az = i2
        else:
            irise_az = i2
            iset_az = i1
        trise_az = ts[irise_az]
        tset_az = ts[iset_az]
        if iset_az < irise_az:
            if j == 0:
                tset_az += TimeDelta(1,format='jd')
            else:
                tset_az += TimeDelta(1436./60./24.,format='jd')
        if j == 1:
            up, = np.where(alt[j] > 10.)
            j1 = np.where(np.abs(az_deg[j,up] - 35.0) < 1.0)[0][0]
            j2 = np.where(np.abs(az_deg[j,up] - 325.0) < 1.0)[0][0]
            jset = up[j1]
            jrise = up[j2]
            tset_gap = ts[jset]
            trise_gap = ts[jrise]
            if jrise < jset:
                trise_gap += TimeDelta(1436./60./24.,format='jd')
            taz.append(Time([trise_az.iso,tset_az.iso]))
            teq.append(Time([trise_eq.iso,tset_eq.iso]))
            tgap.append(Time([tset_gap.iso,trise_gap.iso]))
            lines.append('{0} {1} {2} {3} {4} {5} {6}'.format(srclist[j], trise_az.iso[11:16], tset_az.iso[11:16], trise_eq.iso[11:16], tset_eq.iso[11:16], tset_gap.iso[11:16], trise_gap.iso[11:16]))
        else:
            taz.append(Time([trise_az.iso,tset_az.iso]))
            teq.append(Time([trise_eq.iso,tset_eq.iso]))
            tgap.append((None,None))
            lines.append('{0} {1} {2} {3} {4} {5} {6}'.format(srclist[j], trise_az.iso[11:16], tset_az.iso[11:16], trise_eq.iso[11:16], tset_eq.iso[11:16], ' --- ',' --- '))
    if verbose:
        for line in lines:
            print line
    return {'source':srclist,'taz':taz, 'teq':teq, 'tgap':tgap, 'lines':lines}
コード例 #2
0
def sunup(daterange):
    ''' Find out the times when the Sun is up for a given date range. 
           
        Returns: dictionary of time objects with keys 'taz', 'teq', each
                 being a two-element Time() object, where first time is
                 start (rise) and second is end (set)
    '''
    # Use the 24-h day specified by daterange (i.e. drop the time of day)
    mjd1 = int(daterange[0].mjd)
    mjd2 = int(daterange[1].mjd)
    aa = eovsa_cat.eovsa_array_with_cat()
    taz_rise = []
    teq_rise = []
    taz_set = []
    teq_set = []
    mjd_list = []
    for mjd in range(mjd1,mjd2+1):
        t = Time(mjd,format='mjd')
        # Add times in 1-min steps up to duration dur (hours)
        ts = t + TimeDelta(np.arange(0.,24.,1./60.)/24.,format='jd')

        nt = len(ts)
        ha = np.zeros(nt)
        alt = np.zeros(nt)
        az = np.zeros(nt)
        lines = []
        for i in range(nt):
            aa.set_jultime(ts[i].jd)    
            lst = aa.sidereal_time()

            src = aa.cat['Sun']
            src.compute(aa)
            ha[i] = lst - src.ra
            alt[i] = src.alt
            az[i] = src.az

        ha_deg = deg(ha)
        alt = deg(alt)
        az_deg = deg2(az)
        iset_eq = np.where(np.abs(ha_deg - 55.0) < 0.15)[0][0]
        irise_eq = np.where(np.abs(ha_deg + 55.0) < 0.15)[0][0]
        trise_eq = ts[irise_eq]
        tset_eq = ts[iset_eq]
        if iset_eq < irise_eq:
            tset_eq += TimeDelta(1,format='jd')
        for iwindow in np.arange(0.1,0.2,0.01):
            try:
                idx, = np.where(np.abs(alt - 10.0) < iwindow)  #****Was 0.1
                i1 = idx[0]
                i2 = idx[1]
                if i2 == i1+1:
                    if len(idx) > 2:
                        i2 = idx[2]
                    else:
                        i2 = 1439  # Transition is at end
                break
            except:
                print 'Window',iwindow,'did not work.  Trying again'
        if alt[i1] < alt[i1+1]:
            irise_az = i1
            iset_az = i2
        else:
            irise_az = i2
            iset_az = i1
        trise_az = ts[irise_az]
        tset_az = ts[iset_az]
        if iset_az < irise_az:
            tset_az += TimeDelta(1,format='jd')
        taz_rise.append(trise_az.mjd)
        taz_set.append(tset_az.mjd)
        teq_rise.append(trise_eq.mjd)
        teq_set.append(tset_eq.mjd)
        mjd_list.append(mjd)
    return {'date':Time(mjd_list,format='mjd'),
            'taz_rise':Time(taz_rise,format='mjd'),'teq_rise':Time(teq_rise,format='mjd'),
             'taz_set':Time(taz_set, format='mjd'), 'teq_set':Time(teq_set, format='mjd')}
コード例 #3
0
def whatup(minflux=7., dur=24., t=None, showtp=False):
    ''' Find out what sources are up at what times.  Produces a plot with some
        mouse interactivity (click once to activate, click a second time to deactivate)
        
        Optional arguments:
           minflux: low-flux cutoff for the plot
           dur: duration in hours from the start time
           t: Time() object giving start time of the plot, on None for current time.
           showtp: If True, show total power sources. Default False
    '''
    os.chdir(os.path.expanduser('~') + '/Dropbox/PythonCode/Current')

    if showtp:
        srclist0 = ['Sun', 'Moon', 'CAS-A', 'CYG-A', 'TAU-A', 'VIR-A']
    else:
        srclist0 = ['Sun']
    ntp = len(srclist0)
    morelist = []
    moreflux = []
    # additional srclist from VLA calibrator catalogue
    cal = readvlacaldb()
    # find all bright sources with flux > 10 Jy at C band
    for i, c in enumerate(cal):
        if 'C' in c.band and c.flux[c.band.index('C')] > minflux:
            morelist.append(c.name)
            moreflux.append(c.flux[c.band.index('C')])
    # sort the VLA cal src list by flux
    morelist = [l for (f, l) in sorted(zip(moreflux, morelist))]
    moreflux.sort()
    moreflux.reverse()
    morelist.reverse()

    srclist = srclist0 + morelist

    if t is None:
        t = util.Time.now()

    try:
        float(dur)
    except ValueError:
        print 'Bad value for dur. Use default dur=8.'
        dur = 8.

    # Add times in 1-min steps up to duration dur (hours)
    ts = t + TimeDelta(arange(0., dur, 1. / 60.) / 24., format='jd')

    aa = eovsa_cat.eovsa_array_with_cat()

    nt = len(ts)
    ra = zeros((len(srclist), nt))
    ha = zeros((len(srclist), nt))
    dec = zeros((len(srclist), nt))
    alt = zeros((len(srclist), nt))
    for i in range(nt):
        aa.set_jultime(ts[i].jd)
        lst = aa.sidereal_time()

        for j, srcname in enumerate(srclist):
            src = aa.cat[srcname]
            src.compute(aa)
            ra[j, i] = src.ra
            ha[j, i] = lst - src.ra
            dec[j, i] = src.dec
            alt[j, i] = src.alt

    ra_deg = deg(ra)
    ha_deg = deg(ha)
    dec_deg = deg(dec)
    alt = deg(alt)
    eq_alt = copy.deepcopy(alt)
    az_alt = copy.deepcopy(alt)
    colors = cm.rainbow(np.linspace(0, 1, len(srclist)))
    f = plt.figure(figsize=(10, 6))
    ax = plt.subplot(111)

    for j in range(len(srclist)):
        #idx=where(abs(ha_deg[j]) < 55.)[0]
        bad, = where(abs(ha_deg[j]) > 55.)  # Back to nominal +/- 55 HA
        eq_alt[j, bad] = nan
        #ax.plot_date(ts.plot_date[idx],alt[j,idx],'-',linewidth=6,color=colors[j])
        ax.plot_date(ts.plot_date,
                     eq_alt[j],
                     '-',
                     linewidth=6,
                     color=colors[j])  #,alpha=0.5)

    for j in range(len(srclist)):
        # Plot thin lines
        ax.plot_date(ts.plot_date, alt[j], '-', color=colors[j])
    for j in range(len(srclist)):
        bad, = where(
            abs(alt[j]) < 10.)  # Eliminate points < 10-degrees altitude
        az_alt[j, bad] = nan
        # Plot width = 2 lines
        ax.plot_date(ts.plot_date,
                     az_alt[j],
                     '-',
                     linewidth=2,
                     color=colors[j])
    for j in range(len(srclist)):
        # Replot width = 6 lines
        ax.plot_date(ts.plot_date,
                     eq_alt[j],
                     '-',
                     linewidth=6,
                     color=colors[j])  #,alpha=0.5)

    srclegend = []
    for i, s in enumerate(srclist):
        if i < ntp:
            srclegend.append(s)
        else:
            srclegend.append(s + ' ({0:.1f} Jy)'.format(moreflux[i - ntp]))

    ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M'))
    ax.set_ylim([0, 90])

    def format_coord(x, y, ts, srclist, alt):
        col = np.argmin(np.absolute(ts.plot_date - x))
        nsrc, nt = alt.shape
        if col >= 0 and col < len(ts):
            tm = ts.plot_date[col]
            ft = mdates.DateFormatter('%Y-%m-%d %H:%M')
            timstr = str(ft(tm))
            # find out source name at the given time
            alt_t = alt[:, col]
            ind = np.argmin(np.absolute(alt_t - y))
            srcname = srclist[ind]
            ra0 = np.degrees(ra[ind, col]) / 15.
            ha0 = ha_deg[ind, col] / 15.
            dec0 = dec_deg[ind, col]
            if ind < ntp:
                return '{2} (RA:{3:.1f}h, HA:{4:.1f}h, DEC:{5:.1f}d)'.format(
                    timstr, y, srcname, ra0, ha0, dec0)
            else:
                flux = moreflux[ind - ntp]
            return '{2} ({6:.1f}Jy RA:{3:.1f}h, HA:{4:.1f}h, DEC:{5:.1f}d)'.format(
                timstr, y, srcname, ra0, ha0, dec0, flux)
        else:
            return 'x = {0:.1f}, y = {1:.1f}'.format(x, y)
#    ax.format_coord = format_coord

    plt.xticks(rotation=40)
    box = ax.get_position()
    ax.set_position(
        [box.x0 - 0.05, box.y0 + 0.15, box.width * 0.82, box.height * 0.85])
    ax.legend(srclegend,
              loc='center left',
              bbox_to_anchor=(1., 0.5),
              fancybox=True,
              shadow=True)
    ax.set_xlabel('UTC Time')
    ax.set_ylabel('Altitude (deg)')
    ax.set_title('Bright sources visible by EOVSA 27-m Antenna')
    txt = tt.tooltip(f, ax, format_coord, ts, srclist, alt)
コード例 #4
0
ファイル: sat_o3b_list.py プロジェクト: sjyu1988/eovsa
import eovsa_cat as ec
import copy
satnames = array(['O3B FM'] * 11)
sats = []
for i in range(2, 13):
    sats.append(satnames[i - 2] + str(i))
aa = ec.eovsa_array_with_cat()
t = aa.get_jultime()
ot = copy.copy(t)
for satname in sats:
    t = copy.copy(ot)
    aa.set_jultime(ot)
    for i in range(144):
        t += 300. / 86400.
        aa.set_jultime(t)
        sat = aa.cat[satname]
        sat.compute(aa)
        if sat.alt > 10. * pi / 180.:
            print aa.date, satname, sat.ra, sat.dec
コード例 #5
0
ファイル: whatup.py プロジェクト: binchensolar/eovsa
def whatup(minflux=7., dur=24., t=None, showtp=False):
    ''' Find out what sources are up at what times.  Produces a plot with some
        mouse interactivity (click once to activate, click a second time to deactivate)
        
        Optional arguments:
           minflux: low-flux cutoff for the plot
           dur: duration in hours from the start time
           t: Time() object giving start time of the plot, on None for current time.
           showtp: If True, show total power sources. Default False
    '''
    os.chdir(os.path.expanduser('~')+'/Dropbox/PythonCode/Current')

    if showtp:
        srclist0 = ['Sun','Moon','CAS-A','CYG-A','TAU-A','VIR-A']
    else:
        srclist0 = ['Sun']
    ntp = len(srclist0)
    morelist = []
    moreflux = []
    # additional srclist from VLA calibrator catalogue
    cal = readvlacaldb()
    # find all bright sources with flux > 10 Jy at C band
    for i, c in enumerate(cal):
        if 'C' in c.band and c.flux[c.band.index('C')] > minflux:
            morelist.append(c.name)
            moreflux.append(c.flux[c.band.index('C')])
    # sort the VLA cal src list by flux
    morelist=[l for (f,l) in sorted(zip(moreflux,morelist))]
    moreflux.sort()
    moreflux.reverse()
    morelist.reverse()

    srclist = srclist0 + morelist

    if t is None:
        t = util.Time.now()

    try:
        float(dur)
    except ValueError:
        print 'Bad value for dur. Use default dur=8.'
        dur = 8.

    # Add times in 1-min steps up to duration dur (hours)
    ts = t + TimeDelta(arange(0.,dur,1./60.)/24.,format='jd')

    aa = eovsa_cat.eovsa_array_with_cat()

    nt = len(ts)
    ra = zeros((len(srclist),nt))
    ha = zeros((len(srclist),nt))
    dec = zeros((len(srclist),nt))
    alt = zeros((len(srclist),nt))
    for i in range(nt):
        aa.set_jultime(ts[i].jd)    
        lst = aa.sidereal_time()

        for j,srcname in enumerate(srclist):
            src = aa.cat[srcname]
            src.compute(aa)
            ra[j,i] = src.ra
            ha[j,i] = lst - src.ra
            dec[j,i] = src.dec
            alt[j,i] = src.alt

    ra_deg = deg(ra)
    ha_deg = deg(ha)
    dec_deg = deg(dec)
    alt = deg(alt)
    eq_alt = copy.deepcopy(alt)
    az_alt = copy.deepcopy(alt)
    colors = cm.rainbow(np.linspace(0, 1, len(srclist)))
    f=plt.figure(figsize=(10,6))
    ax=plt.subplot(111)

    for j in range(len(srclist)):
        #idx=where(abs(ha_deg[j]) < 55.)[0]
        bad, = where(abs(ha_deg[j]) > 55.)   # Back to nominal +/- 55 HA
        eq_alt[j,bad] = nan
        #ax.plot_date(ts.plot_date[idx],alt[j,idx],'-',linewidth=6,color=colors[j])
        ax.plot_date(ts.plot_date,eq_alt[j],'-',linewidth=6,color=colors[j])#,alpha=0.5)

    for j in range(len(srclist)):
        # Plot thin lines
        ax.plot_date(ts.plot_date,alt[j],'-',color=colors[j])
    for j in range(len(srclist)):
        bad, = where(abs(alt[j]) < 10.)   # Eliminate points < 10-degrees altitude
        az_alt[j,bad] = nan
        # Plot width = 2 lines
        ax.plot_date(ts.plot_date,az_alt[j],'-',linewidth=2,color=colors[j])
    for j in range(len(srclist)):
        # Replot width = 6 lines
        ax.plot_date(ts.plot_date,eq_alt[j],'-',linewidth=6,color=colors[j])#,alpha=0.5)

    srclegend=[]
    for i,s in enumerate(srclist):
        if i < ntp:
            srclegend.append(s)
        else:
            srclegend.append(s + ' ({0:.1f} Jy)'.format(moreflux[i-ntp]))

    ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M'))
    ax.set_ylim([0,90])
    def format_coord(x, y, ts, srclist, alt):
        col = np.argmin(np.absolute(ts.plot_date - x))
        nsrc, nt = alt.shape
        if col >= 0 and col < len(ts):
            tm = ts.plot_date[col]
            ft = mdates.DateFormatter('%Y-%m-%d %H:%M')
            timstr = str(ft(tm))
            # find out source name at the given time
            alt_t = alt[:, col]
            ind = np.argmin(np.absolute(alt_t - y))
            srcname = srclist[ind]
            ra0 = np.degrees(ra[ind, col])/15.
            ha0 = ha_deg[ind, col]/15.
            dec0 = dec_deg[ind, col]
            if ind < ntp:
                return '{2} (RA:{3:.1f}h, HA:{4:.1f}h, DEC:{5:.1f}d)'.format(timstr, y, srcname, ra0, ha0, dec0)
            else:
                flux=moreflux[ind-ntp]
            return '{2} ({6:.1f}Jy RA:{3:.1f}h, HA:{4:.1f}h, DEC:{5:.1f}d)'.format(timstr, y, srcname, ra0, ha0, dec0, flux)
        else:
            return 'x = {0:.1f}, y = {1:.1f}'.format(x,y)
#    ax.format_coord = format_coord

    plt.xticks(rotation=40)
    box = ax.get_position()
    ax.set_position([box.x0-0.05, box.y0+0.15, box.width * 0.82, box.height * 0.85])
    ax.legend(srclegend,loc='center left', bbox_to_anchor=(1., 0.5),
                      fancybox=True, shadow=True)
    ax.set_xlabel('UTC Time')
    ax.set_ylabel('Altitude (deg)')
    ax.set_title('Bright sources visible by EOVSA 27-m Antenna')
    txt = tt.tooltip(f, ax, format_coord, ts, srclist, alt)
コード例 #6
0
ファイル: sat_o3b_list.py プロジェクト: binchensolar/eovsa
import eovsa_cat as ec
import copy
satnames = array(['O3B FM']*11)
sats = []
for i in range(2,13):
    sats.append(satnames[i-2]+str(i))
aa = ec.eovsa_array_with_cat()
t = aa.get_jultime()
ot = copy.copy(t)
for satname in sats:
    t = copy.copy(ot)
    aa.set_jultime(ot)
    for i in range(144):
        t += 300./86400.
        aa.set_jultime(t)
        sat = aa.cat[satname]
        sat.compute(aa)
        if sat.alt > 10.*pi/180.:
            print aa.date,satname,sat.ra,sat.dec