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 信息、原子数与网格信息)。
Metadata
Release files for cube-compress 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cube_compress-0.1.0.tar.gz | 5.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cube_compress-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.2 kB
Release files / cube_compress-0.1.0.tar.gz
| Download URL | cube_compress-0.1.0.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6148909a10440bc4c2f7df42253fc9d78f3ee5272bb057004e7eb919e05bb344
|
|
BLAKE2b-256 checksum How to use checksums |
d96df399ed039269d6c3a392f77dcc0b4c7e41d5b21807565827a590e4bc2c75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / cube_compress-0.1.0-py3-none-any.whl
| Download URL | cube_compress-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3839c4fea4e09645f128cea040f23c98d197c643e4ba5f01b87daae7e021050
|
|
BLAKE2b-256 checksum How to use checksums |
6d1afdeb3cb844c980daa706d02a5294cb77b0f5fc9f3b0ce57eda429a242446
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for cube-compress 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.