Skip to content

Commit d9c05ae

Browse files
authored
Merge pull request #787 from nschloe/med-no-compression
MED doesn't support compression
2 parents f82b313 + ab5039d commit d9c05ae

File tree

2 files changed

+18
-61
lines changed

2 files changed

+18
-61
lines changed

meshio/med/_med.py

Lines changed: 17 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,13 @@ def _read_families(fas_data):
206206
return families
207207

208208

209-
def write(filename, mesh, add_global_ids=True, compression="gzip", compression_opts=4):
209+
def write(filename, mesh, add_global_ids=True):
210210
import h5py
211211

212+
# MED doesn't support compression,
213+
# <https://github.com/nschloe/meshio/issues/781#issuecomment-616438066>
214+
# compression = None
215+
212216
f = h5py.File(filename, "w")
213217

214218
# Strangely the version must be 3.0.x
@@ -248,23 +252,13 @@ def write(filename, mesh, add_global_ids=True, compression="gzip", compression_o
248252
nodes_group.attrs.create("CGS", 1)
249253
profile = "MED_NO_PROFILE_INTERNAL"
250254
nodes_group.attrs.create("PFL", numpy.string_(profile))
251-
coo = nodes_group.create_dataset(
252-
"COO",
253-
data=mesh.points.flatten(order="F"),
254-
compression=compression,
255-
compression_opts=compression_opts,
256-
)
255+
coo = nodes_group.create_dataset("COO", data=mesh.points.flatten(order="F"))
257256
coo.attrs.create("CGT", 1)
258257
coo.attrs.create("NBR", len(mesh.points))
259258

260259
# Point tags
261260
if "point_tags" in mesh.point_data: # only works for med -> med
262-
family = nodes_group.create_dataset(
263-
"FAM",
264-
data=mesh.point_data["point_tags"],
265-
compression=compression,
266-
compression_opts=compression_opts,
267-
)
261+
family = nodes_group.create_dataset("FAM", data=mesh.point_data["point_tags"])
268262
family.attrs.create("CGT", 1)
269263
family.attrs.create("NBR", len(mesh.points))
270264

@@ -279,22 +273,14 @@ def write(filename, mesh, add_global_ids=True, compression="gzip", compression_o
279273
med_cells.attrs.create("CGT", 1)
280274
med_cells.attrs.create("CGS", 1)
281275
med_cells.attrs.create("PFL", numpy.string_(profile))
282-
nod = med_cells.create_dataset(
283-
"NOD",
284-
data=cells.flatten(order="F") + 1,
285-
compression=compression,
286-
compression_opts=compression_opts,
287-
)
276+
nod = med_cells.create_dataset("NOD", data=cells.flatten(order="F") + 1)
288277
nod.attrs.create("CGT", 1)
289278
nod.attrs.create("NBR", len(cells))
290279

291280
# Cell tags
292281
if "cell_tags" in mesh.cell_data: # works only for med -> med
293282
family = med_cells.create_dataset(
294-
"FAM",
295-
data=mesh.cell_data["cell_tags"][k],
296-
compression=compression,
297-
compression_opts=compression_opts,
283+
"FAM", data=mesh.cell_data["cell_tags"][k]
298284
)
299285
family.attrs.create("CGT", 1)
300286
family.attrs.create("NBR", len(cells))
@@ -309,15 +295,15 @@ def write(filename, mesh, add_global_ids=True, compression="gzip", compression_o
309295
try:
310296
if len(mesh.point_tags) > 0:
311297
node = families.create_group("NOEUD")
312-
_write_families(node, mesh.point_tags, compression, compression_opts)
298+
_write_families(node, mesh.point_tags)
313299
except AttributeError:
314300
pass
315301

316302
# For cell tags
317303
try:
318304
if len(mesh.cell_tags) > 0:
319305
element = families.create_group("ELEME")
320-
_write_families(element, mesh.cell_tags, compression, compression_opts)
306+
_write_families(element, mesh.cell_tags)
321307
except AttributeError:
322308
pass
323309

@@ -329,9 +315,7 @@ def write(filename, mesh, add_global_ids=True, compression="gzip", compression_o
329315
if name == "point_tags": # ignore point_tags already written under FAS
330316
continue
331317
supp = "NOEU" # nodal data
332-
_write_data(
333-
fields, mesh_name, profile, name, supp, data, compression, compression_opts
334-
)
318+
_write_data(fields, mesh_name, profile, name, supp, data)
335319

336320
# Cell data
337321
# Only support writing ELEM fields with only 1 Gauss point per cell
@@ -351,28 +335,12 @@ def write(filename, mesh, add_global_ids=True, compression="gzip", compression_o
351335
else: # general ELGA data defined at unknown Gauss points
352336
supp = "ELGA"
353337
_write_data(
354-
fields,
355-
mesh_name,
356-
profile,
357-
name,
358-
supp,
359-
data,
360-
compression,
361-
compression_opts,
362-
med_type,
338+
fields, mesh_name, profile, name, supp, data, med_type,
363339
)
364340

365341

366342
def _write_data(
367-
fields,
368-
mesh_name,
369-
profile,
370-
name,
371-
supp,
372-
data,
373-
compression,
374-
compression_opts,
375-
med_type=None,
343+
fields, mesh_name, profile, name, supp, data, med_type=None,
376344
):
377345
# Skip for general ELGA fields defined at unknown Gauss points
378346
if supp == "ELGA":
@@ -422,12 +390,7 @@ def _write_data(
422390
profile.attrs.create("GAU", numpy_void_str)
423391

424392
# Dataset
425-
profile.create_dataset(
426-
"CO",
427-
data=data.flatten(order="F"),
428-
compression=compression,
429-
compression_opts=compression_opts,
430-
)
393+
profile.create_dataset("CO", data=data.flatten(order="F"))
431394

432395

433396
def _component_names(n_components):
@@ -447,7 +410,7 @@ def _family_name(set_id, name):
447410
return "FAM" + "_" + str(set_id) + "_" + "_".join(name)
448411

449412

450-
def _write_families(fm_group, tags, compression, compression_opts):
413+
def _write_families(fm_group, tags):
451414
"""
452415
Write point/cell tag information under FAS/[mesh_name]
453416
"""
@@ -456,13 +419,7 @@ def _write_families(fm_group, tags, compression, compression_opts):
456419
family.attrs.create("NUM", set_id)
457420
group = family.create_group("GRO")
458421
group.attrs.create("NBR", len(name)) # number of subsets
459-
dataset = group.create_dataset(
460-
"NOM",
461-
(len(name),),
462-
dtype="80int8",
463-
compression=compression,
464-
compression_opts=compression_opts,
465-
)
422+
dataset = group.create_dataset("NOM", (len(name),), dtype="80int8")
466423
for i in range(len(name)):
467424
name_80 = name[i] + "\x00" * (80 - len(name[i])) # make name 80 characters
468425
dataset[i] = [ord(x) for x in name_80]

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = meshio
3-
version = 4.0.10
3+
version = 4.0.11
44
author = Nico Schlömer et al.
55
66
description = I/O for many mesh formats

0 commit comments

Comments
 (0)