property_topomesh_analysis.py 文件源码

python
阅读 15 收藏 0 点赞 0 评论 0

项目:cellcomplex 作者: VirtualPlants 项目源码 文件源码
def compute_topomesh_cell_property_from_faces(topomesh, property_name, aggregate='mean', weighting='area'):
    """Compute a property on degree 3 using the same property defined at degree 2.

    The cell property is computed by averaging or summing the properties of its
    border faces, weighting them differently according to the chosen method.

    Args:
        topomesh (:class:`openalea.cellcomplex.property_topomesh.PropertyTopomesh`): 
            The structure on which to compute the property.
        property_name (str): 
            The name of the property to compute (must be already computed on faces).
        aggregate (str): 
            The way weighted face properties are combined to compute the cell property  (default is *mean*):
                * *mean*: the cell property is the weighted average of face properties
                * *sum*: the cell property is the weighted sum of face properties
        weighting (str): 
            The way weights are assigned to each face to compute the property (default is *area*):
                * *uniform*: all the faces have the same weight (1)
                * *area*: the weight on the faces is equal to their area

    Returns:
        None

    Note: 
        The PropertyTopomesh passed as argument is updated.

    """

    start_time = time()
    print "--> Computing cell property from faces"

    assert topomesh.has_wisp_property(property_name,2,is_computed=True)
    assert weighting in ['uniform','area']

    face_property = topomesh.wisp_property(property_name,2)

    cell_faces = np.concatenate([list(topomesh.borders(3,c)) for c in topomesh.wisps(3)]).astype(np.uint32)
    cell_face_cells = np.concatenate([c*np.ones(topomesh.nb_borders(3,c)) for c in topomesh.wisps(3)]).astype(np.uint32)

    if weighting == 'uniform':
        cell_face_weight = np.ones_like(cell_faces)
    elif weighting == 'area':
        compute_topomesh_property(topomesh,'area',2)
        cell_face_weight = topomesh.wisp_property('area',2).values(cell_faces)

    cell_face_property = face_property.values(cell_faces)

    if cell_face_property.ndim == 1:
        cell_property = nd.sum(cell_face_weight*cell_face_property,cell_face_cells,index=list(topomesh.wisps(3)))/nd.sum(cell_face_weight,cell_face_cells,index=list(topomesh.wisps(3)))
    elif cell_face_property.ndim == 2:
        cell_property = np.transpose([nd.sum(cell_face_weight*cell_face_property[:,k],cell_face_cells,index=list(topomesh.wisps(3)))/nd.sum(cell_face_weight,cell_face_cells,index=list(topomesh.wisps(3))) for k in xrange(cell_face_property.shape[1])])
    elif cell_face_property.ndim == 3:
        cell_property = np.transpose([[nd.sum(cell_face_weight*cell_face_property[:,j,k],cell_face_cells,index=list(topomesh.wisps(3)))/nd.sum(cell_face_weight,cell_face_cells,index=list(topomesh.wisps(3))) for k in xrange(cell_face_property.shape[2])] for j in xrange(cell_face_property.shape[1])])

    topomesh.update_wisp_property(property_name,degree=3,values=array_dict(cell_property,keys=list(topomesh.wisps(3))))

    end_time = time()
    print "<-- Computing cell property from faces [",end_time-start_time,"s]"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号