Skip to content

Commit a876cce

Browse files
authored
Merge pull request #11 from Renumics/lint.-format
Lint-format
2 parents 91d9ec9 + a8d2444 commit a876cce

14 files changed

+1226
-1325
lines changed

docs/examples/aggregate_warpage.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Aggregate Warpage
33
===================
44
"""
5+
56
# pylint: disable=pointless-statement
67
from pathlib import Path
78
import numpy as np

docs/examples/plot_neighbor_distances.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
========================
44
This example shows ho to plot the distances of nearby elements to a specific element (d<10)
55
"""
6+
67
# pylint: disable=pointless-statement
78
from pathlib import Path
89
import numpy as np

docs/examples/plot_stress.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
====================
44
55
"""
6+
67
# pylint: disable=pointless-statement
78
from pathlib import Path
89
import numpy as np

docs/examples/quickstart.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Quick Start Example
33
====================
44
"""
5+
56
# pylint: disable=pointless-statement
67
from pathlib import Path
78
import numpy as np

mesh2vec/helpers.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""helper functions"""
2+
23
from typing import OrderedDict, List, Dict
34
from collections import deque
45
from abc import ABC, abstractmethod
56

67
import numpy as np
78
from scipy.sparse import csr_array, coo_array, eye
89

10+
911
# pylint: disable=invalid-name
1012
class AbstractAdjacencyStrategy(ABC):
1113
# pylint: disable=too-few-public-methods

mesh2vec/mesh2vec_base.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Mesh2VecBase"""
2+
23
import collections
34
from pathlib import Path
45
from typing import List, Optional, Callable, OrderedDict, Dict, Union, Iterable

mesh2vec/mesh2vec_cae.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Mesh2VecCae"""
2+
23
import json
34
import os
45
import subprocess
@@ -254,15 +255,18 @@ def from_d3plot_shell(
254255
return Mesh2VecCae(distance, mesh, element_info, calc_strategy=calc_strategy)
255256

256257
@staticmethod
257-
def from_keyfile_shell(distance: int, keyfile: Path, partid="", calc_strategy="bfs") -> "Mesh2VecCae":
258+
def from_keyfile_shell(
259+
distance: int, keyfile: Path, partid="", calc_strategy="bfs"
260+
) -> "Mesh2VecCae":
258261
"""
259262
Read the given keyfile and use the shell elements to generate a hypergraph, using mesh
260263
nodes as hyperedges, and adjacent elements as hypervertices.
261264
262265
Args:
263266
distance: the maximum distance for neighborhood generation and feature aggregation
264267
keyfile: path to keyfile
265-
partid: part id to use for hypergraph generation (default empty string, use all shell parts)
268+
partid: part id to use for hypergraph generation
269+
(default empty string, use all shell parts)
266270
calc_strategy: choose the algorithm to calculate adjacencies
267271
268272
* "dfs": depth first search (defaultl fast)

mesh2vec/mesh2vec_exceptions.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Exceptions for mesh2vec"""
2+
23
from typing import Any, Dict, List
34
from loguru import logger
45
import numpy as np

mesh2vec/mesh_features.py

+40-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""calculation of mesh based features"""
2+
23
from typing import Tuple, List, Any, Optional
34

45
import numpy as np
@@ -34,17 +35,21 @@ def _quad_to_tris(element_node_idxs: np.ndarray) -> Tuple[List[bool], np.ndarray
3435
if len(element_node_idxs.shape) == 3: # points
3536
is_quads = [any(element[3] != element[2]) for element in element_node_idxs]
3637
tri_faces_nested = [
37-
[element[:3].tolist(), element[[0, 2, 3]].tolist()]
38-
if is_quad
39-
else [element[:3].tolist()]
38+
(
39+
[element[:3].tolist(), element[[0, 2, 3]].tolist()]
40+
if is_quad
41+
else [element[:3].tolist()]
42+
)
4043
for is_quad, element in zip(is_quads, element_node_idxs)
4144
]
4245
else:
4346
is_quads = [element[3] != element[2] for element in element_node_idxs]
4447
tri_faces_nested = [
45-
[element[:3].tolist(), element[[0, 2, 3]].tolist()]
46-
if is_quad
47-
else [element[:3].tolist()]
48+
(
49+
[element[:3].tolist(), element[[0, 2, 3]].tolist()]
50+
if is_quad
51+
else [element[:3].tolist()]
52+
)
4853
for is_quad, element in zip(is_quads, element_node_idxs)
4954
]
5055
tri_faces = np.array([tri_face for tri_faces in tri_faces_nested for tri_face in tri_faces])
@@ -125,10 +130,12 @@ def _make_ids_unique(
125130
cumcounts = pd.DataFrame(array, columns=["ids"]).groupby("ids").cumcount().values
126131
return np.array(
127132
[
128-
old_id
129-
if postfix == 0
130-
else f"{old_id}_{point_uid[e[0]]}_{point_uid[e[1]]}_"
131-
f"{point_uid[e[2]]}_{point_uid[e[3]]}"
133+
(
134+
old_id
135+
if postfix == 0
136+
else f"{old_id}_{point_uid[e[0]]}_{point_uid[e[1]]}_"
137+
f"{point_uid[e[2]]}_{point_uid[e[3]]}"
138+
)
132139
for old_id, e, postfix in zip(array, element_node_idxs, cumcounts)
133140
]
134141
)
@@ -252,6 +259,7 @@ def from_keyfile(keyfile: str, partid: str = "") -> "CaeShellMesh":
252259
(6400, 3)
253260
"""
254261

262+
# pylint: disable=too-many-branches, too-many-nested-blocks
255263
def parse_contents(file_contents):
256264
lines = file_contents.split("\n")
257265
current_section = ""
@@ -265,34 +273,46 @@ def parse_contents(file_contents):
265273
for line in lines:
266274
if line.startswith("*"):
267275
current_section = line.split()[0].upper()
268-
current_section_options = set(current_section.split('_')[1:])
276+
current_section_options = set(current_section.split("_")[1:])
269277
current_section_lines_per_entry = 1
270278
current_section_lineno = 0
271279
continue
272280
if line.startswith("$"): # comment
273281
continue
274282
if current_section == "*NODE":
275283
try:
276-
point_coordinates.append([float(line[8+i*16:8+(i+1)*16]) for i in range(3)])
284+
point_coordinates.append(
285+
[float(line[8 + i * 16 : 8 + (i + 1) * 16]) for i in range(3)]
286+
)
277287
pnt_ids.append(line[:8].strip())
278-
except:
288+
except [ValueError, IndexError]:
279289
pass
280290
elif current_section.startswith("*ELEMENT_SHELL"):
281-
282291

283292
if current_section_lineno % current_section_lines_per_entry == 0:
284293
if partid == "" or partid == line[8:16].strip():
285-
node_ids = [line[16+i*8:16+(i+1)*8].strip() for i in range(8)]
286-
node_ids = [node_id for node_id in node_ids if len(node_id) > 0 and node_id != "0"]
294+
node_ids = [
295+
line[16 + i * 8 : 16 + (i + 1) * 8].strip() for i in range(8)
296+
]
297+
node_ids = [
298+
node_id
299+
for node_id in node_ids
300+
if len(node_id) > 0 and node_id != "0"
301+
]
302+
# pylint: disable=fixme
287303
# TODO: Check for unhandled options, e.g. COMPOSITE, DOF
288304
if current_section_lineno == 0:
289305
if len(current_section_options & thickcard_options_set) > 0:
290-
current_section_lines_per_entry += 1 # skip thickness card
306+
current_section_lines_per_entry += 1 # skip thickness card
291307
if len(node_ids) > 4:
292-
current_section_lines_per_entry += 1 # skip additional thickness card for mid-side nodes
308+
current_section_lines_per_entry += (
309+
1 # skip additional thickness card for mid-side nodes
310+
)
293311
if "OFFSET" in current_section_options:
294-
current_section_lines_per_entry += 1 # skip offset card
295-
elem_node_ids.append([node_id for node_id in node_ids if len(node_id) > 0])
312+
current_section_lines_per_entry += 1 # skip offset card
313+
elem_node_ids.append(
314+
[node_id for node_id in node_ids if len(node_id) > 0]
315+
)
296316
if node_ids[0] == 1.0:
297317
print("HERE")
298318
elem_ids.append(line[:8].strip())

0 commit comments

Comments
 (0)