Beispiel #1
0
 def test_applyChannelFlagCut(self):
     freqs = [0.1, 0.2, 0.3, 0.4]
     chans = range(len(freqs))
     chan2FreqDict = {chan: freqs[chan] for chan in chans}
     bl2SepDict = {(0, 1): np.asarray([45.0, 0.0]), (0, 2): np.asarray([90.0, 0.0])}
     reds = uc.uCalReds(freqs, bl2SepDict.keys(), chan2FreqDict, bl2SepDict)
     reds.applyChannelFlagCut([0])
     self.assertEqual(len(reds.blChanPairs), 1)
     reds.applyChannelFlagCut([1])
     self.assertEqual(len(reds.blChanPairs), 0)
Beispiel #2
0
 def test_init(self):
     freqs = [0.1, 0.2, 0.3, 0.4]
     chans = range(len(freqs))
     chan2FreqDict = {chan: freqs[chan] for chan in chans}
     bl2SepDict = {(0, 1): np.asarray([45.0, 0.0]), (0, 2): np.asarray([90.0, 0.0])}
     reds = uc.uCalReds(freqs, bl2SepDict.keys(), chan2FreqDict, bl2SepDict)
     self.assertEqual(reds.blChanPairs[0, (0, 2), 1, (0, 1)][0][0], 9.0)
     self.assertEqual(reds.blChanPairs[1, (0, 2), 3, (0, 1)][0][0], 18.0)
     self.assertEqual(reds.blChanPairs[0, (0, 2), 1, (0, 1)][0][1], 0)
     self.assertEqual(reds.blChanPairs[1, (0, 2), 3, (0, 1)][0][1], 0)
     self.assertEqual(len(reds.blChanPairs), 2)
Beispiel #3
0
 def test_applyChannelFlagCut(self):
     freqs = [.1, .2, .3, .4]
     chans = range(len(freqs))
     chan2FreqDict = {chan: freqs[chan] for chan in chans}
     bl2SepDict = {
         (0, 1): np.asarray([45.0, 0.0]),
         (0, 2): np.asarray([90.0, 0.0])
     }
     reds = uc.uCalReds(freqs, bl2SepDict.keys(), chan2FreqDict, bl2SepDict)
     reds.applyChannelFlagCut([0])
     self.assertEqual(len(reds.blChanPairs), 1)
     reds.applyChannelFlagCut([1])
     self.assertEqual(len(reds.blChanPairs), 0)
Beispiel #4
0
 def test_init(self):
     freqs = [.1, .2, .3, .4]
     chans = range(len(freqs))
     chan2FreqDict = {chan: freqs[chan] for chan in chans}
     bl2SepDict = {
         (0, 1): np.asarray([45.0, 0.0]),
         (0, 2): np.asarray([90.0, 0.0])
     }
     reds = uc.uCalReds(freqs, bl2SepDict.keys(), chan2FreqDict, bl2SepDict)
     self.assertEqual(reds.blChanPairs[0, (0, 2), 1, (0, 1)][0][0], 9.0)
     self.assertEqual(reds.blChanPairs[1, (0, 2), 3, (0, 1)][0][0], 18.0)
     self.assertEqual(reds.blChanPairs[0, (0, 2), 1, (0, 1)][0][1], 0)
     self.assertEqual(reds.blChanPairs[1, (0, 2), 3, (0, 1)][0][1], 0)
     self.assertEqual(len(reds.blChanPairs), 2)
Beispiel #5
0
#PAPER 128 Setup
intSeps = np.arange(1,16) #* 15m  = baseline lengths
dx = 15.0 / scipy.constants.c * 1e9
chan2FreqDict = {chan: freqs[chan] for chan in chans}
separations = dx*intSeps
if calFile is None: calFile = 'psa6622_v003'
bls = getBaselines(freqs, intSeps, dataFiles[0], calFile=calFile)
bl2SepDict = {bl: np.asarray([sep,0.0]) for bl,sep in zip(bls,separations)}
redundancyDict = blRedundancyDictFromCalFile(calFile=calFile)

pickleFileName = dataFiles[0].replace('.npz', '.uCalDataWithBootstraps.p')
if loadPickle:
    uReds, uCal, uCalBootstraps, loadedDataFiles = pickle.load(open(pickleFileName,'rb'))
    if not len(uCalBootstraps) == nBootstraps or not loadedDataFiles == dataFiles: raise RuntimeError('Loaded uCalDataWithBootstraps.p does not match current specifications.')
else:
    uReds = uc.uCalReds(freqs, bls, chan2FreqDict, bl2SepDict, maxDeltau=maxDeltau, verbose=verbose) #just pass in freqs
    uCal = uc.uCalibrator(uReds.getBlChanPairs())
    data, samples = loadVisibilitiesAndSamples(dataFiles, pol, bls, redundancyDict)
    uCal.computeVisibilityCorrelations(data, samples, verbose=verbose)
    uCalBootstraps = [uc.uCalibrator(uReds.getBlChanPairs()) for i in range(nBootstraps)]
    dataBootstraps, samplesBootstraps = dataAndSamplesBootstraps(data, samples, bls, nBootstraps)
    for i in range(nBootstraps): 
        if verbose: print 'Now computing visibility correlations for bootstrap ' + str(i) + ' of ' + str(nBootstraps) + '...'
        uCalBootstraps[i].computeVisibilityCorrelations(dataBootstraps[i], samplesBootstraps[i], verbose=verbose)
    harmonizeChannelFlags(chans, uCal, uCalBootstraps, verbose=verbose)
    if verbose: print 'Now saving intermediate data products to ' + pickleFileName + ' for easy rerunning...'
    pickle.dump([uReds, uCal, uCalBootstraps, dataFiles], open(pickleFileName, 'wb'))


#%%##########################################
#   uCal Functionality
Beispiel #6
0
bl2SepDict = {bl: np.asarray([sep, 0.0]) for bl, sep in zip(bls, separations)}
redundancyDict = blRedundancyDictFromCalFile(calFile=calFile)

pickleFileName = dataFiles[0].replace('.npz', '.uCalDataWithBootstraps.p')
if loadPickle:
    uReds, uCal, uCalBootstraps, loadedDataFiles = pickle.load(
        open(pickleFileName, 'rb'))
    if not len(
            uCalBootstraps) == nBootstraps or not loadedDataFiles == dataFiles:
        raise RuntimeError(
            'Loaded uCalDataWithBootstraps.p does not match current specifications.'
        )
else:
    uReds = uc.uCalReds(freqs,
                        bls,
                        chan2FreqDict,
                        bl2SepDict,
                        maxDeltau=maxDeltau,
                        verbose=verbose)  #just pass in freqs
    uCal = uc.uCalibrator(uReds.getBlChanPairs())
    data, samples = loadVisibilitiesAndSamples(dataFiles, pol, bls,
                                               redundancyDict)
    uCal.computeVisibilityCorrelations(data, samples, verbose=verbose)
    uCalBootstraps = [
        uc.uCalibrator(uReds.getBlChanPairs()) for i in range(nBootstraps)
    ]
    dataBootstraps, samplesBootstraps = dataAndSamplesBootstraps(
        data, samples, bls, nBootstraps)
    for i in range(nBootstraps):
        if verbose:
            print 'Now computing visibility correlations for bootstrap ' + str(
                i) + ' of ' + str(nBootstraps) + '...'
Beispiel #7
0
                samples[b] = redundancyDict[b] * np.ones(data[b].shape)
                samples[b][data[b]==0] = 0 #TODO: we need a more sophisticated way of handling flagging than this!!!
        return data, samples

    data, samples = loadVisibilitiesAndSamples(dataFiles, pol, bls, redundancyDict)
        


#############################################
#   uCal Script
#############################################

print '\nNow performing uCal...\n'

if regenerateEverything: #regenerate uReds and data
    uReds = uc.uCalReds(freqs, bls, chan2FreqDict, bl2SepDict, maxDeltau=.3) #just pass in freqs
    uReds.applyuCut(uMin=25, uMax=150)
    uReds.applyChannelFlagCut(flaggedChannels) 
    uCal = uc.uCalibrator(uReds.getBlChanPairs())
    uCal.computeVisibilityCorrelations(data, samples)
    pickle.dump([uReds, uCal], open('./Data/uCalData.p', 'wb'))
else:
    uReds, uCal = pickle.load(open('./Data/uCalData.p','rb'))

uCal.setupBinning(uBinSize = .72**.5, duBinSize = 5.0/203) #TODO: investigate uBinSize = .5 (nyquist sampling)
#uCal.setupBinning(uBinSize = .5, duBinSize = 5.0/203)

print 'Now performing logcal...'
betasLogcal, SigmasLogcal, DsLogcal = uCal.performLogcal()
noiseCovDiag = uCal.generateNoiseCovariance(betasLogcal)
betas, Sigmas, Ds = betasLogcal.copy(), SigmasLogcal.copy(), DsLogcal.copy()