Metadata-Version: 2.4
Name: batcamp
Version: 0.3.1
Summary: Octree reconstruction and interpolation utilities
Author: Dag Evensberget
License-Expression: MIT
Project-URL: Homepage, https://github.com/svaberg/batcamp
Project-URL: Repository, https://github.com/svaberg/batcamp
Project-URL: Issues, https://github.com/svaberg/batcamp/issues
Project-URL: Changelog, https://github.com/svaberg/batcamp/releases
Keywords: octree,interpolation,amr,batsrus,simulation
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: batread
Requires-Dist: numpy
Requires-Dist: numba
Provides-Extra: tests
Requires-Dist: pytest; extra == "tests"
Requires-Dist: pytest-cov; extra == "tests"
Requires-Dist: flake8; extra == "tests"
Requires-Dist: pooch; extra == "tests"
Requires-Dist: tqdm; extra == "tests"
Requires-Dist: nbclient; extra == "tests"
Requires-Dist: nbformat; extra == "tests"
Requires-Dist: ipykernel; extra == "tests"
Requires-Dist: matplotlib; extra == "tests"
Requires-Dist: scipy; extra == "tests"
Requires-Dist: build; extra == "tests"
Requires-Dist: twine; extra == "tests"
Provides-Extra: examples
Requires-Dist: scipy; extra == "examples"
Requires-Dist: matplotlib; extra == "examples"
Requires-Dist: pooch; extra == "examples"
Requires-Dist: tqdm; extra == "examples"
Requires-Dist: jupyter; extra == "examples"
Requires-Dist: nbconvert; extra == "examples"
Requires-Dist: ipykernel; extra == "examples"
Dynamic: license-file

<h1><img src="https://raw.githubusercontent.com/svaberg/batcamp/main/assets/batcamp.png" alt="batcamp logo"> batcamp</h1>

[![Tests](https://github.com/svaberg/batcamp/actions/workflows/tests.yml/badge.svg)](https://github.com/svaberg/batcamp/actions/workflows/tests.yml) [![PyPI version](https://badge.fury.io/py/batcamp.svg)](https://pypi.org/project/batcamp/) [![Codacy Badge](https://app.codacy.com/project/badge/Grade/ac23b58aa5f14f9098d47c63ef054a63)](https://app.codacy.com/gh/svaberg/batcamp/dashboard) [![Codacy Badge](https://app.codacy.com/project/badge/Coverage/ac23b58aa5f14f9098d47c63ef054a63)](https://app.codacy.com/gh/svaberg/batcamp/dashboard) [![DOI](https://zenodo.org/badge/1177665095.svg)](https://doi.org/10.5281/zenodo.19163499)

`batcamp` reconstructs traversable octrees from BATSRUS-like outputs, and supports both spherical and cartesian data.

## What it does

- Rebuilds a usable octree from simulation output, and
- provides fast, octree-aware resampling to e.g. planes, spheres, and rays.

## Why

Some numerical codes provide leaf-cell values without storing the octree data. `batcamp` rebuilds that structure, permitting rapid interpolation and resampling.

## Installation
Install the package with `pip`:

```bash
pip install batcamp
```

## Quick start
The octree interpolator interface is made to resemble the [`scipy` `LinearNDInterpolator`](https://scipy.github.io/devdocs/reference/generated/scipy.interpolate.LinearNDInterpolator.html). The following code plots a two-dimensional density slice.
```python
# Read an example dataset using the batread library
from batread import Dataset
ds = Dataset.from_file("MY_FILE")
print(ds)

# Build the octree from the dataset points and corners.
from batcamp import Octree
octree = Octree(
    points=ds[["X [R]", "Y [R]", "Z [R]"]],
    corners=ds.corners)
print(octree)

# Build the interpolator object from the octree and data values
from batcamp import OctreeInterpolator
octree_interpolator = OctreeInterpolator(octree, values=ds["Rho [g/cm^3]", "ti [K]"])
print(octree_interpolator)

# Create a regular grid of points, interpolate the data 
# onto them, and display the result with matplotlib
import numpy as np
import matplotlib.pyplot as plt
X, Y = np.meshgrid(np.linspace(-24, 24, 512), np.linspace(-24, 24, 512))
Z = np.zeros_like(X)
rho_and_ti = octree_interpolator(X, Y, Z)
plt.pcolormesh(X, Y, rho_and_ti[..., 0], norm="log")
plt.title("Equatorial slice")
plt.colorbar()
plt.show()
```

See [examples/quick_start.ipynb](https://github.com/svaberg/batcamp/blob/main/examples/quick_start.ipynb) for a larger example.

## Synthetic images
`batcamp` also provides a specialised ray tracer, which can be used e.g. to create synthetic images.

```python
ds = Dataset.from_file("MY_FILE")
tree = Octree.from_ds(ds)
interp = OctreeInterpolator(tree, ds["Rho [g/cm^3]"])

from batcamp import OctreeRayTracer
octree_ray_tracer = OctreeRayTracer(tree)
print(octree_ray_tracer)

# Create rays that will form the image
x, z = np.meshgrid(
    np.linspace(-4, 4, 512),
    np.linspace(-4, 4, 512),
    indexing="xy")
y = -24 * np.ones_like(x)
origins_xyz = np.stack((x, y, z), axis=-1)
direction = np.array([0.0, 1.0, 0.0])

# Create the image and show it
image, _ = octree_ray_tracer.trilinear_image(interp, origins_xyz, direction)
plt.pcolormesh(x, z, image, norm="log")
plt.colorbar()
plt.title("Synthetic image")
plt.show()
```

A raytracing example using a larger, more realistic data set can be seen in [examples/ray_image.ipynb](https://github.com/svaberg/batcamp/blob/main/examples/ray_image.ipynb).
