Skip to main content

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 的结构为:

  1. .cube 的头部文本(UTF-8,逐行写入)
  2. 三行元数据:
    • compressed_size=...
    • original_size=...
    • num_values=...
  3. gzip 压缩后的二进制数据(24-bit 数据重排后压缩)

注意事项

  • 该压缩是有损的(尾数从 23 位缩减为 15 位)。
  • .cube 文件头部必须符合标准格式(前几行标题、Fermi 信息、原子数与网格信息)。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cube_compress-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cube_compress-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for cube_compress-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6148909a10440bc4c2f7df42253fc9d78f3ee5272bb057004e7eb919e05bb344
MD5 fbd3b0d9f15a86abaeed350e4bd975df
BLAKE2b-256 d96df399ed039269d6c3a392f77dcc0b4c7e41d5b21807565827a590e4bc2c75

See more details on using hashes here.

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

Hashes for cube_compress-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3839c4fea4e09645f128cea040f23c98d197c643e4ba5f01b87daae7e021050
MD5 c83c7a89d07088bcf8907bc9b7f706f2
BLAKE2b-256 6d1afdeb3cb844c980daa706d02a5294cb77b0f5fc9f3b0ce57eda429a242446

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page