Exemplo n.º 1
0
    def from_system(klass):
        """
        Factory method to create a Time instance from current system clock value.
        """

        return klass(astro.get_julian_from_sys(), klass.FORMAT_JD,
                     klass.TIMESYS_UTC)
Exemplo n.º 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()
Exemplo n.º 3
0
def main(args):
    # Parse command line
    config = parseOptions(args)
    
    # Get the site information
    if config['site'] == 'lwa1':
        sta = stations.lwa1
    elif config['site'] == 'lwasv':
        sta = stations.lwasv
    elif config['site'] == 'ovro':
        sta = stations.lwa1
        sta.lat, sta.lon, sta.elev = ('37.2397808', '-118.2816819', 1183.4839)
    else:
        raise RuntimeError("Unknown site: %s" % config['site'])
        
    # Read in the skymap (GSM or LF map @ 74 MHz)
    if config['GSM']:
        smap = skymap.SkyMapGSM(freqMHz=config['freq']/1e6)
        if config['verbose']:
            print "Read in GSM map at %.2f MHz of %s pixels; min=%f, max=%f" % (config['freq']/1e6, len(smap.ra), smap._power.min(), smap._power.max())
    else:
        smap = skymap.SkyMapLFSM(freqMHz=config['freq']/1e6)
        if config['verbose']:
            print "Read in LFSM map at %.2f MHz of %s pixels; min=%f, max=%f" % (config['freq']/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 config['pol'] == 'EW':
        beamCoeff = beamDict['fitX']
    else:
        beamCoeff = beamDict['fitY']
    try:
        beamDict.close()
    except AttributeError:
        pass
    alphaE = numpy.polyval(beamCoeff[0,0,:], config['freq'])
    betaE =  numpy.polyval(beamCoeff[0,1,:], config['freq'])
    gammaE = numpy.polyval(beamCoeff[0,2,:], config['freq'])
    deltaE = numpy.polyval(beamCoeff[0,3,:], config['freq'])
    alphaH = numpy.polyval(beamCoeff[1,0,:], config['freq'])
    betaH =  numpy.polyval(beamCoeff[1,1,:], config['freq'])
    gammaH = numpy.polyval(beamCoeff[1,2,:], config['freq'])
    deltaH = numpy.polyval(beamCoeff[1,3,:], config['freq'])
    if config['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 config['corr']:
        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 config['freq']/1e6 < cFreqs.min()-11 or config['freq']/1e6 > cFreqs.max()+11:
            print "WARNING: Input frequency of %.3f MHz is out of range, skipping correction"
            corrFnc = None
        else:
            fCors = cAlts*0.0
            for i in xrange(fCors.size):
                ffnc = interpextrap1d(cFreqs, cCorrs[:,i])
                fCors[i] = ffnc(config['freq']/1e6)
            corrFnc = interp1d(cAlts, fCors, bounds_error=False)
            
    else:
        corrFnc = None
        
    def BeamPattern(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 config['enableDisplay']:
        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" % (config['pol'], config['freq']/1e6))
        pylab.imshow(BeamPattern(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, config['tStep']/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 config['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 config['enableDisplay']:
        pylab.figure(2)
        pylab.title("Driftcurve: %s pol. @ %0.2f MHz - %s" % \
            (config['pol'], config['freq']/1e6, config['site'].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" % (config['site'], config['pol'], config['freq']/1e6)
    if config['tag'] is not None:
        base, ext = os.path.splitext(outputFile)
        outputFile = "%s_%s%s" % (base, config['tag'], ext)
    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()
Exemplo n.º 4
0
def main(args):
    # Parse command line
    config = parseOptions(args)

    # Get the site information for LWA-1
    sta = stations.lwa1

    # Read in the skymap (GSM or LF map @ 74 MHz)
    if config['GSM']:
        smap = skymap.SkyMapGSM(freqMHz=config['freq'] / 1e6)
        if config['verbose']:
            print "Read in GSM map at %.2f MHz of %s pixels; min=%f, max=%f" % (
                config['freq'] / 1e6, len(
                    smap.ra), smap._power.min(), smap._power.max())
    else:
        smap = skymap.SkyMap(freqMHz=config['freq'] / 1e6)
        if config['verbose']:
            print "Read in LF map at %.2f MHz of %d x %d pixels; min=%f, max=%f" % (
                config['freq'] / 1e6, smap.numPixelsX, smap.numPixelsY,
                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 config['pol'] == 'EW':
        beamCoeff = beamDict['fitX']
    else:
        beamCoeff = beamDict['fitY']
    try:
        beamDict.close()
    except AttributeError:
        pass
    alphaE = numpy.polyval(beamCoeff[0, 0, :], config['freq'])
    betaE = numpy.polyval(beamCoeff[0, 1, :], config['freq'])
    gammaE = numpy.polyval(beamCoeff[0, 2, :], config['freq'])
    deltaE = numpy.polyval(beamCoeff[0, 3, :], config['freq'])
    alphaH = numpy.polyval(beamCoeff[1, 0, :], config['freq'])
    betaH = numpy.polyval(beamCoeff[1, 1, :], config['freq'])
    gammaH = numpy.polyval(beamCoeff[1, 2, :], config['freq'])
    deltaH = numpy.polyval(beamCoeff[1, 3, :], config['freq'])
    if config['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)

    def BeamPattern(az, alt):
        zaR = numpy.pi / 2 - alt * numpy.pi / 180.0
        azR = az * numpy.pi / 180.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 numpy.sqrt((pE * numpy.cos(azR))**2 + (pH * numpy.sin(azR))**2)

    if config['enableDisplay']:
        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" %
                    (config['pol'], config['freq'] / 1e6))
        pylab.imshow(BeamPattern(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, config['tStep'] / 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)

        if config['GSM']:
            cdec = numpy.ones_like(pmap.visibleDec)
        else:
            cdec = numpy.cos(pmap.visibleDec * smap.degToRad)

        # Convolution of user antenna pattern with visible skymap
        gain = BeamPattern(pmap.visibleAz, pmap.visibleAlt)
        powerAnt = (pmap.visiblePower * gain * cdec).sum() / (gain *
                                                              cdec).sum()
        powListAnt.append(powerAnt)

        if config['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 config['enableDisplay']:
        pylab.figure(2)
        pylab.title("Driftcurve: %s pol. @ %0.2f MHz - LWA-1" % \
         (config['pol'], config['freq']/1e6))
        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" % ('lwa1', config['pol'],
                                                config['freq'] / 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()
Exemplo n.º 5
0
 
 print('---------------------------------------------------------------')
 print('%s location' % nam)
 print('---------------------------------------------------------------')
 print('Longitude:         %s (%0.3f)' % (lng, lwa_lnlat.lng))
 print('Latitude:          %s (%0.3f)' % (lat, lwa_lnlat.lat)) 
     
 # calculate offset from GM
 
 lwa_gm_hms = astro.deg_to_hms(-lwa_lnlat.lng)
 lwa_gm_off = lwa_gm_hms.to_sec()
 print('GM Offset:         %s (%0.3f)' % (lwa_gm_hms, lwa_gm_off))
 
 # get current UTC time from system clock
 
 utc = astro.get_julian_from_sys()
 utcd = astro.get_date(utc)
 lcld = utcd.to_zone()
 unixt = astro.get_timet_from_julian(utc)
 
 # caculate sidereal times
 
 gm_sid = astro.get_apparent_sidereal_time(utc)
 lwa_sid = astro.get_local_sidereal_time(lwa_lnlat.lng, utc)
     
 print('---------------------------------------------------------------')
 print('Current time')
 print('---------------------------------------------------------------')
 print('UTC time:             %s (%0.3f)' % (utcd, utc))
 print('%s local time:     %s' % (nam, str(lcld)))
 print('GM sidereal time:     %0.3f' % gm_sid)
Exemplo n.º 6
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()
Exemplo n.º 7
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()
Exemplo n.º 8
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())