Skip to main content

A structured cartesian mesh field representation for scientific computing

Project description

numfield

A structured cartesian mesh field representation for scientific computing.

Overview

numfield provides a powerful and 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 1D, 2D, and 3D 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

From PyPI (recommended)

pip install numfield

From source

git clone https://github.com/louis-drouard/numfield.git
cd numfield
pip install -e .

Development installation

pip install -e ".[dev]"

Quick Start

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

# Create a 2D mesh
mesh = CartesianMesh([0, 0], [2, 2], [10, 10])  # origins, ends, nb_cells

# 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 field 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([0, 0], [2, 2], [20, 20])
projected_field = temp_field.project_on(target_mesh)

# Merge multiple fields from different regions
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

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

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).

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

numfield-0.1.0.tar.gz (27.3 kB view details)

Uploaded Source

Built Distribution

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

numfield-0.1.0-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file numfield-0.1.0.tar.gz.

File metadata

  • Download URL: numfield-0.1.0.tar.gz
  • Upload date:
  • Size: 27.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for numfield-0.1.0.tar.gz
Algorithm Hash digest
SHA256 03e14cf5feefb122f6ed00e984029ab613db9cb5d9e6296c2615bc86ff10b086
MD5 cb3842b070cdd6f7c999dbf4d61a6d69
BLAKE2b-256 9029c9b417d006121437ced3ec9bd94385946a74d4cb014f0c4b7f98382e5e68

See more details on using hashes here.

File details

Details for the file numfield-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: numfield-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for numfield-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a9c05c93794e1bebe0820cb3565e72c3db2f03ae87492312bea2c8597477d98b
MD5 b66f1bbdf0e4cdd53e0f747a235eb9bf
BLAKE2b-256 26fc22633f9b0abef9a98bd02b4faaabdb6484d171670b474db39097fe48c111

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