예제 #1
0
    def karim2014(self,
                  nu,
                  mjd=51544,
                  lon=0,
                  lat=0,
                  source='jupiter',
                  allpos=False,
                  return_jansky=False,
                  **kwargs):
        """
        args:
        nu - in GHz
        mjd - 
        """

        self.P = {'a': jupfit[0], 'b': jupfit[1], 'c': 0}

        r0, d0, dist = Coordinates.getPlanetPosition(source,
                                                     lon,
                                                     lat,
                                                     mjd,
                                                     allpos=allpos)
        jupAng = self.jupAng0 * (5.2 / dist)**2

        if return_jansky:
            return 2. * kb * (nu / cspeed)**2 * 10**jupfit(np.log10(
                nu / 30.)) * jupAng * 1e26
        else:
            return 10**jupfit(np.log10(nu / 30.)) * jupAng, dist
예제 #2
0
def fnoise_list(mode = 'GFields'):
    filelist = np.loadtxt(sys.argv[1],dtype=str)
    obsid = np.array([int(f.split('-')[1]) for f in filelist])
    filelist = filelist[np.argsort(obsid)]
    obsid = np.sort(obsid)

    fnoise = np.zeros(filelist.size)
    enoise = np.zeros(filelist.size)
    feed = None
    ifeed = 0
    isfg4 = np.zeros(filelist.size,dtype=bool)
    dist = np.zeros(filelist.size)
    pyplot.figure(figsize=(20,5))
    for ifile, filename in enumerate(filelist):
        
        print(filename)
        try:
            data = h5py.File(filename,'r')
        except OSError:
            print('{} cannot be opened (Resource unavailable)'.format(filename))
            fnoise[ifile] = np.nan

        if mode.lower() in data['level1/comap'].attrs['source'].decode('utf-8').lower():
            isfg4[ifile] = True

        try:
            fits = data['level2/fnoise_fits'][ifeed,-1,1:-2,:]
            fnoise[ifile] = np.median(fits[:,1])
            enoise[ifile] = np.sqrt(np.median(np.abs(fits[:,1]-fnoise[ifile])**2))*1.4826
        except:
            print('{} not processed'.format(filename.split('/')[-1]))
            fnoise[ifile] = np.nan

        if isinstance(feed, type(None)):
            feed = data['level1/spectrometer/feeds'][ifeed]

        # Calculate sun distance
        mjd = data['level1/spectrometer/MJD'][0:1]
        lon=-118.2941
        lat=37.2314
        ra_sun, dec_sun, raddist = Coordinates.getPlanetPosition('SUN', lon, lat, mjd)
        az_sun, el_sun = Coordinates.e2h(ra_sun, dec_sun, mjd, lon, lat)
        ra  = data['level1/spectrometer/pixel_pointing/pixel_ra'][0,0:1]
        dec = data['level1/spectrometer/pixel_pointing/pixel_dec'][0,0:1]
        dist[ifile] = el_sun[0]#angular_seperation(ra_sun, ra, dec_sun, dec)
        data.close()
    good = (fnoise > -1.2) & (fnoise < -0.5) & np.isfinite(fnoise) & (fnoise != -1)
    with open('Plots/{}_good.list'.format(mode),'w') as f:
        for line in filelist[good]:
            f.write('{}\n'.format(line))

    pyplot.errorbar(np.arange(fnoise.size),fnoise,fmt='.',yerr=enoise,capsize=3)
    pyplot.errorbar(np.arange(fnoise.size)[good],fnoise[good],fmt='.',yerr=enoise[good],capsize=3)

    pyplot.xticks(np.arange(fnoise.size),obsid, rotation=90,size=8)
    pyplot.ylim(-2,-0.8)
    pyplot.grid()
    pyplot.savefig('Plots/Fnoise_feed{}_{}.png'.format(feed,mode),bbox_inches='tight')
    pyplot.savefig('Plots/Fnoise_feed{}_{}.pdf'.format(feed,mode),bbox_inches='tight')
    pyplot.clf()
예제 #3
0
    def setLevel1(self, datafile, source=''):
        """
        """
        self.setSource(source)

        self.teleLon = self.datafile['hk/antenna0/tracker/siteActual'][
            0, 0] / (60.**2 * 1000.)
        self.teleLat = self.datafile['hk/antenna0/tracker/siteActual'][
            0, 1] / (60.**2 * 1000.)

        self.datafile = datafile

        self.attributes = self.datafile['comap'].attrs

        self.tsamp = float(self.attributes['tsamp'].decode())
        self.obsid = self.attributes['obsid'].decode()
        self.source = self.attributes['source'].decode()

        # load but do not read yet.
        self.x = self.datafile['spectrometer/pixel_pointing/pixel_ra']
        self.y = self.datafile['spectrometer/pixel_pointing/pixel_dec']
        self.utc = self.datafile['spectrometer/MJD']
        sunra, sundec, sundist = Coordinates.getPlanetPosition('Sun',
                                                               self.teleLon,
                                                               self.teleLat,
                                                               self.utc[:],
                                                               returnall=True)
        sunra, sundec = Coordinates.precess(sunra, sundec, self.utc[:])
        pa = Coordinates.pa(sunra, sundec, self.utc, self.teleLon,
                            self.teleLat)
        for i in range(self.x.shape[0]):
            self.x[i, :], self.y[i, :] = Coordinates.Rotate(
                self.x[i, :], self.y[i, :], sunra, sundec, -pa)

        self.xCoordinateName = r'$\Delta$A'
        self.yCoordinateName = r'$\Delta$E'

        self.el = self.datafile['spectrometer/pixel_pointing/pixel_el']

        self.tod_bavg = self.datafile['spectrometer/band_average']
        self.features = self.datafile['spectrometer/features'][:]
        self.mask = np.ones(self.features.size).astype(int)
        self.mask[self.featureBits(self.features.astype(float), 13)] = 0
        self.mask[self.features == 0] = 0
        self.mask = self.mask.astype(int)

        # If we don't spe
        self.setCrval()

        self.setWCS(self.crval, self.cdelt, self.crpix, self.ctype)
예제 #4
0
def JupiterFlux(nu,
                mjd,
                lon=0,
                lat=0,
                source='jupiter',
                allpos=False,
                return_jansky=False):
    """
    """

    r0, d0, dist = Coordinates.getPlanetPosition(source,
                                                 lon,
                                                 lat,
                                                 mjd,
                                                 allpos=allpos)

    jupAng = jupAng0 * (5.2 / dist)**2

    if return_jansky:
        return 2. * kb * (nu / cspeed)**2 * 10**jupfit(np.log10(
            nu / 30.)) * jupAng * 1e26
    else:
        return 10**jupfit(np.log10(nu / 30.)) * jupAng, dist
예제 #5
0
 def getJupiter(self, data):
     mjd = data.getdset('spectrometer/MJD')
     self.x0, self.y0, self.dist = Coordinates.getPlanetPosition(
         'Jupiter', self.lon, self.lat, mjd)
     return self.x0, self.y0, self.dist
예제 #6
0
def fnoise_plots(mode,ifeed):
    filelist = np.loadtxt(sys.argv[1],dtype=str)
    obsid = np.array([int(f.split('-')[1]) for f in filelist])
    filelist = filelist[np.argsort(obsid)]
    obsid = np.sort(obsid)

    fnoise = np.zeros(filelist.size)
    enoise = np.zeros(filelist.size)
    feed = None
    isfg4 = np.zeros(filelist.size,dtype=bool)
    dist = np.zeros(filelist.size)

    fnoise_power = np.zeros((filelist.size,64*4))
    alphas = np.zeros((filelist.size,64*4))

    for ifile, filename in enumerate(filelist):
        
        try:
            data = h5py.File(filename,'r')
        except OSError:
            print('{} cannot be opened (Resource unavailable)'.format(filename))
            fnoise[ifile] = np.nan

        if mode.lower() in data['level1/comap'].attrs['source'].decode('utf-8').lower():
            isfg4[ifile] = True

        try:
            fits = data['level2/fnoise_fits'][ifeed,:,:,:]
            fnoise[ifile] = np.median(fits[:,1])
            enoise[ifile] = np.sqrt(np.median(np.abs(fits[:,1]-fnoise[ifile])**2))*1.4826
            ps = data['level2/powerspectra'][ifeed,:,:,:]
            rms = data['level2/wnoise_auto'][ifeed,:,:,:]
            nu = data['level2/freqspectra'][ifeed,:,:,:]
            freq = data['level1/spectrometer/frequency'][...]
            bw = 16
            freq = np.mean(np.reshape(freq, (freq.shape[0],freq.shape[1]//bw, bw)),axis=-1).flatten()
            sfreq = np.argsort(freq)
        
            fnoise_power[ifile,:] = (rms[:,:,0]**2 * (1/fits[:,:,0])**fits[:,:,1]).flatten()[sfreq]
            alphas[ifile,:] = (fits[:,:,1]).flatten()[sfreq]

            #print(nu.shape,ps.shape, rms.shape, fits.shape)
            #pyplot.plot(freq[sfreq],fnoise_power[ifile,:])
        except IOError:
            print('{} not processed'.format(filename.split('/')[-1]))
            fnoise[ifile] = np.nan

        if isinstance(feed, type(None)):
            feed = data['level1/spectrometer/feeds'][ifeed]

        # Calculate sun distance
        mjd = data['level1/spectrometer/MJD'][0:1]
        lon=-118.2941
        lat=37.2314
        ra_sun, dec_sun, raddist = Coordinates.getPlanetPosition('SUN', lon, lat, mjd)
        az_sun, el_sun = Coordinates.e2h(ra_sun, dec_sun, mjd, lon, lat)
        ra = data['level1/spectrometer/pixel_pointing/pixel_ra'][0,0:1]
        dec = data['level1/spectrometer/pixel_pointing/pixel_dec'][0,0:1]
        dist[ifile] = el_sun[0]#angular_seperation(ra_sun, ra, dec_sun, dec)
        data.close()


    # Plot obs ID vs fnoise power
    pyplot.imshow(np.log10(fnoise_power*1e3),aspect='auto',origin='lower',
                  extent=[np.min(freq),np.max(freq),-.5,fnoise_power.shape[0]-0.5])
    pyplot.yticks(np.arange(fnoise_power.shape[0])-0.5, obsid, rotation=0,
                  ha='right',va='center',size=10)
    ax = pyplot.gca()
    fig = pyplot.gcf()
    offset = ScaledTranslation(-0.08,0.02,fig.transFigure)
    for label in ax.yaxis.get_majorticklabels():
        label.set_transform(label.get_transform() + offset)
    pyplot.grid()
    pyplot.xlabel('Frequency (GHz)')
    pyplot.ylabel('obs ID')
    pyplot.colorbar(label=r'$\mathrm{log}_{10}$(mK)')
    pyplot.title('Feed {}'.format(feed))
    pyplot.savefig('Plots/fnoise_gfields_Feed{}.png'.format(feed),bbox_inches='tight')
    pyplot.clf()
    # Plot obs ID vs fnoise power
    pyplot.imshow(alphas,aspect='auto',origin='lower',vmin=-1.5,vmax=-0.9,
                  extent=[np.min(freq),np.max(freq),-.5,fnoise_power.shape[0]-0.5])
    pyplot.yticks(np.arange(fnoise_power.shape[0])-0.5, obsid, rotation=0,
                  ha='right',va='center',size=10)
    ax = pyplot.gca()
    fig = pyplot.gcf()
    for label in ax.yaxis.get_majorticklabels():
        label.set_transform(label.get_transform() + offset)
    pyplot.grid()
    pyplot.xlabel('Frequency (GHz)')
    pyplot.ylabel('obs ID')
    pyplot.colorbar(label=r'$\alpha$')
    pyplot.title('Feed {}'.format(feed))
    pyplot.savefig('Plots/alphas_gfields_Feed{}.png'.format(feed),bbox_inches='tight')
    pyplot.clf()