Пример #1
0
def main(args):
    # Validate
    if args.pol not in ('EW', 'NS'):
        raise ValueError("Invalid polarization: %s" % args.pol)
        
    # Get the site information
    if args.lwasv:
        nam = 'lwasv'
        sta = stations.lwasv
    elif args.ovrolwa:
        nam = 'ovro'
        sta = stations.lwa1
        sta.lat, sta.lon, sta.elev = ('37.23977727', '-118.2816667', 1182.89)
    else:
        nam = 'lwa1'
        sta = stations.lwa1
        
    # Read in the skymap (GSM or LF map @ 74 MHz)
    if not args.lfsm:
        smap = skymap.SkyMapGSM(freq_MHz=args.frequency/1e6)
        if args.verbose:
            print("Read in GSM map at %.2f MHz of %s pixels; min=%f, max=%f" % (args.frequency/1e6, len(smap.ra), smap._power.min(), smap._power.max()))
    else:
        smap = skymap.SkyMapLFSM(freq_MHz=args.frequency/1e6)
        if args.verbose:
            print("Read in LFSM map at %.2f MHz of %s pixels; min=%f, max=%f" % (args.frequency/1e6, len(smap.ra), smap._power.min(), smap._power.max()))
    
    # Get the emperical model of the beam and compute it for the correct frequencies
    beamDict = numpy.load(os.path.join(dataPath, 'lwa1-dipole-emp.npz'))
    if args.pol == 'EW':
        beamCoeff = beamDict['fitX']
    else:
        beamCoeff = beamDict['fitY']
    try:
        beamDict.close()
    except AttributeError:
        pass
    alphaE = numpy.polyval(beamCoeff[0,0,:], args.frequency)
    betaE =  numpy.polyval(beamCoeff[0,1,:], args.frequency)
    gammaE = numpy.polyval(beamCoeff[0,2,:], args.frequency)
    deltaE = numpy.polyval(beamCoeff[0,3,:], args.frequency)
    alphaH = numpy.polyval(beamCoeff[1,0,:], args.frequency)
    betaH =  numpy.polyval(beamCoeff[1,1,:], args.frequency)
    gammaH = numpy.polyval(beamCoeff[1,2,:], args.frequency)
    deltaH = numpy.polyval(beamCoeff[1,3,:], args.frequency)
    if args.verbose:
        print("Beam Coeffs. X: a=%.2f, b=%.2f, g=%.2f, d=%.2f" % (alphaH, betaH, gammaH, deltaH))
        print("Beam Coeffs. Y: a=%.2f, b=%.2f, g=%.2f, d=%.2f" % (alphaE, betaE, gammaE, deltaE))
        
    if args.empirical:
        corrDict = numpy.load(os.path.join(dataPath, 'lwa1-dipole-cor.npz'))
        cFreqs = corrDict['freqs']
        cAlts  = corrDict['alts']
        if corrDict['degrees'].item():
            cAlts *= numpy.pi / 180.0
        cCorrs = corrDict['corrs']
        corrDict.close()
        
        if args.frequency/1e6 < cFreqs.min() or args.frequency/1e6 > cFreqs.max():
            print("WARNING: Input frequency of %.3f MHz is out of range, skipping correction" % (args.frequency/1e6,))
            corrFnc = None
        else:
            fCors = cAlts*0.0
            for i in range(fCors.size):
                ffnc = interp1d(cFreqs, cCorrs[:,i], bounds_error=False)
                fCors[i] = ffnc(args.frequency/1e6)
            corrFnc = interp1d(cAlts, fCors, bounds_error=False)
            
    else:
        corrFnc = None
        
    def compute_beam_pattern(az, alt, corr=corrFnc):
        zaR = numpy.pi/2 - alt*numpy.pi / 180.0 
        azR = az*numpy.pi / 180.0
        
        c = 1.0
        if corrFnc is not None:
            c = corrFnc(alt*numpy.pi / 180.0)
            c = numpy.where(numpy.isfinite(c), c, 1.0)
            
        pE = (1-(2*zaR/numpy.pi)**alphaE)*numpy.cos(zaR)**betaE + gammaE*(2*zaR/numpy.pi)*numpy.cos(zaR)**deltaE
        pH = (1-(2*zaR/numpy.pi)**alphaH)*numpy.cos(zaR)**betaH + gammaH*(2*zaR/numpy.pi)*numpy.cos(zaR)**deltaH

        return c*numpy.sqrt((pE*numpy.cos(azR))**2 + (pH*numpy.sin(azR))**2)

    if args.do_plot:
        az = numpy.zeros((90,360))
        alt = numpy.zeros((90,360))
        for i in range(360):
            az[:,i] = i
        for i in range(90):
            alt[i,:] = i
        pylab.figure(1)
        pylab.title("Beam Response: %s pol. @ %0.2f MHz" % (args.pol, args.frequency/1e6))
        pylab.imshow(compute_beam_pattern(az, alt), extent=(0,359, 0,89), origin='lower')
        pylab.xlabel("Azimuth [deg]")
        pylab.ylabel("Altitude [deg]")
        pylab.grid(1)
        pylab.draw()
    
    # Calculate times in both site LST and UTC
    t0 = astro.get_julian_from_sys()
    lst = astro.get_local_sidereal_time(sta.long*180.0/math.pi, t0) / 24.0
    t0 -= lst*(23.933/24.0) # Compensate for shorter sidereal days
    times = numpy.arange(0.0, 1.0, args.time_step/1440.0) + t0
    
    lstList = []
    powListAnt = [] 
    
    for t in times:
        # Project skymap to site location and observation time
        pmap = skymap.ProjectedSkyMap(smap, sta.lat*180.0/math.pi, sta.long*180.0/math.pi, t)
        lst = astro.get_local_sidereal_time(sta.long*180.0/math.pi, t)
        lstList.append(lst)
        
        # Convolution of user antenna pattern with visible skymap
        gain = compute_beam_pattern(pmap.visibleAz, pmap.visibleAlt)
        powerAnt = (pmap.visiblePower * gain).sum() / gain.sum()
        powListAnt.append(powerAnt)

        if args.verbose:
            lstH = int(lst)
            lstM = int((lst - lstH)*60.0)
            lstS = ((lst - lstH)*60.0 - lstM)*60.0
            sys.stdout.write("LST: %02i:%02i:%04.1f, Power_ant: %.1f K\r" % (lstH, lstM, lstS, powerAnt))
            sys.stdout.flush()
    sys.stdout.write("\n")
            
    # plot results
    if args.do_plot:
        pylab.figure(2)
        pylab.title("Driftcurve: %s pol. @ %0.2f MHz - %s" % \
            (args.pol, args.frequency/1e6, nam.upper()))
        pylab.plot(lstList, powListAnt, "ro", label="Antenna Pattern")
        pylab.xlabel("LST [hours]")
        pylab.ylabel("Temp. [K]")
        pylab.grid(2)
        pylab.draw()
        pylab.show()
    
    outputFile = "driftcurve_%s_%s_%.2f.txt" % (nam, args.pol, args.frequency/1e6)
    print("Writing driftcurve to file '%s'" % outputFile)
    mf = file(outputFile, "w")
    for lst,pow in zip(lstList, powListAnt):
        mf.write("%f  %f\n" % (lst, pow))
    mf.close()
Пример #2
0
def main(args):
    # Beam
    beamFilename = args.filename
    beamDict = numpy.load(beamFilename)
    beam = beamDict['beam']
    beam /= beam.max()
    
    # Station, polarization, frequency, and beam simulation resolution
    name = beamDict['station'].item()
    pol = beamDict['pol'].item()
    freq = beamDict['freq'].item()
    try:
        res = beamDict['res'].item()
    except KeyError:
        res = 1.0
    ires = 1.0 / (min([1.0, res]))
        
    # Get the site information
    if name == 'lwa1':
        sta = stations.lwa1
    elif name == 'lwasv':
        sta = stations.lwasv
    else:
        raise RuntimeError("Unknown site: %s" % name)
        
    # Read in the skymap (GSM or LF map @ 74 MHz)
    if not args.lfsm:
        smap = skymap.SkyMapGSM(freq_MHz=freq/1e6)
        if args.verbose:
            print("Read in GSM map at %.2f MHz of %s pixels; min=%f, max=%f" % (freq/1e6, len(smap.ra), smap._power.min(), smap._power.max()))
    else:
        smap = skymap.SkyMapLFSM(freq_MHz=freq/1e6)
        if args.verbose:
            print("Read in LFSM map at %.2f MHz of %s pixels; min=%f, max=%f" % (freq/1e6, len(smap.ra), smap._power.min(), smap._power.max()))
            
    def BeamPattern(az, alt, beam=beam, ires=ires):
        iAz = (numpy.round(az*ires)).astype(numpy.int32)
        iAlt = (numpy.round(alt*ires)).astype(numpy.int32) 
        
        return beam[iAz,iAlt]
        
    if args.do_plot:
        az = numpy.arange(0,360*ires+1,1) / float(ires)
        alt = numpy.arange(0,90*ires+1,1) / float(ires)
        alt, az = numpy.meshgrid(alt, az)
        pylab.figure(1)
        pylab.title("Beam Response: %s pol. @ %0.2f MHz" % (pol, freq/1e6))
        pylab.imshow(BeamPattern(az, alt), interpolation='nearest', extent=(0,359, 0,89), origin='lower')
        pylab.xlabel("Azimuth [deg]")
        pylab.ylabel("Altitude [deg]")
        pylab.grid(1)
        pylab.draw()
        
    # Calculate times in both site LST and UTC
    t0 = astro.get_julian_from_sys()
    lst = astro.get_local_sidereal_time(sta.long*180.0/math.pi, t0) / 24.0
    t0 -= lst*(23.933/24.0) # Compensate for shorter sidereal days
    times = numpy.arange(0.0, 1.0, args.time_step/1440.0) + t0
    
    lstList = []
    powListAnt = [] 
    
    for t in times:
        # Project skymap to site location and observation time
        pmap = skymap.ProjectedSkyMap(smap, sta.lat*180.0/math.pi, sta.long*180.0/math.pi, t)
        lst = astro.get_local_sidereal_time(sta.long*180.0/math.pi, t)
        lstList.append(lst)
        
        # Convolution of user antenna pattern with visible skymap
        gain = BeamPattern(pmap.visibleAz, pmap.visibleAlt)
        powerAnt = (pmap.visiblePower * gain).sum() / gain.sum()
        powListAnt.append(powerAnt)

        if args.verbose:
            lstH = int(lst)
            lstM = int((lst - lstH)*60.0)
            lstS = ((lst - lstH)*60.0 - lstM)*60.0
            sys.stdout.write("LST: %02i:%02i:%04.1f, Power_ant: %.1f K \r" % (lstH, lstM, lstS, powerAnt))
            sys.stdout.flush()
    sys.stdout.write("\n")
    
    # Plot results
    if args.do_plot:
        pylab.figure(2)
        pylab.title("Driftcurve: %s pol. @ %0.2f MHz - %s" % \
            (pol, freq/1e6, name.upper()))
        pylab.plot(lstList, powListAnt, "ro",label="Antenna Pattern")
        pylab.xlabel("LST [hours]")
        pylab.ylabel("Temp. [K]")
        pylab.grid(2)
        pylab.draw()
        pylab.show()
        
    outputFile = "driftcurve_%s_%s_%.2f.txt" % (name, pol, freq/1e6)
    print("Writing driftcurve to file '%s'" % outputFile)
    mf = open(outputFile, "w")
    for lst,pow in zip(lstList, powListAnt):
        mf.write("%f  %f\n" % (lst,pow))
    mf.close()
Пример #3
0
    def test_ProjectedSkyMap_get_direction_cosines_LFSM(self):
        """Test skymap.ProjectedSkyMap.get_direction_cosines() method using SkyMapLFSM."""

        s = skymap.SkyMapLFSM()
        p = skymap.ProjectedSkyMap(s, 20, 30, astro.get_julian_from_sys())
        p.get_direction_cosines()
Пример #4
0
    def test_ProjectedSkyMap_compute_visible_power_LFSM(self):
        """Test skymap.ProjectedSkyMap.compute_visible_power() method using SkyMapLFSM."""

        s = skymap.SkyMapLFSM()
        p = skymap.ProjectedSkyMap(s, 20, 30, astro.get_julian_from_sys())
        p.compute_visible_power()
Пример #5
0
    def test_ProjectedSkyMap_init_LFSM(self):
        """Test skymap.ProjectedSkyMap constructor method using SkyMapLFSM."""

        s = skymap.SkyMapLFSM()
        skymap.ProjectedSkyMap(s, 20, 30, astro.get_julian_from_sys())
Пример #6
0
    def test_SkyMapLFSM_compute_total_power(self):
        """Test skymap.SkyMapLFSM.compute_total_power() method."""

        s = skymap.SkyMapLFSM()
        s.compute_total_power()
Пример #7
0
    def test_SkyMapLFSM_init(self):
        """Test skymap.SkyMapLFSM class constructor method."""

        skymap.SkyMapLFSM()