Metadata-Version: 2.4
Name: FAMRT2
Version: 1.1.0
Summary: Flash-AMR-Tools-2: lightweight native-AMR analysis for FLASH
Author: Tim-Eric Rathjen
Maintainer: Tim-Eric Rathjen
License-Expression: BSD-3-Clause
Project-URL: Homepage, https://gitlab.com/rathjen/famrt2
Project-URL: Repository, https://gitlab.com/rathjen/famrt2
Project-URL: Issues, https://gitlab.com/rathjen/famrt2/-/issues
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: numpy>=1.23
Requires-Dist: h5py>=3.7
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Provides-Extra: examples
Requires-Dist: matplotlib; extra == "examples"
Requires-Dist: jupyter; extra == "examples"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Requires-Dist: build; extra == "dev"
Provides-Extra: docs
Requires-Dist: sphinx<9,>=7; extra == "docs"
Dynamic: license-file

# FAMRT2 — Flash-AMR-Tools-2

A simple, fast, lightweight NumPy/h5py toolkit for 3D Cartesian FLASH AMR data.
Read native leaf blocks, select physical cutouts, and make area-averaged slices
at any orientation and conservative on-axis projections. Uniform cubes are
optional. Version: **1.1.0**. Stability applies to the
documented non-experimental public API; experimental APIs remain experimental.

## Installation

Install the published version from PyPI :

```sh
pip install famrt2
```

For optional example and notebook dependencies:

```sh
pip install 'famrt2[examples]'
```

For the 1.1.0 API, install this checkout with `pip install .`.
Runtime dependencies are NumPy and h5py only.
Python **3.9+** is supported; 3.9 is retained for legacy/HPC environments and
is [upstream end-of-life](https://devguide.python.org/versions/).
Prefer a supported Python release for new environments.

## Minimal example

```python
from pathlib import Path
from famrt2 import FlashAMRDataset

data_file = Path("/path/to/SILCC_hdf5_plt_cnt_XXXX")
dataset = FlashAMRDataset(data_file)
dens = dataset.read_field("dens")

region = FlashAMRDataset(
    data_file,
    lower_bound=(-250.0, -250.0, -1000.0),
    upper_bound=(250.0, 250.0, 1000.0),
    length_unit="pc",
)
region_dens = region.read_field("dens")
column = region.project(region_dens, axis="z", resolution=(512, 512))
cube = region.uniform_cube(region_dens, resolution=(128, 128, 512))
```

**CGS is the default convention.** Bounds default to centimetres; `length_unit`
converts supplied bounds from `cm`, `m`, `km`, `pc` or `kpc` to centimetres.
Geometry, slice positions, camera lengths and ray distances remain centimetres.
Explicit non-CGS `unitsystem` or `pc_unitsbase` metadata are rejected; missing
metadata use the documented CGS assumption. Field arrays retain stored values
and units; there is no general unit framework or automatic field conversion.

A region of interest (ROI) retains whole intersecting leaves. Operations clip
partial cells to its exact bounds. Native arrays are `(block, z, y, x)`;
geometry uses XYZ. Cubes are `(x, y, z)`. A z image is `(x, y)`: plot `column.T`.
Use the same selection and row order when passing external arrays back.
The example cube is explicitly requested and can require substantial memory;
prefer native blocks and explicit modest resolutions.

Version 1.1.0 includes the native binding and cell-geometry APIs below.
Native geometry can be generated per field chunk:

```python
for selection, density in region.iter_field("dens", chunk_blocks=128):
    xyz = region.cell_centres(selection)  # native layout + final XYZ axis, cm
    volumes = region.cell_volumes(selection, clipped=True)  # ROI volume, cm³
```

`bind_native_array` optionally attaches scalar or trailing-component arrays to
this exact geometry and selected-row slice. `validate_native_components` checks
`native_shape + (C,)`; geometric operations still require scalar arrays.
See the [native integration guide](docs/user/guide.rst) for provenance limits,
chunk alignment, full-cell volumes and external-model examples.

## Particle tables

Version 1.1.0 includes lazy generic particle tables and SILCC `sinkList` support:

```python
if "sinkList" in dataset.particle_populations:
    sinks = dataset.particles()  # full snapshot, including inactive rows
    active = sinks.filter(sinks.read("active")["active"] > 0)
    xyz = active.positions  # (N, 3), XYZ, native units
    properties = active.read(["uv_luminosity", "effective_temperature"])
```

Use `in_roi=True` for explicit gas-ROI filtering, `iter_properties` for bounded
outputs, and `ParticleCollection.from_hdf5` for other named tables with explicit
column mappings and optional stored IDs. All columns remain accessible; returned
arrays are read-only. Cardinal projection and sphere/slice geometry are available.
FAMRT2 reads raw properties; downstream adapters own their physical interpretation.
See the [particle guide](docs/user/guide.rst) for schemas and limitations.

## Off-axis slices

`slice_off_axis()` is an experimental zero-thickness physical plane through the
native AMR hierarchy, area-averaged onto camera-plane pixels. Each native cell
contributes its value times its exact plane/pixel intersection area, divided by
the full pixel area. Uncovered area contributes zero. It uses neither a thin slab,
a LOS integral nor uniform-grid interpolation.

```python
PC_CM = 3.0856775814913673e18

density = region.read_field("dens")
image = region.slice_off_axis(
    density,
    normal=(1.0, -1.0, 0.5),
    up=(0.0, 0.0, 1.0),
    center=(0.0, 0.0, 0.0),
    width=(500.0 * PC_CM, 1500.0 * PC_CM),
    resolution=(128, 384),
)
# With matplotlib.pyplot imported as plt:
plt.imshow(image.T, origin="lower")
```

The plane passes through `center` (default ROI midpoint). Camera lengths are cm;
output retains the input field units and uses `(u, v)` order with
`u × v = normal`. The vector and angular forms share `project_off_axis()`'s
camera conventions. For a +y view the default north is -z, so comparisons with
`slice(axis="y")` reverse the second image axis. Named scalar fields are also
accepted, with bounded `chunk_size=256` reads. `max_bytes` guards estimated raster
buffers, not total process memory. Outside planes return zeros; exact shared
faces select positive-side cells, and the ROI upper face is excluded.

## Projection choices

| Operation              | Physical meaning                        | Pixel values                                                                                                  |
| ---------------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `slice()`            | Zero-thickness Cartesian plane          | Exact area average; field units                                                                               |
| `slice_off_axis()`   | Zero-thickness plane at any orientation | Exact polygon-area average; field units                                                                       |
| `project()`          | Cartesian LOS through the ROI           | Area-averaged integral; field × cm, or a weighted mean                                                       |
| `project_off_axis()` | Orthographic LOS through the ROI        | Oblique pixel-centre ray integral, or a weighted mean; cardinal views default to conservative area deposition |

- `project(array)`: fast serial one-shot projection. Named inputs load the selection.
- `project("dens", chunk_size=512)`: bounded native-field reads and direct deposition.
- `project_adaptive("dens")`: reusable native 2D contributions; call `to_array()`.
- `project_off_axis(...)`: experimental orthographic pixel-centre ray integration.

On-axis integrals include physical path lengths; weighted means include them in
both numerator and denominator. Conservative pixel-area deposition preserves
clipped volume integrals. Oblique centre rays do **not** give exact finite-pixel
area averages; check resolution convergence. No 3D cube is needed for projection.
Parallelise independent snapshots externally, for example with Slurm job arrays.

```python
oblique = region.project_off_axis(
    "dens",
    inclination=60,
    azimuth=45,
    roll=20,
    resolution=(128, 96),
    chunk_size=128,
    ray_batch_size=256,
)
# Alternatively: normal=(1, 1, 0.5), with optional up=(0, 1, 0).
```

Inclination is away from +z; azimuth runs from +x towards +y. Positive roll
follows the right-hand rule about the LOS. Vector and angular definitions are
mutually exclusive. `chunk_size` counts input blocks; `ray_batch_size` counts rays.

## Documentation and examples

The [user manual source](docs/user/index.rst) and
[local development PDF](docs/FAMRT2_documentation.pdf) document version
1.1.0, including its complete API reference. Documentation builds are local;
they do not authorise publication.
From a local checkout, build HTML with `pip install '.[docs]'` then
`sphinx-build -W -b html docs/user build/html`. PDF builds additionally need
LaTeX and latexmk: `sphinx-build -M latexpdf docs/user build/docs`.

Five notebooks use an editable `DATA_FILE` or `FAMRT2_DATA_FILE`:

1. [Native AMR, cell geometry and physical cutouts](examples/01_native_amr.ipynb)
2. [Slices and projections](examples/02_slices_and_projections.ipynb)
3. [External scalar/component arrays and provenance](examples/03_external_field_roundtrip.ipynb)
4. [Adaptive and streamed projections](examples/04_adaptive_and_streamed_projection.ipynb)
5. [Oblique slices and projections, vector and angular views](examples/05_off_axis_projection.ipynb)

Non-Cartesian geometry, periodic regions and guard-cell layouts are
unsupported. Off-axis slices, off-axis projection and `trace_ray` remain experimental.

See the [release notes](docs/user/releases.rst) for the 1.1.0 scope.

## Citation

Citation metadata are provided in [CITATION.cff](CITATION.cff).
The top-level version is the 1.1.0 version. A software
reference preserves version 1.0.0 and its DOI; that DOI does not identify 1.1.0.

FAMRT2 v1.0.0 is archived on Zenodo:

**Rathjen, T.-E. (2026). FAMRT2: Flash-AMR-Tools-2 (Version 1.0.0). Zenodo. https://doi.org/10.5281/zenodo.22997664**

A preferred paper citation may be added in the future.

## Licence and acknowledgements

FAMRT2 is developed by Tim-Eric Rathjen and distributed under the
[BSD-3-Clause licence](LICENSE).

FAMRT2 was inspired by flash-amr-tools by Keito Watanabe and earlier work by
Pierre Nürnberger. We gratefully acknowledge these projects as important
predecessors; no endorsement is implied. See [NOTICE](NOTICE).

Package: [PyPI](https://pypi.org/project/FAMRT2/).
Source and issues: [GitLab](https://gitlab.com/rathjen/famrt2).
