Skip to main content

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

  • Swig
  • For Windows: C/C++ compilers.
  • Git bash (for running build.sh script)
  • uv (recommended) or pip + setuptools + numpy + wheel

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
    $ uv build               # Modern, fast build
    $ uv pip install .       # Or: pip 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pynec-2.2.2.tar.gz (226.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pynec-2.2.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pynec-2.2.2-cp313-cp313-macosx_11_0_arm64.whl (289.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pynec-2.2.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pynec-2.2.2-cp312-cp312-macosx_11_0_arm64.whl (289.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pynec-2.2.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pynec-2.2.2-cp311-cp311-macosx_11_0_arm64.whl (289.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pynec-2.2.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pynec-2.2.2-cp310-cp310-macosx_11_0_arm64.whl (289.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file pynec-2.2.2.tar.gz.

File metadata

  • Download URL: pynec-2.2.2.tar.gz
  • Upload date:
  • Size: 226.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pynec-2.2.2.tar.gz
Algorithm Hash digest
SHA256 24c9edcd8ec21764a17bd0bba537f50fe87165c401fa0d0ee4fafc618d75da6b
MD5 560e98b15eb7ec4e34dbd97b3835e9cd
BLAKE2b-256 1fefb48960a7d478253fa96dcfb0af7d108e36c6923e2a929ec8275213ca37cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.2.tar.gz:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-2.2.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 08b98c1d746d7f5087f98b04b44272d60913921691b055fd5bcf8332ec81cef9
MD5 5690d2515939753c3f34b234794d91ff
BLAKE2b-256 e63e2eabaf5efa33c1f2b81b429eba16714f4a635e505b89a4f949f752a7289b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-2.2.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c173dfe418d3ac5296fc937c420b2ed94b2a589a89115de1625b03bf3de5477a
MD5 c77685ab6f74e0df63ce09c48ecacdf9
BLAKE2b-256 b6271c55af8c4ad53ae51a2cbb5e928c0f9f2848ece6adf04ddc408e39cdef8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-2.2.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cf4cd4d25ef9e71865b579abeeb29ee5247ba8fda3f823f35b98b9dbe35cdbc0
MD5 3e14ce1c3193c7dd5161d3db0fa899f0
BLAKE2b-256 02ef86db7578b259797dc73de1cb108f98cff272c1354bd8c0d0366ec284cbad

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-2.2.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8dc4e2bdc6ab6e2c586a83145f06c80928d7ddf275feca91d57e9ac98d916c60
MD5 45d0f008b3b97906b7d934c97853dcad
BLAKE2b-256 547bf52fe7b48ed58056cc5804a40745c6b6d4e5bb7351c28fa6ee246ed5006f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-2.2.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c64d6d41e9c2bd674db6f4148cdb4b840355adb948c874162156bc360f125b31
MD5 3bfb4aff53da3842877aa3126bd3f5ef
BLAKE2b-256 eeb5fa5ad68ed477649d1d3e81241ae7a409d27c58e1b5d67e9ddc41d313e740

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-2.2.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 30a74d0ac37caa5f14f122977bb28f7e6111afa2a5a6f188b7b0dad976b732b1
MD5 e20230c7dfe62f77888e512946226ce0
BLAKE2b-256 82257304d01156325ae967fb02251dbaaa46d8f2225f10d7bf4f41886b0de83b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-2.2.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 80aabf291ac16475f0351b4b078d1b4e9df86ad63386147eca9b30f2bb9f7a67
MD5 5d532c725dcec06f289e614d2cfc39c0
BLAKE2b-256 269a93b8117b3f132940ab3ae2ab1793f89b80f2dd76f31edab9ac36a323f4be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pynec-2.2.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e1635d3dac83baa586fc17754257b862379fe2044de18f09e1a4ad25dc9cc4d9
MD5 4a6744415d19d865685979ed7017860d
BLAKE2b-256 3eb1b8e4adab7942a6142bdaf333e6d27fbcc6f1eed93458eb14c9e174ec8e55

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build-pynec-wheels.yml on tmolteno/python-necpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page