Skip to main content

chnet-xrf-raw-data-converter (import: xrfraw)

Converter for raw MA-XRF files (Fi MA-XRF, INFN-CHNet) to NPZ / HDF5 / OME-TIFF / FITS: a per-pixel event datacube in (y, x, channel) order, ADC channel indices, spatial axes, acquisition mask, serialized metadata — with the energy calibration carried as an attachment (energy[i] = m·i + q), so the raw counts are never modified.

What it does

  • Reads both raw variants (XML+data, data-only); validates before allocating the cube (inspect_raw).
  • Builds the datacube (Y, X, n_channels) with a choice of dtype: uint32 (default), uint16, float32, float64 — exact depth: the output is always (Y, X, n_channels), trailing channels zero-filled.
  • Energy calibration as attachment: counts are element-identical before and after (the legacy converter silently lost this).
  • No auto-rebinning / auto energy-crop. Explicit rebin (sum/mean) and rebin-to-target-depth (rebin_to, sum-only, totals preserved) on demand.
  • Writes .h5, .npz, .ome.tif (OME-TIFF/BigTIFF) or .fits (FITS multi-extension; requires the optional [fits] extra → astropy) with the same logical schema.
  • Minimal Dash UI, embeddable in Jupyter: from xrfraw.ui import build_app (requires the [ui] extra).

Install

python -m pip install chnet-xrf-raw-data-converter             # core
python -m pip install "chnet-xrf-raw-data-converter[ui]"       # + Dash UI
python -m pip install "chnet-xrf-raw-data-converter[fits]"     # + FITS read/write (astropy)

The core works without astropy: FITS read/write then raises an explicit ImportError telling you to install the [fits] extra, and the FITS option simply does not appear in the UI.

Usage

CLI

xrf-raw-to-h5 — exit code 0 ok / 1 conversion error / 2 usage; no silent overwrite (use --overwrite):

xrf-raw-to-h5 FILE_OR_DIR -o OUT_DIR --format h5|npz|ome|fits \
    [--n-channels N] [--dtype uint32|uint16|float32|float64] [--metadata meta.json] \
    [--rebin N sum|mean] [--rebin-to 512|1024|2048|4096|8192] \
    [--compress 0-9] [--overwrite]

When m/q are known (XML header or external JSON) the calibration is applied as attachment (with_calibration); otherwise the output is uncalibrated (channel axis, no energy). --compress applies to h5/npz/ome (FITS is uncompressed in 0.1.x).

Python

from xrfraw import inspect_raw, read_raw, read_ome, read_fits, with_calibration, rebin, rebin_to
from xrfraw.io import write_dataset, convert_file

report = inspect_raw("mappa11.txt")   # validation, no allocation
ds = read_raw("mappa11.txt")          # (NY, NX, NC) + axes + mask + metadata
ds = with_calibration(ds, 0.00259259, -0.0355556, provenance="xml")  # counts untouched
ds = rebin(ds, 2)                     # optional, explicit (sum|mean)
ds = rebin_to(ds, 2048)               # optional: target depth, sum-only
write_dataset(ds, "out.h5", fmt="h5") # fmt: "h5" | "npz" | "ome" | "fits"

# one-liner: raw -> calibrated -> rebinned -> file (same pipeline as CLI/UI)
ds = convert_file("mappa11.txt", "out/mappa11.fits", fmt="fits", rebin_to=512)

Reading back the converted files

Same cube + metadata in all four formats; the total event count must match the raw in every one of them:

# NPZ — plain numpy (attrs is a 0-dim ndarray: .item(); metadata_json inside)
import json, numpy as np
z = np.load("mappa11.npz")
img = z["img"]                                   # (y, x, channels) uint32
energy = z["energy_axis"]                        # only present if calibrated
meta = json.loads(json.loads(z["attrs"].item())["metadata_json"])

# HDF5 — h5py (native attrs, single JSON level)
import h5py
with h5py.File("mappa11.h5", "r") as f:
    img = f["img"][...]
    meta = json.loads(f.attrs["metadata_json"])

# OME-TIFF / FITS — xrfraw readers, return a ready Dataset (.img, .energy, .metadata)
from xrfraw import read_ome, read_fits
ds = read_ome("mappa11.ome.tif")
ds = read_fits("mappa11.fits")      # requires the [fits] extra

Uncalibrated files have no energy_axis/ds.energy: axis 3 is the channel index; convert to energy by hand with the known m/q. OME-TIFF and FITS carry the calibration in standard containers (OME attributes / FITS WCS CTYPE3=ENERGY, keV) plus the full metadata JSON, readable by any OME/FITS reader. Runnable examples for all four formats: example-open-converted.ipynb + how_to_open_converted.md (in the repo).

UI (Dash)

from xrfraw.ui import build_app
app = build_app(src="./mappa11.txt")
app.run()                                        # browser
app.run(jupyter_mode="inline", jupyter_height=800)  # notebook

Every convert_file parameter is exposed as an input; the FITS option is enabled only when astropy is installed. Upload is limited to ~48 MB (the browser base64-encodes the file in memory) — use src= for bigger files.

Docs (in the repo)

output_schema.md — shared metadata schema (incl. FITS HDU/WCS technical note) · data_format.md — raw file grammar · scientific_notes.md — calibration, counts, precision · simple_guide.md — from-scratch guide (uv, UI, Python, CLI) · user_guide.md — operational guide.

Metadata

Release files for chnet-xrf-raw-data-converter 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chnet-xrf-raw-data-converter 0.1.4
File Size Uploaded Provenance Actions
chnet_xrf_raw_data_converter-0.1.4.tar.gz 153.1 kB With provenance Details for chnet_xrf_raw_data_converter-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for chnet-xrf-raw-data-converter 0.1.4
File Interpreter ABI Platform Actions
chnet_xrf_raw_data_converter-0.1.4-py3-none-any.whl Python 3 none any Details for chnet_xrf_raw_data_converter-0.1.4-py3-none-any.whl

Total release size: 186.8 kB

Release files / chnet_xrf_raw_data_converter-0.1.4.tar.gz

Download URL chnet_xrf_raw_data_converter-0.1.4.tar.gz
Size 153.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3246cf0a6fd1a7df47b73176e2e3625e026b0aa82f3430f96eed4dbd2e994ec5
BLAKE2b-256 checksum
How to use checksums
724e6d84cc95592f722ef20e0afd09b0b00532d8a677113376ac41cd74d31669
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / chnet_xrf_raw_data_converter-0.1.4-py3-none-any.whl

Download URL chnet_xrf_raw_data_converter-0.1.4-py3-none-any.whl
Size 33.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68d8ade96d526cd66787da1cbbea644303531c1a525c332890675360778c2406
BLAKE2b-256 checksum
How to use checksums
482228698fc9dee7504daeb01bfcfe12804cff2e72ef34e69aedbbd48c05069e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for chnet-xrf-raw-data-converter 0.1.4

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for chnet_xrf_raw_data_converter-0.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page