Skip to main content

xpypact: FISPACT output to Polars or DuckDB datasets converter

Aggregate results of FISPACT runs to efficient datasets.

Maintained License PyPI - Python Version PyPI Documentation Status

Description

The module loads FISPACT JSON output files and converts to Polars dataframes with minor data normalization. The dataframes can be stored either to parquet files or DuckDb database. This allows efficient data aggregation and analysis. Multiple JSON files for different FISPACT runs can be combined using simple additional identification. So far, we use just two-dimensional identification by material and case. The case usually identifies certain neutron flux energy distribution.

More details in documentation.

Implemented functionality

  • export to DuckDB

  • export to parquet files

  • neutron flux presentation conversion

Installation

From PyPI

pip install xpypact
# or
uv pip install xpypact

As dependency

uv add xpypact

From source

pip install htpps://github.com/MC-kit/xpypact.git
# or
uv pip install htpps://github.com/MC-kit/xpypact.git

Examples

from xpypact import FullDataCollector, Inventory

def get_material_id(p: Path) -> int:
    ...

def get_case_id(p: Path) -> int:
    ...

jsons = [path1, path2, ...]
material_ids = {p: get_material_id(p) for p in jsons }
case_ids = {c: get_case_id(p) for p in jsons }

collector = FullDataCollector()

if sequential_load:
    for json in jsons:
        inventory = Inventory.from_json(json)
        collector.append(inventory, material_id=material_ids[json], case_id=case_ids[json])

else:  # multithreading is allowed for collector as well

    task_list = ...  # list of tuples[directory, case_id, tasks_sequence]
    threads = 16  # whatever

    def _find_path(arg) -> tuple[int, int, Path]:
        _case, path, inventory = arg
        json_path: Path = (Path(path) / inventory).with_suffix(".json")
        if not json_path.exists():
            msg = f"Cannot find file {json_path}"
            raise FindPathError(msg)
        try:
            material_id = int(inventory[_LEN_INVENTORY:])
            case_str = json_path.parent.parts[-1]
            case_id = int(case_str[_LEN_CASE:])
        except (ValueError, IndexError) as x:
            msg = f"Cannot define material_id and case_id from {json_path}"
            raise FindPathError(msg) from x
        if case_id != _case:
            msg = f"Contradicting values of case_id in case path and database: {case_id} != {_case}"
            raise FindPathError(msg)
        return material_id, case_id, json_path

    with futures.ThreadPoolExecutor(max_workers=threads) as executor:
        mcp_futures = [
            executor.submit(_find_path, arg)
            for arg in (
                (task_case[0], task_case[1], task)
                for task_case in task_list
                for task in task_case[2].split(",")
                if task.startswith("inventory-")
            )
        ]

    mips = [x.result() for x in futures.as_completed(mcp_futures)]
    mips.sort(key=lambda x: x[0:2])  # sort by material_id, case_id

    def _load_json(arg) -> None:
        collector, material_id, case_id, json_path = arg
        collector.append(from_json(json_path.read_text(encoding="utf8")), material_id, case_id)

    with futures.ThreadPoolExecutor(max_workers=threads) as executor:
        executor.map(_load_json, ((collector, *mip) for mip in mips))


collected = collector.get_result()

# save to parquet files

collected.save_to_parquets(Path.cwd() / "parquets")

# or use DuckDB database

import from xpypact.dao save
import duckdb as db

con = db.connect()
save(con, collected)

gamma_from_db = con.sql(
    """
    select
    g, rate
    from timestep_gamma
    where material_id = 1 and case_id = 54 and time_step_number = 7
    order by g
    """,
).fetchall()

Contributing

Tests Coverage pre-commit linter & style

Just follow ordinary practice:

Some specific: in development environment we use uv, just, ruff.

To setup development environment, run:

just install | reinstall

To build documentation, run:

just docs        # - for local online docs rendering, while editing
just docs-build  # - to build documentation

To release, run:

just bump [major|minor|patch]  # - in `devel` branch

Then merge devel to master (via Pull Request) and if all the checks are passed create Release. Manually.

References

Metadata

Release files for xpypact 0.13.2

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

Source distribution (sdist)

Source distribution for xpypact 0.13.2
File Size Uploaded Provenance Actions
xpypact-0.13.2.tar.gz 18.7 kB Without provenance Details for xpypact-0.13.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for xpypact 0.13.2
File Interpreter ABI Platform Actions
xpypact-0.13.2-py3-none-any.whl Python 3 none any Details for xpypact-0.13.2-py3-none-any.whl

Total release size: 40.1 kB

Release files / xpypact-0.13.2.tar.gz

Download URL xpypact-0.13.2.tar.gz
Size 18.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0175fa261af1d9a90c9c8fe6608ebf7494b6d17dde461d8345e1a5169a5f3208
BLAKE2b-256 checksum
How to use checksums
057a8cfef2680bce7f1cbeeaedf738ae6e457f591774f7a0baafac6025e21c61
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / xpypact-0.13.2-py3-none-any.whl

Download URL xpypact-0.13.2-py3-none-any.whl
Size 21.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8ad45ef2ff00a85aaa445ee6eb65b9d55f026314b565d9b1d93edf69b2a69a4e
BLAKE2b-256 checksum
How to use checksums
7a4dcd7eda48bcdd65d9f8dc3c72adbd7da28a8a1f68a64b04cec5eb7e1d1f81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for xpypact 0.13.2

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.

Release history Release notifications | RSS feed

This release

0.13.2 This release

2 release files No provenance

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