Exemple #1
0
 def __setitem__(self, crd, val):
     """Assign data to a sphere via hpm[crd] = val.  Functionality slightly
     complicated to make repeat coordinates assign sum of values (i.e.
     crd = ([1,1], [2,2]), val = [3,3] will assign 6 to location (1,2).
     crd = either 1d array of pixel indices, (th,phi), or (x,y,z), where
     th,phi,x,y,z are numpy arrays of coordinates."""
     if type(crd) is tuple:
         crd = [mk_arr(c, dtype=n.double) for c in crd]
         px = self.crd2px(*crd)
     else:
         if type(crd) is n.ndarray: assert(len(crd.shape) == 1)
         px = mk_arr(crd, dtype=n.int)
     if px.size == 1:
         if type(val) is n.ndarray: val = mk_arr(val, dtype=self.map.dtype)
         self.map[px] = val
     else:
         m = n.zeros_like(self.map)
         px = px.reshape(px.size,1)
         cnt = n.zeros(self.map.shape, dtype=n.bool)
         val = mk_arr(val, dtype=m.dtype)
         utils.add2array(m, px, val)
         utils.add2array(cnt, px, n.ones(val.shape, dtype=n.bool))
         self.map = n.where(cnt, m, self.map)
Exemple #2
0
             if i == 0: wgts.append(n.ones_like(data))
             else: wgts.append(n.zeros_like(data))
     if len(self.bm) == 1 and len(wgts) != 1: wgts = [wgts]
     assert(len(wgts) == len(self.bm))
     if apply: uv,bm = self.uv,self.bm
     else:
         uv = n.zeros_like(self.uv)
         bm = [n.zeros_like(i) for i in self.bm]
     if not USEDSP:
         inds = self.get_indices(u,v)
         
         ok = n.logical_and(n.abs(inds[:,0]) < self.shape[0],
             n.abs(inds[:,1]) < self.shape[1])
         data = data.compress(ok)
         inds = inds.compress(ok, axis=0)
         utils.add2array(uv, inds, data.astype(uv.dtype))
     else:
         u,v = self.get_indices(u,v)
         _dsp.grid2D_c(uv, u, v, data.astype(uv.dtype))
     
     for i,wgt in enumerate(wgts):
         if not USEDSP:
             wgt = wgt.compress(ok)
             utils.add2array(bm[i], inds, wgt.astype(bm[0].dtype))
         else:
             _dsp.grid2D_c(bm[i], u, v, wgt.astype(bm[0].dtype))
     if not apply: return uv, bm
 def get(self, (u,v,w), uv=None, bm=None):
     """Generate data as would be observed at the provided (u,v,w) based on
     this Img's current uv data.  Phase due to 'w' will be applied to data
     before returning."""
Exemple #3
0
                else: wgts.append(n.zeros_like(data))
        if len(self.bm) == 1 and len(wgts) != 1: wgts = [wgts]
        assert (len(wgts) == len(self.bm))
        if apply: uv, bm = self.uv, self.bm
        else:
            uv = n.zeros_like(self.uv)
            bm = [n.zeros_like(i) for i in self.bm]
        if not USEDSP:
            inds = self.get_indices(u, v)

            ok = n.logical_and(
                n.abs(inds[:, 0]) < self.shape[0],
                n.abs(inds[:, 1]) < self.shape[1])
            data = data.compress(ok)
            inds = inds.compress(ok, axis=0)
            utils.add2array(uv, inds, data.astype(uv.dtype))
        else:
            u, v = self.get_indices(u, v)
            _dsp.grid2D_c(uv, u, v, data.astype(uv.dtype))

        for i, wgt in enumerate(wgts):
            if not USEDSP:
                wgt = wgt.compress(ok)
                utils.add2array(bm[i], inds, wgt.astype(bm[0].dtype))
            else:
                _dsp.grid2D_c(bm[i], u, v, wgt.astype(bm[0].dtype))
        if not apply: return uv, bm

    def get(self, (u, v, w), uv=None, bm=None):
        """Generate data as would be observed at the provided (u,v,w) based on
        this Img's current uv data.  Phase due to 'w' will be applied to data