Skip to main content

Octree reconstruction and interpolation utilities

Project description

batcamp logo batcamp

Tests PyPI version Codacy Badge Codacy Badge DOI

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:

pip install batcamp

Quick start

The octree interpolator interface is made to resemble the scipy LinearNDInterpolator. The following code plots a two-dimensional density slice.

# 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 for a larger example.

Synthetic images

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

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.

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

batcamp-0.3.1.tar.gz (112.4 kB view details)

Uploaded Source

Built Distribution

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

batcamp-0.3.1-py3-none-any.whl (62.2 kB view details)

Uploaded Python 3

File details

Details for the file batcamp-0.3.1.tar.gz.

File metadata

  • Download URL: batcamp-0.3.1.tar.gz
  • Upload date:
  • Size: 112.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for batcamp-0.3.1.tar.gz
Algorithm Hash digest
SHA256 20b097f56483f43ea6a329d8298d12471f73b588e96c0ef62311d494a750ec5b
MD5 d46167db7ec0376a4c539ece0dacea3b
BLAKE2b-256 7459179068ef739091dad1dca14d8e86f8a7f4902ed0c18413342e11ffa7fd22

See more details on using hashes here.

File details

Details for the file batcamp-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: batcamp-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 62.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for batcamp-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47cf31ad5ee8a5ae0a2f42dff34684d1312876ffb286b34df11693cbbf775c7d
MD5 012d889367823247f8e5c767da222605
BLAKE2b-256 84d97eaa7a21a2dc1b1105de894844446eb01138a468a7228f86d1672d83aa06

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