示例#1
0
def average( names):
    """
    Compute an average spectrum from a list of input file names
    """

    rs = radioastronomy.Spectrum()   # create input and average structures
    asum = radioastronomy.Spectrum()
    nsum = 0

    # now average coldest data for calibration
    for filename in names:

        rs.read_spec_ast(filename)
        rs.azel2radec()    # compute ra,dec from az,el

        if nsum == 0:
            asum = copy.deepcopy( rs)
            firstlon = rs.gallon
            asum.ydataA = rs.ydataA * rs.durationSec
            asum.gallat = rs.gallat * rs.durationSec
            asum.gallon = rs.gallon * rs.durationSec
            nsum = 1
            firstutc = rs.utc
            lastutc = rs.utc
        else:
            asum.ydataA = asum.ydataA + (rs.ydataA * rs.durationSec)
            asum.count = asum.count + rs.count
            asum.durationSec = asum.durationSec + rs.durationSec
            # fix wrap of longitudes
            if abs(rs.gallon - firstlon) > 180:
                crossZero = True
                if rs.gallon > firstlon:
                    rs.gallon = rs.gallon - 360.
                else:
                    rs.gallon = rs.gallon + 360.
            asum.gallon = asum.gallon + (rs.gallon * rs.durationSec)
            asum.gallat = asum.gallat + (rs.gallat * rs.durationSec)
            # keep track of observing time for weighted sum
            lastutc = rs.utc
            nsum = nsum + 1
    #end for all files loop

    if nsum < 1:
        print "No acceptable files in average list"
    else:
        asum.ydataA = asum.ydataA/float(asum.durationSec)
        asum.gallon = asum.gallon/float(asum.durationSec)
        asum.gallat = asum.gallat/float(asum.durationSec)
        aveutc,duration = radioastronomy.aveutcs( firstutc, lastutc)
        asum.utc = aveutc
        if (duration < 1.):
            print 'hotcold.average: very short average interval: ',duration
    return nsum, asum
示例#2
0
 def __init__(self, noteName, vlen, frequency, bandwidth, record, note, observer, telescope, device,
              gain1, azimuth, elevation):
     """
     Initialize the event writing setup, recording the observing parameters
     """
     gr.sync_block.__init__(self,
                            name="ra_event_sink",
                            # inputs: time sequence of I,Q values,
                            # peak, rms, Event MJD
                            in_sig=[(np.complex64, int(vlen))],
                            out_sig=None, )
     vlen = int(vlen)
     self.vlen = vlen
     self.ecount = 1
     self.record = int(record)
     noteName = str(noteName)
     # first keep setup info in class header
     self.observer = str(observer)
     self.site = str(telescope)
     self.noteA = str(note)
     self.device = str(device)
     self.telaz = float(azimuth)
     self.telel = float(elevation)
     self.bandwidthMHz = float(bandwidth)
     self.frequencyMHz = float(frequency)
     self.gain1 = float(gain1)
     self.obs = radioastronomy.Spectrum(nChan=0, nSamples=vlen)
     # now transfer parameters to the observations file
     self.setupdir = "./"
     # read all generic setup info in the note file
     self.set_setup(noteName, doSave=True)
     # report newly discovered tags once
     self.lasttag = ""
示例#3
0
 def __init__(self, noteName, vlen, frequency, bandwidth, record, note,
              observer, telescope, device, gain1, azimuth, elevation):
     gr.sync_block.__init__(
         self,
         name="ra_event_sink",
         # inputs: time sequence of I,Q values,
         # peak, rms, Event MJD
         in_sig=[(np.complex64, int(vlen))],
         out_sig=None,
     )
     vlen = int(vlen)
     self.vlen = vlen
     self.ecount = 1
     self.record = int(record)
     noteName = str(noteName)
     # first keep setup info in class header
     self.observer = str(observer)
     self.site = str(telescope)
     self.noteA = str(note)
     self.device = str(device)
     self.gains = np.zeros(3)
     self.gains[0] = float(gain1)
     self.telaz = float(azimuth)
     self.telel = float(elevation)
     self.bandwidthMHz = float(bandwidth)
     self.frequencyMHz = float(frequency)
     self.obs = radioastronomy.Spectrum(nChan=0, nSamples=vlen)
     self.setupdir = "./"
     # read all generic setup info in the note file
     self.set_setup(noteName, doSave=True)
示例#4
0
 def __init__(self, noteName, observers, vlen, frequency, bandwidth, azimuth, elevation, record, obstype, 
              nmedian, nave, site, device, gain1, gain2, gain3):
     gr.sync_block.__init__(self,
         name="ascii_sink",
                  # spectrum
         in_sig=[(np.float32, int(vlen))],
         out_sig=None)
     vlen = int(vlen)
     self.vlen = vlen
     self.nave = nave
     self.avecount = 0
     self.record = radioastronomy.INTWAIT
     self.sum = np.zeros(vlen)
     self.noteName = str(noteName)
     self.obs = radioastronomy.Spectrum()
     self.obs.read_spec_ast(self.noteName)    # read the parameters 
     self.obs.observer = observers
     self.obs.nChan = vlen
     self.obs.nSpec = 1
     self.obs.ydataA = np.zeros(vlen)
     self.obs.ydataB = np.zeros(vlen)
     self.obs.xdata = np.zeros(vlen)
     now = datetime.datetime.utcnow()
     self.startutc = now
     self.stoputc = now
     self.obs.utc = now
     self.setupdir = ""#"./"
     self.notesName = noteName
     self.obstype = int( obstype)
     print 'Setup File       : ',self.noteName
     if not os.path.exists(self.obs.datadir):
         os.makedirs(self.obs.datadir)
     nd = len(self.obs.datadir)
     if self.obs.datadir[nd-1] != '/':
         self.obs.datadir = self.obs.datadir + "/"
         print 'DataDir          : ',self.obs.datadir
     print 'Observer Names   : ',self.obs.observer
     # skip writing notes until the end of init
     dosave = False
     self.set_frequency( frequency, dosave)
     self.set_bandwidth( bandwidth, dosave)
     self.set_azimuth( azimuth, dosave)
     self.set_elevation( elevation, dosave)
     self.set_nave( nave, dosave)
     self.set_nmedian( nmedian, dosave)
     self.set_gain1( gain1, dosave)
     self.set_gain2( gain2, dosave)
     self.set_gain3( gain3, dosave)
     self.set_record( record)
     self.save_setup()
示例#5
0
def read_cold(names, ave_cold, minel, minGLat, maxGlat):
    """
    read_cold() reads all files and averages selected files with high elevation and 
    galactic Latitude.
    Inputs:
       minel   minimum elevation to accept for cold load 
       minGLat minimum galactic latitude
       maxGlat maximum galactic latitude
    """

    # flag starting a new sum of cold (high elevation and galactic latitude) obs
    ncold = 0
    rs = radioastronomy.Spectrum()
    # now average coldest data for calibration
    for filename in names:

        rs.read_spec_ast(filename)
        rs.azel2radec()  # compute ra,dec from az,el

        if rs.telel < lowel:  #if elevation too low for a cold load obs
            continue

        # note this test excludes low galactic latitude ranges
        if rs.gallat > maxGlat or rs.gallat < minGlat:
            if ncold == 0:
                firstutc = rs.utc
                lastutc = rs.utc
            ave_cold, rs, ncold, firstutc, lastutc = \
                average_spec( ave_cold, rs, ncold, firstutc, lastutc)

    # end of all files to average
    if ncold < 1:
        print("No high galactic latitude data: can not calibrate")
        exit()
    else:
        ave_cold, ncold = normalize_spec(ave_cold, ncold, firstutc, lastutc)

    if flagRfi:
        yv = ave_cold.ydataA
        xv = ave_cold.xdata * 1.E-6
        cv = interpolate.lines(linelist, linewidth, xv, yv)  # interpolate rfi
        ave_cold.ydataA = cv

    if doFold:
        ave_cold.foldfrequency()

    print("Found %3d High Galactic Latitude spectra" % (ncold))
    return ave_cold, ncold
示例#6
0
def hotaverage( names):
    """
    Read in all spectra from a list of names and return the average hot spectrum
    """
    rs = radioastronomy.Spectrum()   # create input and average structures
    nhot = 0

    avenames = names                 # create a list of files to average

    # for all input files
    for filename in names:

        parts = filename.split('/')
        nparts = len(parts)
        if nparts == 1:
            aname = parts[0]
        else:
            aname = parts[nparts-1]

        parts = aname.split('.')
        nparts = len(parts)
        if nparts < 2:
            print 'File is not an astronomy file: ',filename
            continue
        else:
            extension = parts[nparts-1]

        extension = extension.upper()
        if extension != 'HOT':  # speed up by only  looking at hot load files
            continue
        
        rs.read_spec_ast(filename)

        if rs.telel > 0: # only working with hot load, skip elevation > 0.
            continue

        avenames[nhot] = filename
        nhot = nhot + 1
    # end of for all files loop

    nhot, hot = average( avenames[0:nhot])   # now use generic program for averages
    if nhot < 1:
        print 'No hot load files;  can not calibrate!'
        exit()

    return nhot, hot
示例#7
0
 def __init__(self, noteName, observers, vlen, frequency, bandwidth,
              azimuth, elevation, record, obstype, nmedian, nave, site,
              device, gain1, gain2, gain3):
     gr.sync_block.__init__(
         self,
         name="ra_ascii_sink",
         in_sig=[(np.float32, int(vlen))],  # input is 1 spectrum
         out_sig=[np.float32],  # output is time remaining
     )
     vlen = int(vlen)
     self.vlen = vlen
     self.nave = nave
     self.avecount = 0
     self.record = radioastronomy.INTWAIT
     self.sum = np.zeros(vlen)
     self.noteName = str(noteName)
     # split out extension name
     noteParts = self.noteName.split('.')
     #always use .not extension for notes files
     self.noteName = noteParts[0] + '.not'
     if len(noteParts) > 2:
         print '!!! Warning, unexpected Notes File name! '
         print '!!! Using file: ', self.noteName
     self.obs = radioastronomy.Spectrum()
     self.obs.read_spec_ast(self.noteName)  # read the parameters
     self.obs.observer = observers
     self.obs.nChan = vlen
     self.obs.refChan = self.obs.nChan / 2.
     self.obs.nSpec = 1
     self.obs.ydataA = np.zeros(vlen)
     self.obs.ydataB = np.zeros(vlen)
     self.obs.xdata = np.zeros(vlen)
     now = datetime.datetime.utcnow()
     self.startutc = now
     self.stoputc = now
     self.obs.utc = now
     self.average_done = 0.0  # no data averaged yet
     self.setupdir = "./"
     self.noteName = noteName
     # split out extension name
     noteParts = self.noteName.split('.')
     #always use .not extension for notes files
     self.noteName = noteParts[0] + '.not'
     if len(noteParts) > 2:
         print '!!! Warning, unexpected Notes File name! '
         print '!!! Using file: ', self.noteName
     else:
         if os.path.isfile(self.noteName):
             print 'Setup File       : ', self.noteName
         else:
             if os.path.isfile("Watch.not"):
                 try:
                     import shutil
                     shutil.copyfile("Watch.not", self.noteName)
                     print "Created %s from file: Watch.not" % (
                         self.noteName)
                 except:
                     print "! Create the Note file %s, and try again !" % (
                         self.noteName)
     if not os.path.exists(self.obs.datadir):
         os.makedirs(self.obs.datadir)
     nd = len(self.obs.datadir)
     if self.obs.datadir[nd - 1] != '/':
         self.obs.datadir = self.obs.datadir + "/"
         print 'DataDir          : ', self.obs.datadir
     print 'Observer Names   : ', self.obs.observer
     # skip writing notes until the end of init
     dosave = False
     self.set_obstype(obstype)
     self.set_frequency(frequency, dosave)
     self.set_bandwidth(bandwidth, dosave)
     self.set_azimuth(azimuth, dosave)
     self.set_elevation(elevation, dosave)
     self.set_nmedian(nmedian, dosave)
     self.set_nave(nave, dosave)
     self.set_gain1(gain1, dosave)
     self.set_gain2(gain2, dosave)
     self.set_gain3(gain3, dosave)
     self.set_site(site, dosave)
     self.set_device(device, dosave)
     self.set_record(record)
     self.save_setup()
示例#8
0
文件: z.py 项目: bzhao13/CSE-490
def findzero( names, gain, vel, azoffset, eloffset, avetimesec):
    lastgain = 0.
    global nprint
    # flag start of search for a latitude zero crossing
    ncrossings = -1
    crossingsum = 0.
    lastgallat = -100.
    lastsum = 0.

    nData = len(vel)
    minGlat = +90.
    maxGlat = -90.
    nhot = 0         # number of obs with el < 0
    ncold = 0
    nhigh = 0        # highest galactic latitude
    lastfreq = 0.
    lastbw = 0.
    lastgain = 0.
    lastel = 0.
    lastaz = 0.
    firstrun = True

    avetime = datetime.timedelta(seconds=avetimesec)
    firstgallon = -1.
    ncrossings = 0

    nread = 0        
# now read through all data and average cold sky obs
    for filename in names:

        parts = filename.split('/')
        nparts = len(parts)
        aname = parts[nparts-1]
        parts = aname.split('.')
        aname = parts[0]
        extension = parts[1]
        parts = aname.split('T')
        date = parts[0]
        time = parts[1]
        time = time.replace('_', ':')  # put time back in normal hh:mm:ss format

# exclude hot load data for averaging
        if extension == 'hot':
            continue

        rs = radioastronomy.Spectrum()
#  print filename
        rs.read_spec_ast(filename)
        rs.telaz = rs.telaz + azoffset
        rs.telel = rs.telel + eloffset
        rs.azel2radec()    # compute ra,dec from az,el

# if a sky observation and close to galactic plane
        if rs.telel > 0. and (rs.gallat > -5.0 and rs.gallat < 5.0) :

# if first time reading data, set obs parameters
            if lastfreq == 0.:
                lastfreq = rs.centerFreqHz 
                lastbw = rs.bandwidthHz
                lastgain = rs.gains[0]
                lastaz = rs.telaz
                lastel = rs.telel
                cold = copy.deepcopy( rs)
                ncold = 0
                timesum = 0.
                firstutc = cold.utc
                lastutc = cold.utc

            newAzEl = (lastaz != rs.telaz) or (lastel != rs.telel)
            if newAzEl and nprint < 5:
                print 'Must keep az,el constant to find pointing offsets!'
                print 'Last %7.2f,%7.2f; New: %7.2f,%7.2f' % (lastaz, lastel, rs.telaz, rs.telel)
                lastaz = rs.telaz
                lastel = rs.telel
                nprint = nprint + 1
                break

            if ncold > 1:
            # time difference is between mid-points of integrations
                dt = rs.utc - cold.utc 
            # add the time since midpoint of latests
                dt = dt + datetime.timedelta(seconds=rs.durationSec)
                lastutc = rs.utc

           # if time to average (or end of all files)
                if (dt > avetime) or (filename == sys.argv[nargs-1]):
                    cold.ydataA = cold.ydataA/float(timesum)
                # have complicated steps to simple get the average time.
                    deltatime = endtime - starttime
                    aveutc,duration = radioastronomy.aveutcs( firstutc, lastutc)
                    cold.utc = aveutc
                    cold.azel2radec() # recompute coordinates for average time
                    ra = cold.ra
                    dec = cold.dec
                    gallat = cold.gallat
                    gallon = cold.gallon

                    if ncrossings < 0:
                        lastgallat = gallat
                        ncrossings = 0
                        crossingsum = 0.
                        
                    xv = cold.xdata * 1.E-6
                    yv = cold.ydataA * scalefactor
                    yv = interpolate.lines( linelist, linewidth, xv, yv) # interpolate rfi
                    xmin = min(xv)
                    xmax = max(xv)
                    count = cold.count
                    note = cold.noteA
                    #print('%s' % note)
                    ncolor = min(nmax-1, nplot) 
                
                    tsky  = np.zeros(nData)    # initialize arrays
                    for jjj in range (0, nData):
                        tsky[jjj] = yv[jjj]/gain[jjj]
                        
                    imin, imax = velocity_to_indicies( vel, minvel, maxvel)
                    
                    ymed = np.median(tsky[imin:imax])
                    ya = np.median(tsky[(imin-10):(imin+10)])
                    yb = np.median(tsky[(imax-10):(imax+10)])
                    slope = (yb-ya)/(imax-imin)
                    nFit = 20
                    baseline = fit_baseline( vel, tsky, imin, imax, nFit)
                    tsky = tsky - baseline

                    ymin = min(tsky[imin:imax])
                    ymax = max(tsky[imin:imax])
                    thesum = compute_sum( minvel, maxvel, ra, dec, gallon, gallat, vel, tsky, ncold)
                    
                # finallly if this is a latitude crossing sum.
                    if ((lastgallat < 0. and gallat > 0.) or (lastgallat > 0. and gallat < 0.)) and lastgallat > -100.:
                        if abs(gallat) < 5.:
                    # if first crossing, init sum
                            if ncrossings == 0:
                                ncrossings = 1
                                crossingsum = thesum 
#                                print 'Zero Latitude: %7.1f %7.1f: %10.0f, %10.0f' % (lastgallat, gallat, lastsum, thesum)
                            else:
                                # else average crossings
                                ncrossings = ncrossings + 1
                                crossingsum = crossingsum + thesum 
                        if abs(lastgallat) < 5.:
                            if ncrossings == 0:
                                ncrossings = 1
                                crossingsum = lastsum
#                                print 'Zero Latitude: %7.1f %7.1f: %10.0f, %10.0f' % (lastgallat, gallat, lastsum, thesum)
                            else:
                                # else average crossings
                                ncrossings = ncrossings + 1
                                crossingsum = crossingsum + lastsum 

                    lastgallat = gallat
                    lastsum = thesum
                    # computation done, start sum over gain
                    ncold = 0

# if this was a new obs; restart the sums
            if ncold == 0:
                cold = copy.deepcopy(rs)  # initial spectrum is one just read
                starttime = cold.utc
                endtime = starttime
                ncold = 1
            # sums are weighted by durations
                crossZero = False
                crossZeroLat = False
                crossZeroRa = False
                firstlon = rs.gallon # try to keep track of crossing zero in angular coordinates
                firstra = rs.ra #
                cold.ydataA = rs.ydataA * cold.durationSec
            # keep track of observing time for weighted sum
                timesum = rs.durationSec
            else: # else not enough time yet, average cold data
                # fix wrap of longitudes
                cold.count = cold.count + rs.count
                ncold = ncold + 1
                cold.ydataA = cold.ydataA + (rs.ydataA * rs.durationSec)
                cold.ra = cold.ra + (rs.ra * cold.durationSec)
                cold.dec = cold.dec + (rs.dec * cold.durationSec)
                cold.gallon = cold.gallon + (rs.gallon * rs.durationSec)
                cold.gallat = cold.gallat + (rs.gallat * rs.durationSec)
            # keep track of observing time for weighted sum
                endtime = rs.utc
                timesum = timesum + rs.durationSec
            # end if not a enough time
        # end if a cold file
    #end for all files to sum

    if ncrossings > 0:
        crossingsum = crossingsum/float(ncrossings)
    return crossingsum
示例#9
0
lastel = 0.
lastaz = 0.
firstdate = ""
lastdate = ""
minel = 200.
maxel = -200.
firstaz = -1
otheraz = -1
dt = datetime.timedelta(seconds=0.)

# rest of arguments are file names
names = sys.argv[namearg:]
names = sorted(names)
nFiles = len(names)
# create the spectrum class/structure to receive spectra
rs = radioastronomy.Spectrum()
ave_hot = radioastronomy.Spectrum()
ave_cold = radioastronomy.Spectrum()


def average_spec(ave_spec, in_spec, nave, firstutc, lastutc):
    """
    Averages spectra and deal with issues of weighting functions by observing duration
    input/output
    ave_spec   spectrum structure containing weighted average
    input:
    in_spec    spectrum to be added to the average
    in/out:
    nave       Count of number of spectra averaged so far.
               nave = 0 implies initializing the sum.
    firstutc   date of first observation averaged
示例#10
0
    def __init__(self, noteName, vlen, bandwidth, record):
        gr.sync_block.__init__(
            self,
            name="ra_event_sink",
            # inputs: time sequence of I,Q values,
            # peak, rms, Event MJD
            in_sig=[(np.complex64, int(vlen))],
            out_sig=None,
        )
        vlen = int(vlen)
        self.vlen = vlen
        self.ecount = 1
        self.record = int(record)
        self.obs = radioastronomy.Spectrum()
        self.setupdir = "./"
        noteParts = noteName.split('.')
        self.noteName = noteParts[0] + '.not'
        if len(noteParts) > 2:
            print '!!! Warning, unexpected Notes File name! '
            print '!!! Using file: ', self.noteName
        else:
            if os.path.isfile(self.noteName):
                print 'Setup File       : ', self.noteName
            else:
                if os.path.isfile("Watch.not"):
                    try:
                        import shutil
                        shutil.copyfile("Watch.not", self.noteName)
                        print "Created %s from file: Watch.not" % (
                            self.noteName)
                    except:
                        pformat = "! Create the Note file %s, and try again !"
                        print pformat % (self.noteName)
        self.obs.read_spec_ast(self.noteName)  # read the parameters

        # prepare to Event get messages
        #        print 'Registered event on input port of sink'

        #        self.set_tag_propagation_policy(gr.TPP_ALL_TO_ALL)
        #        self.set_msg_handler(pmt.intern('in_port'), self.event_handler)

        self.obs.datadir = "../events/"  # writing events not spectra
        self.obs.noteB = "Event Detection"
        if not os.path.exists(self.obs.datadir):
            os.makedirs(self.obs.datadir)
        nd = len(self.obs.datadir)
        if self.obs.datadir[nd - 1] != '/':
            self.obs.datadir = self.obs.datadir + "/"
            print 'DataDir          : ', self.obs.datadir
        self.obs.nSpec = 0  # not working with spectra
        self.obs.nChan = 0
        self.obs.nTime = 1  # working with time series
        self.obs.nSamples = vlen
        vlen2 = int(vlen / 2)
        self.obs.refSample = vlen2 + 1  # event is in middle of time sequence
        self.obs.ydataA = np.zeros(vlen, dtype=np.complex64)
        self.obs.xdata = np.zeros(vlen)
        now = datetime.datetime.utcnow()
        self.eventutc = now
        self.obs.utc = now
        self.eventmjd = jdutil.datetime_to_mjd(now)
        self.lastmjd = self.eventmjd
        self.emagnitude = 0.
        self.erms = 0.
        self.set_sample_rate(bandwidth)
示例#11
0
def gridAFile(nChan=128, filename=""):
    """
    Compute a grided image of the fourier transform of a time series
    Inputs: filename - name of the Event file to read
    nblock - number of samples to use to compute a single Fourier Transform
    """

    maxMagnitude = 0.
    maxEvent = radioastronomy.Spectrum()
    maxFile = ""

    nblock = 2 * int(nChan)
    nblock1 = nblock - 1
    N = nblock  # abreviation
    N2 = N // 2
    #    print "N, N2: ", N, N2

    yp = np.zeros(N2)
    yp2 = np.zeros(N2)
    ysum = np.zeros(N2 - 1)
    nsum = 0  # count total number of spectra summed

    rs = radioastronomy.Spectrum()
    #    print filename
    rs.read_spec_ast(filename)
    rs.azel2radec()  # compute ra,dec from az,el

    #    print("GAL Lon,Lat: %8.3f, %8.3f"  % (rs.gallon, rs.gallat))
    parts = filename.split('/')
    nparts = len(parts)
    aname = parts[nparts - 1]
    parts = aname.split('.')
    aname = parts[0]
    parts = aname.split('T')
    date = parts[0]
    time = parts[1]
    #    time  = time.replace('_',':')

    gallon = rs.gallon
    gallat = rs.gallat
    label = '%s, AZ,EL: %5s,%5s, Lon,Lat=%5.1f,%5.1f' % (
        time, rs.telaz, rs.telel, gallon, gallat)
    xs = rs.xdata
    if rs.nTime < 1:
        print "Not an Event: ", filename
        return 0

    # now reorganize data into a single time series
    xv = np.zeros(rs.nSamples * 2)
    yv = np.zeros(rs.nSamples * 2)
    yc = np.zeros(rs.nSamples, dtype=np.complex)
    ymag = np.zeros(rs.nSamples)
    nSamples = 2L * rs.nSamples
    j = 0
    dt = 0.5 / rs.bandwidthHz
    t = xs[0]
    for i in range(rs.nSamples):
        yv[j] = rs.ydataA[i]
        yc[i] = rs.ydataA[i] + 1j * rs.ydataB[i]
        xv[j] = t
        j = j + 1
        t = t + dt
        yv[j] = rs.ydataB[i]
        xv[j] = t
        j = j + 1
        t = t + dt

    # compute magnitude of I/Q samples with vector math
    ymag = np.absolute(yc)
    # now find the maximum event in data series
    ymagmax = max(ymag)
    # compute RMS of entire time series
    yrms = np.sqrt(yv.dot(yv) / yv.size)
    # if a valid, noisy observation
    if yrms > 0.:
        nsigma = ymagmax / yrms
        if nsigma > maxMagnitude:
            maxEvent = copy.deepcopy(rs)
            maxMagnitude = nsigma
            maxFile = filename
    else:
        print "Problem observation: %7.3f rms in file %s\n", yrms, filename
    # end else not a signficant event

    # will compute several FFTs, discarding any extra samples at end
    nfft = int(nSamples / nblock) - 1
    lll = 0
    # instead start at half a block to center event
    lll = int(nblock / 2)
    #
    BW = 1.E-6 * rs.bandwidthHz
    # average time for spectra without event
    aveTime = (nfft - 1) * nblock * 1.e-6 / (2. * BW)
    # frequency axis is always the same
    nu = np.linspace(0.0, BW, nblock /
                     2) + (1.E-6 * (rs.centerFreqHz - rs.bandwidthHz / 2.))
    xp = nu[1:N2]
    xmin = min(nu)
    xmax = max(nu)
    # zero sum of all spectra in this file

    #create the grid with map parameters
    mygrid = GridClass.Grid(xmin=xmin, xmax=xmax, ymin=0, ymax=nfft, width=nChan, \
                                height=nfft, dpi=1, FWHM=1., \
                                projection="Mercator", gridtype="")

    for jjj in range(nfft):
        J = float(jjj)
        # for each block of samples
        for kkk in range(nblock):
            ablock[kkk] = yv[lll]
            lll += 1
        yf = fft(ablock * w)  # apply blackman window/weighting to samples
        #        yf = fft(ablock)   # fft without window
        yp = 2.0 / N * np.abs(yf[1:N2])

        ymin = min(yp)
        ymax = max(yp)

        # unwrap spectra
        nnn = ((N2 / 2) - 1)
        for kkk in range(N2 - 1):
            #            if jjj == nfft/2:
            #                print "kkk, nnn: ",kkk,nnn
            yp2[kkk] = yp[nnn]
            nnn -= 1
            if nnn < 0:
                nnn = N2 - 2

        for mmm in range(N2 - 1):
            mygrid.convolve(xp[mmm], J, yp2[mmm], 1.0)

        if jjj == 0:
            print(' Max: %9.3f Min: %9.3f ; %3d %s' %
                  (ymax * kpercount, ymax * kpercount, nfft, label))
            nyp = len(yp2)
            ysum = np.zeros(nyp)


# plot the middle spectrum for each events, until out of colors
        if jjj == (nfft / 2):
            nplot = 1
            yp2 = kpercount * yp2
            yp3 = yp2[1:N2]
            label = '%s %s Lon,Lat=%5.1f,%5.1f' % (date, time, gallon, gallat)
            plt.plot(xp,
                     yp3,
                     colors[nplot - 1],
                     linestyle=linestyles[nplot - 1],
                     label=label)
            note = rs.noteA
            print "Number of FFTs per time series: %5d" % (nfft)
            print "Duration of Observations      : %12.6f s" % (aveTime)
        else:
            #            print "Ysum, yp2: ", len(ysum), len(yp2)
            ysum = ysum + yp2
            nsum += 1

    # now average of all spectra not during the peak event
    ysum = kpercount * ysum / float(nsum)
    ysum = ysum[1:N2]
    avelabel = "Average (%8.6f s)" % aveTime
    plt.plot(xp, ysum, colors[1], linestyle=linestyles[1], label=avelabel)

    # put the average in the top row of the image
    J = float(nfft)
    for mmm in range(N2 - 1):
        mygrid.convolve(xp[mmm], J, ysum[mmm], 1.0)
    print "Event Time         : ", maxEvent.utc
    print "Event File         : ", maxFile
    print "Maximum Event Sigma: %8.2f" % (maxMagnitude)
    print "Event RA           :   %8.4f d Dec %8.4f d" % (maxEvent.ra,
                                                          maxEvent.dec)
    print "Event G Lon        :   %6.2f d  Lat %6.2f d" % (maxEvent.gallon,
                                                           maxEvent.gallat)

    datetime = "%s" % (maxEvent.utc)
    parts = datetime.split('.')
    date = parts[0]

    #        plt.xlim(xallmin,xallmax)
    plt.title(note)
    plt.xlabel('Frequency (MHz)')
    if kpercount == 1.:
        plt.ylabel('Intensity (Counts)')
        #            plt.ylim(yallmin,1.25*yallmax)
    else:
        plt.ylabel('Intensity (Kelvins)')
        #            plt.ylim(kpercount*yallmin,kpercount*1.25*yallmax)
    plt.legend(loc='upper right')
    plt.show()

    return nChan, nfft, xmin, xmax, mygrid
示例#12
0
def main():
    """
    Main executable for matching transient events
    """
    dpi = 1

    nargs = len(sys.argv)
    if nargs < 2:
        print('MATCH: MATCH pairs of events in directories')
        print('usage: MATCH [-OF seconds] dir1 dir2')
        exit()

    from os import listdir
    from os.path import isfile, join

    ndir = np.zeros(50)

    files1 = [f for f in listdir(dirs[0]) if isfile(join(dirs[0], f))]
    ndir[0] = len(files1)
    files2 = [f for f in listdir(dirs[1]) if isfile(join(dirs[1], f))]
    ndir[1] = len(files2)
    if len(dirs[2]) > 0:
        files3 = [f for f in listdir(dirs[2]) if isfile(join(dirs[2], f))]
        ndir[2] = len(files3)
    else:
        files3 = ""
    if len(dirs[3]) > 0:
        files4 = [f for f in listdir(dirs[3]) if isfile(join(dirs[3], f))]
        ndir[3] = len(files4)
    else:
        files4 = ""

    count = 0
    if doDebug:
        for i in range(4):
            print("%5d Files in Directory %d" % (ndir[i], i + 1))

    nSpec1 = 0
    nSpec2 = 0
    nSpec3 = 0
    nSpec4 = 0
    nHot1 = 0
    nHot2 = 0
    nHot3 = 0
    nHot4 = 0

    rs = radioastronomy.Spectrum()

    # now start reading all the files
    spec1s = files1
    spec2s = files2
    spec3s = files3
    spec4s = files4

    hot1s = files1
    hot2s = files2
    hot3s = files3
    hot4s = files4

    # first directory
    for filename in files1:
        parts = filename.split(".")
        nparts = len(parts)
        if nparts < 2:  # if not fooo.eve type file name
            continue
        if parts[nparts - 1] == "ast":
            spec1s[nSpec1] = filename
            nSpec1 = nSpec1 + 1
        if parts[nparts - 1] == "hot":
            hot1s[nHot1] = filename
            nHot1 = nHot1 + 1

    if nSpec1 < 1:
        nSpec1 = 1
    mjd1s = np.zeros(nSpec1)
    peak1s = np.zeros(nSpec1)
    rms1s = np.zeros(nSpec1)
    dt12s = np.zeros(nSpec1)
    ii12s = np.arange(nSpec1) * 0
    spec1s = spec1s[0:nSpec1]
    if nSpec1 == 1:
        nSpec1 = 0

    iii = 0
    for filename in spec1s:
        fullname = join(dirs[0], filename)
        rs.read_spec_ast(fullname)
        rs.azel2radec()  # compute ra,dec from az,el
        if (100 * int(iii / 100) == iii) and doDebug:
            print("Event %5d: %12.9f: %7.3f+/-%5.3f" %
                  (iii, rs.emjd, rs.epeak, rs.erms))
        iii = iii + 1

    if nHot1 > 0:
        hot1s = hot1s[0:nHot1]

    print("%5d Spectra in Directory: %s; Calibration Files: %5d" %
          (nSpec1, dirs[0], nHot1))

    # second directory
    for filename in files2:
        parts = filename.split(".")
        nparts = len(parts)
        if nparts < 2:  # if not fooo.eve type file name
            continue
        if parts[nparts - 1] == "ast":
            spec2s[nSpec2] = filename
            nSpec2 = nSpec2 + 1
        if parts[nparts - 1] == "hot":
            hot2s[nSpec2] = filename
            nHot2 = nHot2 + 1

# directory 2
    if nSpec2 < 1:
        nSpec2 = 1
    mjd2s = np.zeros(nSpec2)

    if nSpec2 == 1:
        nSpec2 = 0

    if nHot2 > 0:
        hot2s = hot2s[0:nHot2]

    iii = 0
    for filename in spec2s:
        fullname = join(dirs[1], filename)
        rs.read_spec_ast(fullname)
        rs.azel2radec()  # compute ra,dec from az,el
        iii = iii + 1

    print("%5d Spectra in Directory: %s; Calibration Files: %5d" %
          (nSpec2, dirs[1], nHot2))

    # third directory
    for filename in files3:
        parts = filename.split(".")
        nparts = len(parts)
        if nparts < 2:  # if not fooo.eve type file name
            continue
        if parts[nparts - 1] == "ast":
            spec3s[nSpec3] = filename
            nSpec3 = nSpec3 + 1
        if parts[nparts - 1] == "hot":
            hot3s[nHot3] = filename
            nHot3 = nHot3 + 1

    if nHot3 > 0:
        hot3s = hot3s[0:nHot3]

# directory 3
    if nSpec3 < 1:
        nSpec3 = 1

    for filename in spec3s:
        fullname = join(dirs[2], filename)
        rs.read_spec_ast(fullname)
        rs.azel2radec()  # compute ra,dec from az,el
        if (100 * int(iii / 100) == iii) and doDebug:
            print("Event %5d: %12.9f: %7.3f+/-%5.3f" %
                  (iii, rs.emjd, rs.epeak, rs.erms))
        iii = iii + 1

    print("%5d Spectra in Directory: %s; Calibration Files: %5d" %
          (nSpec3, dirs[2], nHot3))

    # forth directory
    for filename in files4:
        parts = filename.split(".")
        nparts = len(parts)
        if nparts < 2:  # if not fooo.eve type file name
            continue
        if parts[nparts - 1] == "ast":
            spec4s[nSpec4] = filename
            nSpec4 = nSpec4 + 1
        if parts[nparts - 1] == "hot":
            hot4s[nHot4] = filename
            nHot4 = nHot4 + 1


# directory 4
    if nSpec4 < 1:
        nSpec4 = 1
        spec4s = spec4s[0:nSpec4]
    if nHot4 > 0:
        hot4s = hot4s[0:nHot4]

    iii = 0
    for filename in spec4s:
        fullname = join(dirs[3], filename)
        rs.read_spec_ast(fullname)
        rs.azel2radec()  # compute ra,dec from az,el
        if (100 * int(iii / 100) == iii) and doDebug:
            print("Event %5d: %12.9f: %7.3f+/-%5.3f" %
                  (iii, rs.emjd, rs.epeak, rs.erms))
        iii = iii + 1

    print("%5d Spectra in Directory: %s; Calibration Files: %5d" %
          (nSpec4, dirs[3], nHot4))

    # there are 4 directories and 3 x 2 x 1 = 6 pairs of directories for matchs
    # for each of the directories there are 4 sets of files
    #   mjdNs      - full mjds of events
    #   peakNs     - peaks of each events
    #   rmsNs      - noise in samples near events
    #   eventNs    - names of event files
    # now for each of the matches there are different Indecies
    # 1 = Match between 1+2
    # iiMs    - index to second directory for event match
    # dtMs    - time offset between first and second directory
    # eventMs - name of second event that matches the first directory
    # 1 = Match between 1+2
    # 2 = Match between 2+3
    # 3 = Match between 1+3
    # 4 = Match between 1+4
    # 5 = Match between 2+4
    # 6 = Match between 3+4

    # determine the maximum number of matches
    mjd1 = 0.
    mjd2 = 0.
    mjd3 = 0.
    mjd4 = 0.

    #    maxMatch = max(nSpec1, nSpec2, nSpec3, nSpec4)+1
    maxMatch = nSpec1 + nSpec2 + nSpec3 + nSpec4 + 1
    nMatch = 0
    match1s = np.arange(maxMatch) * 0
    match2s = np.arange(maxMatch) * 0
    match3s = np.arange(maxMatch) * 0
    match4s = np.arange(maxMatch) * 0
示例#13
0
def main():
    """
    Main executable for gridding astronomical data
    """
    dpi = 1
    dpi = 2
    width = int(360)
    height = int(180)
    mywidth = int(width*dpi)
    myheight = int(height*dpi)
    FWHM = 1.0  # degrees
    weight = 1.

    nargs = len(sys.argv)
    if nargs < 2:
        print 'GO: Grid Observations'
        print 'GO RA|GAL|VLAT|VTIME datafiles'
        exit()

    gridtype = sys.argv[1]
    gridtype = gridtype.upper()
    print 'Grid Type: ', gridtype

    if gridtype == 'VTIME':
        xmin = 0.
        xmax = 360..
        ymin = -120.
        ymax = 120.

    if gridtype == 'VLON':
        xmin = 0.
        xmax = 360..
        ymin = -120.
        ymax = 120.

    if gridtype == 'VLAT':
        xmin = 0.
        xmax = 360..
        ymin = -120.
        ymax = 120.

    if gridtype != 'VLON' and gridtype != 'VLAT' and gridtype != 'VTIME':
        print 'Error parsing grid type: ', gridtype
        print '1st argument should be either VLON, VLAT or VTIME'
        exit()


    #create the grid with map parameters
    mygrid = GridClass.Grid(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, width=width, \
                                height=height, dpi=dpi, FWHM=FWHM, \
                                projection="Mercator", gridtype=gridtype)

# first read through all data and find hot load
    names = sys.argv[2:]
    names = sorted(names)

    firsttime = ""
    lasttime = ""
    count = 0
    rs = radioastronomy.Spectrum()

    for filename in names:
        
        rs.read_spec_ast(filename)
        rs.azel2radec()

                float(parts[0])
            except ValueError:
                print "Not a float"
                print 'Parts: ', parts
                continue
示例#14
0
 def __init__(self, setupFile, observers, vlen, frequency, bandwidth,
              azimuth, elevation, inttype, obstype, nmedian, units, thot,
              tcold):
     gr.sync_block.__init__(
         self,
         name="integrate",
         # spectrum
         in_sig=[(np.float32, int(vlen))],
         out_sig=[(np.float32, int(vlen)), (np.float32, int(vlen)),
                  (np.float32, int(vlen)), (np.float32, int(vlen)),
                  (np.float32, int(vlen))])
     self.vlen = int(vlen)
     self.nave = 1L
     self.setupFile = str(setupFile)
     self.obstype = obstype
     self.inttype = inttype
     self.obs = radioastronomy.Spectrum()
     self.ave = radioastronomy.Spectrum()
     self.frequency = frequency
     self.bandwidth = bandwidth
     self.record = radioastronomy.INTWAIT
     self.hot = radioastronomy.Spectrum()
     self.cold = radioastronomy.Spectrum()
     self.ref = radioastronomy.Spectrum()
     self.obs.read_spec_ast(self.setupFile)  # read the parameters
     self.obs.observer = observers
     self.ave.read_spec_ast(self.setupFile)  # read the parameters
     if os.path.isfile(HOTFILE):
         self.hot.read_spec_ast(HOTFILE)
     else:
         self.hot.read_spec_ast(self.setupFile)  # read the parameters
     if os.path.isfile(COLDFILE):
         self.cold.read_spec_ast(COLDFILE)
     else:
         self.cold.read_spec_ast(self.setupFile)  # read the parameters
     if os.path.isfile(REFFILE):
         self.ref.read_spec_ast(REFFILE)
     else:
         self.ref.read_spec_ast(self.setupFile)  # read the parameters
     if self.obs.nChan != vlen:
         self.update_len(self.obs)
     if self.ave.nChan != vlen:
         self.update_len(self.ave)
     if self.hot.nChan != vlen:
         self.update_len(self.hot)
     if self.cold.nChan != vlen:
         self.update_len(self.cold)
     if self.ref.nChan != vlen:
         self.update_len(self.ref)
     now = datetime.datetime.utcnow()
     self.startutc = now
     self.stoputc = now
     self.obs.utc = now
     print 'Setup File       : ', self.setupFile
     # prepare to start writing observations
     if not os.path.exists(self.obs.datadir):
         os.makedirs(self.obs.datadir)
     nd = len(self.obs.datadir)
     if self.obs.datadir[nd - 1] != '/':
         self.obs.datadir = self.obs.datadir + "/"
         print 'DataDir          : ', self.obs.datadir
     print 'Observer Names   : ', self.obs.observer
     self.obstypes = range(radioastronomy.NOBSTYPES)
     self.intstatus = range(radioastronomy.NINTTYPES)
     self.set_frequency(frequency)
     self.set_bandwidth(bandwidth)
     self.set_azimuth(azimuth)
     self.set_elevation(elevation)
     self.set_inttype(inttype)
     self.set_obstype(obstype)
     self.set_units(units)
     self.set_nmedian(nmedian)
     self.set_thot(thot)
     self.set_tcold(tcold)
     self.epsilons = np.full(self.vlen, EPSILON)
示例#15
0
def main():
    """
    Main executable for gridding astronomical data
    """
    global offset

    nargs = len(sys.argv)
    if nargs < 2:
        print('GROUP: GROUP events into long and short duration')
        print('usage: GROUP [-OF seconds] [-G number] [-M] [-P] [-D] dir1')
        print('where: -M  move groups into a sub-directory')
        print('       -P  plot ungrouped events')
        print(
            '       -G  <number> is the minimum number of events to call a group'
        )
        print('       -D  print debugging info')
        exit()

    dir1 = sys.argv[ifile]
    print("Dir 1: ", dir1)

    from os import listdir
    from os.path import isfile, join
    files1 = [f for f in listdir(dir1) if isfile(join(dir1, f))]

    groupDir = dir1 + "/groups"

    print("Time offset to identify a group: %7.2f s " % (offset))

    offset = offset / 86400.  # convert to MJDs

    print("%5d Files in Directory 1" % (len(files1)))
    #    print files
    nGroups = 0

    rs = radioastronomy.Spectrum()

    event1s = files1
    nEve1 = 0

    for filename in files1:
        parts = filename.split(".")
        nparts = len(parts)
        if nparts < 2:  # if not fooo.eve type file name
            continue
        if parts[nparts - 1] == "eve":
            event1s[nEve1] = filename
            nEve1 = nEve1 + 1
        else:
            continue

    # now extract only the list of events, sorted in time order
    event1s = sorted(event1s[0:nEve1])
    mjd1s = np.zeros(nEve1)
    peak1s = np.zeros(nEve1)
    rms1s = np.zeros(nEve1)

    # now get event signficances
    iii = 0
    for filename in event1s:
        fullname = join(dir1, filename)
        rs.read_spec_ast(fullname)
        rs.azel2radec()  # compute ra,dec from az,el
        # if this is a significant event
        if rs.epeak / rs.erms > sigma:
            mjd1s[iii] = rs.emjd
            peak1s[iii] = rs.epeak
            rms1s[iii] = rs.erms
            event1s[iii] = filename
            iii = iii + 1
        if 50 * int(iii / 50) == iii:
            print("Event %5d: %12.9f: %7.3f+/-%5.3f" %
                  (iii, rs.emjd, rs.epeak, rs.erms))

    print("Read %5d events, of which %5d are > %7.2f sigma" %
          (nEve1, iii, sigma))

    # new count of significant events
    nEve1 = iii

    inGroup = False
    nInGroup = 0
    nAlone = 0
    groupFiles = copy.deepcopy(event1s)
    aloneEvents = copy.deepcopy(event1s)

    # now group event times

    lastt = mjd1s[0]

    if doDebug:
        print(" Offset limit for grouping: %7.2fs" % (offset * 86400.))

    iFirst = 0
    iLast = 0

    for iii in range(nEve1):
        t = mjd1s[iii]
        dt = abs(t - lastt)

        if doDebug:
            print("Event %d offset from previous: %7.2f (%d): " %
                  (iii, dt * 86400., nInGroup))
        if dt == 0.:
            inGroup = False
            groupFiles[0] = event1s[iii]
            nInGroup = 1
            firstFile = event1s[iii]
            iFirst = iii
            lastFile = event1s[iii]
            iLast = iii
        elif dt < offset:
            inGroup = True
            groupFiles[nInGroup] = event1s[iii]
            nInGroup = nInGroup + 1
            lastFile = event1s[iii]
            iLast = iii
        else:
            if doDebug:
                print("N in Group: %d" % (nInGroup))
            # if was in a group, but no longer
            if nInGroup >= ngroup:
                if doMove:
                    moveFiles(dir1, groupDir, nInGroup, groupFiles)
                dMjd = mjd1s[iLast] - mjd1s[iFirst]
                duration = 86400. * dMjd
                print("Group of %5d events (%s-%s), dur: %9.3f (s)" %
                      (nInGroup, firstFile, lastFile, duration))
                nGroups = nGroups + 1
            else:
                kkk = iFirst
                if doDebug:
                    print(" First: %d, Last: %d" % (iFirst, iLast))
                for jjj in range(nInGroup):
                    if doDebug:
                        print(" Index: %d, nAlone: %d; File Index %d" %
                              (jjj, nAlone, kkk))
                    aloneEvents[nAlone] = event1s[kkk]
                    nAlone = nAlone + 1
                    kkk = kkk + 1
            # start a new group with this file
            groupFiles[0] = event1s[iii]
            nInGroup = 1
            firstFile = event1s[iii]
            iFirst = iii
            lastFile = event1s[iii]
            iLast = iii
            inGroup = False
        lastt = t

    # if was in a group, but no longer
    if nInGroup >= ngroup:
        if doMove:
            moveFiles(dir1, groupDir, nInGroup, groupFiles)
        nGroups = nGroups + 1
    else:
        kkk = iFirst
        for jjj in range(nInGroup):
            aloneEvents[nAlone] = event1s[kkk]
            nAlone = nAlone + 1
            kkk = kkk + 1

    print("Found %5d groups and %5d isolated events " % (nGroups, nAlone))
    return
示例#16
0
def main():
    """
    Main executable for gridding astronomical data
    """
    dpi = 1
    dpi = 2
    width = int(360)
    height = int(130)
    mywidth = int(width * dpi)
    myheight = int(height * dpi)
    FWHM = 7.5  # degrees
    FWHM = 10.0  # degrees
    FWHM = 5.0  # degrees
    FWHM = 3.0  # degrees
    FWHM = 1.0  # degrees
    weight = 1.

    nargs = len(sys.argv)
    if nargs < 2:
        print(
            'GR: GRid Observations of integrated intensity produced by the T Command'
        )
        print(
            'GR produces fits images for each of the horns used for the observations.'
        )
        print(
            'For observations at the same coordinates, the ratios of intensities are also produced.'
        )
        print(
            'The FITS format files require header information, which is copied from the'
        )
        print('Cold Load File provided by the user')
        print(
            'GR RA|GAL <cold file name> <savefile1> [<savefile2> ... <savefileN>]'
        )
        print("")
        print('Glen Langston, National Science Foundation -- 20 May 12')
        exit()

    gridtype = sys.argv[1]
    gridtype = gridtype.upper()
    print('Grid Type: ', gridtype)

    # enable having ra going from 24 to 0 hours == 360 to 0 degrees
    xsign = 1.
    xoffset = 0.
    if gridtype == 'RA':
        xmin = 0.
        xmax = 360.
        ymin = -40.
        ymax = 90.
        maptype = 'RA'
    elif gridtype == '-RA':
        xmin = 0.
        xmax = 360.
        ymin = -40.
        ymax = 90.
        xsign = -1.
        xoffset = 360.  # when x = 360. should be at zero.
        maptype = 'RA'
    elif gridtype == '-EL':
        xmin = 0.
        xmax = 360.
        ymin = 0.
        ymax = 90.
        xsign = -1.
        xoffset = 360.  # when x = 360. should be at zero.
        maptype = 'AZEL'
    elif gridtype == 'RA0':
        xmin = 0.
        xmax = 360.
        ymin = -41.
        ymax = 89.
        xsign = -1.
        xoffset = 180.  # when x = 360. should be at zero.
        gridtype = 'RA'
    elif gridtype == 'GAL':
        xmin = -180.
        xmax = 180.
        ymin = -90.
        ymax = 90.
        maptype = 'GAL'

    if gridtype != 'RA' and gridtype != 'GAL' and gridtype != '-RA' and gridtype != "RA0":
        print('Error parsing grid type: ', gridtype)
        print('1st argument should be either RA, -RA or GAL')
        exit()

    rs = radioastronomy.Spectrum()

    if doRatio:
        #create the grid with map parameters
        grid1 = GridClass.Grid(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, width=width, \
                                height=height, dpi=dpi, FWHM=FWHM, \
                                projection="-CAR", gridtype=maptype)
        grid2 = GridClass.Grid(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, width=width, \
                                height=height, dpi=dpi, FWHM=FWHM, \
                                projection="-CAR", gridtype=maptype)
        grid3 = GridClass.Grid(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, width=width, \
                                height=height, dpi=dpi, FWHM=FWHM, \
                                projection="-CAR", gridtype=maptype)
        grid4 = GridClass.Grid(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, width=width, \
                                height=height, dpi=dpi, FWHM=FWHM, \
                                projection="-CAR", gridtype=maptype)
        # put each telescope in a different grid
        grids = [grid1, grid2, grid3, grid4]

    gridall = GridClass.Grid(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, width=width, \
                                height=height, dpi=dpi, FWHM=FWHM, \
                                projection="-CAR", gridtype=maptype)

    projection = "-AIT"
    # coldfile
    coldfile = sys.argv[2]
    # get telescope geographic location etc
    print("Reading Observing parameters from: %s" % (coldfile))
    rs.read_spec_ast(coldfile)
    print("Observer: %s " % (rs.observer))

    # first read through all data and find hot load
    names = sys.argv[3:]
    names = sorted(names)

    firsttime = ""
    lasttime = ""
    count = 0
    # setup grid indicies so that cpuIndex goes to the correct grid
    # This assumes telescopes 2,3,4,5 are being used]
    gridIndex = [0, 0, 0, 1, 2, 3]
    # for all save Files to Grid
    for filename in names:
        print("File: %s" % (filename))
        f = open(filename)

        date = "Unknown"
        while date != "":
            date, time, cpuIndex, telaz, telel, tSys, tRx, tRms, tint, KperC, tSourcemax, velSource, dV, tVSum, tVSumRms, tSumKmSec, dTSumKmSec, gainFactor = gainfactor.readSaveValues(
                f)
            dlen = len(date)
            if dlen < 1:
                break
            if date[0] == "#":
                continue
            # else not a comment process the line
            count = count + 1
            isodate = "20" + date + "T" + time
            #            print("DateTime: %s" % (isodate))
            rs.utc = datetime.datetime.strptime(isodate, "%Y-%m-%dT%H:%M:%S")
            #            print("Utc: %s" % (rs.utc))
            rs.telaz = telaz
            rs.telel = telel
            rs.azel2radec()

            ra = rs.ra
            dec = rs.dec
            lon = rs.gallon
            lat = rs.gallat
            tsum = tSumKmSec
            tsdv = dTSumKmSec
            tmax = tSourcemax
            vave = tVSum
            vsdv = tVSumRms
            if firsttime == "":
                firsttime = date
            else:
                lasttime = date

#            if vave > -100. and vave < 100:
#                mygrid.convolve( lon, lat, vave, 1.)
            iGrid = gridIndex[cpuIndex]
            gainCorr = telescopefactors[iGrid]
            tsum = tsum * gainCorr
            if gridtype == 'RA':
                if doRatio:
                    grids[iGrid].convolve(ra, dec, tsum, weight)
                gridall.convolve(ra, dec, tsum, weight)
            elif gridtype == '-RA':
                x = (ra * xsign) + xoffset
                if doRatio:
                    grids[iGrid].convolve(x, dec, tsum, weight)
                gridall.convolve(x, dec, tsum, weight)
            elif gridtype == 'RA0':
                x = (ra * xsign) + xoffset
                if x < 0:
                    x = x + xmax
                elif x > xmax:
                    x = x - xmax
                if doRatio:
                    grids[iGrid].convolve(x, dec, tsum, weight)
                gridall.convolve(x, dec, tsum, weight)
            else:
                if doRatio:
                    grids[iGrid].convolve(lon, lat, tsum, weight)
                gridall.convolve(lon, lat, tsum, weight)

            if count == 0:
                print('Convolving Coordinates: ', ra, dec, lon, lat)
                print('Convolving Intensities: ', tsum, tsdv, vave, vsdv)
                print('Convolvign Parameters : ', n, time)
            count = count + 1
        # end reading all lines in save file
        f.close()

    # normalize each of the gridded images
    if doRatio:
        grids[0].normalize()
        grids[1].normalize()
        grids[2].normalize()
        grids[3].normalize()
    gridall.normalize()
    #    mygrid.check()
    #    zmin = -1000.
    #    zmax = 3000.
    # limit grid intensities for plotting
    #    mygrid.set_ij( 0, 0, zmax, 1.)
    #    mygrid.set_ij( 1, 1, zmin, 1.)
    #    mygrid.limit(zmin, zmax)

    subplots = False

    if subplots:
        fig, ax = plt.subplots(figsize=(myheight, mywidth), dpi=dpi)

        if gridtype == 'RA':
            cax = fig.add_axes([-180, 180], [-90, 90])
        else:
            cax = fig.add_axes([0, 24], [-90, 90])

        cbar = fig.colorbar(cax, ticks=[zmin, zmax], orientation='horizontal')
        cbar.ax.set_yticklabels([str(zmin), str(zmax)])

        ax.set_title("Citizen Science: Horn observations of our Galaxy")
    else:
        #y_ticks = ymin + (ymax-ymin)*ticks/myheight

        ticks = np.arange(0, mywidth, 30 * dpi)
        x_ticks = xmin + ((xmax - xmin) * ticks / mywidth)

        plt.imshow(gridall.image,
                   interpolation='nearest',
                   cmap=plt.get_cmap('jet'))

        if firsttime != lasttime:
            plt.title("Citizen Science: Observing our Galaxy: %s to %s" %
                      (firsttime, lasttime))
        else:
            plt.title("Citizen Science: Observing our Galaxy: %s" %
                      (firsttime))
        if gridtype == 'RA':
            plt.xlabel("Right Ascension (hours)")
            plt.ylabel("Declination (degrees)")
            labels = ticks / (mywidth / 24)
            yticks = np.arange(0, myheight, 15 * dpi)
        elif gridtype == '-RA':
            plt.xlabel("Right Ascension (hours)")
            plt.ylabel("Declination (degrees)")
            labels = 24 - (ticks / (mywidth / 24))
            labels[0] = 0
            labels[0] = 24
            yticks = np.arange(0, myheight, 15 * dpi)
        elif gridtype == '-EL':
            plt.xlabel("Right Ascension (hours)")
            plt.ylabel("Elevation (degrees)")
            labels = 24 - (ticks / (mywidth / 24))
            labels[0] = 0
            labels[0] = 24
            yticks = np.arange(0, myheight, 15 * dpi)
        elif gridtype == 'RA0':  # put 0 hours in middle of plot
            plt.xlabel("Right Ascension (hours)")
            plt.ylabel("Declination (degrees)")
            labels = 12 - (ticks / (mywidth / 24))
            nlabels = len(labels)
            for iii in range(nlabels):
                if labels[iii] < 0:
                    labels[iii] = 24 + labels[iii]
                if labels[iii] == 24:
                    labels[iii] = 0
            yticks = np.arange(0, myheight, 15 * dpi)
        else:
            yticks = np.arange(0, myheight, 30 * dpi)
            ticks = np.arange(0, mywidth, 30 * dpi)
            x_ticks = xmin + (xmax - xmin) * ticks / mywidth
            labels = x_ticks
            plt.xlabel("Galactic Longitude (degrees)")
            plt.ylabel("Galactic Latitude (degrees)")
        # wnat an integer list of labels


#        slabels = str(labels)
        print(ticks, labels)
        y_ticks = ymax - (ymax - ymin) * yticks / myheight
        plt.yticks(yticks, y_ticks)
        plt.xticks(ticks, labels, rotation='horizontal')
        plt.colorbar()

    crval2 = (xmin + xmax) / 2.
    crval1 = (ymin + ymax) / 2.
    cdelt1 = (-1. / float(dpi)) - .001
    cdelt2 = (1. / float(dpi)) + .001
    if doRatio:
        # now show eacsh of the images
        for iGrid in range(4):
            imagetemp = copy.deepcopy(grids[iGrid].image)
            imagetemp2 = copy.deepcopy(grids[iGrid].image)
            kkk = myheight - 1
            for jjj in range(myheight):
                imagetemp[:][kkk] = imagetemp2[:][jjj]
                kkk = kkk - 1
                grids[iGrid].image = imagetemp
            writeFitsImage(rs, iGrid + 2, grids[iGrid], projection)

        # put each telescope in a different grid
        ratio1 = copy.deepcopy(grid1)
        ratio2 = copy.deepcopy(grid1)
        ratio3 = copy.deepcopy(grid1)
        gratios = [ratio1, ratio2, ratio3]
        ratios = np.zeros(3)
        rmss = np.zeros(3)

        jGrid = 3
        for iGrid in range(3):
            print("Gain Ratios for Telescopes T%d and T%d" %
                  (iGrid + 2, jGrid + 2))
            ratio, rms, aratio = gridratio(grids[iGrid], grids[jGrid])
            ratios[iGrid] = ratio
            rmss[iGrid] = rms
            writeFitsImage(rs, iGrid + 2, aratio, projection)

    writeFitsImage(rs, 0, gridall, projection)
    plt.show()
示例#17
0
文件: fft.py 项目: bzhao13/CSE-490
if nfiles < 1:
    print "FFT: Fourier Transform and sum a time series of events"
    print "Usage: FFT [-bl <n samples>] [-sigma <n sigma>] [-nd <n day parts>] [-kp <kelvins per count>] [-note <note for plot title>] <file 1> [<file 2>] ... [<file N>]"
    print "Where optionally the following paramters may be applied"
    print " -bl <n samples>     - Number of samples to FFT to produce a spectra (power of 2"
    print " -sigma <n sigma>    - Number of sigma of a sample to declare an event"
    print " -kpercount <factor> - Gain factor to convert counts to Kelvin"
    print "   Estimate by an assumed system temperature for the band pass"
    print "   And running FFT without this factor to get the value in counts"
    print " -note <text>        - Note for the top of the plot"
    exit()

print "First File     :                ", sys.argv[ifile]

maxMagnitude = 0.
maxEvent = radioastronomy.Spectrum()
maxFile = ""

for iii in range(nfiles):

    filename = sys.argv[iii + ifile]

    rs = radioastronomy.Spectrum()
    #    print filename
    rs.read_spec_ast(filename)
    if note != "":
        rs.noteA = note
    rs.azel2radec()  # compute ra,dec from az,el

    #    print("GAL Lon,Lat: %8.3f, %8.3f"  % (rs.gallon, rs.gallat))
    parts = filename.split('/')
示例#18
0
nhigh = 0        # highest galactic latitude
lastfreq = 0.
lastbw = 0.
lastgain = 0.
lastel = 0.
lastaz = 0.
firstdate = ""
lastdate = ""
minel = 200.
maxel = -200.
firstaz = -1
otheraz = -1
DT = dt.timedelta(seconds=0.)

# Read the hot and cold files
hot = radioastronomy.Spectrum()
hot.read_spec_ast(hotfilename)
xv = hot.xdata
yv = copy.deepcopy( hot.ydataA)

nData = len( xv)        # get data length and indicies for middle of spectra 
if nData < 1:
    print "Error reading hot file: %s" %s (hotfilename)
    print "No data!"
    exit()

n6 = int(nData/6)
n56 = int(5*n6)

# default indexs for summing and interplating
xa = int(n6)
示例#19
0
lastdate = ""
minel = 200.
maxel = -200.

#first argument is the averaging time in seconds

avetimesec = float(sys.argv[1])
print "Average time: ", avetimesec, " (seconds)"

hotfile = str(sys.argv[2])
coldfile = str(sys.argv[3])

names = sys.argv[4:]
names = sorted(names)

hot = radioastronomy.Spectrum()
hot.read_spec_ast(hotfile)

hv = hot.ydataA

high = radioastronomy.Spectrum()
high.read_spec_ast(coldfile)

xv = high.xdata * 1.E-6
nData = len(xv)

vel = np.zeros(nData)
# create index array
iv = np.zeros(nData)
for jjj in range(0, nData):
    vel[jjj] = c * (nuh1 - xv[jjj]) / nuh1
示例#20
0
def main():
    """
    Main executable for gridding astronomical data
    """
    dpi = 1

    nargs = len(sys.argv)
    if nargs < 2:
        print 'MATCH: MATCH pairs of events in directories'
        print 'usage: MATCH [-OF seconds] dir1 dir2'
        exit()

    dir1 = sys.argv[ifile]
    dir2 = sys.argv[ifile + 1]
    if doDebug:
        print "Dir 1: ", dir1
        print "Dir 2: ", dir2
    gridtype = 'PULSAR'

    from os import listdir
    from os.path import isfile, join
    files1 = [f for f in listdir(dir1) if isfile(join(dir1, f))]
    files2 = [f for f in listdir(dir2) if isfile(join(dir2, f))]

    count = 0
    if doDebug:
        print "%5d Files in Directory 1" % (len(files1))
        print "%5d Files in Directory 2" % (len(files2))
    nEve1 = 0
    nEve2 = 0

    rs = radioastronomy.Spectrum()

    event1s = files1
    event2s = files2

    for filename in files1:
        parts = filename.split(".")
        nparts = len(parts)
        if nparts < 2:  # if not fooo.eve type file name
            continue
        if parts[nparts - 1] == "eve":
            event1s[nEve1] = filename
            nEve1 = nEve1 + 1
        else:
            continue

    mjd1s = np.zeros(nEve1)
    peak1s = np.zeros(nEve1)
    rms1s = np.zeros(nEve1)
    dt1s = np.zeros(nEve1)
    ii1s = np.arange(nEve1) * 0
    event1s = event1s[0:nEve1]

    iii = 0
    for filename in event1s:
        fullname = join(dir1, filename)
        rs.read_spec_ast(fullname)
        rs.azel2radec()  # compute ra,dec from az,el
        mjd1s[iii] = rs.emjd
        peak1s[iii] = rs.epeak
        rms1s[iii] = rs.erms
        if (50 * int(iii / 50) == iii) and doDebug:
            print "Event %5d: %12.9f: %7.3f+/-%5.3f" % (iii, rs.emjd, rs.epeak,
                                                        rs.erms)
        iii = iii + 1

    for filename in files2:
        parts = filename.split(".")
        nparts = len(parts)
        if nparts < 2:  # if not fooo.eve type file name
            continue
        if parts[nparts - 1] == "eve":
            event2s[nEve2] = filename
            nEve2 = nEve2 + 1
        else:
            continue

    mjd2s = np.zeros(nEve2)
    peak2s = np.zeros(nEve2)
    rms2s = np.zeros(nEve2)
    dt2s = np.zeros(nEve2)
    ii2s = np.arange(nEve2) * 0
    event2s = event2s[0:nEve2]

    iii = 0
    for filename in event2s:
        fullname = join(dir2, filename)
        rs.read_spec_ast(fullname)
        rs.azel2radec()  # compute ra,dec from az,el
        mjd2s[iii] = rs.emjd
        peak2s[iii] = rs.epeak
        rms2s[iii] = rs.erms
        if (50 * int(iii / 50) == iii) and doDebug:
            print "Event %5d: %12.9f: %7.3f+/-%5.3f" % (iii, rs.emjd, rs.epeak,
                                                        rs.erms)
        iii = iii + 1

    if doDebug:
        print "%5d Events in Directory: %s" % (nEve1, dir1)
        print "%5d Events in Directory: %s" % (nEve2, dir2)

    # now match event times
    for iii in range(nEve1):
        mjd1 = mjd1s[iii]
        dtj = 0
        dtMin = abs(mjd1 - mjd2s[0])
        for jjj in range(nEve2):
            mjd2 = mjd2s[jjj]
            dt = abs(mjd1 - mjd2)
            if dt < dtMin:
                dtMin = dt
                dtj = jjj
        ii1s[iii] = dtj
        dt1s[iii] = dtMin

    # now report out the minimum time offsets and times less than 1 second off
    OneMjdSec = 1. / 86400.
    TwoMjdSec = 2. * OneMjdSec

    nMatch = 0
    for iii in range(nEve1):
        if dt1s[iii] < offset:
            nMatch = nMatch + 1
            dts = dt1s[iii] / OneMjdSec
            jjj = ii1s[iii]
            print "Event %s Matches %s; Offset: %9.6f s" % (event1s[iii],
                                                            event2s[jjj], dts)
            if doDebug:
                print "%5d %18.9f: %5d %18.9f" % (iii, mjd1s[iii], jjj,
                                                  mjd2s[jjj])
            if doPlot:
                eventAName = dir1 + "/" + event1s[iii]
                eventBName = dir2 + "/" + event2s[jjj]
                plotEvent = "~/bin/E %s %s" % (eventAName, eventBName)
                os.system(plotEvent)

    print "Found %d Event Matches" % (nMatch)
    # now match event times
    for iii in range(nEve2):
        mjd2 = mjd2s[iii]
        dtj = 0
        dtMin = abs(mjd2 - mjd1s[0])
        for jjj in range(nEve1):
            mjd1 = mjd1s[jjj]
            dt = abs(mjd1 - mjd2)
            if dt < dtMin:
                dtMin = dt
                dtj = jjj
        ii2s[iii] = dtj
        dt2s[iii] = dtMin
示例#21
0
文件: l.py 项目: bzhao13/CSE-490

# first read through all data and find hot load
for iii in range(6, nargs):

    filename = sys.argv[iii]
    parts = filename.split('/')
    nparts = len(parts)
    aname = parts[nparts - 1]
    parts = aname.split('.')
    extension = parts[1]
    # now only processing hot loads
    if extension != 'hot':
        #        print parts[1], extension
        continue
    rs = radioastronomy.Spectrum()
    rs.read_spec_ast(filename)
    rs.azel2radec()  # compute ra,dec from az,el

    if rs.telel < 0:
        if nhot == 0:
            hot = copy.deepcopy(rs)
            nhot = 1
        else:
            hot.ydataA = hot.ydataA + rs.ydataA
            hot.count = hot.count + rs.count
            nhot = nhot + 1

if nhot > 0:
    hot.ydataA = scalefactor * hot.ydataA / float(nhot)
    print "Found %3d hot load obs" % nhot
示例#22
0
 def __init__(self, noteName, observers, vlen, frequency, bandwidth,
              azimuth, elevation, inttype, obstype, nmedian, units, thot,
              tcold):
     gr.sync_block.__init__(
         self,
         name="integrate",
         in_sig=[(np.float32, int(vlen))],  # 1 input spectrum
         out_sig=[
             (np.float32, int(vlen)),
             (np.float32, int(vlen)),
             (np.float32, int(vlen)),  # 5 output spectra
             (np.float32, int(vlen)),
             (np.float32, int(vlen))
         ])
     vlen = int(vlen)
     self.vlen = vlen
     self.nintegrate = 1L
     self.noteName = str(noteName)
     noteParts = self.noteName.split('.')
     #always use .not extension for notes files
     self.noteName = noteParts[0] + '.not'
     if len(noteParts) > 2:
         print '!!! Warning, unexpected Notes File name! '
         print '!!! Using file: ', self.noteName
     if os.path.isfile(self.noteName):
         print 'Setup File       : ', self.noteName
     else:
         if os.path.isfile("Watch.not"):
             try:
                 import shutil
                 shutil.copyfile("Watch.not", self.noteName)
                 print "Created %s from file: Watch.not" % (self.noteName)
             except:
                 print "! Create the Note file %s, and try again !" % (
                     self.noteName)
     self.obstype = obstype
     self.inttype = inttype
     self.obs = radioastronomy.Spectrum()
     self.obs.read_spec_ast(self.noteName)  # read the parameters
     self.obs.observer = observers
     self.ave = radioastronomy.Spectrum()
     self.ave.read_spec_ast(self.noteName)  # read the parameters
     self.frequency = frequency
     self.bandwidth = bandwidth
     self.record = radioastronomy.INTWAIT
     self.hot = radioastronomy.Spectrum()
     self.cold = radioastronomy.Spectrum()
     self.ref = radioastronomy.Spectrum()
     if os.path.isfile(HOTFILE):
         self.hot.read_spec_ast(HOTFILE)
     else:
         self.hot.read_spec_ast(self.noteName)  # read the parameters
     if os.path.isfile(COLDFILE):
         self.cold.read_spec_ast(COLDFILE)
     else:
         self.cold.read_spec_ast(self.noteName)  # read the parameters
     if os.path.isfile(REFFILE):
         self.ref.read_spec_ast(REFFILE)
     else:
         self.ref.read_spec_ast(self.noteName)  # read the parameters
     if self.obs.nChan != vlen:
         self.update_len(self.obs)
     if self.ave.nChan != vlen:
         self.update_len(self.ave)
     if self.hot.nChan != vlen:
         self.update_len(self.hot)
     if self.cold.nChan != vlen:
         self.update_len(self.cold)
     if self.ref.nChan != vlen:
         self.update_len(self.ref)
     now = datetime.datetime.utcnow()
     self.startutc = now
     self.stoputc = now
     self.obs.utc = now
     self.printutc = now
     self.printinterval = 5.  # print averages every few seconds
     print 'Setup File       : ', self.noteName
     self.obs.read_spec_ast(self.noteName)  # read the parameters
     self.obs.observer = observers
     self.ave.read_spec_ast(self.noteName)  # read the parameters
     # prepare to start writing observations
     if not os.path.exists(self.obs.datadir):
         os.makedirs(self.obs.datadir)
     nd = len(self.obs.datadir)
     if self.obs.datadir[nd - 1] != '/':
         self.obs.datadir = self.obs.datadir + "/"
         print 'DataDir          : ', self.obs.datadir
     print 'Observer Names   : ', self.obs.observer
     self.obstypes = range(radioastronomy.NOBSTYPES)
     self.intstatus = range(radioastronomy.NINTTYPES)
     self.set_frequency(frequency)
     self.set_bandwidth(bandwidth)
     self.set_azimuth(azimuth)
     self.set_elevation(elevation)
     self.set_inttype(inttype)
     self.set_obstype(obstype)
     self.set_units(units)
     self.set_nmedian(nmedian)
     self.set_thot(thot)
     self.set_tcold(tcold)
     self.epsilons = np.full(self.vlen, EPSILON)
示例#23
0
def read_hot(names, ave_hot):
    """
    read_hot() reads in all files in the names list and averages hot load
    observations.   The hot load file is returned.
    While reading the files, the minmum elevation and galactic latitudes are recorded
    """

    rs = radioastronomy.Spectrum()
    nhot = 0  # init count of hot files
    minGlat = +90.
    maxGlat = -90.
    minel = 200.
    maxel = -200.

    # now run through and find hot and cold loads obs
    for filename in names:

        parts = filename.split('/')
        nparts = len(parts)
        if nparts == 1:
            aname = parts[0]
        else:
            aname = parts[nparts - 1]
        parts = aname.split('.')
        nparts = len(parts)
        if nparts < 2:
            print('File is not an astronomy file: ', filename)
            continue
        else:
            extension = parts[nparts - 1]
        extension = extension.upper()
        if (extension != 'HOT') and (extension != 'AST') and (extension !=
                                                              'CLD'):
            print('Extension not recognized : ', parts[nparts - 1])
            continue

        rs.read_spec_ast(filename)
        rs.azel2radec()  # compute ra,dec from az,el

        # if a hot load observation
        if rs.telel < 0:
            if nhot == 0:
                firstutc = rs.utc
                lastutc = rs.utc
        # accumulate spectra
            ave_hot, rs, nhot, firstutc, lastutc = \
                average_spec( ave_hot, rs, nhot, firstutc, lastutc)
        else:  # else above horizon, find min, max galactic latitudes
            if rs.gallat > maxGlat:
                maxGlat = rs.gallat
            if rs.gallat < minGlat:
                minGlat = rs.gallat
            if minel > rs.telel:
                minel = rs.telel
            if maxel < rs.telel:
                maxel = rs.telel

        # end for all files

    if nhot > 0:
        print("Found %3d Hot load observations" % (nhot))
        ave_hot, nhot = normalize_spec(ave_hot, nhot, firstutc, lastutc)
    else:
        print("No Hot load data, can not calibrate")
        exit()

    # do more cleanup on spectra for RFI
    if flagRfi:
        yv = copy.deepcopy(ave_hot.ydataA)
        xv = ave_hot.xdata * 1.E-6
        hv = interpolate.lines(linelist, linewidth, xv, yv)  # interpolate rfi
        ave_hot.ydataA = hv

    # now obsolete option to fold spectra, when a problem with SDR I-Q balance
    if doFold:
        ave_hot.foldfrequency()

    return ave_hot, minel, maxel, minGlat, maxGlat
示例#24
0
文件: z.py 项目: bzhao13/CSE-490
def findhotgain( names, avetimesec):
    lastgain = 0.
    # flag start of search for a latitude zero crossing
    ncrossings = -1
    crossingsum = 0.
    lastgallat = -100.
    lastsum = 0.

    minGlat = +90.
    maxGlat = -90.
    nhot = 0         # number of obs with el < 0
    ncold = 0
    nhigh = 0        # highest galactic latitude
    lastfreq = 0.
    lastbw = 0.
    lastgain = 0.
    lastel = 0.
    lastaz = 0.
    firstrun = True

    for filename in names:

        rs = radioastronomy.Spectrum()
        rs.read_spec_ast(filename)
        rs.telel = rs.telel + eloffset
        rs.telaz = rs.telaz + azoffset
        rs.azel2radec()    # compute ra,dec from az,el

        if rs.gains[0] != lastgain:
            if lastgain != 0:
                print 'Gain Change: ', lastgain, ' -> ', rs.gains[0]
                lastgain = rs.gains[0]

        if rs.telel < 0:
            if nhot == 0:
                hot = copy.deepcopy( rs)
                nhot = 1
            else:
                hot.ydataA = hot.ydataA + rs.ydataA
                hot.count = hot.count + rs.count
                nhot = nhot + 1
        else: # else above horizon, find min, max galactic latitudes
            if rs.gallat > maxGlat:
                maxGlat = rs.gallat
            if rs.gallat < minGlat:
                minGlat = rs.gallat

    if nhot > 0:
        hot.ydataA = scalefactor * hot.ydataA / float(nhot)
        print "Found %3d hot load obs" % nhot
    else:
        print "No hot load data, can not calibrate"
        exit()

    xv = hot.xdata * 1.E-6
    yv = hot.ydataA
    nData = len(xv)
    hv = interpolate.lines( linelist, linewidth, xv, yv) # interpolate rfi

    print 'Min,Max Galactic Latitudes %7.1f,%7.1f (d)' % (minGlat, maxGlat)

# assume only a limited range of galactic latitudes are available
# not range about +/-60.
    use60Range = False

# all galactic latitudes above +/-60d can be used
    if minGlat < -60. or maxGlat > 60.:
        minGlat = -60.
        maxGlat = 60.
    else: # else no high galactic latitude data
    # use highest galactic latitudes - +/-5.degrees
        if -minGlat > maxGlat:  # if negative latitudes higher
            minGlat = minGlat + 5.
            maxGlat = 90.
        else: # else positive latitudes higher
            maxGlat = maxGlat - 5.
            minGlat = -90.

    outnames = names
    nout = 0
# now average coldest data for calibration
    for filename in names:

        rs = radioastronomy.Spectrum()
        rs.read_spec_ast(filename)
        rs.telaz = rs.telaz + azoffset
        rs.telel = rs.telel + eloffset
        rs.azel2radec()    # compute ra,dec from az,el

        if rs.telel < 0:
            continue
        if rs.gallat > maxGlat or rs.gallat < minGlat:
            if nhigh == 0:
                high = copy.deepcopy( rs)
                high.ydataA = rs.ydataA
                nhigh = 1
            else:
                high.ydataA = high.ydataA + rs.ydataA
                high.count = high.count + rs.count
                nhigh = nhigh + 1
        else:
            # if here, then only these names will be used to find zero crossings
            outnames[nout] = filename
            nout = nout + 1

    if nhigh < 1.:
        print "No high galactic latitude data: can not calibrate"
        exit()
    else:
        high.ydataA = scalefactor * high.ydataA/nhigh
        print "Found %d High Galactic Latidue spectra" % (nhigh)
        yv = high.ydataA
        cv = interpolate.lines( linelist, linewidth, xv, yv) # interpolate rfi

# finally compute gain on a channel by chanel basis
    gain = np.zeros(nData)
    vel = np.zeros(nData)
    for iii in range(nData):
        gain[iii] = (hv[iii] - cv[iii])/(thot - tcold)
        vel[iii] = c * (nuh1 - xv[iii])/nuh1

# now interpolate over galactic velocities
    gain = interpolate_range( minvel, maxvel, vel, gain)

    if nout > 0:
        outnames = outnames[0:(nout-1)]
    else:
        print 'No low latitude file names left!'
        exit()
    return gain, vel, outnames
示例#25
0
 def __init__(self, noteName, observers, vlen, frequency, bandwidth,
              azimuth, elevation, inttype, obstype, nmedian, units, thot,
              tcold):
     gr.sync_block.__init__(
         self,
         name="integrate",
         in_sig=[(np.float32, int(vlen))],  # 1 input spectrum
         out_sig=[
             (np.float32, int(vlen)),
             (np.float32, int(vlen)),
             (np.float32, int(vlen)),  # 5 output spectra
             (np.float32, int(vlen)),
             (np.float32, int(vlen))
         ])
     vlen = int(vlen)
     self.vlen = vlen
     self.nintegrate = 1L
     self.noteName = str(noteName)
     noteParts = self.noteName.split('.')
     #always use .not extension for notes files
     self.noteName = noteParts[0] + '.not'
     if len(noteParts) > 2:
         print '!!! Warning, unexpected Notes File name! '
         print '!!! Using file: ', self.noteName
     if os.path.isfile(self.noteName):
         print 'Setup File       : ', self.noteName
     else:
         if os.path.isfile("Watch.not"):
             try:
                 import shutil
                 shutil.copyfile("Watch.not", self.noteName)
                 print "Created %s from file: Watch.not" % (self.noteName)
             except:
                 print "! Create the Note file %s, and try again !" % (
                     self.noteName)
     self.obstype = obstype
     self.inttype = inttype
     self.obs = radioastronomy.Spectrum()
     self.obs.read_spec_ast(self.noteName)  # read the parameters
     self.obs.nspec = 1  # make sure we're working with spectra
     self.obs.ntime = 0  # not events
     self.obs.xdata = np.zeros(self.vlen)
     self.obs.ydataA = np.zeros(self.vlen)
     self.obs.ydataB = np.zeros(self.vlen)
     self.shortave = np.zeros(self.vlen)
     self.shortlast = np.zeros(self.vlen)
     self.nshort = 0
     self.maxshort = 20  # count before restart sum
     self.oneovermax = float(1. / self.maxshort)  # normalization factor
     self.obs.nchan = self.vlen
     self.obs.refchan = self.vlen / 2.
     self.obs.observer = observers
     self.ave = radioastronomy.Spectrum()
     self.ave.read_spec_ast(self.noteName)  # read the parameters
     self.frequency = frequency
     self.bandwidth = bandwidth
     self.record = radioastronomy.INTWAIT
     self.hot = radioastronomy.Spectrum()
     self.cold = radioastronomy.Spectrum()
     self.ref = radioastronomy.Spectrum()
     if os.path.isfile(HOTFILE):
         self.hot.read_spec_ast(HOTFILE)
     else:
         self.hot.read_spec_ast(self.noteName)  # read the parameters
     if os.path.isfile(COLDFILE):
         self.cold.read_spec_ast(COLDFILE)
     else:
         self.cold.read_spec_ast(self.noteName)  # read the parameters
     if os.path.isfile(REFFILE):
         self.ref.read_spec_ast(REFFILE)
     else:
         self.ref.read_spec_ast(self.noteName)  # read the parameters
     if self.obs.nChan != vlen:
         self.update_len(self.obs)
     if self.ave.nChan != vlen:
         self.update_len(self.ave)
     if self.hot.nChan != vlen:
         self.update_len(self.hot)
     if self.cold.nChan != vlen:
         self.update_len(self.cold)
     if self.ref.nChan != vlen:
         self.update_len(self.ref)
     now = datetime.datetime.utcnow()
     self.startutc = now
     self.stoputc = now
     self.obs.utc = now
     self.printutc = now
     self.printinterval = 5.  # print averages every few seconds
     n32 = int(self.vlen /
               32)  # make an array of indices for baseline fitting
     xa = np.arange(n32) + (3 * n32)
     xb = np.arange(n32) + (n32 * 28)
     self.xfit = np.concatenate((xa, xb))  # indicies for fit
     self.xindex = np.arange(self.vlen)  # array of integers
     self.yfit = self.obs.ydataA[self.xfit]  # sub-array of fittable data
     self.allchan = np.array(range(self.vlen))
     print 'Setup File       : ', self.noteName
     self.obs.read_spec_ast(self.noteName)  # read the parameters
     self.obs.observer = observers
     self.ave.read_spec_ast(self.noteName)  # read the parameters
     # prepare to start writing observations
     if not os.path.exists(self.obs.datadir):
         os.makedirs(self.obs.datadir)
     nd = len(self.obs.datadir)
     if self.obs.datadir[nd - 1] != '/':
         self.obs.datadir = self.obs.datadir + "/"
         print 'DataDir          : ', self.obs.datadir
     print 'Observer Names   : ', self.obs.observer
     self.obstypes = range(radioastronomy.NOBSTYPES)
     self.intstatus = range(radioastronomy.NINTTYPES)
     self.set_frequency(frequency)
     self.set_bandwidth(bandwidth)
     self.set_azimuth(azimuth)
     self.set_elevation(elevation)
     self.set_inttype(inttype)
     self.set_obstype(obstype)
     self.set_units(units)
     self.set_nmedian(nmedian)
     self.set_thot(thot)
     self.set_tcold(tcold)
     self.epsilons = np.full(self.vlen, EPSILON)
示例#26
0
def coldaverage( names):
    """
    Compute a reference cold spectrum from a list of input file names
    Returns number of cold spectra average, cold average spectrum and min and max el in list of names
    """

    rs = radioastronomy.Spectrum()   # create input and average structures
    avenames = names                 # create an output list to average

# assume only a limited range of galactic latitudes are available
# not range above +/-60.
    use60Range = False
    minGlat = 90.                    # initialize to extremea
    maxGlat = -90.
    maxEl = -90.
    minEl =  90.
    ncold = 0

    # for all input files
    for filename in names:

        parts = filename.split('/')
        nparts = len(parts)
        if nparts == 1:
            aname = parts[0]
        else:
            aname = parts[nparts-1]

        parts = aname.split('.')
        nparts = len(parts)
        if nparts < 2:
            print 'File is not an astronomy file: ',filename
            continue
        else:
            extension = parts[nparts-1]

        extension = extension.upper()
        if extension != 'AST':  # speed up by only looking at astronomy files
            continue
        
        rs.read_spec_ast(filename)  # An observation, read values

        if rs.telel < 0: # only working with observations, skip elevation <= 0.
            continue

        maxGlat = max( rs.gallat, maxGlat)
        minGlat = min( rs.gallat, minGlat)
        maxEl = max( rs.telel, maxEl)
        minEl = min( rs.telel, minEl)
    # end for all files loop, looking for max el and latitude ranges

    # if any high galactic latitudes, use only above +/-60d 
    if minGlat < -60. or maxGlat > 60.:
        minGlat = -60.
        maxGlat = 60.
    else: # else no high galactic latitude data
    # use highest galactic latitudes - +/-5.degrees
        if -minGlat > maxGlat:  # if negative latitudes higher
            minGlat = minGlat + 5.
            maxGlat = 90.
        else: # else positive latitudes higher
            maxGlat = maxGlat - 5.
            minGlat = -90.

    # only use the elevations above 60 degrees, if any
    if maxEl > 60.:
        maxEl = 60.
    else:
        maxEl = maxEl - 10.    #else must use highest elevations available

    # now average coldest data for calibration
    for filename in names:

        rs.read_spec_ast(filename)
        rs.azel2radec()    # compute ra,dec from az,el

        if rs.telel < maxEl:
            continue

        if rs.gallat > maxGlat or rs.gallat < minGlat:
            avenames[ncold] = filename
            ncold = ncold + 1
    # end of for all files loop

    ncold, cold = average( avenames[0:ncold])   # now use generic program for averages
    if ncold < 1:
        print 'No Cold load files;  can not calibrate!'
        exit()

    return ncold, cold, minEl, maxEl