d3plot-compress 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- d3plot_compress/__init__.py +3 -0
- d3plot_compress/cli.py +89 -0
- d3plot_compress/core.py +138 -0
- d3plot_compress-0.1.0.dist-info/METADATA +97 -0
- d3plot_compress-0.1.0.dist-info/RECORD +9 -0
- d3plot_compress-0.1.0.dist-info/WHEEL +5 -0
- d3plot_compress-0.1.0.dist-info/entry_points.txt +2 -0
- d3plot_compress-0.1.0.dist-info/licenses/LICENSE +21 -0
- d3plot_compress-0.1.0.dist-info/top_level.txt +1 -0
d3plot_compress/cli.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Command-line interface for d3plot_compress."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from .core import compress_folder, decompress_folder
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
parser = argparse.ArgumentParser(
|
|
12
|
+
prog="d3plot-compress",
|
|
13
|
+
description=(
|
|
14
|
+
"Lossless gzip compression for LS-DYNA d3plot files.\n"
|
|
15
|
+
"Compressed files are readable directly by BETA CAE META post-processor."
|
|
16
|
+
),
|
|
17
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
18
|
+
epilog="""
|
|
19
|
+
Examples:
|
|
20
|
+
d3plot-compress compress ./results
|
|
21
|
+
d3plot-compress compress ./results --keep-original --level 9
|
|
22
|
+
d3plot-compress decompress ./results
|
|
23
|
+
d3plot-compress decompress ./results --keep-compressed
|
|
24
|
+
""",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"action",
|
|
29
|
+
choices=["compress", "decompress"],
|
|
30
|
+
help="compress: d3plot → d3plot.gz | decompress: d3plot.gz → d3plot",
|
|
31
|
+
)
|
|
32
|
+
parser.add_argument(
|
|
33
|
+
"folder",
|
|
34
|
+
type=Path,
|
|
35
|
+
help="Folder containing d3plot files",
|
|
36
|
+
)
|
|
37
|
+
parser.add_argument(
|
|
38
|
+
"--keep-original",
|
|
39
|
+
action="store_true",
|
|
40
|
+
help="(compress) Keep uncompressed originals alongside .gz files",
|
|
41
|
+
)
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--keep-compressed",
|
|
44
|
+
action="store_true",
|
|
45
|
+
help="(decompress) Keep .gz files alongside restored originals",
|
|
46
|
+
)
|
|
47
|
+
parser.add_argument(
|
|
48
|
+
"--level",
|
|
49
|
+
type=int,
|
|
50
|
+
default=6,
|
|
51
|
+
choices=range(1, 10),
|
|
52
|
+
metavar="1-9",
|
|
53
|
+
help="Gzip compression level: 1=fastest, 9=smallest (default: 6)",
|
|
54
|
+
)
|
|
55
|
+
parser.add_argument(
|
|
56
|
+
"--quiet",
|
|
57
|
+
action="store_true",
|
|
58
|
+
help="Suppress progress output",
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
args = parser.parse_args()
|
|
62
|
+
|
|
63
|
+
if not args.folder.is_dir():
|
|
64
|
+
print(f"Error: folder not found: {args.folder}", file=sys.stderr)
|
|
65
|
+
sys.exit(1)
|
|
66
|
+
|
|
67
|
+
verbose = not args.quiet
|
|
68
|
+
|
|
69
|
+
if args.action == "compress":
|
|
70
|
+
results = compress_folder(
|
|
71
|
+
args.folder,
|
|
72
|
+
keep_original=args.keep_original,
|
|
73
|
+
level=args.level,
|
|
74
|
+
verbose=verbose,
|
|
75
|
+
)
|
|
76
|
+
if verbose and results:
|
|
77
|
+
print(f"\nDone. {len(results)} file(s) compressed.")
|
|
78
|
+
else:
|
|
79
|
+
results = decompress_folder(
|
|
80
|
+
args.folder,
|
|
81
|
+
keep_compressed=args.keep_compressed,
|
|
82
|
+
verbose=verbose,
|
|
83
|
+
)
|
|
84
|
+
if verbose and results:
|
|
85
|
+
print(f"\nDone. {len(results)} file(s) decompressed.")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
main()
|
d3plot_compress/core.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Core compress/decompress logic for LS-DYNA d3plot files."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import gzip
|
|
6
|
+
import os
|
|
7
|
+
import re
|
|
8
|
+
import shutil
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
# Matches: d3plot, d3plot01, d3plot02, ..., d3plot99, d3plot100, etc.
|
|
12
|
+
_D3PLOT_PATTERN = re.compile(r"^d3plot(\d*)$", re.IGNORECASE)
|
|
13
|
+
_D3PLOT_GZ_PATTERN = re.compile(r"^d3plot(\d*)\.gz$", re.IGNORECASE)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def find_d3plot_files(folder: Path) -> list[Path]:
|
|
17
|
+
"""Return uncompressed d3plot files in folder, sorted by sequence number."""
|
|
18
|
+
files = [
|
|
19
|
+
f for f in folder.iterdir()
|
|
20
|
+
if f.is_file() and _D3PLOT_PATTERN.match(f.name)
|
|
21
|
+
]
|
|
22
|
+
return sorted(files, key=lambda f: _sort_key(f.name))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def find_compressed_files(folder: Path) -> list[Path]:
|
|
26
|
+
"""Return compressed d3plot.gz files in folder, sorted by sequence number."""
|
|
27
|
+
files = [
|
|
28
|
+
f for f in folder.iterdir()
|
|
29
|
+
if f.is_file() and _D3PLOT_GZ_PATTERN.match(f.name)
|
|
30
|
+
]
|
|
31
|
+
return sorted(files, key=lambda f: _sort_key(f.name))
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _sort_key(name: str) -> tuple:
|
|
35
|
+
m = _D3PLOT_PATTERN.match(name) or _D3PLOT_GZ_PATTERN.match(name)
|
|
36
|
+
suffix = m.group(1) if m else ""
|
|
37
|
+
return (int(suffix),) if suffix else (0,)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def compress_file(src: Path, keep_original: bool = False, level: int = 6) -> Path:
|
|
41
|
+
"""
|
|
42
|
+
Compress a single d3plot file to <name>.gz in the same folder.
|
|
43
|
+
Returns path to the compressed file.
|
|
44
|
+
"""
|
|
45
|
+
dst = src.with_name(src.name + ".gz")
|
|
46
|
+
with src.open("rb") as f_in, gzip.open(dst, "wb", compresslevel=level) as f_out:
|
|
47
|
+
shutil.copyfileobj(f_in, f_out)
|
|
48
|
+
if not keep_original:
|
|
49
|
+
src.unlink()
|
|
50
|
+
return dst
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def decompress_file(src: Path, keep_compressed: bool = False) -> Path:
|
|
54
|
+
"""
|
|
55
|
+
Decompress a single d3plot.gz file, restoring original name.
|
|
56
|
+
Returns path to the decompressed file.
|
|
57
|
+
"""
|
|
58
|
+
# d3plot01.gz → d3plot01
|
|
59
|
+
dst = src.with_suffix("") # strips .gz
|
|
60
|
+
with gzip.open(src, "rb") as f_in, dst.open("wb") as f_out:
|
|
61
|
+
shutil.copyfileobj(f_in, f_out)
|
|
62
|
+
if not keep_compressed:
|
|
63
|
+
src.unlink()
|
|
64
|
+
return dst
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def compress_folder(
|
|
68
|
+
folder: str | os.PathLike,
|
|
69
|
+
keep_original: bool = False,
|
|
70
|
+
level: int = 6,
|
|
71
|
+
verbose: bool = True,
|
|
72
|
+
) -> list[Path]:
|
|
73
|
+
"""
|
|
74
|
+
Compress all d3plot files in *folder*.
|
|
75
|
+
|
|
76
|
+
Parameters
|
|
77
|
+
----------
|
|
78
|
+
folder : path containing d3plot, d3plot01, d3plot02, ...
|
|
79
|
+
keep_original: keep uncompressed originals alongside .gz files
|
|
80
|
+
level : gzip compression level 1 (fastest) – 9 (smallest), default 6
|
|
81
|
+
verbose : print progress
|
|
82
|
+
|
|
83
|
+
Returns list of compressed file paths.
|
|
84
|
+
"""
|
|
85
|
+
folder = Path(folder)
|
|
86
|
+
files = find_d3plot_files(folder)
|
|
87
|
+
if not files:
|
|
88
|
+
if verbose:
|
|
89
|
+
print(f"No uncompressed d3plot files found in: {folder}")
|
|
90
|
+
return []
|
|
91
|
+
|
|
92
|
+
results = []
|
|
93
|
+
for f in files:
|
|
94
|
+
if verbose:
|
|
95
|
+
size_mb = f.stat().st_size / 1_048_576
|
|
96
|
+
print(f" Compressing {f.name} ({size_mb:.1f} MB) ...", end=" ", flush=True)
|
|
97
|
+
out = compress_file(f, keep_original=keep_original, level=level)
|
|
98
|
+
if verbose:
|
|
99
|
+
out_mb = out.stat().st_size / 1_048_576
|
|
100
|
+
print(f"→ {out.name} ({out_mb:.1f} MB)")
|
|
101
|
+
results.append(out)
|
|
102
|
+
return results
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def decompress_folder(
|
|
106
|
+
folder: str | os.PathLike,
|
|
107
|
+
keep_compressed: bool = False,
|
|
108
|
+
verbose: bool = True,
|
|
109
|
+
) -> list[Path]:
|
|
110
|
+
"""
|
|
111
|
+
Decompress all d3plot.gz files in *folder*.
|
|
112
|
+
|
|
113
|
+
Parameters
|
|
114
|
+
----------
|
|
115
|
+
folder : path containing d3plot.gz, d3plot01.gz, ...
|
|
116
|
+
keep_compressed: keep .gz files alongside restored originals
|
|
117
|
+
verbose : print progress
|
|
118
|
+
|
|
119
|
+
Returns list of decompressed file paths.
|
|
120
|
+
"""
|
|
121
|
+
folder = Path(folder)
|
|
122
|
+
files = find_compressed_files(folder)
|
|
123
|
+
if not files:
|
|
124
|
+
if verbose:
|
|
125
|
+
print(f"No compressed d3plot.gz files found in: {folder}")
|
|
126
|
+
return []
|
|
127
|
+
|
|
128
|
+
results = []
|
|
129
|
+
for f in files:
|
|
130
|
+
if verbose:
|
|
131
|
+
size_mb = f.stat().st_size / 1_048_576
|
|
132
|
+
print(f" Decompressing {f.name} ({size_mb:.1f} MB) ...", end=" ", flush=True)
|
|
133
|
+
out = decompress_file(f, keep_compressed=keep_compressed)
|
|
134
|
+
if verbose:
|
|
135
|
+
out_mb = out.stat().st_size / 1_048_576
|
|
136
|
+
print(f"→ {out.name} ({out_mb:.1f} MB)")
|
|
137
|
+
results.append(out)
|
|
138
|
+
return results
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: d3plot-compress
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lossless gzip compression for LS-DYNA d3plot binary result files
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: ls-dyna,d3plot,fea,compression,cae
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Classifier: Topic :: Scientific/Engineering
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Dynamic: license-file
|
|
20
|
+
|
|
21
|
+
# d3plot-compress
|
|
22
|
+
|
|
23
|
+
Lossless gzip compression for **LS-DYNA d3plot** binary result files.
|
|
24
|
+
|
|
25
|
+
Compressed files are read **directly** by BETA CAE META post-processor — no manual decompression needed before viewing animations.
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install d3plot-compress
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
### Command line
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
# Compress all d3plot files in a folder (replaces originals with .gz)
|
|
39
|
+
d3plot-compress compress /path/to/results
|
|
40
|
+
|
|
41
|
+
# Compress but keep originals
|
|
42
|
+
d3plot-compress compress /path/to/results --keep-original
|
|
43
|
+
|
|
44
|
+
# Use maximum compression (slower but smallest size)
|
|
45
|
+
d3plot-compress compress /path/to/results --level 9
|
|
46
|
+
|
|
47
|
+
# Decompress (if you need raw files for a tool that doesn't support .gz)
|
|
48
|
+
d3plot-compress decompress /path/to/results
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Python API
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from d3plot_compress import compress_folder, decompress_folder
|
|
55
|
+
|
|
56
|
+
# Compress
|
|
57
|
+
compress_folder("/path/to/results")
|
|
58
|
+
|
|
59
|
+
# Decompress
|
|
60
|
+
decompress_folder("/path/to/results")
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## How it works
|
|
64
|
+
|
|
65
|
+
LS-DYNA writes results as a sequence of binary files:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
d3plot ← header + first state
|
|
69
|
+
d3plot01 ← subsequent time steps
|
|
70
|
+
d3plot02
|
|
71
|
+
...
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This tool compresses each file individually using gzip (lossless), producing:
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
d3plot.gz
|
|
78
|
+
d3plot01.gz
|
|
79
|
+
d3plot02.gz
|
|
80
|
+
...
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
BETA CAE META post-processor recognises the `.gz` extension and decompresses on-the-fly, so animations play exactly as with the original files.
|
|
84
|
+
|
|
85
|
+
## Options
|
|
86
|
+
|
|
87
|
+
| Flag | Description |
|
|
88
|
+
|------|-------------|
|
|
89
|
+
| `--level 1-9` | Compression level (1=fastest, 9=smallest, default=6) |
|
|
90
|
+
| `--keep-original` | Keep uncompressed files alongside `.gz` |
|
|
91
|
+
| `--keep-compressed` | (decompress) Keep `.gz` alongside restored files |
|
|
92
|
+
| `--quiet` | Suppress progress output |
|
|
93
|
+
|
|
94
|
+
## Requirements
|
|
95
|
+
|
|
96
|
+
- Python 3.10+
|
|
97
|
+
- No external dependencies (uses Python's built-in `gzip` module)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
d3plot_compress/__init__.py,sha256=M_uueK0TKRnZUWCwPqNFQTsEjbSi3r-lkLDqBVgM6bQ,101
|
|
2
|
+
d3plot_compress/cli.py,sha256=0ZIE0KLiJITKMZ-QZahMtQ8lbQW9dACEpTUfybd1HSY,2475
|
|
3
|
+
d3plot_compress/core.py,sha256=1Sj4YwXkkHhb4lCDe-tzPdaN1whsmPVW-n9LDqI1xmM,4306
|
|
4
|
+
d3plot_compress-0.1.0.dist-info/licenses/LICENSE,sha256=ESYyLizI0WWtxMeS7rGVcX3ivMezm-HOd5WdeOh-9oU,1056
|
|
5
|
+
d3plot_compress-0.1.0.dist-info/METADATA,sha256=SHPdAQZygewm_klf8nWSjSXH8C__7wjbHdNz0LiZLCU,2530
|
|
6
|
+
d3plot_compress-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
d3plot_compress-0.1.0.dist-info/entry_points.txt,sha256=mdc2wjSxyJoCqRH3VFVOLWIjDxFpIAbHuy4y_C5uGiU,61
|
|
8
|
+
d3plot_compress-0.1.0.dist-info/top_level.txt,sha256=MvMjrWBDm7tCGRtGlNNqOWHOIrEK1iJUILR_lqvqMd4,16
|
|
9
|
+
d3plot_compress-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
d3plot_compress
|