← 返回 Skills 市场
tianyima96

diffraction-scatter-background-substract

作者 TIANYI MA · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
85
总下载
1
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install diffraction-scatter-background-substract
功能描述
BGsub — X-ray diffraction (SAXS/WAXS/XRD) background subtraction toolkit for 2D images and 1D curves. X射线衍射(SAXS/WAXS/XRD)数据背景扣除工具,覆盖2D图像处理和1D曲线处理。 Use this...
使用说明 (SKILL.md)

BGsub Skill — 2D Image & 1D Curve Background Subtraction / 2D图像与1D曲线背景扣除

BGsub is a self-contained CLI toolkit for background subtraction of X-ray diffraction data. It covers 2D detector image processing (TIFF/EDF/H5) and 1D curve processing (XY/DAT/CSV), with SSRF ionchamber transmission auto-correction. No external BGsub package installation is required — all dependencies are bundled in lib/, though standard scientific Python dependencies are still needed. BGsub 是一套自包含的 X 射线衍射数据背景扣除 CLI 工具集,覆盖2D探测器图像处理(TIFF/EDF/H5)和1D曲线处理(XY/DAT/CSV),集成 SSRF 电离室透射率自动校正。无需安装外部 BGsub 包——所有依赖已打包在 lib/ 中,但仍需标准科学计算 Python 依赖。

Latest 1D highlights / 最新 1D 特性:

  • T-背景扣除 为首要模式 / T-background subtraction is the primary mode
  • 支持多列文本结构 single / xyxy / xyyy
  • 支持 逐一文件合并单文件 导出
  • 合并导出支持文本/CSV/HDF5;多列模式下暂不支持电离室自动 T

Core Capabilities / 核心能力

# Capability / 能力 Domain / 领域 Script / 脚本
1 Reference-based 2D background subtraction / 有参考2D背景扣除 2D Image bg_subtract.py
2 Batch 2D processing with ionchamber / 批量2D处理+电离室 2D Image bg_batch.py
3 Ionchamber stats + sample/background transmission / 电离室统计与样品/背景透过率 Shared ionchamber.py
4 1D curve background estimation & T-corrected reference subtraction / 1D曲线算法背景估计与T修正参考扣除 1D Curve curve_process_1d.py
5 Batch 1D curve processing with unified / per-file / ionchamber T / 批量1D曲线处理(统一T/分别设置/电离室) 1D Curve curve_batch_1d.py
6 Format conversion (TIFF/EDF/H5) / 格式转换 2D Image format_convert.py
7 silx image comparison popup / silx图像对比弹窗 2D Image compare_images.py

Processing Flow / 处理流程

2D Image Background Subtraction / 2D图像背景扣除

Sample image + Ionchamber file / 样品图像 + 电离室文件
         ↓
    Calculate T = I_sample / I_background / 计算透射率
         ↓
result = sample / T - background
         ↓
    Save result image / 保存结果图像

1D Curve Background Estimation / 1D曲线背景估计

Load 1D curve file (XY/DAT/CSV) / 加载1D曲线文件
         ↓
Choose column layout: single / xyxy / xyyy / 选择列结构
         ↓
    Estimate background using algorithm / 使用算法估计背景
    (Morphological / Polynomial / Rolling Ball)
         ↓
    Subtract: result = curve - background / 扣除背景
         ↓
    Save raw, background, subtracted / 保存原始、背景、扣除结果

1D Reference Background Subtraction / 1D参考背景扣除

Sample curve + background curve / 样品曲线 + 背景曲线
         ↓
Transmission source / 透过率来源
  - manual unified / 手动统一值
  - manual per-file / 手动分别设置
  - ionchamber auto / 电离室自动计算
         ↓
result = sample / (T/100) - background
         ↓
Save raw, background, subtracted / 保存原始、背景、扣除结果

Quick Usage / 快速使用

Run Scripts Directly / 直接运行脚本

Scripts are self-contained — they import from the bundled lib/ package instead of requiring the BGsub package to be installed. Run from the project root directory. Only standard scientific dependencies are needed: numpy, scipy, fabio, h5py, pandas. 脚本为自包含可执行文件——从内含的 lib/ 包导入,无需安装 BGsub 包。在项目根目录下运行。仅需标准科学计算依赖:numpyscipyfabioh5pypandas

# 2D: Single file background subtraction / 单文件背景扣除
python BGsub_skills/scripts/bg_subtract.py sample.tif background.tif --ion-dir ./ionchamber -o result.tif

# 2D: Batch processing / 批量处理
python BGsub_skills/scripts/bg_batch.py ./data background.tif --ion-dir ./ionchamber -o ./results

# 2D/1D: Ionchamber analysis / 电离室数据分析
python BGsub_skills/scripts/ionchamber.py sample.Ionchamber

# 2D/1D: Sample-vs-background transmission / 样品-背景透过率
python BGsub_skills/scripts/ionchamber.py sample.Ionchamber --background-ion background.Ionchamber

# 2D: Format conversion / 格式转换
python BGsub_skills/scripts/format_convert.py input.tif -o output.edf --format edf

# 2D: Image comparison (silx popup) / 图像对比(silx弹窗)
python BGsub_skills/scripts/compare_images.py image1.tif image2.tif

# 1D: Single curve processing / 单曲线处理
python BGsub_skills/scripts/curve_process_1d.py curve.xy --method morph --radius 50 -o result.xy

# 1D: Multi-column XYYY merged export / 多列 XYYY 合并导出
python BGsub_skills/scripts/curve_process_1d.py curve.txt --parse-mode xyyy --output-mode merged -o merged_curves.h5

# 1D: Reference background + manual T / 参考背景 + 手动T
python BGsub_skills/scripts/curve_process_1d.py curve.xy --background bg.xy --transmission 87.5 -o result.xy

# 1D: Reference background + ionchamber / 参考背景 + 电离室
python BGsub_skills/scripts/curve_process_1d.py curve.xy --background bg.xy --ion-dir ./ionchamber -o result.xy

# 1D: Batch curve processing / 批量曲线处理
python BGsub_skills/scripts/curve_batch_1d.py ./curves --method morph --radius 50 -o ./output

# 1D: Batch reference background + per-file T / 批量参考背景 + 分别设置T
python BGsub_skills/scripts/curve_batch_1d.py ./curves --background bg.xy --transmission-map transmissions.csv -o ./output

SSRF Ionchamber File Format / SSRF电离室文件格式

Plain text format (extension .Ionchamber or .txt) / 纯文本格式:

# Time  Ionchamber0  Ionchamber1  Ionchamber2
2026-01-19 12:34:34.130671238  2.807135e-7  2.388761e-8  9.71103e-10
Channel / 通道 Description / 说明
Ionchamber0 Incident beam intensity / 入射光强度
Ionchamber1 Transmitted beam (intermediate) / 透射光(中间)
Ionchamber2 Transmitted beam (primary measurement) / 透射光(主测量)

Transmission / 透射率: T = I_sample / I_background × 100%

Where I_sample and I_background are user-selectable channel statistics (mean / median / trimmed_mean). 其中 I_sampleI_background 由用户选择通道和统计方式(mean / median / trimmed_mean)。

File Matching Rules / 文件匹配规则

Ionchamber files auto-match with images by number / 电离室文件通过编号自动匹配:

PBS-sd1-1s_00046.tif  ←→  PBS-sd1-1s_046.Ionchamber
   (auto-match _00046.tif → _046.Ionchamber)

1D Curve Processing Details / 1D曲线处理详情

Supported Input Formats / 支持的输入格式

Format / 格式 Extensions / 扩展名
XY / DAT / TXT .xy, .dat, .txt (single XY / xyxy / xyyy)
CSV .csv (single XY / xyyy)
GR .gr

Background Estimation Methods / 背景估计方法

Method / 方法 Key Parameter / 关键参数 Use Case / 适用场景
morph (Morphological) / 形态学 --radius (default: 50) Broad features, smooth background / 宽衍射峰, 平滑背景
poly (Polynomial) / 多项式 --degree (default: 4), --quantile Amorphous halo fitting / 非晶晕拟合
rolling_ball / 滚球 --radius (default: 50) Complex baseline / 复杂基线

1D Output Format / 1D输出格式

Default batch output is per-file split export. Merged single-file output is also supported / 默认批处理为逐文件拆分导出,也支持合并单文件导出:

原始: sample_001.xy
→ sample_001_raw.xy   (raw data / 原始数据)
→ sample_001_bg.xy    (estimated background / 估计背景, optional / 可选)
→ sample_001_sub.xy   (subtracted result / 扣除结果, optional / 可选)

1D Transmission Sources / 1D透过率来源

  • --transmission 85 → unified manual transmission / 手动统一透过率
  • --transmission-map transmissions.csv → per-file transmission / 分别设置透过率
  • --ion-dir ./ionchamber → auto-match ionchamber files and calculate T / 自动匹配电离室并计算逐文件 T

Multi-column Constraints / 多列约束

  • --parse-mode xyxy:按 (x1,y1)(x2,y2)... 展开多条曲线
  • --parse-mode xyyy:按 x,y1,y2,... 展开多条曲线
  • 多列模式下若使用 --background,当前不支持 --ion-dir 自动电离室 T

When --background is provided, BGsub uses the traditional reference formula: 当提供 --background 时,BGsub 使用传统参考扣除公式:

result = sample / (T/100) - background

Reference Documents / 参考文档

When the user's request goes beyond the quick usage examples above, read the appropriate reference file for detailed guidance. Each file serves a specific purpose — only read what you need. 当用户的需求超出上方快速使用示例时,请阅读对应的参考文档获取详细指引。每个文件有特定用途——只读你需要的。

When to read / 何时阅读 File / 文件 Content / 内容
User is new to BGsub or needs step-by-step walkthrough / 新手入门或需要分步引导 references/quickstart.md 5-minute quick start with 4 real scenarios / 5分钟快速入门,含4个实际场景
User asks about specific CLI flags, parameters, or default values / 用户询问具体 CLI 参数或默认值 references/cli_commands.md Full CLI command reference for all 7 scripts / 全部 7 个脚本的 CLI 命令参考
User provides real data and wants end-to-end processing guidance / 用户提供真实数据需要端到端处理指引 references/examples.md 9 real-world SSRF PBS processing examples / 9 个 SSRF PBS 实际处理示例

Script Reference / 脚本参考

Directory Structure / 目录结构

BGsub_skills/
├── SKILL.md           # This file / 本文件
├── lib/               # Self-contained library (no external BGsub needed) / 自包含库(无需外部BGsub)
│   ├── __init__.py
│   ├── image_io.py    # Image I/O (TIFF/EDF/H5) / 图像读写
│   ├── common.py      # Ionchamber & transmission utilities / 电离室与透射率工具
│   ├── curve_data.py  # 1D curve data model / 1D曲线数据模型
│   ├── curve_io.py    # 1D curve I/O / 1D曲线读写
│   ├── curve_processor.py  # Background estimation algorithms / 背景估计算法
│   └── task_pipeline.py    # Batch pipeline engine / 批处理管线引擎
├── scripts/           # CLI scripts (import from lib/) / CLI脚本(从lib/导入)
└── references/        # Detailed docs / 详细文档

Scripts / 脚本

Script / 脚本 Function / 功能
scripts/bg_subtract.py Single 2D image background subtraction / 单文件2D背景扣除
scripts/bg_batch.py Batch 2D image processing / 批量2D处理
scripts/ionchamber.py Ionchamber data analysis / 电离室数据分析
scripts/curve_process_1d.py Single 1D curve processing / 单曲线1D处理
scripts/curve_batch_1d.py Batch 1D curve processing / 批量1D曲线处理
scripts/format_convert.py TIFF/EDF/H5 format conversion / 格式转换
scripts/compare_images.py silx CompareImages popup / silx图像对比弹窗

Usage / 使用方法: python BGsub_skills/scripts/\x3Cscript>.py --help

安全使用建议
This skill appears to be what it says: a local Python toolkit for background subtraction of X‑ray diffraction images and curves. Before installing or running it: - Be prepared to provide the data files you want processed (the scripts read and write local files). Do not run it on sensitive files you do not intend to process. - Ensure the required scientific Python packages (numpy, scipy, fabio, h5py, pandas) are available in your environment — otherwise the scripts will fail. - The skill can be triggered automatically by many keywords (it instructs broad activation). If you do not want the agent to auto-invoke this skill, disable autonomous invocation for this skill or avoid using the trigger keywords in prompts. - Review the bundled scripts (they are included) before running them if you have strict security or data‑handling policies. No evidence of network calls, external endpoints, credential access, or code-download/install behavior was found in the provided files.
功能分析
Type: OpenClaw Skill Name: diffraction-scatter-background-substract Version: 1.0.0 The bundle is a legitimate scientific toolkit for X-ray diffraction (SAXS/WAXS/XRD) data processing, specifically focused on background subtraction and transmission correction. It provides a comprehensive set of CLI scripts (e.g., bg_subtract.py, curve_batch_1d.py) and a supporting library (lib/) for handling 2D detector images and 1D curves. The code implements standard scientific algorithms such as morphological opening, polynomial fitting, and rolling ball estimation. Analysis of the Python scripts and the SKILL.md instructions reveals no evidence of malicious intent, data exfiltration, or unauthorized system access; all behaviors are strictly aligned with the stated purpose of processing diffraction data.
能力评估
Purpose & Capability
Name/description (BGsub for SAXS/WAXS/XRD background subtraction) match the provided scripts and libraries: 2D image I/O and processing (bg_subtract.py, bg_batch.py, image_io.py), 1D curve I/O and processing (curve_* files), ionchamber handling (ionchamber.py). No unrelated credentials, binaries, or cloud APIs are requested.
Instruction Scope
SKILL.md instructs the agent to run bundled CLI scripts on local files and to trigger on a broad set of keywords (various translations and related terms). The runtime instructions and code operate on local files, temporary directories, and save outputs — no evidence of network endpoints or exfiltration. The broad trigger list may cause the skill to be invoked in many contexts; users should be aware it will attempt local file processing when triggered.
Install Mechanism
No install spec (instruction-only) and all source files are bundled. There are no downloads, brew/npm, or archive extractions. The code relies on standard scientific Python packages (numpy, scipy, fabio, h5py, pandas) which must be present in the runtime environment; missing dependencies will cause runtime errors but are not a security risk.
Credentials
The skill declares no environment variables, no credentials, and no config paths. The code inspects filesystem paths supplied by the user and reads/writes files as expected for data processing; there are no requests for unrelated secrets.
Persistence & Privilege
always:false and no code indicates modification of other skills or system-wide settings. The skill will run locally and uses temporary cache directories (CacheDir) for transient files; it does not persist credentials or alter other skill configs. Note: model invocation is enabled by default (normal for skills) and combined with the broad trigger list may cause autonomous invocation in more cases.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install diffraction-scatter-background-substract
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /diffraction-scatter-background-substract 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
BGsub 1.0.0 — Initial release providing a comprehensive toolkit for X-ray diffraction (SAXS/WAXS/XRD) background subtraction in both 2D images and 1D curves. - Self-contained CLI scripts for background subtraction and file format conversion; no external BGsub package installation required. - Supports 2D detector image processing (TIFF/EDF/H5) and 1D curve processing (XY/DAT/CSV), including SSRF ionchamber transmission correction. - Multiple processing methods: reference-based, algorithmic estimation (morphological/polynomial/rolling ball), and batch operations. - Handles transmission correction automatically from ionchamber files or by manual input. - Includes quick-start instructions and details for supported input formats and file matching.
元数据
Slug diffraction-scatter-background-substract
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

diffraction-scatter-background-substract 是什么?

BGsub — X-ray diffraction (SAXS/WAXS/XRD) background subtraction toolkit for 2D images and 1D curves. X射线衍射(SAXS/WAXS/XRD)数据背景扣除工具,覆盖2D图像处理和1D曲线处理。 Use this... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 85 次。

如何安装 diffraction-scatter-background-substract?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install diffraction-scatter-background-substract」即可一键安装,无需额外配置。

diffraction-scatter-background-substract 是免费的吗?

是的,diffraction-scatter-background-substract 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

diffraction-scatter-background-substract 支持哪些平台?

diffraction-scatter-background-substract 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 diffraction-scatter-background-substract?

由 TIANYI MA(@tianyima96)开发并维护,当前版本 v1.0.0。

💬 留言讨论