PyForeFire provides Python bindings for the ForeFire library, enabling users to access ForeFire’s functionality directly from Python. The bindings link against the precompiled ForeFire library and include support for NetCDF and other dependencies.
The PyForeFire package is designed to:
- Expose core ForeFire functionality to Python via pybind11.
- Link against a precompiled ForeFire library located in the top-level
lib/directory. - Optionally incorporate NetCDF support by detecting either a static NetCDF installation (via
SRC_MESONHandXYZ) or a dynamic installation viaNETCDF_HOME. - Provide helper functions that leverage additional packages such as NumPy and Matplotlib.
Before installation, ensure that:
- The ForeFire library is precompiled and the dynamic library (e.g.,
libforefireL.dylib,libforefireL.so, orlibforefireL.dll) is located in the top-levellib/directory. - The ForeFire source (headers) is available in the top-level
src/directory. - A compatible NetCDF installation is available. Either:
- Set
SRC_MESONHandXYZto enable auto-detection of a static NetCDF installation, or - Set
NETCDF_HOMEto the path where NetCDF (and its headers) is installed.
- Set
- Python (>=3.8) and a C++17 compiler are installed.
- The following Python packages are required:
- pybind11
- numpy
- matplotlib
You can build and install the package into your current Python interpreter in editable mode. This mode allows you to recompile the extension without needing to reinstall the package.
-
Editable Installation
In the
bindings/pythondirectory, run:pip install -e .Editable mode links the installed package to the source directory. Any recompilation (e.g., via
python setup.py build_ext --inplace) will be immediately available. -
Wheel Build
To build a wheel without installing it directly, run:
pip wheel .You can later install the generated wheel with:
pip install <wheel_file>
After installation, you can use PyForeFire in your Python code as follows:
import pyforefire as forefire
# Create an instance of the ForeFire class
ff = forefire.ForeFire()
# Example usage: define a domain command
sizeX = 300
sizeY = 200
myCmd = "FireDomain[sw=(0.,0.,0.);ne=(%f,%f,0.);t=0.]" % (sizeX, sizeY)
# Execute the command
ff.execute(myCmd)Additionally, helper modules are provided which make use of NumPy and Matplotlib for data processing and visualization.
For development or when modifying the underlying C++ code:
-
Rebuild the Python extension module in-place using:
python setup.py build_ext --inplace
-
This approach updates the extension module immediately without the need for a full reinstall.
-
NetCDF Not Found:
If you encounter an error such asfatal error: 'netcdf' file not found, ensure that either:- Your environment variables
SRC_MESONHandXYZ(for static linking) orNETCDF_HOME(for dynamic linking) are correctly set, or - Your system includes the necessary NetCDF headers and libraries in the default search paths.
- Your environment variables
-
Editable Installation Issues:
Ensure you are running the command in the correct directory (bindings/python) and that no legacy configuration files (like asetup.cfg) conflict with thepyproject.toml.
This project is licensed under the terms specified in the LICENSE file.
- Homepage: https://github.com/forefireAPI/forefire
- Documentation: https://forefire.readthedocs.io/en/latest/