Exemple #1
0
            minRa  = np.min(ra)
            maxRa  = np.max(ra)
            minDec = np.min(dec)
            maxDec = np.max(dec)

            if (crval[0] < minRa) | (crval[0] > maxRa) | (crval[1] < minDec) | (crval[1] > maxDec):
                print('WARNING: MAP CENTRE DOES NOT MATCH TELESCOPE POINTING CENTRE. CHECK COORDINATES')
                print('MEAN RA: {:.2f}, MEAN DEC: {:.2f}'.format(np.mean(ra), np.mean(dec)))
            

            wcs,_,_ = Mapping.DefineWCS(naxis, cdelt, crval)
            maps, hits = Mapping.MakeMaps(tod, ra, dec, wcs)
            dataout['hits']  = hits
            dataout['maps']  = maps
            dataout['naxis'] = np.array(naxis)
            dataout['cdelt'] = np.array(cdelt)
            dataout['crval'] = np.array(crval)


        sbStr = ''.join(str(e) for e in sidebands)
        hoStr = ''.join(str(e) for e in pixels)
        FileTools.WriteH5Py('{}/{}_{}_Horns{}_Sidebands{}.h5'.format(Parameters.get('Inputs', 'outputDir'), 
                                                                     Parameters.get('Inputs', 'outputname'),
                                                                     prefix,
                                                                     hoStr,
                                                                     sbStr), dataout)



        dataout = {} # clear data
Exemple #2
0
amps = np.zeros((len(filenames), 32 * 4))
rms = np.zeros((len(filenames), 32 * 4))
nu = np.zeros((32 * 4))
r = np.zeros((len(filenames)))

fwhm = np.zeros((4, 32, 2, 2, len(filenames)))
fwhmErrs = np.zeros((4, 32, 2, 2, len(filenames)))
outputs = np.zeros((4, 2, len(filenames)))
az, el = np.zeros(filenames.size), np.zeros(filenames.size)
horn = 1
hornID = [1, 12]
markers = ['x', 'o']
for i, filename in enumerate(filenames):
    print(filename)
    d = FileTools.ReadH5Py(filename)
    P = d['TODFits']

    for horn in [0, 1]:
        amps[i, :] = d['TODFits'][horn, :, :, 0].flatten()
        rms[i, :] = d['TODFits'][horn, :, :, -1].flatten()

        # sideband, frequency, x/y, horn, date
        fwhm[:, :, :, horn, i] = d['TODFits'][horn, :, :, 1:3]
        fwhmErrs[:, :, :, horn, i] = d['TODFitsErrors'][horn, :, :, 1:3]

        #print(d.keys())
        r[i] = d['Jupiter'][2]

        if i == 0:
            #print(d['nu'])
def MeasureAmps(filename):
    d = FileTools.ReadH5Py(filename)

    naxis = d['naxis']
    cdelt = d['cdelt']
    crval = d['crval']
    mAzEl = d['mAzEl']

    print(crval)
    wcs = DefineWCS(naxis, cdelt, crval)
    ra, dec = RaDecGrid(naxis, cdelt, crval)
    if crval[0] == 0:
        ra[ra > 180] -= 360.

    w = d['maps']
    h = d['hits']
    A = d['atmos']
    nhorns = w.shape[0]
    nsbs = w.shape[1]
    nfreqs = w.shape[2]

    amps = np.zeros((nhorns, nsbs * nfreqs))
    stds = np.zeros((nhorns, nsbs * nfreqs))
    fits = np.zeros((nhorns, nsbs * nfreqs, 7))
    tfits = np.zeros((nhorns, nsbs, 7))

    amaxs = np.zeros((nhorns, nsbs * nfreqs, 2))

    for i in range(nhorns):
        l = 0
        for j in range(nsbs):
            m = w[i, j, :, ...] / h[i, ...]
            xpix, ypix = FindPeaks(
                np.nanmean(m, axis=0)
            )  # first perform quick estimate of peak location per sideband

            print ra[xpix, ypix], dec[xpix, ypix]

            for k in range(nfreqs):
                try:
                    fits[i, l, :] = AperFit(m[k], ra, dec, ra[xpix, ypix],
                                            dec[xpix, ypix], 10. / 60.)
                except TypeError:
                    fits[i, l, :] = np.nan

                amps[i, l], stds[i, l] = AperPhot(m[k], ra, dec, crval[0],
                                                  crval[1], 6. / 60., 8. / 60.,
                                                  15. / 60.)
                l += 1
            if (j == 0) | (j == 2):
                amps[i, j * nfreqs:(j + 1) *
                     nfreqs] = (amps[i, j * nfreqs:(j + 1) * nfreqs:1])[::-1]
                stds[i, j * nfreqs:(j + 1) *
                     nfreqs] = (stds[i, j * nfreqs:(j + 1) * nfreqs:1])[::-1]
                fits[i, j * nfreqs:(j + 1) *
                     nfreqs, :] = (fits[i, j * nfreqs:(j + 1) *
                                        nfreqs:1, :])[::-1, :]

    # Then plot the images
    for i in range(nhorns):
        fig = pyplot.figure(figsize=(15, 10))
        for j in range(nsbs):
            m = w[i, j, :, ...] / h[i, ...]
            xpix, ypix = FindPeaks(
                np.nanmean(m, axis=0)
            )  # first perform quick estimate of peak location per sideband

            # weighted mean by amplitude of jupiter e.g., the gain
            if (j == 0) | (j == 2):
                signal = amps[0, (j + 1) * nfreqs:j * nfreqs:-1]
                noise = stds[0, (j + 1) * nfreqs:j * nfreqs:-1]
                weight = (signal / noise)**2
                amax = np.nansum(signal * weight) / np.nansum(weight)
                nmax = np.nansum(noise * weight) / np.nansum(weight)

            else:
                signal = amps[0, j * nfreqs:(j + 1) * nfreqs:1]
                noise = stds[0, j * nfreqs:(j + 1) * nfreqs:1]
                weight = (signal / noise)**2
                weight[np.isnan(weight)] = 0.
                amax = np.nansum(signal * weight) / np.nansum(weight)
                nmax = np.nansum(noise * weight) / np.nansum(weight)

            #print(np.sum(weight))
            #pyplot.plot(weight)
            #pyplot.show()
            m = np.nanmean(m, axis=0)
            #m = np.nansum(m*weight[:,np.newaxis,np.newaxis], axis=0)/np.nansum(np.ones(m.shape) * weight[:,np.newaxis,np.newaxis],axis=0)
            if np.nansum(m) == 0:
                print('Horn {} SB {} has no data'.format(i, j))
                continue
            tfits[i, j, :] = AperFit(m, ra, dec, ra[xpix, ypix],
                                     dec[xpix, ypix], 10. / 60.)

            ax = fig.add_subplot(2, 4, 2 * j + 1, projection=wcs)
            pyplot.imshow(m,
                          origin='lower',
                          vmax=amax + nmax * 3,
                          vmin=-nmax * 3)
            pyplot.plot([crval[0]], [crval[1]],
                        'kx',
                        transform=ax.get_transform('world'),
                        alpha=0.7)
            pyplot.title('SB {}'.format(j))
            if crval[0] == 0:
                pyplot.xlabel(r'$\Delta \alpha$')
                pyplot.ylabel(r'$\Delta \delta$')
            else:
                pyplot.xlabel(r'$\alpha$')
                pyplot.ylabel(r'$\delta$')

            if j < 2:
                ax.coords[0].set_ticklabel_visible(False)
                ax.coords[0].set_axislabel('')

            if (j == 1) | (j == 3):
                ax.coords[1].set_ticklabel_visible(False)
                ax.coords[1].set_axislabel('')

            ax.coords[0].set_ticks(size=10)
            ax.coords[1].set_ticks(size=10)

            ax = fig.add_subplot(2, 4, 2 * j + 2, projection=wcs)
            mdl = Gauss2D(tfits[i, j, :], ra, dec, ra[xpix, ypix], dec[xpix,
                                                                       ypix])
            pyplot.imshow(m - mdl,
                          origin='lower',
                          vmax=amax + nmax * 3,
                          vmin=-nmax * 3)
            pyplot.plot([crval[0]], [crval[1]],
                        'kx',
                        transform=ax.get_transform('world'),
                        alpha=0.7)
            pyplot.title('SB {}'.format(j))
            if crval[0] == 0:
                pyplot.xlabel(r'$\Delta \alpha$')
                pyplot.ylabel(r'$\Delta \delta$')
            else:
                pyplot.xlabel(r'$\alpha$')
                pyplot.ylabel(r'$\delta$')
            ax.coords[1].set_ticklabel_visible(False)
            ax.coords[1].set_axislabel('')

            if j < 2:
                ax.coords[0].set_ticklabel_visible(False)
                ax.coords[0].set_axislabel('')

            if (j == 1) | (j == 3):
                ax.coords[1].set_ticklabel_visible(False)
                ax.coords[1].set_axislabel('')

            ax.coords[0].set_ticks(size=10)
            ax.coords[1].set_ticks(size=10)

        pyplot.subplots_adjust(wspace=0.2, hspace=0.05)
        outname = filename.split('.')[0] + 'horn{}_images.png'.format(i)
        pyplot.savefig('Plots/{}'.format(outname), bbox_inches='tight')
        pyplot.clf()

    return amps, fits, mAzEl, tfits
        self.bVec  *= 1.
        
    def Ax(self, r):
            
        self.AxVec = self.A.dot(r[:,np.newaxis]).flatten()

if __name__ == "__main__":
    
    # Read in parameter file
    #inputParameters = sys.argv[1]
    #Parameters = ConfigParser.ConfigParser()
    #Parameters.read(inputParameters)
    
    filename = 'Continuous_El37_4-2deg_Full_25Hz_1Channel_60Day_Fnoise_TOD-DATA_realisation0_FileNo0314.hdf5'
    from pipeline.Tools import FileTools
    d = FileTools.ReadH5Py(filename)
    filename = 'Continuous_El37_4-2deg_Full_25Hz_1Channel_60Day_TOD-DATA_realisation0_FileNo0314.hdf5'
    nonoise = FileTools.ReadH5Py(filename)['TOD'].flatten().astype(float) - 20.
    
    ra = d['RA'].flatten()
    dec = d['DEC'].flatten()
    
    nside = 128
    npix = 12*nside**2
    import healpy as hp
    pixels = hp.ang2pix(nside, (90-dec)*np.pi/180., ra*np.pi/180.).astype(int)
        
    t = d['TOD'][0,0,:].flatten()-200# np.random.normal(size=1000)
    pstod = np.abs(np.fft.fft(t[250000:500000]))
    ftod = np.fft.fftfreq(pstod.size, d=1./25.)
    offsetLength = 20
            if (j == 1) | (j == 3):
                ax.coords[1].set_ticklabel_visible(False)
                ax.coords[1].set_axislabel('')

            ax.coords[0].set_ticks(size=10)
            ax.coords[1].set_ticks(size=10)

        pyplot.subplots_adjust(wspace=0.2, hspace=0.05)
        outname = filename.split('.')[0] + 'horn{}_images.png'.format(i)
        pyplot.savefig('Plots/{}'.format(outname), bbox_inches='tight')
        pyplot.clf()

    return amps, fits, mAzEl, tfits


listname = sys.argv[1]
filelist = np.loadtxt(listname, dtype='string', ndmin=1)

for i, filename in enumerate(filelist):
    amps, fits, mAzEl, tfits = MeasureAmps(filename)
    outname = filename.split('.')[0] + '_amps.h5'
    FileTools.WriteH5Py('amps/{}'.format(outname), {
        'amps': amps,
        'fits': fits,
        'mAzEl': mAzEl,
        'meanFits': tfits
    })

#