跳转到主要内容

Python天线仿真模块(nec2++)面向对象接口

项目描述

Python NEC2++ 模块

本模块封装了 nec2++ 的天线仿真 C++ API。与 C 风格 API 封装相比,它更易于使用,功能更强大。适用于 Python 2.7 和 3+。

用法

以下是一个绘制辐射模式的示例。

from PyNEC import *
import numpy as np

#creation of a nec context
context=nec_context()

#get the associated geometry
geo = context.get_geometry()

#add wires to the geometry
geo.wire(0, 36, 0, 0, 0, -0.042, 0.008, 0.017, 0.001, 1.0, 1.0)
context.geometry_complete(0)

context.gn_card(-1, 0, 0, 0, 0, 0, 0, 0)

#add a "ex" card to specify an excitation
context.ex_card(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0)

#add a "fr" card to specify the frequency 
context.fr_card(0, 2, 2400.0e6, 100.0e6)

#add a "rp" card to specify radiation pattern sampling parameters and to cause program execution
context.rp_card(0, 91, 1, 0, 5, 0, 0, 0.0, 45.0, 4.0, 2.0, 1.0, 0.0)

#get the radiation_pattern
rp = context.get_radiation_pattern(0)

# Gains are in decibels
gains_db = rp.get_gain()
gains = 10.0**(gains_db / 10.0)
thetas = rp.get_theta_angles() * 3.1415 / 180.0
phis = rp.get_phi_angles() * 3.1415 / 180.0


# Plot stuff
import matplotlib.pyplot as plt

ax = plt.subplot(111, polar=True)
ax.plot(thetas, gains[:,0], color='r', linewidth=3)
ax.grid(True)

ax.set_title("Gain at an elevation of 45 degrees", va='bottom')
plt.savefig('RadiationPattern.png')
plt.show()

手动构建和安装

需求

  • Pandoc
  • Swig
  • 对于Windows:C/C++ 编译器
  • Git bash(用于运行 build.sh 脚本)
  • 最新 Python 包:pip、setuptools、numpy、wheel、numpy。运行:$ pip install --upgrade pip setuptools wheel numpy

注意:下载并解压 swigwin.zip,并将 swig.exe 的路径添加到环境变量中。

然后执行以下操作

    $ git clone --recursive https://github.com/tmolteno/python-necpp.git
    $ cd python-necpp
    $ cd PyNEC
    $ ./build.sh
	$ python setup.py bdist_wheel (For generating wheel, requires wheel package)
    $ sudo python setup.py install

注意:Windows 中不需要 'sudo'。

从 PyPI 安装

$ sudo pip install pynec

注意:Windows 中不需要 'sudo'。

测试

需求

  • python 包:matplotlib

    $ python example/test_rp.py

示例目录包含以下附加示例(这些示例受天线课程练习的启发)

  • logperiodic_opt.py 是一个示例,展示如何将 PyNECPP 与 scipy.optimize 结合使用,通过遗传算法同时 优化天线以适应多个频段(我认为在 4nec2 中这是不可能的)。结果增益和 VSWR 在感兴趣的频率范围内绘制。这需要 scipy >= 0.15.0,因为使用了 scipy.optimize.differential_evolution。
  • monopole_realistic_ground_plane.py 绘制了单极天线垂直增益模式。其尺寸通过局部搜索进行优化,搜索空间的路径通过热图进行可视化。
  • dipole.py 对偶极子进行非常简单的优化,并将不同系统阻抗下的 VSWR 在给定的频率范围内绘制到文件中。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

PyNEC-1.7.3.6.tar.gz (24.5 kB 查看散列值)

上传时间

由以下支持