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.3.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.3-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.3-cp313-cp313-macosx_11_0_arm64.whl (289.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pynec-2.2.3-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.3-cp312-cp312-macosx_11_0_arm64.whl (289.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pynec-2.2.3-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.3-cp311-cp311-macosx_11_0_arm64.whl (289.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pynec-2.2.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: pynec-2.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 9fc4a19b0da13736cddc9a6ae47fb49061c2f38bb35c1b588fe74a3be8dc6a4e
MD5 42c5899f50522c7009b9e5f28b99c8c7
BLAKE2b-256 8ea6241d134da305aaf2696d8a07f74a4ea07e6fe7d5619c3d1e1991841590d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.3.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.3-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.3-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 84e16216f0fb2dea0ee0efba212026a0f20e4b343e48f90efa6d0026792afc14
MD5 2d15db940e17ba47a9270cc73a014c5f
BLAKE2b-256 30a111bc3363415e62406f48bb772efb88abf4e5c0cefcfef8c40d208f673246

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.3-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.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e0b9d5f37fd7d0180064cbd9c5b7eb4eb29df516fbe3eaafb9b38ec2bc0ce48a
MD5 66693ced4865ae7480cd4db0b7aec4e6
BLAKE2b-256 91e2eae347542082bdd239f27730cb40ba60951f702fa36d92f9b8b020dc936c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.3-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.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.3-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0d6be508d908043574b2c84d914922a894c5e34231eb1d263b6c9928fb07e00b
MD5 e6afd5247673ff8a1aec7c9bcd238483
BLAKE2b-256 6537bedd478d50a50e55a8bde5a682e605d79148e5d6273c5e18dad9ff213344

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.3-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.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 290604f0b695d7d5d76620ea4d5a9629171d260e3a6bea511c6d360bc1c26f69
MD5 b14824abd75f2e5ffffd6da325aa5152
BLAKE2b-256 28ed575a8958566515f6a13e87b121cf1c80f5b43539d71b0d73374a6be02492

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.3-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.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.3-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cf0ea2d25943c9670f128bda91e09b0d853029cca8ba3d14934748ec615e493f
MD5 1e5a5fe9fed47b2e5728ea6b94e3e354
BLAKE2b-256 5320fc447fb1ec0023628ccad0bb443b6c392adf194331ce1e3028e8a3bb9e06

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.3-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.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b781aa42fc5786bea550f58a314c6aaf68cef7f77a05bada2e7cf53e8b223c27
MD5 b7f5170e7119343d9bbe1295b0bab072
BLAKE2b-256 58e72392781329523a7d2f50c8092b5dd9dec0d5d11879f239bb756a42021d2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.3-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.3-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.2.3-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ebc935a3695cfede2a26b7239c973db3da5ae976fae1c0bc7e9410742bd31d78
MD5 d45d1add7406e47b489988bb5c1063ad
BLAKE2b-256 ab8d58bf7df66bee85c55d41a9181952e382f9a4efc9126009702ad4ca172516

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.3-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.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.2.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d608fd287be5df4cf99b79bdaafc2ea0477762ddfbbb3568fc8dc091d614f1a
MD5 fb2fe61e85cb44b16e34363a5f88e7cb
BLAKE2b-256 c853fc1871e677ad7e6be72f7e6ad1dca9b151e791d8a9d236451104e83e2b4f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.2.3-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