Skip to main content

The next-generation deep learning toolkit designed specifically for spectral analysis

Project description

inkhinge

inkhinge是一个专为光谱分析设计的下一代深度学习工具集,专注于光谱数据的处理、转换与整合,为光谱分析领域的深度学习应用提供高效的数据预处理支持。通过pip install inkhinge安装后,你可以便捷地处理Omnic SPA格式的光谱文件,实现批量转换与合并等功能。

安装

pip install inkhinge

使用方法

下面是read_to_csv功能的简单使用示例:

1. 单个SPA文件转换为CSV

from inkhinge.core import read_to_csv

# 将单个SPA文件转换为CSV
output_path = read_to_csv(
    input_path="sample.spa",
    output_path="output/sample.csv",
    precision=20  # 保留20位小数精度
)
print(f"转换完成,输出路径:{output_path}")

2. 批量转换目录中的SPA文件

from inkhinge.core import read_to_csv

# 批量转换目录中的SPA文件(包括子目录)
success_count = read_to_csv(
    input_path="spectral_data/",
    output_path="converted_csv/",
    recursive=True,  # 递归处理子目录
    overwrite=True,  # 覆盖已存在的文件
    precision=15
)
print(f"批量转换完成,成功转换{success_count}个文件")

3. 转换并合并为单个CSV文件

from inkhinge.core import read_to_csv

# 转换所有SPA文件并按顺序合并为单个CSV
read_to_csv(
    input_path="spectral_data/",
    output_path="converted_csv/",
    merge_output="merged_spectra.csv",  # 合并后的文件路径)
)
print("转换与合并完成,结果已保存至merged_spectra.csv")

函数文档

read_to_csv(input_path, output_path=None, background_path=None, overwrite=False, recursive=False, precision=20, merge_output=None)

读取Omnic SPA格式的光谱文件并转换为CSV格式,支持批量处理与文件合并。

参数:

  • input_path (str): 输入路径,可为单个SPA文件路径或包含SPA文件的目录路径。
  • output_path (str, 可选): 输出路径,可为单个CSV文件路径或保存CSV文件的目录路径。若未指定,默认与输入文件同目录并添加_converted后缀。
  • background_path (str, 可选): 背景文件(BG.spa)路径,用于对光谱数据进行背景校正(可选)。
  • overwrite (bool, 可选): 是否覆盖已存在的输出文件,默认为False(不覆盖)。
  • recursive (bool, 可选): 当input_path为目录时,是否递归处理子目录中的SPA文件,默认为False
  • precision (int, 可选): 输出数据保留的小数位数精度,默认为20位,确保以定点小数形式表示(非科学计数法)。
  • merge_output (str, 可选): 合并后的CSV文件路径。若指定,将按文件名顺序合并所有转换后的CSV文件,默认为None(不合并)。

返回:

  • input_path为单个文件:返回转换后的CSV文件路径。
  • input_path为目录:返回成功转换的文件数量(当merge_outputNone时)或转换后的文件路径列表(当merge_output指定时)。

功能特点

  1. 精准转换:采用高精度定点小数表示(默认20位),避免科学计数法,确保光谱数据精度无损。
  2. 批量处理:高效处理目录中的多个SPA文件,支持递归遍历子目录。
  3. 智能合并:按文件名顺序合并多个CSV文件,列名从0开始编号(如Kubelka-Munk_0Kubelka-Munk_1),便于后续深度学习模型训练。
  4. 类型适配:自动识别光谱数据类型(吸光度、透射率等),并生成对应的列名与单位。

贡献

如果你想为inkhinge工具集做出贡献,请遵循以下步骤:

  1. Fork这个仓库
  2. 创建你的特性分支 (git checkout -b feature/SpectralFeature)
  3. 提交你的更改 (git commit -m 'Add spectral preprocessing feature')
  4. 将更改推送到你的分支 (git push origin feature/SpectralFeature)
  5. 打开一个Pull Request

许可证

本项目采用MIT许可证 - 详情请见LICENSE文件。

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

inkhinge-0.1.6.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

inkhinge-0.1.6-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file inkhinge-0.1.6.tar.gz.

File metadata

  • Download URL: inkhinge-0.1.6.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for inkhinge-0.1.6.tar.gz
Algorithm Hash digest
SHA256 9560eaa1bd17db90fa4a310df6a334e474043777a81378a7b955b8f130dd2197
MD5 078f15a341761a806cec6a3f399bd83c
BLAKE2b-256 6ecae0156bf2359d5a950028a219a78cf88305eff550ee5533b1225a39d6c88b

See more details on using hashes here.

File details

Details for the file inkhinge-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: inkhinge-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for inkhinge-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 faff323997ef3c00e4b11f6481086711ed3d98f71cde0fb49e2f9d9630a6f0e5
MD5 07ce54d9d5c7d756392de2f029f7e751
BLAKE2b-256 d992ce490d5c092b6d817958bc5b90b7709b8d9cebed14d79ee2568de8da657c

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