python天线仿真模块(nec2++)面向对象接口
PyNEC的Python项目详细描述
python nec2++模块
这个模块封装了C++ API用于NEC2++的天线仿真。它更容易使用,而且更强大 而不是C风格的API包装器。
用法
下面是一个绘制辐射图的例子。
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()
安装
git clone https://github.com/tmolteno/python-necpp.git
cd python-necpp
git submodule init
git submodule update --remote
cd PyNEC
./build.sh
sudo python setup.py install
测试
python example/test_rp.py
示例目录包含以下附加示例(灵感来自天线课程的练习):
- logperiodic_opt.py是一个关于如何将pynecpp与scipy.optimize结合使用遗传算法来同时优化多个频带的天线的示例(4nec2中不可能这样做)。所得的增益和驻波比绘制在感兴趣的频率范围内。由于使用了scipy.optimize.differential_evolution,这需要scipy>;=0.15.0。
- 单极现实地平面。py绘制单极天线的垂直增益模式。通过局部搜索优化其尺寸,并用热图可视化搜索空间的路径。
- py对偶极子做了一个非常简单的优化,并绘制了不同系统阻抗在给定频率范围内的驻波比。