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-1.7.4.tar.gz (225.4 kB view details)

Uploaded Source

Built Distributions

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

pynec-1.7.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pynec-1.7.4-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.12+ i686manylinux: glibc 2.17+ i686

pynec-1.7.4-cp312-cp312-macosx_11_0_arm64.whl (248.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pynec-1.7.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

pynec-1.7.4-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.12+ i686manylinux: glibc 2.17+ i686

pynec-1.7.4-cp311-cp311-macosx_11_0_arm64.whl (248.6 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pynec-1.7.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

pynec-1.7.4-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ i686manylinux: glibc 2.17+ i686

pynec-1.7.4-cp310-cp310-macosx_11_0_arm64.whl (248.6 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pynec-1.7.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

pynec-1.7.4-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (2.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ i686manylinux: glibc 2.17+ i686

pynec-1.7.4-cp39-cp39-macosx_11_0_arm64.whl (248.6 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for pynec-1.7.4.tar.gz
Algorithm Hash digest
SHA256 99be1fad3153e97ac0bc9be02fd184e91ea0f68c746a5b755501e15482121f07
MD5 f684762160cadc8157d384ee012b7a8c
BLAKE2b-256 e14bc7ddae4566ae8cef669ec6e4d5976ac509537130284640fbc1099d314b36

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.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-1.7.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f49d0f57fa59f5779e0e6e4dd30ce0a215cb8a6bc359527bfdfcc42648ff96b8
MD5 5d03e7dc01c6def7253ca2adf4231e88
BLAKE2b-256 fb47d5a1aab0a746a5c9c81c6522ef0575bc4bdbb0917311911ace0b98bdd3c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_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-1.7.4-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 f01a9d6bce0eeed3340e9cf397eac27d8af0af8044d95ae05128341cce06dc07
MD5 5a20cd856d071929244458ec89737f43
BLAKE2b-256 7d52a89c4587d93cfa8fcc2b263cb762cb49da2bdccd9913b3d9fe6eb0f5a7a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.4-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.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-1.7.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4246006b6c57fc419327d374ac85fa8ee06a3d16bb2f78a49a6039f292a01e88
MD5 b17e6d88c8eae11eefbe7d9ba01fb691
BLAKE2b-256 347f822f249b82546b95de82ec10cad15a50a90871b1d3b70199e3a2de6d6bd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.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-1.7.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6667f9fe9ab8a52d94c80ac09e49556d3ffe946fc0a71b4e254c70ad25203eaf
MD5 2340d6cf6ccc5143a014f15326946285
BLAKE2b-256 64811aae2ecb6de18ec1ac70bba15607be615ca811fbde41bdc003f2fe5b5a45

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_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-1.7.4-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 90514ded40278649a3882377c10f227c196f921aa4b7c3b207d779250ec9521a
MD5 3e90b0393d29c6901e160ac1356c5858
BLAKE2b-256 397c112464579b1b94412a157b70e4a61726e8ebf6963f27932d8264c636de7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.4-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.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-1.7.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66e99f51c551a9c330fe9aebbef2e4984508d1837d514763509796449ba1cbdd
MD5 769b7f965b559bcf1b8db026515b441f
BLAKE2b-256 d16e30fc338f5ecc41ba376aa19d3504e5639b687abca2e8a73f89fbf0ec29d3

See more details on using hashes here.

Provenance

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

File details

Details for the file pynec-1.7.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 27113904ea20c9086ab9293c561e69ff53936a3860c04101164653bad1043cc7
MD5 c467985b1a5f66429042d2e6d9fed5b0
BLAKE2b-256 f012658984de9fee1deba55cba675a76279a1cc519c38de620890a15d28fac88

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_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-1.7.4-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 48a8d7728421a6ec591eaf9f708c35f21ea26b0212c70a7d71788a3c5cca208b
MD5 e3cfa856270a9451e7afb52d6cdf147c
BLAKE2b-256 b761b2aa2a6870c8b3f82f67db2ba7ba112172e51c17454fd149beb4efa28bfa

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.4-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.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-1.7.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 808fda10bda9a5a61306a4fba8d0236e719f3cf602dfb97ad00b70fe5f799024
MD5 1612c0d1ea750ab8ffd70450b3edd975
BLAKE2b-256 4000612a6cf3dd165772994c1fdbff0932a3034fe6f2fead927cb84728a75a6c

See more details on using hashes here.

Provenance

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

File details

Details for the file pynec-1.7.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8f8b1e23d825f655aacf430a236a31a5cbbb0f01bd7892dc90ecad01f241a5a1
MD5 68cf44ad9ff1fcd40ddcc474478ce53a
BLAKE2b-256 e3c4386e7835b54a0da3e41490d306bc7e61742e2d8d6244dac1864a0b9c476b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_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-1.7.4-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for pynec-1.7.4-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 27198516e399077d45839162658158d47cd0f28f681da97f372f39ebefdf39b0
MD5 7f9689e9c110a187dcaad7d0d0ec6dae
BLAKE2b-256 99e8210d5d2b9eef5deab86a5676ac4c9acced092de4162bee3e95ac77054764

See more details on using hashes here.

Provenance

The following attestation bundles were made for pynec-1.7.4-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.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-1.7.4-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: pynec-1.7.4-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 248.6 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pynec-1.7.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a789247909c5f4044a4be7cf7171a2ad62ed090fabbe6fbe0ac121231aa2505
MD5 5a4e615614418182143d09fdd649bfea
BLAKE2b-256 b121d50d1523054034c06ff40f6c0f848b5e15e6708fecb6400419304ddd3beb

See more details on using hashes here.

Provenance

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