Lightweight package for iterative tiling over N-dimensional arrays
Project description
ndtiler
A lightweight Python package for iterative tiling over N-dimensional arrays.
Overview
ndtiler is a simple, efficient library that generates tile coordinates for processing large N-dimensional arrays in smaller chunks. This approach is particularly useful for operations on large images, volumetric data, or any N-dimensional matrix that's too large to process at once.
While available as a package, the entire implementation is contained in a single file that can be easily copy-pasted into your project as a "header-only" style Python module.
The library offers two tiling strategies:
- Static tiling: Requires even sampling of the input matrix (default)
- Minimally Dynamic tiling: Adjusts the final tiles in each dimension to fit the matrix size exactly
Installation
pip install ndtiler
Basic Usage
import numpy as np
from ndtiler import tile_nd, dynamic_tile_nd
# Create a sample 2D array
data = np.zeros((512, 512))
# Define tile size and overlap
tile_size = (128, 128)
overlap = (32, 32)
# Generate tile coordinates using static tiling
for ((y0, y1), (x0, x1)) in tile_nd(data.shape, tile_size, overlap):
tile = data[y0:y1, x0:x1] # Extract the tile
#
# Process the tile...
#
# Generate tile coordinates using dynamic tiling
for ((y0, y1), (x0, x1)) in dynamic_tile_nd(data.shape, tile_size, overlap):
tile = data[y0:y1, x0:x1] # Extract the tile
#
# Process the tile...
#
Key Functions
Tiling Functions
tile_nd(size, tile_size, overlap): Static tiling that requires even division of the input shape.dynamic_tile_nd(size, tile_size, overlap): Dynamic tiling that adjusts the final tiles in each dimension.
Utility Functions
get_stride(tile_size, overlap): Calculate the step size between tiles.get_overlap_from_stride(tile_size, stride): Calculate overlap given tile size and stride.get_overflow(size, tile_size, overlap): Calculate the adjustment needed for even tiling.get_tile_count(size, tile_size, overlap): Calculate the number of tiles needed in each dimension.
More in-depth examples can be seen in the examples/ directory.
License
MIT License
Author
Ryan 'RyanIRL' Peters
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ndtiler-0.1.0.tar.gz.
File metadata
- Download URL: ndtiler-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e7fa95c86f151003da76b593ed67edc04012e804473b98ca4ffb9bacb13ba52
|
|
| MD5 |
5da0ab162567c9f64bd725ca04cc3c2e
|
|
| BLAKE2b-256 |
b49e6f56153e719ce6607d1d6e319f8c95f5c3fffc22dab50fea4ca6200f4b7f
|
File details
Details for the file ndtiler-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ndtiler-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d90ad28de549cc024cc15aa69b7493df09775b26add8fb2cc8da7fcb5bc11ab
|
|
| MD5 |
c2507a403d0c5fc1b5de7ad8bc9e8d6d
|
|
| BLAKE2b-256 |
d1de490669178a85b4ae26fa44912c0ead1877774fbf8f65532c3fa0678f9f42
|