# PythonInterpreter **Repository Path**: leoZhangs/python-interpreter ## Basic Information - **Project Name**: PythonInterpreter - **Description**: 一个基于pybind11的C++/Python解释器。可以在C++项目中集成python算法脚本。 - **Primary Language**: C++ - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-09-09 - **Last Updated**: 2026-01-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: Python, Cpp ## README # Python Interpreter Integration Application ## Project Overview This project is a C++ application integrating an embedded Python interpreter. Its main function is to execute Python scripts through pybind11, with a particular focus on visualizing cross-sections of NetCDF data. The project combines the high performance of C++ with the robust scientific computing ecosystem of Python. ## Key Features - Embedded Python interpreter integration - Cross-section visualization of NetCDF data - Support for plotting scalar and vector data - Automatically selects axes based on cross-section orientation - Supports configuration of display parameters such as data range and color levels ## Core Modules - **Python Interpreter Integration**: Embeds a Python interpreter in C++ using the pybind11 library - **Cross-section Plotting**: Implements professional oceanographic data visualization capabilities - **Parameter Configuration System**: Supports flexible plotting parameter settings ## Usage Instructions ### C++ Side Invocation of Python Plotting ```cpp // Example: Calling Python to plot a cross-section std::vector files = {"file1.nc", "file2.nc"}; std::vector vars = {"var1", "var2"}; std::pair point1 = {120.0, 30.0}; std::pair point2 = {125.0, 32.0}; py::list files_list = py::cast(files); py::list vars_list = py::cast(vars); auto my_module = py::module_::import("plot_cross_section"); my_module.attr("plot_cross_section")( py::cast(files), py::cast(vars), py::str("lon"), py::str("lat"), py::str("lay"), py::str("time"), py::make_tuple(point1.first, point1.second), py::make_tuple(point2.first, point2.second), py::int_(0), py::float_(0.0), py::float_(100.0), py::int_(10), py::float_(1.0), py::bool_(true) ); ``` ### Python Side Plotting Function ```python def plot_cross_section(file_list: list[str], var_list: list[str], lon_name: str, lat_name: str, depth_name: str, time_name: str, point1: tuple[float, float], point2: tuple[float, float], time_index: int = 0, vmin: float = None, vmax: float = None, n_levels: int = 10, sigma: float = 1.0, trim_empty_depth: bool = True) -> str: """ Plots NetCDF cross-sections (supports scalar and vector data) Automatically selects the horizontal axis (longitude or latitude) based on cross-section orientation """ # ... plotting implementation code ... return "cross_section.png" ``` ## Dependencies - C++ Side: - pybind11 - Qt5 - Python Side: - matplotlib - netCDF4 - numpy ## License This project uses the MIT License. Please refer to the LICENSE file for details.