Skip to content

Commit

Permalink
Merge pull request #38 from MiraGeoscience/pylint_fix
Browse files Browse the repository at this point in the history
Pylint fix
  • Loading branch information
sebhmg authored Jun 17, 2024
2 parents e278ef5 + 471426b commit 0bfe68b
Showing 1 changed file with 38 additions and 8 deletions.
46 changes: 38 additions & 8 deletions octree_creation_app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def create_octree_from_octrees(meshes: list[Octree | TreeMesh]) -> TreeMesh:
- mesh.max_level
+ mesh.cell_levels_by_index(np.arange(mesh.nC))
)
else:
raise TypeError(
f"All meshes must be Octree or TreeMesh, not {type(mesh)} "
"and must have octree cells defined."
)

treemesh.insert_cells(centers, levels, finalize=False)

Expand All @@ -86,10 +91,17 @@ def collocate_octrees(global_mesh: Octree, local_meshes: list[Octree]):
attributes = get_octree_attributes(global_mesh)
cell_size = attributes["cell_size"]

if global_mesh.octree_cells is not None:
u_grid = global_mesh.octree_cells["I"] * global_mesh.u_cell_size
v_grid = global_mesh.octree_cells["J"] * global_mesh.v_cell_size
w_grid = global_mesh.octree_cells["K"] * global_mesh.w_cell_size
if (
global_mesh.octree_cells is None
or global_mesh.u_cell_size is None
or global_mesh.v_cell_size is None
or global_mesh.w_cell_size is None
):
raise ValueError("Global mesh must have octree_cells and cell sizes.")

u_grid = global_mesh.octree_cells["I"] * global_mesh.u_cell_size
v_grid = global_mesh.octree_cells["J"] * global_mesh.v_cell_size
w_grid = global_mesh.octree_cells["K"] * global_mesh.w_cell_size

xyz = np.c_[u_grid, v_grid, w_grid] + attributes["origin"]
tree = cKDTree(xyz)
Expand Down Expand Up @@ -128,6 +140,10 @@ def densify_curve(curve: Curve, increment: float) -> np.ndarray:
if curve.cells is not None and curve.vertices is not None:
logic = curve.parts == part
cells = curve.cells[np.all(logic[curve.cells], axis=1)]

if len(cells) == 0:
continue

vert_ind = np.r_[cells[:, 0], cells[-1, 1]]
locs = curve.vertices[vert_ind, :]
locations.append(resample_locations(locs, increment))
Expand Down Expand Up @@ -220,12 +236,26 @@ def octree_2_treemesh( # pylint: disable=too-many-locals
:return: Resulting TreeMesh.
"""
if mesh.octree_cells is None:
if (
mesh.octree_cells is None
or mesh.u_count is None
or mesh.v_count is None
or mesh.w_count is None
):
return None

small_cell = [mesh.u_cell_size, mesh.v_cell_size, mesh.w_cell_size]
n_cell_dim = [mesh.u_count, mesh.v_count, mesh.w_count]
cell_sizes = [np.ones(nr) * sz for nr, sz in zip(n_cell_dim, small_cell)]
n_cell_dim, cell_sizes = [], []
for ax in "uvw":
if (
getattr(mesh, f"{ax}_cell_size") is None
or getattr(mesh, f"{ax}_count") is None
):
raise ValueError(f"Cell size in {ax} direction is not defined.")

n_cell_dim.append(getattr(mesh, f"{ax}_count"))
cell_sizes.append(
np.ones(getattr(mesh, f"{ax}_count")) * getattr(mesh, f"{ax}_cell_size")
)

if any(np.any(cell_size < 0) for cell_size in cell_sizes):
raise NotImplementedError("Negative cell sizes not supported.")
Expand Down

0 comments on commit 0bfe68b

Please sign in to comment.