Beispiel #1
0
def query_slice(x0, y0, x1, y1, wcs, shape, width=None):

    nypix, nxpix = shape
    xpix, ypix = np.meshgrid(np.arange(nxpix), np.arange(nypix))
    xpix_world, ypix_world = wcs.wcs_pix2world(xpix.flatten(), ypix.flatten(),
                                               0)

    if isinstance(width, type(None)):
        width = np.abs(wcs.wcs.cdelt[1])

    m = (y1 - y0) / (x1 - x0)
    yvec = m * (xpix_world - x0) + y0

    xmid = (x1 + x0) / 2.
    if x1 != x0:
        xwidth = np.abs(x1 - x0) / 2.
    else:
        xwidth = width
    ymid = (y1 + y0) / 2.
    if y1 != y0:
        ywidth = np.abs(y1 - y0) / 2.
    else:
        ywidth = width

    select = (np.abs(yvec - ypix_world) < width) & (np.abs(
        ypix_world - ymid) < ywidth) & (np.abs(xpix_world - xmid) < xwidth)
    angular_dist = Coordinates.AngularSeperation(x0, y0, xpix_world[select],
                                                 ypix_world[select])
    return select, xpix_world[select], ypix_world[select], angular_dist
Beispiel #2
0
    def average_obs(self,filename,data):
        """
        Average TOD together
        """

        # --- Average down the data
        nHorns, nSBs, nChans, nSamples = data['spectrometer/tod'].shape
        nHorns = len(self.feeds)


        frequencies = data['spectrometer/frequency'][...]
        # Averaging the data either using a Tsys/Calvane measurement or assume equal weights
        try:
            # Altered to allow Skydip files to be calibrated using the neighbouring
            # cal-vane files (following SKYDIP-LISSAJOUS obs. plan)
            if 'Sky nod' in self.comment:
                cname, gain, tsys,spikes = self.getcalibration_skydip(data)
            else:
                cname, gain, tsys,spikes = self.getcalibration_obs(data)
        except ValueError:
            cname = '{}/{}_{}'.format(self.calvanedir,self.calvane_prefix,fname)
            gain = np.ones((2, nHorns, nSBs, nChans))
            tsys = np.ones((2, nHorns, nSBs, nChans))

        crval = [(18 + 47./60.+34.81/60.**2)*15,-(1 + 56./60.+31./60.**2)]

        # Future: Astro Calibration
        # if self.cal_mode.upper() == 'ASTRO':
        # gain = self.getcalibration_astro(data)
        self.output = np.zeros((nHorns,len(self.rrl_frequencies),11,nSamples))
        self.spectra  = np.zeros((len(self.feeds),len(self.rrl_qnumbers),21,nSamples))*np.nan
        self.velocity = np.zeros((len(self.feeds),len(self.rrl_qnumbers),21))*np.nan
        self.frequency = np.zeros((len(self.feeds),len(self.rrl_qnumbers),21))*np.nan
        for ifeed, feed in enumerate(tqdm(self.feeds,desc=self.name)):
            feed_array_index = self.feed_dict[feed]
            ra  = data['spectrometer/pixel_pointing/pixel_ra'][feed_array_index,...]
            dec = data['spectrometer/pixel_pointing/pixel_dec'][feed_array_index,...] 

            select = np.where((Coordinates.AngularSeperation(ra,dec,crval[0],crval[1]) < 1.5/60.))[0]
            d = data['spectrometer/tod'][feed_array_index,...] 
            #for rllfreq,frequency in enumerate(self.rrl_frequencies[1:2]):
            for iqno,(qno,rrl_freq) in enumerate(zip(self.rrl_qnumbers,self.rrl_frequencies)):
                for sb in range(nSBs):
                    # Weights/gains already snipped to just the feeds we want
                    if (rrl_freq > np.min(frequencies[sb])) & (rrl_freq < np.max(frequencies[sb])):
                        w, g,chan_flag = 1./tsys[0,ifeed, sb, :]**2, gain[0,ifeed, sb, :], spikes[0,ifeed,sb,:]
                        w[chan_flag] = 0
                        z = d[sb,:,:]
                        s1 = z[:,:]/g[:,None]
                        velocity = self.frequency2velocity(rrl_freq,frequencies[sb,:])
                        ichan = np.argmin((rrl_freq - frequencies[sb,:])**2)
                        lo = int(np.max([ichan - 10,0]))
                        hi = int(np.min([ichan + 11,nChans]))
                    
                        self.spectra[ifeed,iqno,:(hi-lo),:] = s1[lo:hi]
                        self.velocity[ifeed,iqno,:(hi-lo)]  = velocity[lo:hi]
                        self.frequency[ifeed,iqno,:(hi-lo)]  = frequencies[sb,lo:hi]
Beispiel #3
0
    def run(self, data):
        """
        Expects a level2 file structure to be passed.
        """
        fname = data.filename.split('/')[-1]

        az = data['level1/spectrometer/pixel_pointing/pixel_az'][0, :]
        el = data['level1/spectrometer/pixel_pointing/pixel_el'][0, :]
        mjd = data['level1/spectrometer/MJD'][:]

        self.distances = {k: np.zeros(az.size) for k in ['sun', 'moon']}

        for src, v in self.distances.items():
            s_az, s_el, s_ra, s_dec = Coordinates.sourcePosition(
                src, mjd, Coordinates.comap_longitude,
                Coordinates.comap_latitude)
            self.distances[src] = Coordinates.AngularSeperation(
                az, el, s_az, s_el)

        sources = list(self.distances.keys())
        for src in sources:
            self.distances[f'{src}_mean'] = np.array(
                [np.mean(self.distances[src])])