Python Antenna Simulation Module (nec2++) object-oriented interface
Project description
Python NEC2++ Module
This module wraps the C++ API for antenna simulation of nec2++. It is easier to work with, and more powerful than the C-style API wrapper. Works with Python 2.7 and 3+.
Usage
Here is an example that plots a radiation pattern.
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()
Manual Build & install
Requirements
- Pandoc
- Swig
- For Windows: C/C++ compilers.
- Git bash (for running build.sh script)
- Latest python packages: pip, setuptools, numpy, wheel, numpy. Run:
$ pip install --upgrade pip setuptools wheel numpy
Note: Download and extract swigwin.zip and add the path to swig.exe to environment.
Then do following:
$ 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
Note: 'sudo' is not required in windows.
Install from PyPI
$ sudo pip install pynec
Note: 'sudo' is not required in windows.
Testing
Requirements
-
python package: matplotlib
$ python example/test_rp.py
The example directory contains the following additional examples (that are inspired by excercises from a course on antennas):
- logperiodic_opt.py is an example on how to combine PyNECPP with scipy.optimize to use a genetic algorithm to optimize an antenna for multiple frequency bands at the same time (which I thin is not possible in 4nec2). The resulting gains and VSWR are plotted over the frequency range of interest. This requires scipy >= 0.15.0 due to the usage of scipy.optimize.differential_evolution.
- monopole_realistic_ground_plane.py plots the vertical gain pattern of a monopole antenna. Its dimensions are optimized with a local search, and the path through the search space is visualized with a heat map.
- dipole.py does a very simple optimization of a dipole, and plots the VSWR over a given frequency range for different system impedances to file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file PyNEC-1.7.3.6.tar.gz
.
File metadata
- Download URL: PyNEC-1.7.3.6.tar.gz
- Upload date:
- Size: 24.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.8.0 tqdm/4.43.0 CPython/3.8.3rc1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b31b9fc5ec3c2f6d21d2349935f740559a05c114065c4baa8bacd2852235165c |
|
MD5 | d112f625488fb39d59bc23908ba39b45 |
|
BLAKE2b-256 | fc1f0296312fecf533f87ec00ee6fb97d4693ec15ff3e72d4178fe5005619d14 |