예제 #1
0
파일: grid.py 프로젝트: order/lcp-research
    def are_points_oob(self,points):
        """
        Check if points are out-of-bounds
        """
        (N,D) = points.shape
        assert D == self.dim

        L = np.any(points < row_vect(self.lower_bound),axis=1)
        U = np.any(points > row_vect(self.upper_bound) + self.fuzz,axis=1)
        assert (N,) == L.shape
        assert (N,) == U.shape

        return np.logical_or(L,U)
예제 #2
0
파일: grid.py 프로젝트: order/lcp-research
 def cell_coords_to_low_points(self,cell_coords):
     assert isinstance(cell_coords,Coordinates)
     assert self.dim == cell_coords.dim
     assert cell_coords.check()
     
     C = cell_coords.coords
     oob = cell_coords.oob
     assert np.all(np.isnan(C[oob.mask,:])) 
     low_points = row_vect(self.lower_bound) + C * row_vect(self.delta)
     
     assert is_mat(low_points)
     
     assert np.all(np.isnan(low_points[oob.mask,:])) 
     assert cell_coords.shape == low_points.shape
     return low_points
예제 #3
0
파일: coord.py 프로젝트: order/lcp-research
    def build_from_points(self,grid,points):
        assert is_mat(points)
        (N,D) = points.shape
        
        self.dim = D
        self.num = N
        self.shape = (N,D)
        
        low = grid.get_lower_boundary()
        high = grid.get_upper_boundary()

        # What boundary is violated;
        # -1 lower boundary,
        # +1 upper boundary
        U = sps.csc_matrix(points > high,dtype=np.integer)
        L = sps.csc_matrix(points < row_vect(low),dtype=np.integer)
        self.data = U - L
        
        # Mask of same
        self.mask = np.zeros(N,dtype=bool)
        oob_rows = self.data.nonzero()[0]
        self.mask[oob_rows] = True
        assert isinstance(self.mask,np.ndarray)
        assert (N,) == self.mask.shape

        # Sanity check
        assert np.all(self.mask == grid.are_points_oob(points))

        # Pre-offset oob node or cell indices
        self.indices = self.find_oob_index()
        assert is_vect(self.indices)
        assert np.all(np.isnan(self.indices) == ~self.mask)

        assert self.check()
예제 #4
0
파일: grid.py 프로젝트: order/lcp-research
    def node_indices_to_node_points(self,node_indices):
        assert is_vect(node_indices)
        (N,) = node_indices.shape
        
        node_coords = self.node_indexer.indices_to_coords(node_indices)
        assert isinstance(node_coords,Coordinates)
        
        oob = node_coords.oob
        C = node_coords.coords
        assert np.all(np.isnan(C[oob.mask,:]))

        node_points = row_vect(self.lower_bound) + C * row_vect(self.delta)
        assert is_mat(node_points)
        assert np.all(np.isnan(node_points[oob.mask,:]))
        assert node_coords.shape == node_points.shape
        
        return node_points
예제 #5
0
 def get_neighbors(self,indices):
     (N,) = indices.shape
     D = self.dim
     shift = self.cell_shift()
     
     neighbors = col_vect(indices) + row_vect(shift)
     assert((N,2**D) == neighbors.shape)
     return neighbors
예제 #6
0
파일: grid.py 프로젝트: order/lcp-research
    def cell_indices_to_mid_points(self,cell_indices):
        assert is_vect(cell_indices)

        low_points = cell_indices_to_low_points(self,cell_indices)
        mid_points = low_points + row_vect(0.5 * self.delta)
        assert is_mat(mid_points)
        assert mid_points.shape[0] == cell_indices.shape[0]
        
        return mid_points
예제 #7
0
파일: grid.py 프로젝트: order/lcp-research
    def cell_coords_to_vertex_indices(self,cell_coords):
        assert isinstance(cell_coords,Coordinates)
        (N,D) = cell_coords.shape
        assert self.dim == D


        """
        The low node index in the cell has the same coords in node-land
        as the cell in cell-land:
         |   |
        -o - o-
         | x |
        -x - o-
         |   |
        """        
        low_vertex = self.node_indexer.coords_to_indices(cell_coords)

        # Array of index offsets to reach every vertex in cell
        shift = self.node_indexer.cell_shift()
        assert (2**D,) == shift.shape
        
        vertices = col_vect(low_vertex) + row_vect(shift)
        assert (N,2**D) == vertices.shape

        """
        Handle out of bound nodes. There is a constant offset for 
        converting cell oob indices to node oob indices.
        Also the difference between max spatial indices.
        """
        oob = cell_coords.oob
        if oob.has_oob():
            # Figure out the right oob node
            oob_indices = cell_coords.oob.indices[oob.mask]
            offset = self.node_indexer.get_num_spatial_nodes()
            vertices[oob.mask,0] = oob_indices + offset
            vertices[oob.mask,1:] = np.nan

        return vertices
예제 #8
0
 def are_coords_oob(self,coords):
     (N,D) = coords.shape
     assert D == self.dim
     L = np.any(coords < 0,axis=1)
     U = np.any(coords >= row_vect(self.lens),axis=1)
     return np.logical_or(L,U)