Compress and decompress Gaussian CUBE files using 24-bit float packing.
Project description
cube_compress.py
一个用于将 Gaussian CUBE 体数据文件压缩为 .cubexs,并可解压回 .cube 的小工具。核心思路是把 float32 数据压缩为 24-bit(1 位符号 + 8 位指数 + 15 位尾数),再用 gzip 进行二次压缩。
依赖
- Python 3.x
- numpy
gzip为 Python 标准库,无需额外安装。
功能概览
-
float32_to_24bit(data_array)
将float32数组压缩为 24-bit(3 字节)表示。 -
uint8_from_24bit(byte_array, num_values)
将 24-bit 数据还原为float32数组。 -
compress(input_file, output_file)
读取.cube文件,压缩数据并写入.cubexs。 -
decompress(input_file, output_file)
读取.cubexs文件,解压并输出.cube。
使用示例
from cube_compress import compress, decompress, compress_cube_file
# 压缩
compress("input.cube", "output.cubexs")
# 解压
decompress("output.cubexs", "restored.cube")
安装(本地开发)
在项目根目录执行:
pip install -e .
然后即可通过 import cube_compress 使用。
文件结构说明
.cubexs 的结构为:
- 原
.cube的头部文本(UTF-8,逐行写入) - 三行元数据:
compressed_size=...original_size=...num_values=...
- gzip 压缩后的二进制数据(24-bit 数据重排后压缩)
注意事项
- 该压缩是有损的(尾数从 23 位缩减为 15 位)。
.cube文件头部必须符合标准格式(前几行标题、Fermi 信息、原子数与网格信息)。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cube_compress-0.1.0.tar.gz.
File metadata
- Download URL: cube_compress-0.1.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6148909a10440bc4c2f7df42253fc9d78f3ee5272bb057004e7eb919e05bb344
|
|
| MD5 |
fbd3b0d9f15a86abaeed350e4bd975df
|
|
| BLAKE2b-256 |
d96df399ed039269d6c3a392f77dcc0b4c7e41d5b21807565827a590e4bc2c75
|
File details
Details for the file cube_compress-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cube_compress-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3839c4fea4e09645f128cea040f23c98d197c643e4ba5f01b87daae7e021050
|
|
| MD5 |
c83c7a89d07088bcf8907bc9b7f706f2
|
|
| BLAKE2b-256 |
6d1afdeb3cb844c980daa706d02a5294cb77b0f5fc9f3b0ce57eda429a242446
|