Skip to main content

numfield

A structured cartesian mesh field representation for scientific computing.

Overview

numfield provides an intuitive framework for working with scalar fields defined on structured N-dimensional Cartesian meshes. It offers seamless integration with NumPy, allowing you to perform numerical operations while preserving mesh information.

Features

  • N-dimensional Cartesian meshes: Support for structured grids
  • NumPy integration: Full compatibility with NumPy ufuncs and array operations
  • Intensive/extensive quantities: Proper handling of different field types
  • HDF5 I/O: Save and load fields and mesh data to/from HDF5 files
  • Visualization: Built-in plotting methods for 1D, 2D, and 3D fields with interactive slicing
  • Field operations: Projection, rotation, transposition, and merging of fields
  • Multi-field containers: Manage multiple fields on a common mesh

Installation

pip install numfield[all]

This installs the package with all optional dependencies including matplotlib for visualization features.

Basic installation

pip install numfield

This installs the core package without plotting dependencies. Visualization methods will be unavailable.

From source

git clone https://github.com/louis-drouard/numfield.git
cd numfield
pip install ".[all]"

Development installation

pip install ".[dev]"

Quick Start

import numpy as np
from numfield import CartesianMesh, CartesianField, Fields

# Create a 2D mesh
mesh = CartesianMesh([1., 1.], [2., 2.], [5., 1., 4.])  # deltas (here x, y and z)

# Create a field on the mesh
values = np.random.rand(*mesh.shape)
field = CartesianField("temperature", mesh, values, intensive=True)

# Perform operations (preserves mesh information)
mean_temp = field.mean()
normalized = field.normalize()

# Plot the field
field.plot()

# Save to HDF5
field.to_hdf("output.h5")

# Load from HDF5
loaded_field = CartesianField.from_hdf("output.h5")

Usage Examples

Working with multiple fields

from numfield import Fields

# Create a container for multiple fields
fields = Fields(mesh)
fields.add_values("temperature", np.random.rand(*mesh.shape))
fields.add_values("pressure", np.random.rand(*mesh.shape))

# Access individual fields
temp_field = fields["temperature"]

Field projection and merging

# Project a field onto a different mesh
target_mesh = CartesianMesh.from_linspace([0, 0], [2, 2], [20, 20])
projected_field = temp_field.project_on(target_mesh)

# Merge multiple fields from different regions
from numfield import merge_fields
combined_field = merge_fields("combined", field1, field2, field3)

Interactive visualization

# For 3D fields, use interactive slicing
field_3d.plot(axis=2, dynamic_colorbar=True, display_edges=False)

API Reference

Core Classes

  • CartesianMesh: N-dimensional structured Cartesian mesh
  • CartesianField: Scalar field defined on a Cartesian mesh
  • Fields: Container for multiple fields sharing a mesh

Key Operations

  • Arithmetic: All NumPy operations (+, -, *, /, etc.)
  • Statistical: mean(), sum(), std(), min(), max(), describe()
  • Transformation: project_on(), rot90(), transpose(), normalize()
  • I/O: to_hdf(), from_hdf(), to_hdf_group(), from_hdf_group()

Requirements

Core dependencies

  • Python >= 3.10
  • NumPy >= 1.26.4
  • h5py

Optional dependencies

  • matplotlib (for visualization features, included in [all] extra)

Development

Running tests

pytest --mpl

The --mpl flag enables matplotlib baseline image comparison for visual regression testing.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

This package was developed at the French Alternative Energies and Atomic Energy Commission (CEA).

Building for PyPi

python -m build twine upload dist/*

Metadata

Release files for numfield 0.1.4

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

Source distribution (sdist)

Source distribution for numfield 0.1.4
File Size Uploaded Provenance Actions
numfield-0.1.4.tar.gz 34.2 kB Without provenance Details for numfield-0.1.4.tar.gz

Built distribution (wheel)

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

Total release size: 70.5 kB

Release files / numfield-0.1.4.tar.gz

Download URL numfield-0.1.4.tar.gz
Size 34.2 kB
Tags Source
SHA-256 checksum
How to use checksums
080ee4adf248e6ca6747d452db6e3ec3ff6ad87d085be96b9a420e0be63307ef
BLAKE2b-256 checksum
How to use checksums
9abadfc079ab4295cc652bca67db9b3a7b1c09df61a1c46d735508c1102f9b6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / numfield-0.1.4-py3-none-any.whl

Download URL numfield-0.1.4-py3-none-any.whl
Size 36.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6e1b3945b38d998cdc59646d9586e808fe5a56c72b04ff706d5d91f5e602242
BLAKE2b-256 checksum
How to use checksums
d008969166b93edcdebe7d553d50786c2e3e1a67dab6375761d9533a0891c69b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for numfield 0.1.4

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.

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