Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylint alerts corrections as part of an intervention experiment 1500 #1501

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
0a2b512
src\meshio\obj\_obj.py too-many-statements
evidencebp Dec 29, 2024
400068e
src\meshio\tecplot\_tecplot.py too-many-statements
evidencebp Dec 29, 2024
290cf50
src\meshio\ansys\_ansys.py too-many-statements
evidencebp Dec 29, 2024
f0c1b63
src\meshio\xdmf\main.py too-many-statements
evidencebp Dec 29, 2024
37b6740
src\meshio\ugrid\_ugrid.py too-many-statements
evidencebp Dec 29, 2024
468e91f
src\meshio\vtk\_vtk_42.py too-many-statements
evidencebp Dec 29, 2024
e4b1a8d
src\meshio\flac3d\_flac3d.py too-many-statements
evidencebp Dec 29, 2024
f01fa49
src\meshio\su2\_su2.py too-many-statements
evidencebp Dec 29, 2024
73ae38d
src\meshio\med\_med.py too-many-statements
evidencebp Dec 29, 2024
5ef5be4
src\meshio\ply\_ply.py too-many-statements
evidencebp Dec 29, 2024
2a5b717
src\meshio\vtk\_vtk_51.py too-many-statements
evidencebp Dec 29, 2024
8eedb0a
src\meshio\permas\_permas.py try-except-raise
evidencebp Dec 29, 2024
78088e2
Update __about__.py
evidencebp Dec 29, 2024
03c49b1
src\meshio\gmsh\_gmsh41.py too-many-nested-blocks
evidencebp Dec 29, 2024
b13d71f
src\meshio\gmsh\common.py line-too-long
evidencebp Dec 30, 2024
fec373d
src\meshio\abaqus\_abaqus.py line-too-long
evidencebp Dec 30, 2024
8faa817
src\meshio\medit\_medit_internal.py line-too-long
evidencebp Dec 30, 2024
b839f88
src\meshio\_cli\_convert.py line-too-long
evidencebp Dec 30, 2024
2955079
src\meshio\_helpers.py line-too-long
evidencebp Dec 30, 2024
07811fa
Revert "src\meshio\medit\_medit_internal.py line-too-long"
evidencebp Dec 30, 2024
ef32c16
src\meshio\medit\_medit.py too-many-branches
evidencebp Dec 30, 2024
36a38aa
src\meshio\vtu\_vtu.py too-many-branches
evidencebp Dec 30, 2024
596131a
src\meshio\gmsh\_gmsh22.py too-many-branches
evidencebp Dec 30, 2024
37c6188
src\meshio\exodus\_exodus.py too-many-branches
evidencebp Dec 30, 2024
f3a5f3d
src\meshio\_cli\_compress.py too-many-branches
evidencebp Dec 30, 2024
46191ea
src\meshio\tetgen\_tetgen.py too-many-branches
evidencebp Dec 30, 2024
5b78f48
src\meshio\xdmf\time_series.py too-many-branches
evidencebp Dec 30, 2024
a2d064a
src\meshio\dolfin\_dolfin.py too-many-branches
evidencebp Dec 30, 2024
92bd50f
src\meshio\mdpa\_mdpa.py too-many-branches
evidencebp Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/meshio/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@

try:
__version__ = metadata.version("meshio")
except Exception:
except metadata.PackageNotFoundError:
__version__ = "unknown"
72 changes: 36 additions & 36 deletions src/meshio/_cli/_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,41 +41,41 @@ def compress(args):
# mesh.points = np.ascontiguousarray(mesh.points)

# write it out
if fmt == "ansys":
ansys.write(args.infile, mesh, binary=True)
elif fmt == "cgns":
cgns.write(
args.infile, mesh, compression="gzip", compression_opts=9 if args.max else 4
)
elif fmt == "gmsh":
gmsh.write(args.infile, mesh, binary=True)
elif fmt == "h5m":
h5m.write(
args.infile, mesh, compression="gzip", compression_opts=9 if args.max else 4
)
elif fmt == "mdpa":
mdpa.write(args.infile, mesh, binary=True)
elif fmt == "ply":
ply.write(args.infile, mesh, binary=True)
elif fmt == "stl":
stl.write(args.infile, mesh, binary=True)
elif fmt == "vtk":
vtk.write(args.infile, mesh, binary=True)
elif fmt == "vtu":
vtu.write(
args.infile, mesh, binary=True, compression="lzma" if args.max else "zlib"
)
elif fmt == "xdmf":
xdmf.write(
args.infile,
mesh,
data_format="HDF",
compression="gzip",
compression_opts=9 if args.max else 4,
)
else:
error(f"Don't know how to compress {args.infile}.")
exit(1)

_write_compressed(args.infile, mesh, fmt, args.max)

size = os.stat(args.infile).st_size
print(f"File size after: {size / 1024 ** 2:.2f} MB")

def _write_compressed(filename, mesh, fmt, max_compression):
"""Write mesh to file with compression based on format.

Args:
filename: Output file path
mesh: Mesh object to write
fmt: Format string (e.g. "vtu", "xdmf")
max_compression: Whether to use maximum compression settings
"""
if fmt == "ansys":
ansys.write(filename, mesh, binary=True)
elif fmt == "cgns":
cgns.write(filename, mesh, compression="gzip", compression_opts=9 if max_compression else 4)
elif fmt == "gmsh":
gmsh.write(filename, mesh, binary=True)
elif fmt == "h5m":
h5m.write(filename, mesh, compression="gzip", compression_opts=9 if max_compression else 4)
elif fmt == "mdpa":
mdpa.write(filename, mesh, binary=True)
elif fmt == "ply":
ply.write(filename, mesh, binary=True)
elif fmt == "stl":
stl.write(filename, mesh, binary=True)
elif fmt == "vtk":
vtk.write(filename, mesh, binary=True)
elif fmt == "vtu":
vtu.write(filename, mesh, binary=True, compression="lzma" if max_compression else "zlib")
elif fmt == "xdmf":
xdmf.write(filename, mesh, data_format="HDF", compression="gzip",
compression_opts=9 if max_compression else 4)
else:
error(f"Don't know how to compress {filename}.")
exit(1)
6 changes: 4 additions & 2 deletions src/meshio/_cli/_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ def add_args(parser):
"--sets-to-int-data",
"-s",
action="store_true",
help="if possible, convert sets to integer data (useful if the output type does not support sets)",
help=("if possible, convert sets to integer data "
+ "(useful if the output type does not support sets)"),
)
parser.add_argument(
"--int-data-to-sets",
"-d",
action="store_true",
help="if possible, convert integer data to sets (useful if the output type does not support integer data)",
help=("if possible, convert integer data to sets "
+ "(useful if the output type does not support integer data)"),
)


Expand Down
3 changes: 2 additions & 1 deletion src/meshio/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def write(filename, mesh: Mesh, file_format: str | None = None, **kwargs):
raise WriteError("File format must be supplied if `filename` is a buffer")
if file_format == "tetgen":
raise WriteError(
"tetgen format is spread across multiple files, and so cannot be written to a buffer"
"tetgen format is spread across multiple files,"
+ " and so cannot be written to a buffer"
)
else:
path = Path(filename)
Expand Down
3 changes: 2 additions & 1 deletion src/meshio/abaqus/_abaqus.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ def read_buffer(f):
else:
raise ReadError(f"Unknown cell set '{set_name}'")
elif keyword == "INCLUDE":
# Splitting line to get external input file path (example: *INCLUDE,INPUT=wInclude_bulk.inp)
# Splitting line to get external input file path
# (example: *INCLUDE,INPUT=wInclude_bulk.inp)
ext_input_file = pathlib.Path(line.split("=")[-1].strip())
if ext_input_file.exists() is False:
cd = pathlib.Path(f.name).parent
Expand Down
144 changes: 76 additions & 68 deletions src/meshio/ansys/_ansys.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,84 +214,92 @@ def _read_faces(f, line):
if line.strip()[-1] != "(":
_skip_to(f, "(")

data = {}
if out.group(1) == "":
# ASCII
if key == "mixed":
# From
# <https://www.afs.enea.it/project/neptunius/docs/fluent/html/ug/node1471.htm>:
#
# > If the face zone is of mixed type (element-type = > 0), the body of the
# > section will include the face type and will appear as follows
# >
# > type v0 v1 v2 c0 c1
# >
for k in range(num_cells):
line = ""
while line.strip() == "":
line = f.readline().decode()
dat = line.split()
type_index = int(dat[0], 16)
if type_index == 0:
raise ReadError()
type_string, num_nodes_per_cell = element_type_to_key_num_nodes[
type_index
]
if len(dat) != num_nodes_per_cell + 3:
raise ReadError()
data = _read_faces_ascii(f, num_cells, key, num_nodes_per_cell)
else:
data = _read_faces_binary(f, num_cells, key, num_nodes_per_cell, out.group(1))

if type_string not in data:
data[type_string] = []
# make sure that the data set is properly closed
_skip_close(f, 2)

data[type_string].append(
[int(d, 16) for d in dat[1 : num_nodes_per_cell + 1]]
)
return data

data = {key: np.array(data[key]) for key in data}

else:
# read cell data
data = np.empty((num_cells, num_nodes_per_cell), dtype=int)
for k in range(num_cells):
def _read_faces_ascii(f, num_cells, key, num_nodes_per_cell):
data = {}
if key == "mixed":
# From
# <https://www.afs.enea.it/project/neptunius/docs/fluent/html/ug/node1471.htm>:
#
# > If the face zone is of mixed type (element-type = > 0), the body of the
# > section will include the face type and will appear as follows
# >
# > type v0 v1 v2 c0 c1
# >
for k in range(num_cells):
line = ""
while line.strip() == "":
line = f.readline().decode()
dat = line.split()
# The body of a regular face section contains the grid connectivity, and
# each line appears as follows:
# n0 n1 n2 cr cl
# where n* are the defining nodes (vertices) of the face, and c* are the
# adjacent cells.
if len(dat) != num_nodes_per_cell + 2:
raise ReadError()
data[k] = [int(d, 16) for d in dat[:num_nodes_per_cell]]
data = {key: data}
dat = line.split()
type_index = int(dat[0], 16)
if type_index == 0:
raise ReadError()
type_string, num_nodes_per_cell = element_type_to_key_num_nodes[
type_index
]
if len(dat) != num_nodes_per_cell + 3:
raise ReadError()

if type_string not in data:
data[type_string] = []

data[type_string].append(
[int(d, 16) for d in dat[1 : num_nodes_per_cell + 1]]
)

data = {key: np.array(data[key]) for key in data}

else:
# binary
if out.group(1) == "20":
dtype = np.int32
else:
if out.group(1) != "30":
ReadError(f"Expected keys '20' or '30', got {out.group(1)}.")
dtype = np.int64

if key == "mixed":
raise ReadError("Mixed element type for binary faces not supported yet")

# Read cell data.
# The body of a regular face section contains the grid
# connectivity, and each line appears as follows:
# n0 n1 n2 cr cl
# where n* are the defining nodes (vertices) of the face,
# and c* are the adjacent cells.
shape = (num_cells, num_nodes_per_cell + 2)
count = shape[0] * shape[1]
data = np.fromfile(f, count=count, dtype=dtype).reshape(shape)
# Cut off the adjacent cell data.
data = data[:, :num_nodes_per_cell]
# read cell data
data = np.empty((num_cells, num_nodes_per_cell), dtype=int)
for k in range(num_cells):
line = f.readline().decode()
dat = line.split()
# The body of a regular face section contains the grid connectivity, and
# each line appears as follows:
# n0 n1 n2 cr cl
# where n* are the defining nodes (vertices) of the face, and c* are the
# adjacent cells.
if len(dat) != num_nodes_per_cell + 2:
raise ReadError()
data[k] = [int(d, 16) for d in dat[:num_nodes_per_cell]]
data = {key: data}
return data

# make sure that the data set is properly closed
_skip_close(f, 2)

def _read_faces_binary(f, num_cells, key, num_nodes_per_cell, group):
if group == "20":
dtype = np.int32
else:
if group != "30":
ReadError(f"Expected keys '20' or '30', got {group}.")
dtype = np.int64

if key == "mixed":
raise ReadError("Mixed element type for binary faces not supported yet")

# Read cell data.
# The body of a regular face section contains the grid
# connectivity, and each line appears as follows:
# n0 n1 n2 cr cl
# where n* are the defining nodes (vertices) of the face,
# and c* are the adjacent cells.
shape = (num_cells, num_nodes_per_cell + 2)
count = shape[0] * shape[1]
data = np.fromfile(f, count=count, dtype=dtype).reshape(shape)
# Cut off the adjacent cell data.
data = data[:, :num_nodes_per_cell]
data = {key: data}
return data


Expand Down
15 changes: 9 additions & 6 deletions src/meshio/dolfin/_dolfin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ def _read_mesh(filename):
]
cell_tags = [f"v{i}" for i in range(num_nodes_per_cell)]
elif elem.tag == "vertices":
if dim is None:
raise ReadError("Expected `mesh` before `vertices`")
points = np.empty((int(elem.attrib["size"]), dim))
keys = ["x", "y"]
if dim == 3:
keys += ["z"]
points, keys = _handle_vertices(dim, elem)
elif elem.tag == "vertex":
if points is None or keys is None:
raise ReadError("Expected `vertices` before `vertex`")
Expand All @@ -78,6 +73,14 @@ def _read_mesh(filename):

return points, cells, cell_type

def _handle_vertices(dim, elem):
if dim is None:
raise ReadError("Expected `mesh` before `vertices`")
points = np.empty((int(elem.attrib["size"]), dim))
keys = ["x", "y"]
if dim == 3:
keys += ["z"]
return points, keys

def _read_cell_data(filename):
dolfin_type_to_numpy_type = {
Expand Down
Loading