eitcom / pyEIT

Python based toolkit for Electrical Impedance Tomography
Other
169 stars 96 forks source link

Use dataclass for mesh instead dict #44

Closed DavidMetzIMT closed 2 years ago

DavidMetzIMT commented 2 years ago

Hi,

During the review of the code I was wondering why you don't set a dataclass for the mesh: you could than directly add method or property and allow you to do more with the data itsel without having to unpack the dict each time etc...

for example:

@dataclass
class PyeitMesh:
    element:np.ndarray
    node:np.ndarray
    perm:np.ndarray

    @property
    def n_pts(self)->int:
        return self.node.shape[0]
    @property
    def n_dim(self)->int:
        return self.node.shape[1]
    @property
    def n_elems(self)->int:
        return self.element.shape[0]
    @property
    def n_vertices(self)->int:
        return self.element.shape[1]

    def stats(self):
        """
        print mesh or tetrahedral status

        Parameters
        ----------
        p: array_like
            coordinates of nodes (x, y) in 2D, (x, y, z) in 3D
        t: array_like
            connectives forming elements

        Notes
        -----
        a simple function for illustration purpose only.
        print the status (size) of nodes and elements
        """
        print("mesh status:")
        print(f"{self.n_pts} nodes, {self.n_elems} elements")

then you can avoid such code:

self.pts = mesh["node"]
self.tri = mesh["element"]

shape of the mesh
self.no_num, self.n_dim = self.pts.shape
self.el_num, self.n_vertices = self.tri.shape

and use that instead

self.mesh.node #(instead self.pts )
self.mesh.n_pts #(instead self.no_num ), etc.. 

also you can integrate setting of permittivity... and much more whcih is on the mesh data related! If you are interested I could start to set it!

liubenyuan commented 2 years ago

The data mesh dictionary structure is the one we used at FMMU where I host the repo eitmesh.

I think your mesh data structure is great and you can do it! It requires a lot of work in setting this data structure. I will update eitmesh when you finalize the mesh data structure.

liubenyuan commented 2 years ago

closed as #47