Beispiel #1
0
    def sky_signal(self,data,avg_tod):
        """
        1) Read in a sky map
        2) Sample at observed pixels
        3) Return time ordered data
        """

        feeds = np.arange(self.i_nFeeds,dtype=int)

        ra     = data['spectrometer/pixel_pointing/pixel_ra'][...]
        dec    = data['spectrometer/pixel_pointing/pixel_dec'][...]

        for ifeed in tqdm(feeds.flatten()):
            gl, gb = Coordinates.e2g(ra[ifeed], dec[ifeed]) 
            pixels = ang2pixWCS(self.signal_map_wcs, gl, gb,self.signal_map.shape)
            avg_tod[ifeed] += self.signal_map_flat[None,None,pixels]
Beispiel #2
0
def udgrade_map_wcs(map_in,
                    wcs_in,
                    wcs_target,
                    shape_in,
                    shape_target,
                    ordering='C',
                    weights=None,
                    mask=None,
                    mask_wcs=None):
    """
    """

    if isinstance(weights, type(None)):
        weights = np.ones(map_in.size)
    if isinstance(mask, type(None)):
        mask = np.zeros(map_in.size, dtype=bool)

    # Get pixel coordinates of the input wcs
    nypix, nxpix = shape_in
    ypix, xpix = np.meshgrid(np.arange(nypix), np.arange(nxpix))
    if ordering == 'C':
        ra, dec = wcs_in.wcs_pix2world(xpix.T.flatten(), ypix.T.flatten(), 0)
    else:
        ra, dec = wcs_in.wcs_pix2world(xpix.flatten(), ypix.flatten(), 0)

    c0 = wcs_in.wcs.ctype[0].split('-')[0]
    c1 = wcs_target.wcs.ctype[0].split('-')[0]
    if c0 != c1:
        if c0 == 'GLON':
            ra, dec = Coordinates.g2e(ra, dec)
        else:
            ra, dec = Coordinates.e2g(ra, dec)

    if not isinstance(mask_wcs, type(None)):
        #nypix,nxpix = mask.shape
        #ypix,xpix = np.meshgrid(np.arange(nypix),np.arange(nxpix))
        #ra_mask, dec_mask = wcs_in.wcs_pix2world(xpix.flatten(), ypix.flatten(),0)

        ra_mask, dec_mask = wcs_in.wcs_pix2world(xpix.T.flatten(),
                                                 ypix.T.flatten(), 0)
        c0 = wcs_in.wcs.ctype[0].split('-')[0]
        c1 = mask_wcs.wcs.ctype[0].split('-')[0]
        if c0 != c1:
            if c0 == 'GLON':
                ra_mask, dec_mask = Coordinates.g2e(ra_mask, dec_mask)
            else:
                ra_mask, dec_mask = Coordinates.e2g(ra_mask, dec_mask)
        #xp_mask, yp_mask = mask_wcs.wcs_world2pix(ra_mask, dec_mask, 0)

        pix_mask = ang2pixWCS(mask_wcs, ra_mask, dec_mask, mask.shape)
        mask_flat = mask.flatten()
        weights[~mask_flat[pix_mask]] = 0

    # Convert to pixel coordinate of the output wcs
    #pix_target = ang2pixWCS(wcs_target, ra.flatten(), dec.flatten(), ctype=wcs_target.wcs.ctype)

    nypix, nxpix = shape_target
    xpix, ypix = np.floor(
        np.array(wcs_target.wcs_world2pix(ra.flatten(), dec.flatten(),
                                          0))).astype('int64')
    pix_target = (xpix + ypix * nxpix).astype(np.int64)

    bad = (xpix >= nxpix) | (xpix < 0) | (ypix >= nypix) | (nypix < 0)
    pix_target[bad] = -1

    # Create empty target map
    map_out = np.zeros(shape_target).flatten().astype(np.float64)
    hit_out = np.zeros(shape_target).flatten().astype(np.float64)

    # Bin data to target map
    good = np.isfinite(map_in) & np.isfinite(weights) & (weights > 0) & (
        pix_target != -1)
    binFuncs.binValues(map_out,
                       pix_target[good].astype(np.int64),
                       weights=(map_in[good] / weights[good]).astype(
                           np.float64))  #, mask=good.astype(np.int64))
    binFuncs.binValues(hit_out,
                       pix_target[good].astype(np.int64),
                       weights=(1. / weights[good]).astype(
                           np.float64))  #,mask=good.astype(np.int64))

    return np.reshape(map_out / hit_out,
                      shape_target), np.reshape(1. / hit_out, shape_target)