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.2.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.2-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.2-cp314-cp314-macosx_11_0_arm64.whl (294.4 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

pynec-2.3.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.3.2-cp313-cp313-macosx_11_0_arm64.whl (294.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pynec-2.3.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.3.2-cp312-cp312-macosx_11_0_arm64.whl (294.7 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pynec-2.3.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.3.2-cp311-cp311-macosx_11_0_arm64.whl (294.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pynec-2.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 fbd8a336c8223319b7ae98aa0f45d96cabfffdb67b91b6c1b5443275ffc45d1c
MD5 b06d0de056c729c204a34082d0aaada4
BLAKE2b-256 b49ad1d86847e687e9ba398d9db4af5d4e9855d0f67de676eedf65efea718080

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d48b766563f411502f19458a3b558f960a58a545be47e39526a85b5f3795a847
MD5 ea50a6fb465f6a191da0b562a43daf8b
BLAKE2b-256 e04d23cfc6602233883a74c23dfd991dbcbb2db83584e4a32a9275988dd11286

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e367a8309a520a5cb554dc930d31190f02d6c5fea014a2f7439f1a55446ce85c
MD5 b732fef0a549855291bf0f79722ebd2c
BLAKE2b-256 300b3afade8284ad7c104d4ba5f4dfc468be7529e62063b4281ae5ad4cc5cec4

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 be708555073f33ab5c9f7d2d1732a635d091c119ffc8f1744ce00d9b1ebdb3f4
MD5 2f19c098d339e411dc55a83f384165cc
BLAKE2b-256 520e53aeb3768157c19caa65a18caeaee450dcb0f8f43d22b8438bcff1329afe

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 95e723fc1556bfa001eb2bd904dfcc294229a1c1726bf784805e90984aa6de69
MD5 778407fd29b9e5a59364713743245aa6
BLAKE2b-256 d3d3b5c9615a995f6cfc70efb2a670a20bbed7866e8dfe499fc5b9faeac3351e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bdc86955f179cbe742cf8887694aacec5df58ad35b153c2d49132708125eb9dd
MD5 ea8629e333d0bc928b716598ef781728
BLAKE2b-256 049997d435cad60fd7a63e0bfaa4fa8833d73146ca9b51cb0f43bd2e64e15bdf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d47e9c3c3e8633349df8bc7185ae692b0228b49402f910b4e3206a93c1f23d9d
MD5 aa38967a5418e7f040f35791fa3c8c48
BLAKE2b-256 b93d3d718665abf18f99ec166520ba945f8886a5aa97b6d3de938f3172ef95ef

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aff8c2ddef78d2c6133ab006a80996c00754a74fbc3c5008ddd8de9a30007de2
MD5 7aab45ce69b6a89453eb8e3efb0d2470
BLAKE2b-256 c8b7b338a3cff515d87c5008e85683a50bd22f17ed5384ee44be6ac17c3b2853

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pynec-2.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7a2d83f5f0459e09cf8eab0e33af62db63d42c0732aa307077eeb421e3cc394f
MD5 e9c343c65aabf90ab0b8dd4873ea9c08
BLAKE2b-256 806c1fec8a32293424aad4d9871ef494c6880af1fd268d0eb74403da5d2fcc0d

See more details on using hashes here.

Provenance

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

Release history Release notifications | RSS feed

2.3.4

9 files

This release

2.3.2 This release

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