Skip to main content

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. Requires Python 3.9+.

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

$ 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.

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.3.4.tar.gz (1.5 MB view details)

Uploaded Source

Built Distributions

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

pynec-2.3.4-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (5.4 MB view details)

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

pynec-2.3.4-cp314-cp314-macosx_11_0_arm64.whl (296.0 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pynec-2.3.4-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.3.4-cp313-cp313-macosx_11_0_arm64.whl (296.1 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pynec-2.3.4-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.3.4-cp312-cp312-macosx_11_0_arm64.whl (296.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pynec-2.3.4-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.3.4-cp311-cp311-macosx_11_0_arm64.whl (296.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pynec-2.3.4.tar.gz
  • Upload date:
  • Size: 1.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pynec-2.3.4.tar.gz
Algorithm Hash digest
SHA256 d448d038d2bcb4265d511b2440a5d5ce26081269a776d45139fb8bf17a475df4
MD5 496da847305c2beb156dd84b21417d26
BLAKE2b-256 7d266cd71a6769f254cdd52054620b1f9a86d1aa24ec7e48c2668ab886a5fb15

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.3.4.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.3.4-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pynec-2.3.4-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 99618cecac6488f196c5ea1af175671068563a11507701e7ee966ee5ae48b9fa
MD5 29bcd6be8ee7c86b6795c7040ac26d06
BLAKE2b-256 1eb09d67bcf24ed21043158057c7f6b5e46a3ce3568e2fa06a127919a7b55eb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-2.3.4-cp314-cp314-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.3.4-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-2.3.4-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f0979d46b3d82d167663b6623af948990e3c55c7ae24bd59ee2846e8d93efe7b
MD5 e9bb8ba9b91b976694f0f3031e246c2c
BLAKE2b-256 f538ef0226bfea17342da286276b2b8d5fa120e384d5f3c1117b5f94e8187902

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.4-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a8e732a5814484b2ef12511648fd0e6c38bdfbbd5afa81f816c2ed20cff4509e
MD5 8af456c38ea0d1059d41b9217ec45ef4
BLAKE2b-256 063386f923b75233693a1fbbbebddd377e510e7666f6a26999312f0ac8d133f1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f41e8d2846cc0807de84469d4be8105f7f401f4e741a28db3feeb9d48f493a92
MD5 5f98550f96280765aff4aaa50cfd3a1a
BLAKE2b-256 1e71898fe224c9d7f9c20e6d3d82b78bc1ad51fb2be23edcac70134a1b8ed78d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.4-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 783046fc32b1db71645f57b1dce8fdfad43fc297b07ce27ebcff017c7c1f8eca
MD5 36abd84f88b714ead78874e14527dce2
BLAKE2b-256 653c09dec51bf29a56b00ba6a3b4c092d3b5cf064fcb9cc940f23a61aef6fdaa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 de0500d6acd83d8d0cff913b4538cd040950a1bea93bda12fc81757bc55023c8
MD5 d463753f0974245a008312a780350074
BLAKE2b-256 faf21808dc9590ea210674c7c593197d8268265596a36c7457a58f40011dd12f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.4-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d2b5c803e8402a6ca901c2b87659c03218273a6bd763a3eb92167d4adc1db530
MD5 c421e0770595285b0ffcad10759f2fa3
BLAKE2b-256 c9641bb1e4948fd461a855b50dc75b5f92f074ea039ad9ed445099c7e4a77190

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a609923ea4eeaf2d89657e51963143ff5f6724111e07aa250c65de3d1640aa1
MD5 b58fb112e70dc42cda449389de7f58c3
BLAKE2b-256 cdd8aebbff33881214fa3bba73b4824e4c6834c0decd6a47e48390ed17b44ac1

See more details on using hashes here.

Provenance

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

Release history Release notifications | RSS feed

This release

2.3.4 This release

9 files

2.3.2

9 files

2.2.6

9 files

2.2.5

9 files

2.2.4

9 files

2.2.3

9 files

2.2.2

9 files

2.2.1

9 files

1.8.2

9 files

1.8.1

9 files

1.7.4

13 files

1.7.3.6

1 file

1.7.3.4

1 file

1.7.3.1

1 file

Supported by

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